ImR_Locator.cpp File Reference

#include "ImR_Locator_i.h"
#include "Locator_NT_Service.h"
#include "Locator_Options.h"
#include "orbsvcs/Shutdown_Utilities.h"

Include dependency graph for ImR_Locator.cpp:

Include dependency graph

Go to the source code of this file.

Classes

class  ImR_Locator_Shutdown

Functions

int run_standalone (Options &opts)
 ACE_NT_SERVICE_DEFINE (service, Locator_NT_Service, IMR_LOCATOR_SERVICE_NAME)
int run_service (void)
int run_service_command (Options &opts)
int main (int argc, char *argv[])


Function Documentation

ACE_NT_SERVICE_DEFINE service  ,
Locator_NT_Service  ,
IMR_LOCATOR_SERVICE_NAME 
 

int main int  argc,
char *  argv[]
 

Definition at line 178 of file ImR_Locator.cpp.

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

00179 {
00180   Options opts;
00181 
00182   int result = opts.init (argc, argv);
00183   if (result < 0)
00184     return 1;  // Error
00185   else if (result > 0)
00186     return 0;  // No error, but we should exit anyway.
00187 
00188   result = run_service_command(opts);
00189   if (result < 0)
00190     return 1;  // Error
00191   else if (result > 0)
00192     return 0;  // No error, but we should exit anyway.
00193 
00194   if (opts.service ())
00195   {
00196     return run_service ();
00197   }
00198 
00199   return run_standalone (opts);
00200 }

int run_service void   ) 
 

Definition at line 93 of file ImR_Locator.cpp.

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

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

int run_service_command 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 117 of file ImR_Locator.cpp.

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

Referenced by main().

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

int run_standalone Options opts  ) 
 

Definition at line 40 of file ImR_Locator.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_Locator_i::fini(), ImR_Locator_i::init(), and ImR_Locator_i::run().

Referenced by main().

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


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