#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:
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[]) |
|
|
|
Definition at line 170 of file ImR_Locator.cpp. References Options::init(), run_service(), run_service_command(), run_standalone(), and Options::service().
00171 { 00172 Options opts; 00173 00174 int result = opts.init (argc, argv); 00175 if (result < 0) 00176 return 1; // Error 00177 else if (result > 0) 00178 return 0; // No error, but we should exit anyway. 00179 00180 result = run_service_command(opts); 00181 if (result < 0) 00182 return 1; // Error 00183 else if (result > 0) 00184 return 0; // No error, but we should exit anyway. 00185 00186 if (opts.service ()) 00187 { 00188 return run_service (); 00189 } 00190 00191 return run_standalone (opts); 00192 } |
|
Definition at line 85 of file ImR_Locator.cpp. References ACE_ERROR, ACE_Singleton< TYPE, ACE_LOCK >::instance(), and LM_ERROR.
00086 { 00087 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_SERVICES) 00088 00089 SERVICE::instance ()->name (IMR_LOCATOR_SERVICE_NAME, IMR_LOCATOR_DISPLAY_NAME); 00090 00091 ACE_NT_SERVICE_RUN (service, SERVICE::instance (), ret); 00092 00093 if (ret == 0) 00094 ACE_ERROR ((LM_ERROR, "%p\n", "Couldn't start service")); 00095 00096 return ret; 00097 #else /* ACE_WIN32 */ 00098 return 1; 00099 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_SERVICES */ 00100 } |
|
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 109 of file ImR_Locator.cpp. References ACE_DEBUG, ACE_ERROR, ACE_TEXT(), ACE_TEXT_GetModuleFileName, ACE_Singleton< TYPE, ACE_LOCK >::instance(), LM_DEBUG, LM_ERROR, Options::save_registry_options(), Options::service_command(), and ACE_OS::strcat(). Referenced by main().
00110 { 00111 if (opts.service_command () == Options::SC_NONE) 00112 return 0; 00113 00114 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_SERVICES) 00115 SERVICE::instance()->name (IMR_LOCATOR_SERVICE_NAME, IMR_LOCATOR_DISPLAY_NAME); 00116 00117 if (opts.service_command () == Options::SC_INSTALL) 00118 { 00119 const DWORD MAX_PATH_LENGTH = 4096; 00120 char pathname[MAX_PATH_LENGTH]; 00121 00122 DWORD length = ACE_TEXT_GetModuleFileName (0, pathname, MAX_PATH_LENGTH); 00123 if (length == 0 || length >= MAX_PATH_LENGTH - sizeof(" -s")) 00124 { 00125 ACE_ERROR ((LM_ERROR, "Error: Could not get module file name\n")); 00126 return -1; 00127 } 00128 00129 // Append the command used for running the implrepo as a service 00130 ACE_OS::strcat (pathname, ACE_TEXT (" -s")); 00131 00132 int ret = SERVICE::instance ()->insert (SERVICE_DEMAND_START, 00133 SERVICE_ERROR_NORMAL, 00134 pathname); 00135 if (ret != -1) 00136 { 00137 ACE_DEBUG ((LM_DEBUG, "ImR: Service installed.\n")); 00138 opts.save_registry_options (); 00139 } 00140 else 00141 { 00142 ACE_ERROR ((LM_ERROR, "Error: Failed to install service. error:%d\n", errno)); 00143 } 00144 if (ret == 0) 00145 return 1; 00146 } 00147 else if (opts.service_command () == Options::SC_REMOVE) 00148 { 00149 int ret = SERVICE::instance ()->remove (); 00150 ACE_DEBUG ((LM_DEBUG, "ImR: Service removed.\n")); 00151 if (ret == 0) 00152 return 1; // If successfull, then we don't want to continue. 00153 } 00154 else 00155 { 00156 ACE_ERROR ((LM_ERROR, "Error: Unknown service command :%d \n", 00157 opts.service_command ())); 00158 return -1; 00159 } 00160 00161 return -1; 00162 00163 #else /* ACE_WIN32 */ 00164 ACE_ERROR ((LM_ERROR, "NT Service not supported on this platform")); 00165 return -1; 00166 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_SERVICES */ 00167 } |
|
Definition at line 37 of file ImR_Locator.cpp. References ImR_Locator_i::fini(), ImR_Locator_i::init(), and ImR_Locator_i::run(). Referenced by main().
00038 { 00039 ImR_Locator_i server; 00040 00041 ImR_Locator_Shutdown killer (server); 00042 Service_Shutdown kill_contractor(killer); 00043 00044 try 00045 { 00046 int status = server.init (opts); 00047 if (status == -1) 00048 { 00049 return 1; 00050 } 00051 else 00052 { 00053 // Run the server if it is initialized correctly. 00054 server.run (); 00055 00056 // End the server after its work is done. 00057 status = server.fini (); 00058 00059 if (status == -1) 00060 return 1; 00061 } 00062 return 0; 00063 } 00064 catch (const CORBA::SystemException& sysex) 00065 { 00066 sysex._tao_print_exception ("System Exception"); 00067 } 00068 catch (const CORBA::UserException& userex) 00069 { 00070 userex._tao_print_exception ("User Exception"); 00071 } 00072 catch (const CORBA::Exception& ex) 00073 { 00074 ex._tao_print_exception ("Unknown Exception"); 00075 } 00076 00077 return 1; 00078 } |