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.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 {"clearlogs", "false", false, Option::BOOLEAN, 0, 0, "cl",
88 "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
179 String helpOption;
180
181 if (om.lookupValue("help", helpOption) && helpOption == "true")
182 {
|
183 mike 1.2 PrintHelp(argv[0]);
|
184 karl 1.14 om.printHelp();
|
185 mike 1.1 exit(0);
186 }
187
|
188 karl 1.9 // Check the trace options and set global variable
|
189 karl 1.13 Boolean pegasusIOTrace = false;
|
190 karl 1.9 if (om.valueEquals("trace", "true"))
191 {
|
192 karl 1.14 Handler::setMessageTrace(true);
|
193 karl 1.9 pegasusIOTrace = true;
194 }
|
195 karl 1.13
|
196 karl 1.14 Boolean pegasusIOLog = false;
197 if (om.valueEquals("logtrace", "true"))
198 {
199 Handler::setMessageLogTrace(true);
200 pegasusIOLog = true;
201 }
202
|
203 mike 1.1 // Grab the port otpion:
204
205 String portOption;
206 om.lookupValue("port", portOption);
207
|
208 karl 1.15 // Get the log file directory definition.
209 // We put String into Cstring because
210 // Directory functions only handle Cstring.
211 // ATTN-KS: create String based directory functions.
212 String logsDirectory;
213 om.lookupValue("logdir", logsDirectory);
214
215 char* lgDir = logsDirectory.allocateCString();
216
217 if (!System::isDirectory(lgDir))
218 System::makeDirectory(lgDir);
219
220 if (!System::isDirectory(lgDir))
221 cout << "Logging Disabled";
222 delete [] lgDir;
223
224 cout << "Logs Directory = " << logsDirectory << endl;
225
226
|
227 karl 1.13 char* address = portOption.allocateCString();
228
229 // Put out startup up message.
230 cout << PEGASUS_NAME << PEGASUS_VERSION <<
231 " on port " << address << endl;
232 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
233 cout <<"Started..."
|
234 karl 1.14 << (pegasusIOTrace ? " Tracing to Display ": " ")
235 << (pegasusIOLog ? " Tracing to Log ": " ")
236 << endl;
237
238 // Option to Display the options table. Primarily
239 // a diagnostic tool.
240 if (om.valueEquals("options", "true"))
241 om.print();
|
242 karl 1.13
243 // Set up the Logger
|
244 karl 1.15 Logger::setHomeDirectory(logsDirectory);
245
|
246 karl 1.10
|
247 karl 1.13 // Put server start message to the logger
248 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
|
249 karl 1.15 "Start $0 $1 port $2 $3 ", 88, PEGASUS_NAME,
250 PEGASUS_VERSION, address, (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 }
263 catch(Exception& e)
264 {
|
265 mike 1.8 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
|
266 mike 1.1 }
267
268 return 0;
269 }
|