Branch data Line data Source code
1 : : /*
2 : : * Copyright 2006-2008 Savarese Software Research Corporation
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * http://www.savarese.com/software/ApacheLicense-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : /**
18 : : * @file
19 : : * This header defines the BasicServiceOptions class.
20 : : */
21 : :
22 : : #ifndef __SSRC_WISP_UTILITY_BASIC_SERVICE_OPTIONS_H
23 : : #define __SSRC_WISP_UTILITY_BASIC_SERVICE_OPTIONS_H
24 : :
25 : : #include <ssrc/wisp-packages.h>
26 : :
27 : : #include <boost/program_options.hpp>
28 : :
29 : : __BEGIN_NS_SSRC_WISP_UTILITY
30 : :
31 : : class BasicServiceOptions {
32 : : public:
33 : : // Allocate 64k for message. That's below the max Spread message limit
34 : : // and hopefully large enough to accommodate anything we throw at it.
35 : : enum { DefaultServiceMessageCapacity = 1u << 16 };
36 : :
37 : : private:
38 : : boost::program_options::options_description basic_description;
39 : :
40 : : protected:
41 : :
42 : : BasicServiceOptions() :
43 : : basic_description("Basic"), description("Options"),
44 : : help(false), connection(),
45 : : name(), capacity(DefaultServiceMessageCapacity),
46 : : call_timeout(600),
47 : : locale()
48 : : {
49 : : using namespace boost::program_options;
50 : :
51 : : basic_description.add_options()
52 : : ("help,h", "Display this help message and exit.")
53 : : ("connection,c", value<std::string>(&connection),
54 : : "Specify the name of the Spread daemon to connect to.")
55 : : ("name,n", value<std::string>(&name),
56 : : "The Spread private name to assign the service.")
57 : : ("capacity,C",
58 : : value<unsigned int>(&capacity)->default_value(DefaultServiceMessageCapacity),
59 : : "The ssrc::spread::Message capacity the service requires for message "
60 : : "sends. This value should equal the size in bytes of the largest "
61 : : "message the service will ever send.")
62 : : ("call-timeout,t",
63 : : value<unsigned int>(&call_timeout)->default_value(600),
64 : : "The number of seconds to wait before cancelling an asynchronous call "
65 : : "that has not yet returned.")
66 : : ("locale,l", value<std::string>(&locale),
67 : : "The locale to use for ctype string interpretation.");
68 : :
69 : : description.add(basic_description);
70 : : }
71 : :
72 : 0 : virtual void store(int argc, char *argv[]) {
73 : : namespace po = boost::program_options;
74 : 0 : po::variables_map vm;
75 [ # # ][ # # ]: 0 : po::store(po::parse_command_line(argc, argv, description), vm);
[ # # ][ # # ]
76 [ # # ]: 0 : notify(vm);
77 [ # # ]: 0 : po::notify(vm);
78 : 0 : }
79 : :
80 : 0 : virtual void notify(boost::program_options::variables_map & vm) {
81 : : namespace po = boost::program_options;
82 [ # # ][ # # ]: 0 : help = (vm.count("help") > 0);
[ # # ]
83 [ # # ]: 0 : if(!help) {
84 : : // In order to set help when no options are specified, we can't
85 : : // check vm.empty() because default values add to vm.size().
86 : : // Therefore, we check that no non-default values are specified.
87 : 0 : po::variables_map::iterator it = vm.begin();
88 [ # # ]: 0 : while(it != vm.end()) {
89 [ # # ][ # # ]: 0 : if(!it->second.empty() && !it->second.defaulted())
[ # # ]
90 : 0 : break;
91 : 0 : ++it;
92 : : }
93 : 0 : help = (it == vm.end());
94 : : }
95 : 0 : }
96 : :
97 : : public:
98 : : boost::program_options::options_description description;
99 : : bool help;
100 : : std::string connection;
101 : : std::string name;
102 : : unsigned int capacity;
103 : : unsigned int call_timeout;
104 : : std::string locale;
105 : :
106 [ # # ][ # # ]: 0 : virtual ~BasicServiceOptions() { }
[ # # ][ # # ]
[ # # ]
107 : : };
108 : :
109 : : __END_NS_SSRC_WISP_UTILITY
110 : :
111 : : #endif
|