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 karl 1.10 #include <Pegasus/Common/logger.h>
|
37 mike 1.1
|
38 mike 1.8 PEGASUS_USING_PEGASUS;
39 PEGASUS_USING_STD;
|
40 mike 1.1
|
41 karl 1.9
|
42 mike 1.1
43 void GetEnvironmentVariables(
44 const char* arg0,
45 String& pegasusHome)
46 {
47 // Get environment variables:
48
49 const char* tmp = getenv("PEGASUS_HOME");
50
51 if (!tmp)
52 {
53 cerr << arg0 << ": PEGASUS_HOME environment variable undefined" << endl;
54 exit(1);
55 }
56
57 pegasusHome = tmp;
58 FileSystem::translateSlashes(pegasusHome);
59 }
60
61 void GetOptions(
62 OptionManager& om,
63 mike 1.1 int& argc,
64 char** argv,
65 const String& pegasusHome)
66 {
67 static struct OptionRow options[] =
68 {
69 {"port", "8888", false, Option::WHOLE_NUMBER, 0, 0, "port"},
|
70 karl 1.9 {"trace", "false", false, Option::BOOLEAN, 0, 0, "t"},
|
71 karl 1.10 {"Severity", "ALL", false, Option::STRING, 0, 0, "s"},
72 {"logs", "ALL", false, Option::STRING, 0, 0, "L"},
|
73 mike 1.1 {"version", "false", false, Option::BOOLEAN, 0, 0, "v"},
|
74 karl 1.9 {"help", "false", false, Option::BOOLEAN, 0, 0, "h"},
75 {"debug", "false", false, Option::BOOLEAN, 0, 0, "d"}
|
76 mike 1.1 };
77 const Uint32 NUM_OPTIONS = sizeof(options) / sizeof(options[0]);
78
79 om.registerOptions(options, NUM_OPTIONS);
80
81 String configFile = pegasusHome + "/cimserver.conf";
82
|
83 mike 1.3 if (FileSystem::exists(configFile))
84 om.mergeFile(configFile);
|
85 mike 1.1
86 om.mergeCommandLine(argc, argv);
87
88 om.checkRequiredOptions();
89 }
90
|
91 mike 1.2 void PrintHelp(const char* arg0)
92 {
93 cout << '\n';
|
94 karl 1.6 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
|
95 mike 1.2 cout << '\n';
96 cout << "Usage: " << arg0 << " [-port <port_num> -t -h -v]\n";
97 cout << '\n';
98 cout << " -h - prints this help message\n";
99 cout << " -port - specifies port number to listen on\n";
100 cout << " -v - prints out the version number\n";
101 cout << " -t - turns on trace mode\n";
|
102 karl 1.9 cout << " -d - turns on debug mode\n";
|
103 mike 1.2 cout << endl;
104 }
105
|
106 mike 1.1 int main(int argc, char** argv)
107 {
108 // Get environment variables:
109
110 String pegasusHome;
111 GetEnvironmentVariables(argv[0], pegasusHome);
112
113 // Get options (from command line and from configuration file); this
114 // removes corresponding options and their arguments fromt he command
115 // line.
116
117 OptionManager om;
118
119 try
120 {
121 GetOptions(om, argc, argv, pegasusHome);
122 // om.print();
123 }
124 catch (Exception& e)
125 {
126 cerr << argv[0] << ": " << e.getMessage() << endl;
127 mike 1.1 exit(1);
128 }
129
130 // At this point, all options should have been extracted; print an
131 // error if there are any remaining:
132
133 if (argc != 1)
134 {
135 cerr << argv[0] << ": unrecognized options: ";
136
|
137 mike 1.4 for (int i = 1; i < argc; i++)
|
138 mike 1.1 cerr << argv[i] << ' ';
139 cout << endl;
140 exit(1);
141 }
142
143 // Check to see if user asked for the version (-v otpion):
144
145 String versionOption;
146
147 if (om.lookupValue("version", versionOption) && versionOption == "true")
148 {
149 cerr << PEGASUS_VERSION << endl;
150 exit(0);
151 }
152
153 // Check to see if user asked for help (-h otpion):
154
155 String helpOption;
156
157 if (om.lookupValue("help", helpOption) && helpOption == "true")
158 {
|
159 mike 1.2 PrintHelp(argv[0]);
|
160 mike 1.1 exit(0);
161 }
162
|
163 karl 1.9 // Check the trace options and set global variable
164 Boolean pegasusIOTrace;
165 if (om.valueEquals("trace", "true"))
166 {
167 Handler::sethandlerTrace(true);
168 pegasusIOTrace = true;
169 cout << "Trace Set" << endl;
170 }
|
171 mike 1.1 // Grab the port otpion:
172
173 String portOption;
174 om.lookupValue("port", portOption);
175
|
176 karl 1.10 Logger::setHomeDirectory("./logs");
177
|
178 mike 1.1 try
179 {
180 Selector selector;
181 CIMServer server(&selector, pegasusHome);
182
183 char* address = portOption.allocateCString();
|
184 karl 1.6
185 // Put out startup up message.
186 // Put to cout if not daemon
187 // ATTN: modify when we add daemon
188 cout << PEGASUS_NAME << PEGASUS_VERSION <<
189 " on port " << address << endl;
|
190 karl 1.7 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
|
191 karl 1.9 cout <<"Started..."
192 << (pegasusIOTrace ? " Tracing": " ") << endl;
|
193 karl 1.10
194 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
195 "Start $0 %1 port $2 $3 ", 88, PEGASUS_NAME, PEGASUS_VERSION,
196 address, (pegasusIOTrace ? " Tracing": " "));
|
197 karl 1.6
|
198 mike 1.1 server.bind(address);
199 delete [] address;
200 server.runForever();
201 }
202 catch(Exception& e)
203 {
|
204 mike 1.8 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
|
205 mike 1.1 }
206
207 return 0;
208 }
|