Activator_Loader.cpp

Go to the documentation of this file.
00001 // Activator_Loader.cpp,v 1.5 2006/03/16 15:53:35 sjiang Exp
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[] ACE_ENV_ARG_DECL)
00035 {
00036   ACE_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_ ACE_ENV_ARG_PARAMETER);
00044       ACE_TRY_CHECK;
00045       if (err != 0)
00046         return -1;
00047 
00048       // Create a thread in which to run the service
00049       ACE_ASSERT (this->runner_.get () == 0);
00050       this->runner_.reset (new ImR_Activator_ORB_Runner (*this));
00051       this->runner_->activate ();
00052     }
00053   ACE_CATCHANY
00054     {
00055       return -1;
00056     }
00057   ACE_ENDTRY;
00058   return 0;
00059 }
00060 
00061 int
00062 ImR_Activator_Loader::fini (void)
00063 {
00064   ACE_ASSERT (this->runner_.get() != 0);
00065   ACE_DECLARE_NEW_CORBA_ENV;
00066   ACE_TRY
00067     {
00068       int ret = this->service_.fini (ACE_ENV_SINGLE_ARG_PARAMETER);
00069       ACE_TRY_CHECK;
00070 
00071       this->runner_->wait ();
00072       this->runner_.reset (0);
00073       return ret;
00074     }
00075   ACE_CATCHANY
00076     {
00077       return -1;
00078     }
00079   ACE_ENDTRY;
00080 }
00081 
00082 CORBA::Object_ptr
00083 ImR_Activator_Loader::create_object (CORBA::ORB_ptr,
00084                                   int,
00085                                   ACE_TCHAR **
00086                                   ACE_ENV_ARG_DECL)
00087    ACE_THROW_SPEC ((CORBA::SystemException))
00088 {
00089   ACE_THROW_RETURN(CORBA::NO_IMPLEMENT (), CORBA::Object::_nil ());
00090 }
00091 
00092 int
00093 ImR_Activator_Loader::run (void)
00094 {
00095   ACE_DECLARE_NEW_CORBA_ENV;
00096   ACE_TRY
00097     {
00098       return this->service_.run (ACE_ENV_SINGLE_ARG_PARAMETER);
00099       ACE_TRY_CHECK;
00100     }
00101   ACE_CATCHALL
00102     {
00103       ACE_ERROR ((LM_ERROR, "Exception in ImR_Locator_ORB_Runner()\n"));
00104       return -1;
00105     }
00106   ACE_ENDTRY;
00107 }
00108 
00109 ACE_FACTORY_DEFINE (Activator, ImR_Activator_Loader)

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