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