version 1.6, 2001/05/03 20:18:23
|
version 1.15, 2001/06/03 17:05:03
|
|
|
#include <Pegasus/Common/OptionManager.h> | #include <Pegasus/Common/OptionManager.h> |
#include <Pegasus/Server/CIMServer.h> | #include <Pegasus/Server/CIMServer.h> |
#include <Pegasus/Common/PegasusVersion.h> | #include <Pegasus/Common/PegasusVersion.h> |
|
#include <Pegasus/Protocol/Handler.h> |
|
#include <Pegasus/Common/Logger.h> |
|
#include <Pegasus/Common/System.h> |
|
|
|
PEGASUS_USING_PEGASUS; |
|
PEGASUS_USING_STD; |
| |
using namespace Pegasus; |
|
using namespace std; |
|
| |
// const char PEGASUS_VERSION[] = "Pegasus CIM Server - Version 0.7"; |
|
| |
void GetEnvironmentVariables( | void GetEnvironmentVariables( |
const char* arg0, | const char* arg0, |
|
|
FileSystem::translateSlashes(pegasusHome); | FileSystem::translateSlashes(pegasusHome); |
} | } |
| |
|
/** GetOptions function - This function defines the Options Table |
|
and sets up the options from that table using the option manager. |
|
*/ |
void GetOptions( | void GetOptions( |
OptionManager& om, | OptionManager& om, |
int& argc, | int& argc, |
char** argv, | char** argv, |
const String& pegasusHome) | const String& pegasusHome) |
{ | { |
static struct OptionRow options[] = |
static struct OptionRow optionsTable[] = |
{ | { |
{"port", "8888", false, Option::WHOLE_NUMBER, 0, 0, "port"}, |
{"port", "8888", false, Option::WHOLE_NUMBER, 0, 0, "port", |
{"trace", "false", false, Option::BOOLEAN, 0, 0, "trace"}, |
"specifies port number to listen on" }, |
{"version", "false", false, Option::BOOLEAN, 0, 0, "v"}, |
{"trace", "false", false, Option::BOOLEAN, 0, 0, "t", |
{"help", "false", false, Option::BOOLEAN, 0, 0, "h"} |
"turns on trace of Client IO to console "}, |
|
{"logtrace", "false", false, Option::BOOLEAN, 0, 0, "l", |
|
"Turns on trace of Client IO to trace log "}, |
|
{"options", "false", false, Option::BOOLEAN, 0, 0, "options", |
|
" Displays the settings of the Options "}, |
|
{"severity", "ALL", false, Option::STRING, 0, 0, "s", |
|
"Sets the severity level that will be logged "}, |
|
{"logs", "ALL", false, Option::STRING, 0, 0, "X", |
|
"Not Used "}, |
|
{"logdir", "./logs", false, Option::STRING, 0, 0, "logdir", |
|
"Directory for log files"}, |
|
{"clearlogs", "false", false, Option::BOOLEAN, 0, 0, "cl", |
|
"Clears the log files at startup"}, |
|
{"daemon", "false", false, Option::BOOLEAN, 0, 0, "d", |
|
"Not Used "}, |
|
{"version", "false", false, Option::BOOLEAN, 0, 0, "v", |
|
"Displays Pegasus Version "}, |
|
{"help", "false", false, Option::BOOLEAN, 0, 0, "h", |
|
"Prints help message with command line options "}, |
|
{"debug", "false", false, Option::BOOLEAN, 0, 0, "d", |
|
"Not Used "} |
}; | }; |
const Uint32 NUM_OPTIONS = sizeof(options) / sizeof(options[0]); |
const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]); |
| |
om.registerOptions(options, NUM_OPTIONS); |
om.registerOptions(optionsTable, NUM_OPTIONS); |
| |
String configFile = pegasusHome + "/cimserver.conf"; | String configFile = pegasusHome + "/cimserver.conf"; |
| |
|
cout << "Config file from " << configFile << endl; |
|
|
if (FileSystem::exists(configFile)) | if (FileSystem::exists(configFile)) |
om.mergeFile(configFile); | om.mergeFile(configFile); |
| |
|
|
om.checkRequiredOptions(); | om.checkRequiredOptions(); |
} | } |
| |
|
/* PrintHelp - This is temporary until we expand the options manager to allow |
|
options help to be defined with the OptionRow entries and presented from |
|
those entries. |
|
*/ |
void PrintHelp(const char* arg0) | void PrintHelp(const char* arg0) |
{ | { |
cout << '\n'; | cout << '\n'; |
cout << PEGASUS_NAME << PEGASUS_VERSION << endl; | cout << PEGASUS_NAME << PEGASUS_VERSION << endl; |
cout << '\n'; | cout << '\n'; |
cout << "Usage: " << arg0 << " [-port <port_num> -t -h -v]\n"; |
cout << "Usage: " << arg0 << endl; |
cout << '\n'; |
|
cout << " -h - prints this help message\n"; |
|
cout << " -port - specifies port number to listen on\n"; |
|
cout << " -v - prints out the version number\n"; |
|
cout << " -t - turns on trace mode\n"; |
|
cout << endl; | cout << endl; |
} | } |
| |
|
////////////////////////////////////////////////////////////////////////// |
|
// MAIN |
|
////////////////////////////////////////////////////////////////////////// |
int main(int argc, char** argv) | int main(int argc, char** argv) |
{ | { |
// Get environment variables: | // Get environment variables: |
|
|
if (om.lookupValue("help", helpOption) && helpOption == "true") | if (om.lookupValue("help", helpOption) && helpOption == "true") |
{ | { |
PrintHelp(argv[0]); | PrintHelp(argv[0]); |
|
om.printHelp(); |
exit(0); | exit(0); |
} | } |
| |
|
// Check the trace options and set global variable |
|
Boolean pegasusIOTrace = false; |
|
if (om.valueEquals("trace", "true")) |
|
{ |
|
Handler::setMessageTrace(true); |
|
pegasusIOTrace = true; |
|
} |
|
|
|
Boolean pegasusIOLog = false; |
|
if (om.valueEquals("logtrace", "true")) |
|
{ |
|
Handler::setMessageLogTrace(true); |
|
pegasusIOLog = true; |
|
} |
|
|
// Grab the port otpion: | // Grab the port otpion: |
| |
String portOption; | String portOption; |
om.lookupValue("port", portOption); | om.lookupValue("port", portOption); |
| |
try |
// Get the log file directory definition. |
{ |
// We put String into Cstring because |
Selector selector; |
// Directory functions only handle Cstring. |
CIMServer server(&selector, pegasusHome); |
// ATTN-KS: create String based directory functions. |
|
String logsDirectory; |
|
om.lookupValue("logdir", logsDirectory); |
|
|
|
char* lgDir = logsDirectory.allocateCString(); |
|
|
|
if (!System::isDirectory(lgDir)) |
|
System::makeDirectory(lgDir); |
|
|
|
if (!System::isDirectory(lgDir)) |
|
cout << "Logging Disabled"; |
|
delete [] lgDir; |
|
|
|
cout << "Logs Directory = " << logsDirectory << endl; |
|
|
| |
char* address = portOption.allocateCString(); | char* address = portOption.allocateCString(); |
| |
// Put out startup up message. | // Put out startup up message. |
// Put to cout if not daemon |
|
// ATTN: modify when we add daemon |
|
cout << PEGASUS_NAME << PEGASUS_VERSION << | cout << PEGASUS_NAME << PEGASUS_VERSION << |
" on port " << address << endl; | " on port " << address << endl; |
|
cout << "Built " << __DATE__ << " " << __TIME__ << endl; |
|
cout <<"Started..." |
|
<< (pegasusIOTrace ? " Tracing to Display ": " ") |
|
<< (pegasusIOLog ? " Tracing to Log ": " ") |
|
<< endl; |
|
|
|
// Option to Display the options table. Primarily |
|
// a diagnostic tool. |
|
if (om.valueEquals("options", "true")) |
|
om.print(); |
|
|
|
// Set up the Logger |
|
Logger::setHomeDirectory(logsDirectory); |
|
|
|
|
|
// Put server start message to the logger |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Start $0 $1 port $2 $3 ", 88, PEGASUS_NAME, |
|
PEGASUS_VERSION, address, (pegasusIOTrace ? " Tracing": " ")); |
|
|
|
// try loop to bind the address, and run the server |
|
try |
|
{ |
|
Selector selector; |
|
CIMServer server(&selector, pegasusHome); |
| |
|
// bind throws an exception of the bind fails |
server.bind(address); | server.bind(address); |
delete [] address; | delete [] address; |
server.runForever(); | server.runForever(); |
} | } |
catch(Exception& e) | catch(Exception& e) |
{ | { |
std::cerr << "Error: " << e.getMessage() << std::endl; |
PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); |
} | } |
| |
return 0; | return 0; |