Savarese Software Research Corporation
service_main.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2009 Savarese Software Research Corporation
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     https://www.savarese.com/software/ApacheLicense-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00022 #ifndef __SSRC_WSPR_UTILITY_SERVICE_MAIN_H
00023 #define __SSRC_WSPR_UTILITY_SERVICE_MAIN_H
00024 
00025 #include <ssrc/wispers/service/service.h>
00026 #include <ssrc/wispers/utility/ServiceMainOptions.h>
00027 #include <ssrc/wisp/utility/service_main.h>
00028 
00029 __BEGIN_NS_SSRC_WSPR_UTILITY
00030 
00031 struct ServiceMainOptionsProcessor :
00032   public NS_SSRC_WISP_UTILITY::ServiceMainOptionsProcessor
00033 {
00034   typedef NS_SSRC_WISP_UTILITY::ServiceMainOptionsProcessor super;
00035 
00036   WISP_IMPORT(NS_SSRC_WSPR_SERVICE, ServiceProtocol);
00037   WISP_IMPORT(ServiceProtocol, packing_traits);
00038   WISP_IMPORT(ServiceProtocol, MessageStop);
00039   WISP_IMPORT(ServiceProtocol, CallStop);
00040 
00041   template<typename CustomOptions>
00042   static int process_options(const CustomOptions & options) {
00043     if(options.wspr_version) {
00044       std::cout << "Wispers version: " << WISPERS_VERSION << std::endl;
00045       return 0;
00046     } else {
00047       int exit_code = super::process_options(options);
00048 
00049       if(exit_code != -1) {
00050         return exit_code;
00051       } else if(options.kill) {
00052         NS_SSRC_WISP_PROTOCOL::Caller<packing_traits> call(options.connection);
00053         call(CallStop(), options.name, MessageStop());
00054         return 0;
00055       }
00056     }
00057     return -1;
00058   }
00059 };
00060 
00061 #define WSPR_CUSTOM_SERVICE_MAIN_WITH_INIT(service_type, handler_type, options_type, has_initializer, init_code) \
00062   WISP_CUSTOM_SERVICE_MAIN_WITH_INIT(service_type, handler_type, options_type, NS_SSRC_WSPR_UTILITY::ServiceMainOptionsProcessor, has_initializer, init_code)
00063 
00064 #define WSPR_CUSTOM_SERVICE_MAIN(service_type, handler_type, options_type, has_initializer) \
00065   WISP_CUSTOM_SERVICE_MAIN(service_type, handler_type, options_type, NS_SSRC_WSPR_UTILITY::ServiceMainOptionsProcessor, has_initializer)
00066 
00067 #define WSPR_SERVICE_MAIN_WITH_INIT(service_type, init_code)                  \
00068   WSPR_CUSTOM_SERVICE_MAIN_WITH_INIT(service_type,                            \
00069                                    NS_SSRC_WSPR_SERVICE::ServiceEventHandler, \
00070                                    NS_SSRC_WSPR_UTILITY::ServiceMainOptions,  \
00071                                    false, init_code)
00072 
00073 #define WSPR_SERVICE_MAIN(service_type)                                 \
00074   WSPR_SERVICE_MAIN_WITH_INIT(service_type, WISP_EMPTY_INIT_CODE)
00075 
00076 __END_NS_SSRC_WSPR_UTILITY
00077 
00078 #endif

Savarese Software Research Corporation
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.