BasicServiceOptions.h
Go to the documentation of this file.00001 /* 00002 * Copyright 2006-2008 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 * http://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_WISP_UTILITY_BASIC_SERVICE_OPTIONS_H 00023 #define __SSRC_WISP_UTILITY_BASIC_SERVICE_OPTIONS_H 00024 00025 #include <ssrc/wisp-packages.h> 00026 00027 #include <boost/program_options.hpp> 00028 00029 __BEGIN_NS_SSRC_WISP_UTILITY 00030 00031 class BasicServiceOptions { 00032 public: 00033 // Allocate 64k for message. That's below the max Spread message limit 00034 // and hopefully large enough to accommodate anything we throw at it. 00035 enum { DefaultServiceMessageCapacity = 1u << 16 }; 00036 00037 private: 00038 boost::program_options::options_description basic_description; 00039 00040 protected: 00041 00042 BasicServiceOptions() : 00043 basic_description("Basic"), description("Options"), 00044 help(false), connection(), 00045 name(), capacity(DefaultServiceMessageCapacity), 00046 call_timeout(600), 00047 locale() 00048 { 00049 using namespace boost::program_options; 00050 00051 basic_description.add_options() 00052 ("help,h", "Display this help message and exit.") 00053 ("connection,c", value<std::string>(&connection), 00054 "Specify the name of the Spread daemon to connect to.") 00055 ("name,n", value<std::string>(&name), 00056 "The Spread private name to assign the service.") 00057 ("capacity,C", 00058 value<unsigned int>(&capacity)->default_value(DefaultServiceMessageCapacity), 00059 "The ssrc::spread::Message capacity the service requires for message " 00060 "sends. This value should equal the size in bytes of the largest " 00061 "message the service will ever send.") 00062 ("call-timeout,t", 00063 value<unsigned int>(&call_timeout)->default_value(600), 00064 "The number of seconds to wait before cancelling an asynchronous call " 00065 "that has not yet returned.") 00066 ("locale,l", value<std::string>(&locale), 00067 "The locale to use for ctype string interpretation."); 00068 00069 description.add(basic_description); 00070 } 00071 00072 virtual void store(int argc, char *argv[]) { 00073 namespace po = boost::program_options; 00074 po::variables_map vm; 00075 po::store(po::parse_command_line(argc, argv, description), vm); 00076 notify(vm); 00077 po::notify(vm); 00078 } 00079 00080 virtual void notify(boost::program_options::variables_map & vm) { 00081 namespace po = boost::program_options; 00082 help = (vm.count("help") > 0); 00083 if(!help) { 00084 // In order to set help when no options are specified, we can't 00085 // check vm.empty() because default values add to vm.size(). 00086 // Therefore, we check that no non-default values are specified. 00087 po::variables_map::iterator it = vm.begin(); 00088 while(it != vm.end()) { 00089 if(!it->second.empty() && !it->second.defaulted()) 00090 break; 00091 ++it; 00092 } 00093 help = (it == vm.end()); 00094 } 00095 } 00096 00097 public: 00098 boost::program_options::options_description description; 00099 bool help; 00100 std::string connection; 00101 std::string name; 00102 unsigned int capacity; 00103 unsigned int call_timeout; 00104 std::string locale; 00105 00106 virtual ~BasicServiceOptions() { } 00107 }; 00108 00109 __END_NS_SSRC_WISP_UTILITY 00110 00111 #endif
Copyright © 2006-2010 Savarese Software Research Corporation. All rights reserved.
Copyright © 2010 Savarese Software Research Corporation. All rights reserved