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 karl 1.16 // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
|
25 mike 1.5 //
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.11 #include <Pegasus/Common/Logger.h>
|
37 karl 1.15 #include <Pegasus/Common/System.h>
|
38 mike 1.1
|
39 mike 1.8 PEGASUS_USING_PEGASUS;
40 PEGASUS_USING_STD;
|
41 mike 1.1
|
42 karl 1.9
|
43 mike 1.1
44 void GetEnvironmentVariables(
45 const char* arg0,
46 String& pegasusHome)
47 {
48 // Get environment variables:
49
50 const char* tmp = getenv("PEGASUS_HOME");
51
52 if (!tmp)
53 {
54 cerr << arg0 << ": PEGASUS_HOME environment variable undefined" << endl;
55 exit(1);
56 }
57
58 pegasusHome = tmp;
59 FileSystem::translateSlashes(pegasusHome);
60 }
61
|
62 karl 1.13 /** GetOptions function - This function defines the Options Table
63 and sets up the options from that table using the option manager.
64 */
|
65 mike 1.1 void GetOptions(
66 OptionManager& om,
|
67 karl 1.13 int& argc,
68 char** argv,
|
69 mike 1.1 const String& pegasusHome)
70 {
|
71 karl 1.14 static struct OptionRow optionsTable[] =
|
72 mike 1.1 {
|
73 karl 1.14 {"port", "8888", false, Option::WHOLE_NUMBER, 0, 0, "port",
74 "specifies port number to listen on" },
75 {"trace", "false", false, Option::BOOLEAN, 0, 0, "t",
76 "turns on trace of Client IO to console "},
77 {"logtrace", "false", false, Option::BOOLEAN, 0, 0, "l",
78 "Turns on trace of Client IO to trace log "},
79 {"options", "false", false, Option::BOOLEAN, 0, 0, "options",
80 " Displays the settings of the Options "},
81 {"severity", "ALL", false, Option::STRING, 0, 0, "s",
82 "Sets the severity level that will be logged "},
83 {"logs", "ALL", false, Option::STRING, 0, 0, "X",
84 "Not Used "},
|
85 karl 1.15 {"logdir", "./logs", false, Option::STRING, 0, 0, "logdir",
86 "Directory for log files"},
|
87 karl 1.16 {"cleanlogs", "false", false, Option::BOOLEAN, 0, 0, "clean",
|
88 karl 1.15 "Clears the log files at startup"},
89 {"daemon", "false", false, Option::BOOLEAN, 0, 0, "d",
|
90 karl 1.14 "Not Used "},
91 {"version", "false", false, Option::BOOLEAN, 0, 0, "v",
92 "Displays Pegasus Version "},
93 {"help", "false", false, Option::BOOLEAN, 0, 0, "h",
94 "Prints help message with command line options "},
95 {"debug", "false", false, Option::BOOLEAN, 0, 0, "d",
96 "Not Used "}
|
97 mike 1.1 };
|
98 karl 1.14 const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]);
|
99 mike 1.1
|
100 karl 1.14 om.registerOptions(optionsTable, NUM_OPTIONS);
|
101 mike 1.1
102 String configFile = pegasusHome + "/cimserver.conf";
103
|
104 karl 1.14 cout << "Config file from " << configFile << endl;
105
|
106 mike 1.3 if (FileSystem::exists(configFile))
107 om.mergeFile(configFile);
|
108 mike 1.1
109 om.mergeCommandLine(argc, argv);
110
111 om.checkRequiredOptions();
112 }
113
|
114 karl 1.13 /* PrintHelp - This is temporary until we expand the options manager to allow
115 options help to be defined with the OptionRow entries and presented from
116 those entries.
117 */
|
118 mike 1.2 void PrintHelp(const char* arg0)
119 {
120 cout << '\n';
|
121 karl 1.6 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
|
122 mike 1.2 cout << '\n';
|
123 karl 1.14 cout << "Usage: " << arg0 << endl;
|
124 mike 1.2 cout << endl;
125 }
126
|
127 karl 1.13 //////////////////////////////////////////////////////////////////////////
128 // MAIN
129 //////////////////////////////////////////////////////////////////////////
|
130 mike 1.1 int main(int argc, char** argv)
131 {
132 // Get environment variables:
133
134 String pegasusHome;
135 GetEnvironmentVariables(argv[0], pegasusHome);
136
|
137 karl 1.13 // Get options (from command line and from configuration file); this
|
138 mike 1.1 // removes corresponding options and their arguments fromt he command
139 // line.
140
141 OptionManager om;
142
143 try
144 {
145 GetOptions(om, argc, argv, pegasusHome);
146 // om.print();
147 }
148 catch (Exception& e)
149 {
150 cerr << argv[0] << ": " << e.getMessage() << endl;
151 exit(1);
152 }
153
154 // At this point, all options should have been extracted; print an
155 // error if there are any remaining:
156
157 if (argc != 1)
158 {
159 mike 1.1 cerr << argv[0] << ": unrecognized options: ";
160
|
161 mike 1.4 for (int i = 1; i < argc; i++)
|
162 mike 1.1 cerr << argv[i] << ' ';
163 cout << endl;
164 exit(1);
165 }
166
167 // Check to see if user asked for the version (-v otpion):
168
169 String versionOption;
170
171 if (om.lookupValue("version", versionOption) && versionOption == "true")
172 {
173 cerr << PEGASUS_VERSION << endl;
174 exit(0);
175 }
176
177 // Check to see if user asked for help (-h otpion):
178 String helpOption;
179
180 if (om.lookupValue("help", helpOption) && helpOption == "true")
181 {
|
182 mike 1.2 PrintHelp(argv[0]);
|
183 karl 1.14 om.printHelp();
|
184 mike 1.1 exit(0);
185 }
186
|
187 karl 1.9 // Check the trace options and set global variable
|
188 karl 1.13 Boolean pegasusIOTrace = false;
|
189 karl 1.9 if (om.valueEquals("trace", "true"))
190 {
|
191 karl 1.16 Handler::setMessageTrace(true);
192 pegasusIOTrace = true;
|
193 karl 1.9 }
|
194 karl 1.13
|
195 karl 1.14 Boolean pegasusIOLog = false;
196 if (om.valueEquals("logtrace", "true"))
197 {
198 Handler::setMessageLogTrace(true);
|
199 karl 1.16 pegasusIOLog = true;
|
200 karl 1.14 }
201
|
202 mike 1.1 // Grab the port otpion:
203
204 String portOption;
205 om.lookupValue("port", portOption);
206
|
207 karl 1.15 // Get the log file directory definition.
208 // We put String into Cstring because
209 // Directory functions only handle Cstring.
210 // ATTN-KS: create String based directory functions.
211 String logsDirectory;
212 om.lookupValue("logdir", logsDirectory);
213
|
214 karl 1.16 // Set up the Logger. This does not open the logs
215 // Might be more logical to clean before set.
216 // ATTN: Need tool to completely disable logging.
217 Logger::setHomeDirectory(logsDirectory);
218
219 if (om.valueEquals("cleanlogs", "true"))
220 {
221 Logger::clean(logsDirectory);;
222 }
|
223 karl 1.15
|
224 karl 1.16 // Leave this in until people get familiar with the logs.
|
225 karl 1.15 cout << "Logs Directory = " << logsDirectory << endl;
226
227
|
228 karl 1.13 char* address = portOption.allocateCString();
229
230 // Put out startup up message.
231 cout << PEGASUS_NAME << PEGASUS_VERSION <<
232 " on port " << address << endl;
233 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
234 cout <<"Started..."
|
235 karl 1.14 << (pegasusIOTrace ? " Tracing to Display ": " ")
236 << (pegasusIOLog ? " Tracing to Log ": " ")
237 << endl;
238
239 // Option to Display the options table. Primarily
240 // a diagnostic tool.
241 if (om.valueEquals("options", "true"))
242 om.print();
|
243 karl 1.13
244 // Put server start message to the logger
245 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
|
246 karl 1.16 "Start $0 $1 port $2 $3 ",
247 PEGASUS_NAME,
248 PEGASUS_VERSION,
249 address,
250 (pegasusIOTrace ? " Tracing": " "));
|
251 karl 1.13
252 // try loop to bind the address, and run the server
|
253 mike 1.1 try
254 {
255 Selector selector;
256 CIMServer server(&selector, pegasusHome);
|
257 karl 1.6
|
258 karl 1.15 // bind throws an exception of the bind fails
|
259 mike 1.1 server.bind(address);
260 delete [] address;
261 server.runForever();
|
262 karl 1.16
263 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
264 "Normal Termination");
265
|
266 mike 1.1 }
267 catch(Exception& e)
268 {
|
269 karl 1.16 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
270 "Abnormal Termination $0", e.getMessage());
271
|
272 mike 1.8 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
|
273 mike 1.1 }
274
275 return 0;
276 }
|