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 187 of file ImR_Activator.cpp.

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

00188 {
00189   Activator_Options opts;
00190 
00191   int result = opts.init (argc, argv);
00192   if (result < 0)
00193     return 1;  // Error
00194   else if (result > 0)
00195     return 0;  // No error, but we should exit anyway.
00196 
00197   result = run_service_command (opts);
00198   if (result < 0)
00199     return 1;  // Error
00200   else if (result > 0)
00201     return 0;  // No error, but we should exit anyway.
00202 
00203   if (opts.service ())
00204     return run_service ();
00205 
00206   return run_standalone (opts);
00207 }

int run_service void   ) 
 

Definition at line 88 of file ImR_Activator.cpp.

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

Referenced by main().

00089 {
00090 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_SERVICES)
00091   SERVICE::instance()->name (IMR_ACTIVATOR_SERVICE_NAME, IMR_ACTIVATOR_DISPLAY_NAME);
00092   ACE_NT_SERVICE_RUN (service, SERVICE::instance (), ret);
00093 
00094   if (ret == 0)
00095     ACE_ERROR ((LM_ERROR, "%p\n", "Couldn't start service"));
00096 
00097   return ret;
00098 #else /* ACE_WIN32 */
00099   return 1;
00100 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_SERVICES */
00101 }

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 110 of file ImR_Activator.cpp.

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

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

int run_standalone Activator_Options opts  ) 
 

Definition at line 39 of file ImR_Activator.cpp.

References ImR_Activator_i::fini(), ImR_Activator_i::init(), and ImR_Activator_i::run().

00040 {
00041   ImR_Activator_i server;
00042 
00043   ImR_Activator_Shutdown killer (server);
00044   Service_Shutdown kill_contractor (killer);
00045 
00046   try
00047     {
00048       int status = server.init (opts);
00049 
00050       if (status == -1)
00051         {
00052           return 1;
00053         }
00054       else
00055         {
00056           // Run the server if it is initialized correctly.
00057           server.run ();
00058 
00059           // End the server after its work is done.
00060           status = server.fini ();
00061 
00062           if (status == -1)
00063             return 1;
00064         }
00065       return 0;
00066     }
00067   catch (const CORBA::SystemException& sysex)
00068     {
00069       sysex._tao_print_exception ("System Exception");
00070     }
00071   catch (const CORBA::UserException& userex)
00072     {
00073       userex._tao_print_exception ("User Exception");
00074     }
00075   catch (const CORBA::Exception& ex)
00076     {
00077       ex._tao_print_exception ("Unknown Exception");
00078     }
00079 
00080   return 1;
00081 }


Generated on Sun Jan 27 15:55:08 2008 for TAO_Implementation_Repository by doxygen 1.3.6