00001 // $Id: Activator_Loader.cpp 77020 2007-02-12 13:56:49Z johnnyw $ 00002 00003 #include "Activator_Loader.h" 00004 #include "ace/Dynamic_Service.h" 00005 #include "ace/Task.h" 00006 00007 class ImR_Activator_ORB_Runner : public ACE_Task_Base 00008 { 00009 ImR_Activator_Loader& service_; 00010 public: 00011 ImR_Activator_ORB_Runner (ImR_Activator_Loader& service) 00012 : service_ (service) 00013 { 00014 } 00015 virtual int svc () 00016 { 00017 // Block until service_.fini() calls orb->destroy() 00018 this->service_.run (); 00019 return 0; 00020 } 00021 }; 00022 00023 ImR_Activator_Loader::ImR_Activator_Loader (void) 00024 { 00025 } 00026 00027 // For now, we will assume that it's sufficient to start 00028 // the service in its own thread. Later, if necessary, we 00029 // can add a command line option to allow the imr to use 00030 // the same orb as other tao services, however the imr 00031 // is currently written with the assumption that it's running 00032 // in its own orb. 00033 int 00034 ImR_Activator_Loader::init (int argc, ACE_TCHAR *argv[]) 00035 { 00036 try 00037 { 00038 int err = this->opts_.init (argc, argv); 00039 if (err != 0) 00040 return -1; 00041 00042 // Creates it's own internal orb, which we must run later 00043 err = this->service_.init (this->opts_); 00044 if (err != 0) 00045 return -1; 00046 00047 // Create a thread in which to run the service 00048 ACE_ASSERT (this->runner_.get () == 0); 00049 this->runner_.reset (new ImR_Activator_ORB_Runner (*this)); 00050 this->runner_->activate (); 00051 } 00052 catch (const CORBA::Exception&) 00053 { 00054 return -1; 00055 } 00056 return 0; 00057 } 00058 00059 int 00060 ImR_Activator_Loader::fini (void) 00061 { 00062 ACE_ASSERT (this->runner_.get() != 0); 00063 try 00064 { 00065 int ret = this->service_.fini (); 00066 00067 this->runner_->wait (); 00068 this->runner_.reset (0); 00069 return ret; 00070 } 00071 catch (const CORBA::Exception&) 00072 { 00073 return -1; 00074 } 00075 } 00076 00077 CORBA::Object_ptr 00078 ImR_Activator_Loader::create_object (CORBA::ORB_ptr, 00079 int, 00080 ACE_TCHAR **) 00081 { 00082 throw CORBA::NO_IMPLEMENT (); 00083 } 00084 00085 int 00086 ImR_Activator_Loader::run (void) 00087 { 00088 try 00089 { 00090 return this->service_.run (); 00091 } 00092 catch (...) 00093 { 00094 ACE_ERROR ((LM_ERROR, "Exception in ImR_Locator_ORB_Runner()\n")); 00095 return -1; 00096 } 00097 } 00098 00099 ACE_FACTORY_DEFINE (Activator, ImR_Activator_Loader)