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
35 using namespace Pegasus;
36 using namespace std;
37
38 const char PEGASUS_VERSION[] = "Pegasus CIM Server - Version 0.7";
39
40 void GetEnvironmentVariables(
41 const char* arg0,
42 String& pegasusHome)
43 {
44 // Get environment variables:
45
46 const char* tmp = getenv("PEGASUS_HOME");
47
48 if (!tmp)
49 {
50 cerr << arg0 << ": PEGASUS_HOME environment variable undefined" << endl;
51 mike 1.1 exit(1);
52 }
53
54 pegasusHome = tmp;
55 FileSystem::translateSlashes(pegasusHome);
56 }
57
58 void GetOptions(
59 OptionManager& om,
60 int& argc,
61 char** argv,
62 const String& pegasusHome)
63 {
64 static struct OptionRow options[] =
65 {
66 {"port", "8888", false, Option::WHOLE_NUMBER, 0, 0, "port"},
67 {"trace", "false", false, Option::BOOLEAN, 0, 0, "trace"},
68 {"version", "false", false, Option::BOOLEAN, 0, 0, "v"},
69 {"help", "false", false, Option::BOOLEAN, 0, 0, "h"}
70 };
71 const Uint32 NUM_OPTIONS = sizeof(options) / sizeof(options[0]);
72 mike 1.1
73 om.registerOptions(options, NUM_OPTIONS);
74
75 String configFile = pegasusHome + "/cimserver.conf";
76
|
77 mike 1.3 if (FileSystem::exists(configFile))
78 om.mergeFile(configFile);
|
79 mike 1.1
80 om.mergeCommandLine(argc, argv);
81
82 om.checkRequiredOptions();
83 }
84
|
85 mike 1.2 void PrintHelp(const char* arg0)
86 {
87 cout << '\n';
88 cout << PEGASUS_VERSION << endl;
89 cout << '\n';
90 cout << "Usage: " << arg0 << " [-port <port_num> -t -h -v]\n";
91 cout << '\n';
92 cout << " -h - prints this help message\n";
93 cout << " -port - specifies port number to listen on\n";
94 cout << " -v - prints out the version number\n";
95 cout << " -t - turns on trace mode\n";
96 cout << endl;
97 }
98
|
99 mike 1.1 int main(int argc, char** argv)
100 {
101 // Get environment variables:
102
103 String pegasusHome;
104 GetEnvironmentVariables(argv[0], pegasusHome);
105
106 // Get options (from command line and from configuration file); this
107 // removes corresponding options and their arguments fromt he command
108 // line.
109
110 OptionManager om;
111
112 try
113 {
114 GetOptions(om, argc, argv, pegasusHome);
115 // om.print();
116 }
117 catch (Exception& e)
118 {
119 cerr << argv[0] << ": " << e.getMessage() << endl;
120 mike 1.1 exit(1);
121 }
122
123 // At this point, all options should have been extracted; print an
124 // error if there are any remaining:
125
126 if (argc != 1)
127 {
128 cerr << argv[0] << ": unrecognized options: ";
129
|
130 mike 1.4 for (int i = 1; i < argc; i++)
|
131 mike 1.1 cerr << argv[i] << ' ';
132 cout << endl;
133 exit(1);
134 }
135
136 // Check to see if user asked for the version (-v otpion):
137
138 String versionOption;
139
140 if (om.lookupValue("version", versionOption) && versionOption == "true")
141 {
142 cerr << PEGASUS_VERSION << endl;
143 exit(0);
144 }
145
146 // Check to see if user asked for help (-h otpion):
147
148 String helpOption;
149
150 if (om.lookupValue("help", helpOption) && helpOption == "true")
151 {
|
152 mike 1.2 PrintHelp(argv[0]);
|
153 mike 1.1 exit(0);
154 }
155
156 // Grab the port otpion:
157
158 String portOption;
159 om.lookupValue("port", portOption);
160
161 try
162 {
163 Selector selector;
164 CIMServer server(&selector, pegasusHome);
165
166 char* address = portOption.allocateCString();
167 server.bind(address);
168 delete [] address;
169 server.runForever();
170 }
171 catch(Exception& e)
172 {
173 std::cerr << "Error: " << e.getMessage() << std::endl;
174 mike 1.1 }
175
176 return 0;
177 }
|