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
|
102 mike 1.1 int main(int argc, char** argv)
103 {
104 // Get environment variables:
105
106 String pegasusHome;
107 GetEnvironmentVariables(argv[0], pegasusHome);
108
109 // Get options (from command line and from configuration file); this
110 // removes corresponding options and their arguments fromt he command
111 // line.
112
113 OptionManager om;
114
115 try
116 {
117 GetOptions(om, argc, argv, pegasusHome);
118 // om.print();
119 }
120 catch (Exception& e)
121 {
122 cerr << argv[0] << ": " << e.getMessage() << endl;
123 mike 1.1 exit(1);
124 }
125
126 // At this point, all options should have been extracted; print an
127 // error if there are any remaining:
128
129 if (argc != 1)
130 {
131 cerr << argv[0] << ": unrecognized options: ";
132
133 for (Uint32 i = 1; i < argc; i++)
134 cerr << argv[i] << ' ';
135 cout << endl;
136 exit(1);
137 }
138
139 // Check to see if user asked for the version (-v otpion):
140
141 String versionOption;
142
143 if (om.lookupValue("version", versionOption) && versionOption == "true")
144 mike 1.1 {
145 cerr << PEGASUS_VERSION << endl;
146 exit(0);
147 }
148
149 // Check to see if user asked for help (-h otpion):
150
151 String helpOption;
152
153 if (om.lookupValue("help", helpOption) && helpOption == "true")
154 {
|