ImR_Activator.cpp File Reference

#include "Activator_Options.h"
#include "ImR_Activator_i.h"
#include "Activator_NT_Service.h"
#include "orbsvcs/Shutdown_Utilities.h"

Include dependency graph for ImR_Activator.cpp:

Include dependency graph

Go to the source code of this file.

Classes

class  ImR_Activator_Shutdown

Functions

int run_standalone (Activator_Options &opts)
 ACE_NT_SERVICE_DEFINE (service, Activator_NT_Service, IMR_ACTIVATOR_SERVICE_NAME)
int run_service (void)
int run_service_command (Activator_Options &opts)
int main (int argc, char *argv[])


Function Documentation

ACE_NT_SERVICE_DEFINE service  ,
Activator_NT_Service  ,
IMR_ACTIVATOR_SERVICE_NAME 
 

int main int  argc,
char *  argv[]
 

Definition at line 195 of file ImR_Activator.cpp.

References Activator_Options::init(), run_service(), run_service_command(), run_standalone(), and Activator_Options::service().

00196 {
00197   Activator_Options opts;
00198 
00199   int result = opts.init (argc, argv);
00200   if (result < 0)
00201     return 1;  // Error
00202   else if (result > 0)
00203     return 0;  // No error, but we should exit anyway.
00204 
00205   result = run_service_command (opts);
00206   if (result < 0)
00207     return 1;  // Error
00208   else if (result > 0)
00209     return 0;  // No error, but we should exit anyway.
00210 
00211   if (opts.service ())
00212     return run_service ();
00213 
00214   return run_standalone (opts);
00215 }

int run_service void   ) 
 

Definition at line 96 of file ImR_Activator.cpp.

References ACE_ERROR, ACE_NT_SERVICE_RUN, ACE_Singleton< TYPE, ACE_LOCK >::instance(), and LM_ERROR.

Referenced by main().

00097 {
00098 #if defined (ACE_WIN32)
00099   SERVICE::instance()->name (IMR_ACTIVATOR_SERVICE_NAME, IMR_ACTIVATOR_DISPLAY_NAME);
00100   ACE_NT_SERVICE_RUN (service, SERVICE::instance (), ret);
00101 
00102   if (ret == 0)
00103     ACE_ERROR ((LM_ERROR, "%p\n", "Couldn't start service"));
00104 
00105   return ret;
00106 #else /* ACE_WIN32 */
00107   return 1;
00108 #endif /* ACE_WIN32 */
00109 }

int run_service_command Activator_Options opts  )  [static]
 

Executes the various commands that are useful for a NT service. Right now these include 'install' and 'remove'. Others, such as 'start' and 'stop' can be added, but the 'net' program in Windows already handles these commands.

Definition at line 118 of file ImR_Activator.cpp.

References ACE_DEBUG, ACE_ERROR, ACE_TEXT(), ACE_Singleton< TYPE, ACE_LOCK >::instance(), LM_DEBUG, LM_ERROR, Activator_Options::save_registry_options(), Activator_Options::service_command(), and ACE_OS::strcat().

00119 {
00120   if (opts.service_command () == Activator_Options::SC_NONE)
00121     return 0;
00122 
00123 #if defined (ACE_WIN32)
00124   SERVICE::instance()->name (IMR_ACTIVATOR_SERVICE_NAME, IMR_ACTIVATOR_DISPLAY_NAME);
00125 
00126   if (opts.service_command () == Activator_Options::SC_INSTALL ||
00127     opts.service_command () == Activator_Options::SC_INSTALL_NO_LOCATOR)
00128       {
00129         const DWORD MAX_PATH_LENGTH = 4096;
00130         char pathname[MAX_PATH_LENGTH];
00131 
00132         DWORD length = ACE_TEXT_GetModuleFileName(NULL, pathname, MAX_PATH_LENGTH);
00133         if (length == 0 || length >= MAX_PATH_LENGTH - sizeof(" -s"))
00134           {
00135             ACE_ERROR ((LM_ERROR, "Error: Could not get module file name\n"));
00136             return -1;
00137           }
00138 
00139         // Append the command used for running the implrepo as a service
00140         ACE_OS::strcat (pathname, ACE_TEXT (" -s"));
00141         int ret = -1;
00142         if (opts.service_command () == Activator_Options::SC_INSTALL)
00143           {
00144             const char* DEPENDS_ON = "TAOImR"; // Must match Locator_NT_Service.h
00145 
00146             ret =  SERVICE::instance ()->insert (SERVICE_DEMAND_START,
00147                                                 SERVICE_ERROR_NORMAL,
00148                                                 pathname,
00149                                                 0, // group
00150                                                 0, // tag
00151                                                 DEPENDS_ON
00152                                                 );
00153           }
00154         else
00155           {
00156             ret =  SERVICE::instance ()->insert (SERVICE_DEMAND_START,
00157                                                 SERVICE_ERROR_NORMAL,
00158                                                 pathname);
00159           }
00160       if (ret != -1)
00161         {
00162           ACE_DEBUG ((LM_DEBUG, "ImR Activator: Service installed.\n"));
00163           opts.save_registry_options ();
00164         }
00165       else
00166         {
00167           ACE_ERROR ((LM_ERROR, "Error: Failed to install service.\n"));
00168         }
00169       if (ret == 0)
00170         return 1;
00171     }
00172   else if (opts.service_command () == Activator_Options::SC_REMOVE)
00173     {
00174       int ret = SERVICE::instance ()->remove ();
00175       ACE_DEBUG ((LM_DEBUG, "ImR Activator: Service removed.\n"));
00176       if (ret == 0)
00177         return 1; // If successfull, then we don't want to continue.
00178     }
00179   else
00180     {
00181       ACE_ERROR ((LM_ERROR, "Error: Unknown service command :%d \n",
00182         opts.service_command ()));
00183       return -1;
00184     }
00185 
00186   return -1;
00187 
00188 #else /* ACE_WIN32 */
00189   ACE_ERROR ((LM_ERROR, "NT Service not supported on this platform"));
00190   return -1;
00191 #endif /* ACE_WIN32 */
00192 }

int run_standalone Activator_Options opts  ) 
 

Definition at line 42 of file ImR_Activator.cpp.

References ACE_ANY_EXCEPTION, ACE_CATCH, ACE_CATCHANY, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_PRINT_EXCEPTION, ACE_TRY, ACE_TRY_CHECK, ImR_Activator_i::fini(), ImR_Activator_i::init(), and ImR_Activator_i::run().

00043 {
00044   ImR_Activator_i server;
00045 
00046   ImR_Activator_Shutdown killer (server);
00047   Service_Shutdown kill_contractor (killer);
00048 
00049   ACE_DECLARE_NEW_CORBA_ENV;
00050   ACE_TRY
00051     {
00052       int status = server.init (opts ACE_ENV_ARG_PARAMETER);
00053       ACE_TRY_CHECK;
00054 
00055       if (status == -1)
00056         {
00057           return 1;
00058         }
00059       else
00060         {
00061           // Run the server if it is initialized correctly.
00062           server.run (ACE_ENV_SINGLE_ARG_PARAMETER);
00063           ACE_TRY_CHECK;
00064 
00065           // End the server after its work is done.
00066           status = server.fini (ACE_ENV_SINGLE_ARG_PARAMETER);
00067           ACE_TRY_CHECK;
00068 
00069           if (status == -1)
00070             return 1;
00071         }
00072       return 0;
00073     }
00074   ACE_CATCH (CORBA::SystemException, sysex)
00075     {
00076       ACE_PRINT_EXCEPTION (sysex, "System Exception");
00077     }
00078   ACE_CATCH (CORBA::UserException, userex)
00079     {
00080       ACE_PRINT_EXCEPTION (userex, "User Exception");
00081     }
00082   ACE_CATCHANY
00083     {
00084       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Unknown Exception");
00085     }
00086   ACE_ENDTRY;
00087 
00088   return 1;
00089 }


Generated on Thu Nov 9 13:36:34 2006 for TAO_Implementation_Repository by doxygen 1.3.6