00001 // $Id: Locator_Loader.cpp 77020 2007-02-12 13:56:49Z johnnyw $ 00002 00003 #include "Locator_Loader.h" 00004 #include "ace/Dynamic_Service.h" 00005 #include "ace/Task.h" 00006 00007 class ImR_Locator_ORB_Runner : public ACE_Task_Base 00008 { 00009 public: 00010 ImR_Locator_ORB_Runner (ImR_Locator_Loader& service) 00011 : service_ (service) 00012 { 00013 } 00014 virtual int svc () 00015 { 00016 // Block until service_.fini () calls orb->destroy () 00017 this->service_.run (); 00018 return 0; 00019 } 00020 private: 00021 ImR_Locator_Loader& service_; 00022 }; 00023 00024 ImR_Locator_Loader::ImR_Locator_Loader() 00025 { 00026 } 00027 00028 int 00029 ImR_Locator_Loader::init (int argc, ACE_TCHAR *argv[]) 00030 { 00031 try 00032 { 00033 int err = this->opts_.init (argc, argv); 00034 if (err != 0) 00035 return -1; 00036 00037 err = this->service_.init (this->opts_); 00038 if (err != 0) 00039 return -1; 00040 00041 // Create a thread in which to run the service 00042 ACE_ASSERT(this->runner_.get () == 0); 00043 this->runner_.reset(new ImR_Locator_ORB_Runner (*this)); 00044 this->runner_->activate (); 00045 } 00046 catch (const CORBA::Exception&) 00047 { 00048 return -1; 00049 } 00050 return 0; 00051 } 00052 00053 int 00054 ImR_Locator_Loader::fini (void) 00055 { 00056 ACE_ASSERT(this->runner_.get () != 0); 00057 try 00058 { 00059 int ret = this->service_.fini (); 00060 00061 this->runner_->wait (); 00062 this->runner_.reset (0); 00063 return ret; 00064 } 00065 catch (const CORBA::Exception&) 00066 { 00067 } 00068 return -1; 00069 } 00070 00071 CORBA::Object_ptr 00072 ImR_Locator_Loader::create_object (CORBA::ORB_ptr, 00073 int, 00074 ACE_TCHAR**) 00075 { 00076 throw CORBA::NO_IMPLEMENT(); 00077 } 00078 00079 int 00080 ImR_Locator_Loader::run(void) 00081 { 00082 try 00083 { 00084 return this->service_.run (); 00085 } 00086 catch (...) 00087 { 00088 ACE_ERROR((LM_ERROR, "Exception in ImR_Locator_ORB_Runner ()\n")); 00089 return -1; 00090 } 00091 } 00092 00093 00094 ACE_FACTORY_DEFINE (Locator, ImR_Locator_Loader)