Service_Object.cpp

Go to the documentation of this file.
00001 // $Id: Service_Object.cpp 81452 2008-04-27 17:56:41Z johnnyw $
00002 
00003 #include "ace/config-all.h"
00004 
00005 #include "ace/Service_Object.h"
00006 
00007 #if !defined (__ACE_INLINE__)
00008 #include "ace/Service_Object.inl"
00009 #endif /* __ACE_INLINE__ */
00010 
00011 #include "ace/OS_NS_stdio.h"
00012 #include "ace/Service_Types.h"
00013 #include "ace/DLL.h"
00014 #include "ace/ACE.h"
00015 #include "ace/Log_Msg.h"
00016 #if defined (ACE_OPENVMS)
00017 # include "ace/Lib_Find.h"
00018 #endif
00019 
00020 ACE_RCSID (ace,
00021            Service_Object,
00022            "$Id: Service_Object.cpp 81452 2008-04-27 17:56:41Z johnnyw $")
00023 
00024   ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00025 
00026 ACE_ALLOC_HOOK_DEFINE(ACE_Service_Object)
00027   ACE_ALLOC_HOOK_DEFINE(ACE_Service_Type)
00028 
00029   void
00030 ACE_Service_Type::dump (void) const
00031 {
00032 #if defined (ACE_HAS_DUMP)
00033   ACE_TRACE ("ACE_Service_Type::dump");
00034 #endif /* ACE_HAS_DUMP */
00035 
00036 
00037   // Using printf, since the log facility may not have been
00038   // initialized yet. Using a "//" prefix, in case the executable
00039   // happens to be a code generator and the output gets embedded in
00040   // the generated C++ code.
00041   ACE_OS::fprintf(stderr,
00042                   "// [ST] dump, this=%p, name=%s, type=%p, so=%p, active=%d\n",
00043                   this,
00044                   this->name_,
00045                   this->type_,
00046                   (this->type_ != 0) ? this->type_->object () : 0,
00047                   this->active_);
00048 
00049 }
00050 
00051 ACE_Service_Type::ACE_Service_Type (const ACE_TCHAR *n,
00052                                     ACE_Service_Type_Impl *t,
00053                                     const ACE_DLL &dll,
00054                                     bool active)
00055   : name_ (0),
00056     type_ (t),
00057     dll_ (dll),
00058     active_ (active),
00059     fini_already_called_ (false)
00060 {
00061   ACE_TRACE ("ACE_Service_Type::ACE_Service_Type");
00062   this->name (n);
00063 }
00064 
00065 ACE_Service_Type::ACE_Service_Type (const ACE_TCHAR *n,
00066                                     ACE_Service_Type_Impl *t,
00067                                     ACE_SHLIB_HANDLE handle,
00068                                     bool active)
00069   : name_ (0),
00070     type_ (t),
00071     active_ (active),
00072     fini_already_called_ (false)
00073 {
00074   ACE_TRACE ("ACE_Service_Type::ACE_Service_Type");
00075   this->dll_.set_handle (handle);
00076   this->name (n);
00077 }
00078 
00079 ACE_Service_Type::~ACE_Service_Type (void)
00080 {
00081   ACE_TRACE ("ACE_Service_Type::~ACE_Service_Type");
00082   this->fini ();
00083 
00084   delete [] const_cast <ACE_TCHAR *> (this->name_);
00085 }
00086 
00087 int
00088 ACE_Service_Type::fini (void)
00089 {
00090   if (ACE::debug ())
00091     ACE_DEBUG ((LM_DEBUG,
00092                 ACE_TEXT ("ACE (%P|%t) ST::fini - destroying name=%s, dll=%s\n"),
00093                 this->name_,
00094                 this->dll_.dll_name_));
00095 
00096   if (this->fini_already_called_)
00097     return 0;
00098 
00099   this->fini_already_called_ = true;
00100 
00101   if (this->type_ == 0)
00102     {
00103       // Returning 1 currently only makes sense for dummy instances, used
00104       // to "reserve" a spot (kind of like forward-declarations) for a
00105       // dynamic service. This is necessary to help enforce the correct
00106       // finalization order, when such service also has any (dependent)
00107       // static services
00108 
00109       return 1; // No implementation was found.
00110     }
00111 
00112   int ret = this->type_->fini ();
00113 
00114   // Ensure that closing the DLL is done after type_->fini() as it may
00115   // require access to the code for the service object destructor,
00116   // which resides in the DLL
00117   return (ret | this->dll_.close());
00118 
00119 }
00120 
00121 int
00122 ACE_Service_Type::suspend (void) const
00123 {
00124   ACE_TRACE ("ACE_Service_Type::suspend");
00125   (const_cast<ACE_Service_Type *> (this))->active_ = false;
00126   return this->type_->suspend ();
00127 }
00128 
00129 int
00130 ACE_Service_Type::resume (void) const
00131 {
00132   ACE_TRACE ("ACE_Service_Type::resume");
00133   (const_cast<ACE_Service_Type *> (this))->active_ = true;
00134   return this->type_->resume ();
00135 }
00136 
00137 ACE_Service_Object::ACE_Service_Object (ACE_Reactor *r)
00138   : ACE_Event_Handler (r)
00139 {
00140   ACE_TRACE ("ACE_Service_Object::ACE_Service_Object");
00141 }
00142 
00143 ACE_Service_Object::~ACE_Service_Object (void)
00144 {
00145   ACE_TRACE ("ACE_Service_Object::~ACE_Service_Object");
00146 }
00147 
00148 int
00149 ACE_Service_Object::suspend (void)
00150 {
00151   ACE_TRACE ("ACE_Service_Object::suspend");
00152   return 0;
00153 }
00154 
00155 int
00156 ACE_Service_Object::resume (void)
00157 {
00158   ACE_TRACE ("ACE_Service_Object::resume");
00159   return 0;
00160 }
00161 
00162 void
00163 ACE_Service_Type::name (const ACE_TCHAR *n)
00164 {
00165   ACE_TRACE ("ACE_Service_Type::name");
00166 
00167   delete [] const_cast <ACE_TCHAR *> (this->name_);
00168   this->name_ = ACE::strnew (n);
00169 }
00170 
00171 #if defined (ACE_OPENVMS)
00172 ACE_Dynamic_Svc_Registrar::ACE_Dynamic_Svc_Registrar (const ACE_TCHAR* alloc_name,
00173                                                       void* svc_allocator)
00174 {
00175   // register service allocator function by full name in ACE singleton registry
00176   ACE::ldregister (alloc_name, svc_allocator);
00177 }
00178 #endif
00179 
00180 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:42 2010 for ACE by  doxygen 1.4.7