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

Diff for /pegasus/src/Service/ServerProcessWindows.cpp between version 1.9 and 1.10

version 1.9, 2007/05/11 18:43:54 version 1.10, 2007/06/19 17:58:04
Line 53 
Line 53 
 static bool _shutdown = false; static bool _shutdown = false;
 static Service pegasus_service; static Service pegasus_service;
 static HANDLE pegasus_service_event = NULL; static HANDLE pegasus_service_event = NULL;
 static LPCSTR g_cimservice_key  = TEXT("SYSTEM\\CurrentControlSet\\Services\\%s");  static LPCSTR g_cimservice_key =
       TEXT("SYSTEM\\CurrentControlSet\\Services\\%s");
 static LPCSTR g_cimservice_home = TEXT("home"); static LPCSTR g_cimservice_home = TEXT("home");
 static int g_argc = 0; static int g_argc = 0;
 static char **g_argv = 0; static char **g_argv = 0;
Line 74 
Line 75 
 //------------------------------------------------------------------------- //-------------------------------------------------------------------------
 // NO-OPs for windows platform // NO-OPs for windows platform
 //------------------------------------------------------------------------- //-------------------------------------------------------------------------
 int ServerProcess::cimserver_fork(void) { return(0); }  int ServerProcess::cimserver_fork() { return(0); }
 void ServerProcess::notify_parent(int id) { return; } void ServerProcess::notify_parent(int id) { return; }
 void cimserver_exitRC(int rc) {} void cimserver_exitRC(int rc) {}
 int ServerProcess::cimserver_initialize(void) { return 0; }  int ServerProcess::cimserver_initialize() { return 0; }
 int ServerProcess::cimserver_wait(void) { return 0; }  int ServerProcess::cimserver_wait() { return 0; }
  
  
 //------------------------------------------------------------------------- //-------------------------------------------------------------------------
Line 87 
Line 88 
  
 ServerProcess::ServerProcess() ServerProcess::ServerProcess()
 { {
     //be sure to call cimserver_set_process right after instantiating this in order for everything to work      // Be sure to call cimserver_set_process right after instantiating this in
       // order for everything to work
 } }
  
 ServerProcess::~ServerProcess() ServerProcess::~ServerProcess()
Line 144 
Line 146 
         unsigned threadid = 0;         unsigned threadid = 0;
         g_argc = argc;         g_argc = argc;
         g_argv = argv;         g_argv = argv;
         HANDLE hThread = (HANDLE)_beginthreadex( NULL, 0, cimserver_windows_thread, NULL, 0, &threadid );          HANDLE hThread = (HANDLE)_beginthreadex(
               NULL, 0, cimserver_windows_thread, NULL, 0, &threadid);
         if( hThread == NULL )         if( hThread == NULL )
             return 1;             return 1;
  
Line 170 
Line 173 
         }         }
  
         CloseHandle( hThread );         CloseHandle( hThread );
   
         break;         break;
     }     }
     case Service::SHUTDOWN_FLAG:     case Service::SHUTDOWN_FLAG:
Line 203 
Line 205 
   else   else
     {     {
       pegasus_service.SetServiceName(service_name);       pegasus_service.SetServiceName(service_name);
       sprintf(displayname, "%s - %s", _server_proc->getExtendedName(), service_name);          sprintf(displayname, "%s - %s",
               _server_proc->getExtendedName(),
               service_name);
     }     }
  
   strcpy(descriptionname, _server_proc->getDescription());   strcpy(descriptionname, _server_proc->getDescription());
  
   if(0 != GetModuleFileName(NULL, filename, sizeof(filename)))   if(0 != GetModuleFileName(NULL, filename, sizeof(filename)))
   {   {
      status = pegasus_service.Install(displayname, descriptionname, filename);          status =
               pegasus_service.Install(displayname, descriptionname, filename);
  
      // Upon success, set home in registry      // Upon success, set home in registry
      if (status == Service::SERVICE_RETURN_SUCCESS)      if (status == Service::SERVICE_RETURN_SUCCESS)
Line 228 
Line 233 
   {   {
     status = (Service::ReturnCode) GetLastError();     status = (Service::ReturnCode) GetLastError();
   }   }
   return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false;  
       return (status == Service::SERVICE_RETURN_SUCCESS);
 } }
  
 //------------------------------------------------------------------------- //-------------------------------------------------------------------------
Line 246 
Line 252 
  
   status = pegasus_service.Remove();   status = pegasus_service.Remove();
  
   return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false;      return (status == Service::SERVICE_RETURN_SUCCESS);
 } }
  
 //------------------------------------------------------------------------- //-------------------------------------------------------------------------
 // START // START
 //------------------------------------------------------------------------- //-------------------------------------------------------------------------
 bool cimserver_start_nt_service(char *service_name, int num_args, char **service_args)  bool cimserver_start_nt_service(
       char* service_name,
       int num_args,
       char** service_args)
 { {
   Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS;   Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS;
  
Line 269 
Line 278 
  
   status = pegasus_service.Start(5);   status = pegasus_service.Start(5);
  
   return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false;      return (status == Service::SERVICE_RETURN_SUCCESS);
 } }
  
 //------------------------------------------------------------------------- //-------------------------------------------------------------------------
Line 287 
Line 296 
  
   status = pegasus_service.Stop(5);   status = pegasus_service.Stop(5);
  
   return (status == Service::SERVICE_RETURN_SUCCESS) ? true : false;      return (status == Service::SERVICE_RETURN_SUCCESS);
 } }
  
 //------------------------------------------------------------------------- //-------------------------------------------------------------------------
 // HELPER Utilities // HELPER Utilities
 //------------------------------------------------------------------------- //-------------------------------------------------------------------------
 static bool _getRegInfo(const char *lpchKeyword, char *lpchRetValue)  static bool _getRegInfo(
       const char* lpchKeyword,
       char* lpchRetValue)
 { {
   HKEY   hKey;   HKEY   hKey;
   DWORD  dw                   = _MAX_PATH;   DWORD  dw                   = _MAX_PATH;
Line 301 
Line 312 
  
   sprintf(subKey, g_cimservice_key, pegasus_service.GetServiceName());   sprintf(subKey, g_cimservice_key, pegasus_service.GetServiceName());
  
   if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE,      if ((RegOpenKeyEx(
                HKEY_LOCAL_MACHINE,
                     subKey,                     subKey,
                     0,                     0,
                     KEY_READ,                     KEY_READ,
Line 310 
Line 322 
       return false;       return false;
     }     }
  
   if ((RegQueryValueEx(hKey,      if ((RegQueryValueEx(
                hKey,
                        lpchKeyword,                        lpchKeyword,
                        NULL,                        NULL,
                        NULL,                        NULL,
Line 326 
Line 339 
   return true;   return true;
 } }
  
 static bool _setRegInfo(const char *lpchKeyword, const char *lpchValue)  static bool _setRegInfo(
       const char* lpchKeyword,
       const char* lpchValue)
 { {
   HKEY   hKey;   HKEY   hKey;
   DWORD  dw                   = _MAX_PATH;   DWORD  dw                   = _MAX_PATH;
Line 338 
Line 353 
  
   sprintf(subKey, g_cimservice_key, pegasus_service.GetServiceName());   sprintf(subKey, g_cimservice_key, pegasus_service.GetServiceName());
  
   if ((RegCreateKeyEx (HKEY_LOCAL_MACHINE,      if ((RegCreateKeyEx(
                HKEY_LOCAL_MACHINE,
                       subKey,                       subKey,
                       0,                       0,
                       NULL,                       NULL,
Line 351 
Line 367 
       return false;       return false;
     }     }
  
   if ((RegSetValueEx(hKey,      if ((RegSetValueEx(
                hKey,
                      lpchKeyword,                      lpchKeyword,
                      0,                      0,
                      REG_SZ,                      REG_SZ,
Line 368 
Line 385 
 } }
  
 //void ServerProcess::setHome(const String& home) //void ServerProcess::setHome(const String& home)
 String ServerProcess::getHome(void)  String ServerProcess::getHome()
 { {
     String home;     String home;
  
Line 377 
Line 394 
   char home_pathname[_MAX_PATH] = {0};   char home_pathname[_MAX_PATH] = {0};
   if(0 != GetModuleFileName(NULL, exe_pathname, sizeof(exe_pathname)))   if(0 != GetModuleFileName(NULL, exe_pathname, sizeof(exe_pathname)))
   {   {
   
     // Pegasus home search rules:     // Pegasus home search rules:
     // - look in registry (if set)     // - look in registry (if set)
     // - if not found, look in PEGASUS_HOME (if set)     // - if not found, look in PEGASUS_HOME (if set)
     // - if not found, use exe directory minus one level     // - if not found, use exe directory minus one level
  
     bool found_reg = _getRegInfo("home", home_pathname);     bool found_reg = _getRegInfo("home", home_pathname);
     if (found_reg == true)          if (found_reg)
       {       {
         // Make sure home matches         // Make sure home matches
         String current_home(home_pathname);         String current_home(home_pathname);
Line 537 
Line 553 
                 char **service_args = &argv[1];                 char **service_args = &argv[1];
                 if(cimserver_start_nt_service(opt_arg, num_args, service_args))                 if(cimserver_start_nt_service(opt_arg, num_args, service_args))
                 {                 {
                     //l10n  
                     //cout << "\nPegasus started as NT Service";  
                     MessageLoaderParms parms(                     MessageLoaderParms parms(
                         "src.Server.cimserver.STARTED_NT_SERVICE",                         "src.Server.cimserver.STARTED_NT_SERVICE",
                         "\nPegasus started as a Windows service");                         "\nPegasus started as a Windows service");
Line 562 
Line 576 
                 }                 }
                 if(cimserver_stop_nt_service(opt_arg))                 if(cimserver_stop_nt_service(opt_arg))
                 {                 {
                     //l10n  
                     //cout << "\nPegasus stopped as NT Service";  
                     MessageLoaderParms parms(                     MessageLoaderParms parms(
                         "src.Server.cimserver.STOPPED_NT_SERVICE",                         "src.Server.cimserver.STOPPED_NT_SERVICE",
                         "\nPegasus stopped as a Windows service");                         "\nPegasus stopped as a Windows service");
Line 611 
Line 623 
         Logger::put(         Logger::put(
             Logger::ERROR_LOG, "CIMServer", Logger::SEVERE,             Logger::ERROR_LOG, "CIMServer", Logger::SEVERE,
             MessageLoader::getMessage(parms) );             MessageLoader::getMessage(parms) );
         PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);          PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
               PEGASUS_STD(endl);
         return 1;         return 1;
     }     }
  
Line 643 
Line 656 
         Logger::put_l(         Logger::put_l(
             Logger::ERROR_LOG, "CIMServer", Logger::SEVERE,             Logger::ERROR_LOG, "CIMServer", Logger::SEVERE,
             "src.Server.cimserver_windows.LISTENING_ON_HTTP_PORT",             "src.Server.cimserver_windows.LISTENING_ON_HTTP_PORT",
             "Error during service run: code = $0.", status );              "Error during service run: code = $0.",
               status);
         return 1;         return 1;
     }     }
  


Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2