(file) Return to cimserver.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Server

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2