1 mike 1.5 //%/////////////////////////////////////////////////////////////////////////////
|
2 mike 1.1 //
3 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 // DEALINGS IN THE SOFTWARE.
19 //
|
20 mike 1.5 //==============================================================================
|
21 mike 1.1 //
|
22 mike 1.5 // Author: Mike Brasher (mbrasher@bmc.com)
|
23 mike 1.1 //
|
24 mike 1.5 // Modified By:
25 //
26 //%/////////////////////////////////////////////////////////////////////////////
|
27 mike 1.1
28 #include <iostream>
|
29 mike 1.4 #include <cstdlib>
|
30 mike 1.1 #include <Pegasus/Common/FileSystem.h>
31 #include <Pegasus/Common/Selector.h>
32 #include <Pegasus/Common/OptionManager.h>
33 #include <Pegasus/Server/CIMServer.h>
|
34 karl 1.6 #include <Pegasus/Common/PegasusVersion.h>
|
35 karl 1.9 #include <Pegasus/Protocol/Handler.h>
|
36 mike 1.1
|
37 mike 1.8 PEGASUS_USING_PEGASUS;
38 PEGASUS_USING_STD;
|
39 mike 1.1
|
40 karl 1.9
|
41 mike 1.1
42 void GetEnvironmentVariables(
43 const char* arg0,
44 String& pegasusHome)
45 {
46 // Get environment variables:
47
48 const char* tmp = getenv("PEGASUS_HOME");
49
50 if (!tmp)
51 {
52 cerr << arg0 << ": PEGASUS_HOME environment variable undefined" << endl;
53 exit(1);
54 }
55
56 pegasusHome = tmp;
57 FileSystem::translateSlashes(pegasusHome);
58 }
59
60 void GetOptions(
61 OptionManager& om,
62 mike 1.1 int& argc,
63 char** argv,
64 const String& pegasusHome)
65 {
66 static struct OptionRow options[] =
67 {
68 {"port", "8888", false, Option::WHOLE_NUMBER, 0, 0, "port"},
|
69 karl 1.9 {"trace", "false", false, Option::BOOLEAN, 0, 0, "t"},
|
70 mike 1.1 {"version", "false", false, Option::BOOLEAN, 0, 0, "v"},
|
71 karl 1.9 {"help", "false", false, Option::BOOLEAN, 0, 0, "h"},
72 {"debug", "false", false, Option::BOOLEAN, 0, 0, "d"}
|
73 mike 1.1 };
74 const Uint32 NUM_OPTIONS = sizeof(options) / sizeof(options[0]);
75
76 om.registerOptions(options, NUM_OPTIONS);
77
78 String configFile = pegasusHome + "/cimserver.conf";
79
|
80 mike 1.3 if (FileSystem::exists(configFile))
81 om.mergeFile(configFile);
|
82 mike 1.1
83 om.mergeCommandLine(argc, argv);
84
85 om.checkRequiredOptions();
86 }
87
|
88 mike 1.2 void PrintHelp(const char* arg0)
89 {
90 cout << '\n';
|
91 karl 1.6 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
|
92 mike 1.2 cout << '\n';
93 cout << "Usage: " << arg0 << " [-port <port_num> -t -h -v]\n";
94 cout << '\n';
95 cout << " -h - prints this help message\n";
96 cout << " -port - specifies port number to listen on\n";
97 cout << " -v - prints out the version number\n";
98 cout << " -t - turns on trace mode\n";
|
99 karl 1.9 cout << " -d - turns on debug mode\n";
|
100 mike 1.2 cout << endl;
101 }
102
|
103 mike 1.1 int main(int argc, char** argv)
104 {
105 // Get environment variables:
106
107 String pegasusHome;
108 GetEnvironmentVariables(argv[0], pegasusHome);
109
110 // Get options (from command line and from configuration file); this
111 // removes corresponding options and their arguments fromt he command
112 // line.
113
114 OptionManager om;
115
116 try
117 {
118 GetOptions(om, argc, argv, pegasusHome);
119 // om.print();
120 }
121 catch (Exception& e)
122 {
123 cerr << argv[0] << ": " << e.getMessage() << endl;
124 mike 1.1 exit(1);
125 }
126
127 // At this point, all options should have been extracted; print an
128 // error if there are any remaining:
129
130 if (argc != 1)
131 {
132 cerr << argv[0] << ": unrecognized options: ";
133
|
134 mike 1.4 for (int i = 1; i < argc; i++)
|
135 mike 1.1 cerr << argv[i] << ' ';
136 cout << endl;
137 exit(1);
138 }
139
140 // Check to see if user asked for the version (-v otpion):
141
142 String versionOption;
143
144 if (om.lookupValue("version", versionOption) && versionOption == "true")
145 {
146 cerr << PEGASUS_VERSION << endl;
147 exit(0);
148 }
149
150 // Check to see if user asked for help (-h otpion):
151
152 String helpOption;
153
154 if (om.lookupValue("help", helpOption) && helpOption == "true")
155 {
|
156 mike 1.2 PrintHelp(argv[0]);
|
157 mike 1.1 exit(0);
158 }
159
|
160 karl 1.9 // Check the trace options and set global variable
161 Boolean pegasusIOTrace;
162 if (om.valueEquals("trace", "true"))
163 {
164 Handler::sethandlerTrace(true);
165 pegasusIOTrace = true;
166 cout << "Trace Set" << endl;
167 }
|
168 mike 1.1 // Grab the port otpion:
169
170 String portOption;
171 om.lookupValue("port", portOption);
172
173 try
174 {
175 Selector selector;
176 CIMServer server(&selector, pegasusHome);
177
178 char* address = portOption.allocateCString();
|
179 karl 1.6
180 // Put out startup up message.
181 // Put to cout if not daemon
182 // ATTN: modify when we add daemon
183 cout << PEGASUS_NAME << PEGASUS_VERSION <<
184 " on port " << address << endl;
|
185 karl 1.7 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
|
186 karl 1.9 cout <<"Started..."
187 << (pegasusIOTrace ? " Tracing": " ") << endl;
|
188 karl 1.6
|
189 mike 1.1 server.bind(address);
190 delete [] address;
191 server.runForever();
192 }
193 catch(Exception& e)
194 {
|
195 mike 1.8 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
|
196 mike 1.1 }
197
198 return 0;
199 }
|