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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2