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 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 karl 1.13 /** GetOptions function - This function defines the Options Table
62 and sets up the options from that table using the option manager.
63 */
|
64 mike 1.1 void GetOptions(
65 OptionManager& om,
|
66 karl 1.13 int& argc,
67 char** argv,
|
68 mike 1.1 const String& pegasusHome)
69 {
|
70 karl 1.14 static struct OptionRow optionsTable[] =
|
71 mike 1.1 {
|
72 karl 1.14 {"port", "8888", false, Option::WHOLE_NUMBER, 0, 0, "port",
73 "specifies port number to listen on" },
74 {"trace", "false", false, Option::BOOLEAN, 0, 0, "t",
75 "turns on trace of Client IO to console "},
76 {"logtrace", "false", false, Option::BOOLEAN, 0, 0, "l",
77 "Turns on trace of Client IO to trace log "},
78 {"options", "false", false, Option::BOOLEAN, 0, 0, "options",
79 " Displays the settings of the Options "},
80 {"severity", "ALL", false, Option::STRING, 0, 0, "s",
81 "Sets the severity level that will be logged "},
82 {"logs", "ALL", false, Option::STRING, 0, 0, "X",
83 "Not Used "},
84 {"daemon", "false", false, Option::STRING, 0, 0, "d",
85 "Not Used "},
86 {"version", "false", false, Option::BOOLEAN, 0, 0, "v",
87 "Displays Pegasus Version "},
88 {"help", "false", false, Option::BOOLEAN, 0, 0, "h",
89 "Prints help message with command line options "},
90 {"debug", "false", false, Option::BOOLEAN, 0, 0, "d",
91 "Not Used "}
|
92 mike 1.1 };
|
93 karl 1.14 const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]);
|
94 mike 1.1
|
95 karl 1.14 om.registerOptions(optionsTable, NUM_OPTIONS);
|
96 mike 1.1
97 String configFile = pegasusHome + "/cimserver.conf";
98
|
99 karl 1.14 cout << "Config file from " << configFile << endl;
100
|
101 mike 1.3 if (FileSystem::exists(configFile))
102 om.mergeFile(configFile);
|
103 mike 1.1
104 om.mergeCommandLine(argc, argv);
105
106 om.checkRequiredOptions();
107 }
108
|
109 karl 1.13 /* PrintHelp - This is temporary until we expand the options manager to allow
110 options help to be defined with the OptionRow entries and presented from
111 those entries.
112 */
|
113 mike 1.2 void PrintHelp(const char* arg0)
114 {
115 cout << '\n';
|
116 karl 1.6 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
|
117 mike 1.2 cout << '\n';
|
118 karl 1.14 cout << "Usage: " << arg0 << endl;
|
119 mike 1.2 cout << endl;
120 }
121
|
122 karl 1.13 //////////////////////////////////////////////////////////////////////////
123 // MAIN
124 //////////////////////////////////////////////////////////////////////////
|
125 mike 1.1 int main(int argc, char** argv)
126 {
127 // Get environment variables:
128
129 String pegasusHome;
130 GetEnvironmentVariables(argv[0], pegasusHome);
131
|
132 karl 1.13 // Get options (from command line and from configuration file); this
|
133 mike 1.1 // removes corresponding options and their arguments fromt he command
134 // line.
135
136 OptionManager om;
137
138 try
139 {
140 GetOptions(om, argc, argv, pegasusHome);
141 // om.print();
142 }
143 catch (Exception& e)
144 {
145 cerr << argv[0] << ": " << e.getMessage() << endl;
146 exit(1);
147 }
148
149 // At this point, all options should have been extracted; print an
150 // error if there are any remaining:
151
152 if (argc != 1)
153 {
154 mike 1.1 cerr << argv[0] << ": unrecognized options: ";
155
|
156 mike 1.4 for (int i = 1; i < argc; i++)
|
157 mike 1.1 cerr << argv[i] << ' ';
158 cout << endl;
159 exit(1);
160 }
161
162 // Check to see if user asked for the version (-v otpion):
163
164 String versionOption;
165
166 if (om.lookupValue("version", versionOption) && versionOption == "true")
167 {
168 cerr << PEGASUS_VERSION << endl;
169 exit(0);
170 }
171
172 // Check to see if user asked for help (-h otpion):
173
174 String helpOption;
175
176 if (om.lookupValue("help", helpOption) && helpOption == "true")
177 {
|
178 mike 1.2 PrintHelp(argv[0]);
|
179 karl 1.14 om.printHelp();
|
180 mike 1.1 exit(0);
181 }
182
|
183 karl 1.9 // Check the trace options and set global variable
|
184 karl 1.13 Boolean pegasusIOTrace = false;
|
185 karl 1.9 if (om.valueEquals("trace", "true"))
186 {
|
187 karl 1.14 Handler::setMessageTrace(true);
|
188 karl 1.9 pegasusIOTrace = true;
189 }
|
190 karl 1.13
|
191 karl 1.14 Boolean pegasusIOLog = false;
192 if (om.valueEquals("logtrace", "true"))
193 {
194 Handler::setMessageLogTrace(true);
195 pegasusIOLog = true;
196 }
197
|
198 mike 1.1 // Grab the port otpion:
199
200 String portOption;
201 om.lookupValue("port", portOption);
202
|
203 karl 1.13 char* address = portOption.allocateCString();
204
205 // Put out startup up message.
206 cout << PEGASUS_NAME << PEGASUS_VERSION <<
207 " on port " << address << endl;
208 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
209 cout <<"Started..."
|
210 karl 1.14 << (pegasusIOTrace ? " Tracing to Display ": " ")
211 << (pegasusIOLog ? " Tracing to Log ": " ")
212 << endl;
213
214 // Option to Display the options table. Primarily
215 // a diagnostic tool.
216 if (om.valueEquals("options", "true"))
217 om.print();
|
218 karl 1.13
219 // Set up the Logger
|
220 karl 1.10 Logger::setHomeDirectory("./logs");
221
|
222 karl 1.13 // Put server start message to the logger
223 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
224 "Start $0 %1 port $2 $3 ", 88, PEGASUS_NAME, PEGASUS_VERSION,
225 address, (pegasusIOTrace ? " Tracing": " "));
226
227 // try loop to bind the address, and run the server
|
228 mike 1.1 try
229 {
230 Selector selector;
231 CIMServer server(&selector, pegasusHome);
|
232 karl 1.6
|
233 mike 1.1 server.bind(address);
234 delete [] address;
235 server.runForever();
236 }
237 catch(Exception& e)
238 {
|
239 mike 1.8 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
|
240 mike 1.1 }
241
242 return 0;
243 }
|