(file) Return to cimserver_windows.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / WMIMapper / WMIServer / Attic

Diff for /pegasus/src/WMIMapper/WMIServer/Attic/cimserver_windows.cpp between version 1.1 and 1.2

version 1.1, 2002/11/19 21:32:49 version 1.2, 2003/08/15 22:45:40
Line 25 
Line 25 
 // //
 // Modified By: Mary Hinton (m.hinton@verizon.net) // Modified By: Mary Hinton (m.hinton@verizon.net)
 //              Sushma Fernandes (sushma_fernandes@hp.com) //              Sushma Fernandes (sushma_fernandes@hp.com)
   //              Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
Line 33 
Line 34 
 #include <tchar.h> #include <tchar.h>
 #include <direct.h> #include <direct.h>
  
   
 PEGASUS_USING_PEGASUS; PEGASUS_USING_PEGASUS;
 PEGASUS_USING_STD; PEGASUS_USING_STD;
  
Line 59 
Line 59 
 int cimserver_kill( ) { return(0); } int cimserver_kill( ) { return(0); }
 Boolean isCIMServerRunning( ) { return(false); } Boolean isCIMServerRunning( ) { return(false); }
  
   // notify parent process to terminate so user knows that cimserver
   // is ready to serve CIM requests. If this plateform needs to implement
   // this functionality, please see sample implementation in cimserver_unix.cpp
   void notify_parent(void)
   {
   }
   
 static void __cdecl cimserver_windows_thread(void *parm) static void __cdecl cimserver_windows_thread(void *parm)
 { {
  
Line 66 
Line 73 
     // removes corresponding options and their arguments fromt he command     // removes corresponding options and their arguments fromt he command
     // line.     // line.
  
           String pegasusHome;
   
           // mdh: need to get the environment for the Windows Service to run
           const char* tmp = getenv("PEGASUS_HOME");
           if (tmp)
           {
                   pegasusHome = tmp;
           }
   
           ConfigManager::setPegasusHome(pegasusHome);
   
     ConfigManager* configManager = ConfigManager::getInstance();     ConfigManager* configManager = ConfigManager::getInstance();
     int dummy = 0;     int dummy = 0;
     String pegasusHome;      //String pegasusHome;
  
     try     try
     {     {
Line 98 
Line 116 
     {     {
         pegasusIOLog = true;         pegasusIOLog = true;
     }     }
     Boolean useSSL = false;  
  
     if (String::equal(configManager->getCurrentValue("SSL"), "true"))          // The "SSL" property overrides the enableHttp*Connection properties and
     {      // enables only the HTTPS connection.
        useSSL =  true;          Boolean enableHttpConnection = String::equal(
     }                  configManager->getCurrentValue("enableHttpConnection"), "true");
   
     // mdh: need to get the environment for the Windows Service to run          Boolean enableHttpsConnection = String::equal(
     const char* tmp = getenv("PEGASUS_HOME");                  configManager->getCurrentValue("enableHttpsConnection"), "true");
     if (tmp)  
     {          if (!enableHttpConnection && !enableHttpsConnection)
         pegasusHome = tmp;      {
           Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
               "Neither HTTP nor HTTPS connection is enabled.  "
               "CIMServer will not be started.");
           cerr << "Neither HTTP nor HTTPS connection is enabled.  "
               "CIMServer will not be started." << endl;
           exit(1);
     }     }
     ConfigManager::setPegasusHome(pegasusHome);  
  
     // Grab the port otpion:      // Get the connection port configurations
  
     String portOption;      Uint32 portNumberHttps;
       Uint32 portNumberHttp;
  
     if (useSSL)      if (enableHttpsConnection)
     {     {
         portOption = configManager->getCurrentValue("httpsPort");          String httpsPort = configManager->getCurrentValue("httpsPort");
           CString portString = httpsPort.getCString();
           char* end = 0;
           Uint32 port = strtol(portString, &end, 10);
           assert(end != 0 && *end == '\0');
   
           //
           // Look up the WBEM-HTTPS port number
           //
           portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
     }     }
     else  
       if (enableHttpConnection)
     {     {
         portOption = configManager->getCurrentValue("httpPort");          String httpPort = configManager->getCurrentValue("httpPort");
           CString portString = httpPort.getCString();
           char* end = 0;
           Uint32 port = strtol(portString, &end, 10);
           assert(end != 0 && *end == '\0');
   
           //
           // Look up the WBEM-HTTP port number
           //
           portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
     }     }
     CString address = portOption.getCString();  
  
     // Set up the Logger     // Set up the Logger
     Logger::setHomeDirectory("./logs");     Logger::setHomeDirectory("./logs");
  
     // Put server start message to the logger     // Put server start message to the logger
     Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,     Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
         "Start $0 %1 port $2 $3 ", 88, PEGASUS_NAME, PEGASUS_VERSION,          "Start $0 %1 $2 ", 88, PEGASUS_NAME, PEGASUS_VERSION,
                 (const char*)address, (pegasusIOTrace ? " Tracing": " "));                  (pegasusIOTrace ? " Tracing": " "));
       // ATTN: Should this really be: ?
       //Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
       //            "Started $0 version $1.", PEGASUS_NAME, PEGASUS_VERSION);
   
      // try loop to bind the address, and run the server      // try loop to bind the address, and run the server
     try     try
     {     {
         Monitor monitor;                  Monitor monitor(true);
  
         CIMServer server(&monitor, useSSL);                  CIMServer server(&monitor);
         server_windows = &server;         server_windows = &server;
  
         char* end = 0;                  if (enableHttpConnection)
         long portNumber = strtol(address, &end, 10);                  {
         assert(end != 0 && *end == '\0');                          server_windows->addAcceptor(false, portNumberHttp, false);
                           Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
                                                   "Listening on HTTP port $0.", portNumberHttp);
                   }
                   if (enableHttpsConnection)
                   {
                           server_windows->addAcceptor(false, portNumberHttps, true);
                           Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
                                                   "Listening on HTTPS port $0.", portNumberHttps);
                   }
  
         server_windows->bind(portNumber);                  server_windows->bind();
  
         while(!server_windows->terminated())         while(!server_windows->terminated())
         {         {
Line 165 
Line 219 
 ///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
 //  Windows NT Service Control Code //  Windows NT Service Control Code
 ///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
   
   
   
   
 VOID WINAPI  cimserver_windows_main(int argc, char **argv) VOID WINAPI  cimserver_windows_main(int argc, char **argv)
 { {
   int ccode;   int ccode;
   SERVICE_TABLE_ENTRY dispatch_table[] =   SERVICE_TABLE_ENTRY dispatch_table[] =
   {   {
     {"cimserver", cimserver_service_start},                  {"wmiserver", cimserver_service_start},
     {NULL, NULL}     {NULL, NULL}
   };   };
  
Line 186 
Line 236 
       Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION,       Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION,
                   "Started as a Windows Service");                   "Started as a Windows Service");
     }     }
   
   return;   return;
 } }
  
Line 194 
Line 245 
 // called by the NT service control manager to start the SLP service // called by the NT service control manager to start the SLP service
 // //
 ///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
   
 VOID WINAPI cimserver_service_start(DWORD argc, LPTSTR *argv) VOID WINAPI cimserver_service_start(DWORD argc, LPTSTR *argv)
 { {
  
Line 208 
Line 258 
   pegasus_status.dwServiceSpecificExitCode = 0;   pegasus_status.dwServiceSpecificExitCode = 0;
   pegasus_status.dwCheckPoint = 0;   pegasus_status.dwCheckPoint = 0;
   pegasus_status.dwWaitHint = 0;   pegasus_status.dwWaitHint = 0;
           pegasus_status_handle = RegisterServiceCtrlHandler("wmiserver", cimserver_service_ctrl_handler);
  
   pegasus_status_handle = RegisterServiceCtrlHandler("cimserver", cimserver_service_ctrl_handler);  
   if( pegasus_status_handle == (SERVICE_STATUS_HANDLE)0)   if( pegasus_status_handle == (SERVICE_STATUS_HANDLE)0)
     {     {
       Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION,       Logger::put(Logger::STANDARD_LOG, "CIMServer_Windows", Logger::INFORMATION,
Line 235 
Line 285 
   if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)))   if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)))
     {     {
       if(NULL != (service_handle = OpenService(sc_manager,       if(NULL != (service_handle = OpenService(sc_manager,
                                                "cimserver",                                                                                                   "wmiserver",
                                                SERVICE_ALL_ACCESS)))                                                SERVICE_ALL_ACCESS)))
  
         {         {
Line 260 
Line 310 
                           runPath->remove(position, len - position);                           runPath->remove(position, len - position);
                         }                         }
                     }                     }
   
                   free(svc_config);                   free(svc_config);
                 }                 }
             }             }
   
           CloseServiceHandle(service_handle);           CloseServiceHandle(service_handle);
         }         }
   
       CloseServiceHandle(sc_manager);       CloseServiceHandle(sc_manager);
     }     }
  
Line 295 
Line 348 
   return;   return;
 } }
  
   /////////////////////////////////////////////////////////////////
   //
   /////////////////////////////////////////////////////////////////
 VOID WINAPI cimserver_service_ctrl_handler(DWORD opcode) VOID WINAPI cimserver_service_ctrl_handler(DWORD opcode)
 { {
           switch(opcode)
   switch(opcode) {          {
   case SERVICE_CONTROL_STOP:   case SERVICE_CONTROL_STOP:
   case SERVICE_CONTROL_SHUTDOWN:   case SERVICE_CONTROL_SHUTDOWN:
     if(server_windows != NULL)     if(server_windows != NULL)
Line 313 
Line 369 
     default:     default:
       break;       break;
   }   }
   
   SetServiceStatus(pegasus_status_handle, &pegasus_status);   SetServiceStatus(pegasus_status_handle, &pegasus_status);
   
   return;   return;
 } }
  
   /////////////////////////////////////////////////////////////////
   //
   /////////////////////////////////////////////////////////////////
 DWORD cimserver_initialization(DWORD argc, LPTSTR *argv, DWORD *specificError) DWORD cimserver_initialization(DWORD argc, LPTSTR *argv, DWORD *specificError)
 { {
   
   return( _beginthread(cimserver_windows_thread, 0, NULL ));   return( _beginthread(cimserver_windows_thread, 0, NULL ));
 } }
  
   /////////////////////////////////////////////////////////////////
   //
   /////////////////////////////////////////////////////////////////
 Uint32 cimserver_install_nt_service(String &pegasusHome ) Uint32 cimserver_install_nt_service(String &pegasusHome )
 { {
   SC_HANDLE service_handle, sc_manager;   SC_HANDLE service_handle, sc_manager;
   Uint32 ccode = 0;   Uint32 ccode = 0;
   pegasusHome.append("\\bin\\cimserver.exe");  
           pegasusHome.append("\\bin\\wmiserver.exe");
   
   CString pegHome = pegasusHome.getCString() ;   CString pegHome = pegasusHome.getCString() ;
   LPCSTR path_name = (const char*) pegHome;   LPCSTR path_name = (const char*) pegHome;
   
   if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)))   if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)))
     {     {
       if(NULL != (service_handle = CreateService(sc_manager,       if(NULL != (service_handle = CreateService(sc_manager,
                                                  "cimserver",                                                                                                     "wmiserver",
                                                  "Pegasus CIM Object Manager",                                                                                                     "Pegasus WMI Mapper",
                                                  SERVICE_ALL_ACCESS,                                                  SERVICE_ALL_ACCESS,
                                                  SERVICE_WIN32_OWN_PROCESS,                                                  SERVICE_WIN32_OWN_PROCESS,
                                                  SERVICE_DEMAND_START,                                                  SERVICE_DEMAND_START,
                                                  SERVICE_ERROR_NORMAL,                                                  SERVICE_ERROR_NORMAL,
                                                  path_name,                                                  path_name,
                                                  NULL, NULL, NULL, NULL, NULL)))                                                                                                     NULL,
                                                                                                      NULL,
                                                                                                      NULL,
                                                                                                      NULL,
                                                                                                      NULL)))
         {         {
           ccode = (Uint32)service_handle;           ccode = (Uint32)service_handle;
         }         }
   
       CloseServiceHandle(service_handle);       CloseServiceHandle(service_handle);
     }     }
  
   return(ccode);   return(ccode);
 } }
  
   /////////////////////////////////////////////////////////////////
   //
   /////////////////////////////////////////////////////////////////
 Uint32 cimserver_remove_nt_service(void) Uint32 cimserver_remove_nt_service(void)
 { {
  
   SC_HANDLE service_handle, sc_manager;   SC_HANDLE service_handle, sc_manager;
   int ccode = 0;   int ccode = 0;
   
   if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)))   if(NULL != (sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)))
     {     {
       if(NULL != (service_handle = OpenService(sc_manager, "cimserver", DELETE)))                  if(NULL != (service_handle = OpenService(sc_manager, "wmiserver", DELETE)))
         {         {
           DeleteService(service_handle);           DeleteService(service_handle);
           CloseServiceHandle(service_handle);           CloseServiceHandle(service_handle);
           ccode = 1;           ccode = 1;
         }         }
   
       CloseServiceHandle(sc_manager);       CloseServiceHandle(sc_manager);
     }     }
   
   return(ccode);   return(ccode);
 } }


Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2