Service_Object.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Service_Object.h
00006  *
00007  *  $Id: Service_Object.h 81388 2008-04-23 14:02:05Z johnnyw $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_SERVICE_OBJECT_H
00014 #define ACE_SERVICE_OBJECT_H
00015 #include /**/ "ace/pre.h"
00016 
00017 #include "ace/Shared_Object.h"
00018 #include "ace/Svc_Conf_Tokens.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #include "ace/Event_Handler.h"
00025 #include "ace/DLL.h"
00026 
00027 #include "ace/Service_Gestalt.h"
00028 
00029 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00030 
00031 #define ACE_Component ACE_Service_Object
00032 
00033 /**
00034  * @class ACE_Service_Object
00035  *
00036  * @brief Provide the abstract base class common to all service
00037  * implementations.
00038  *
00039  * Classes that inherit from ACE_Service_Objects are capable
00040  * of being registered with the ACE_Reactor (due to the
00041  * ACE_Event_Handler, as well as being dynamically linked by
00042  * the ACE_Service_Config (due to the ACE_Shared_Object).
00043  */
00044 class ACE_Export ACE_Service_Object
00045   : public ACE_Event_Handler,
00046     public ACE_Shared_Object
00047 {
00048 public:
00049   // = Initialization and termination methods.
00050   /// Constructor.
00051   ACE_Service_Object (ACE_Reactor * = 0);
00052 
00053   /// Destructor.
00054   virtual ~ACE_Service_Object (void);
00055 
00056     /// Temporarily disable a service without removing it completely.
00057   virtual int suspend (void);
00058 
00059     /// Re-enable a previously suspended service.
00060   virtual int resume (void);
00061 };
00062 
00063 // Forward decl.
00064 class ACE_Service_Type_Impl;
00065 
00066 /**
00067  * @class ACE_Service_Type
00068  *
00069  * @brief Keeps track of information related to the various
00070  * ACE_Service_Type_Impl subclasses.
00071  *
00072  * This class acts as the interface of the "Bridge" pattern.
00073  */
00074 class ACE_Export ACE_Service_Type
00075 {
00076 public:
00077   enum
00078   {
00079     /// Delete the payload object.
00080     DELETE_OBJ = 1,
00081 
00082     /// Delete the enclosing object.
00083     DELETE_THIS = 2
00084   };
00085 
00086   enum
00087     {
00088       SERVICE_OBJECT = ACE_SVC_OBJ_T,
00089       MODULE = ACE_MODULE_T,
00090       STREAM = ACE_STREAM_T,
00091       INVALID_TYPE = -1
00092     };
00093 
00094   // = Initialization and termination methods.
00095   ACE_Service_Type (const ACE_TCHAR *n,
00096                     ACE_Service_Type_Impl *o,
00097                     const ACE_DLL &dll,
00098                     bool active);
00099   ACE_Service_Type (const ACE_TCHAR *n,
00100                     ACE_Service_Type_Impl *o,
00101                     ACE_SHLIB_HANDLE handle,
00102                     bool active);
00103   ~ACE_Service_Type (void);
00104 
00105   const ACE_TCHAR *name (void) const;
00106   void name (const ACE_TCHAR *);
00107 
00108   const ACE_Service_Type_Impl *type (void) const;
00109   void type (const ACE_Service_Type_Impl *, bool active = true);
00110 
00111   /// Is this just a stub for the real thing?
00112   bool is_forward_declaration (void) const;
00113 
00114   int suspend (void) const;
00115   int resume (void) const;
00116   bool active (void) const;
00117   void active (bool turnon);
00118 
00119   /// Calls <fini> on <type_>
00120   int fini (void);
00121 
00122   /// Check if the service has been fini'ed.
00123   bool fini_called (void) const;
00124 
00125   /// Dump the state of an object.
00126   void dump (void) const;
00127 
00128   /// Get to the DLL's implentation
00129   const ACE_DLL & dll (void) const;
00130 
00131   /// Sets the DLL
00132   void dll (const ACE_DLL&);
00133 
00134   /// Declare the dynamic allocation hooks.
00135   ACE_ALLOC_HOOK_DECLARE;
00136 
00137 private:
00138   /// Humanly readible name of svc.
00139   const ACE_TCHAR *name_;
00140 
00141   /// Pointer to C++ object that implements the svc.
00142   const ACE_Service_Type_Impl *type_;
00143 
00144   /// ACE_DLL representing the shared object file (non-zero if
00145   /// dynamically linked).
00146   mutable ACE_DLL dll_;
00147 
00148   /// true if svc is currently active, otherwise false.
00149   bool active_;
00150 
00151   /// true if <fini> on <type_> has already been called, otherwise false.
00152   bool fini_already_called_;
00153 };
00154 
00155 /**
00156  * @class ACE_Service_Object_Ptr
00157  *
00158  * @brief This is a smart pointer that holds onto the associated
00159  * ACE_Service_Object * until the current scope is left, at
00160  * which point the object's <fini> hook is called and the
00161  * service_object_ gets deleted.
00162  *
00163  * This class is similar to the Standard C++ Library class
00164  * <auto_ptr>.  It is used in conjunction with statically linked
00165  * <ACE_Service_Objects>, as shown in the
00166  * ./netsvcs/server/main.cpp example.
00167  */
00168 class ACE_Export ACE_Service_Object_Ptr
00169 {
00170 public:
00171   // = Initialization and termination methods.
00172   /// Acquire ownership of the @a so.
00173   ACE_Service_Object_Ptr (ACE_Service_Object *so);
00174 
00175   /// Release the held ACE_Service_Object by calling its <fini> hook.
00176   ~ACE_Service_Object_Ptr (void);
00177 
00178   /// Smart pointer to access the underlying ACE_Service_Object.
00179   ACE_Service_Object *operator-> ();
00180 
00181 private:
00182   /// Holds the service object until we're done.
00183   ACE_Service_Object *service_object_;
00184 };
00185 
00186 #if defined (ACE_OPENVMS)
00187 /**
00188  * @class ACE_Dynamic_Svc_Registrar
00189  *
00190  * @brief Used to register Service allocator function by its full name.
00191  */
00192 class ACE_Dynamic_Svc_Registrar
00193 {
00194 public:
00195   ACE_Dynamic_Svc_Registrar (const ACE_TCHAR* alloc_name,
00196                              void* svc_allocator);
00197 };
00198 #endif
00199 
00200 ACE_END_VERSIONED_NAMESPACE_DECL
00201 
00202 #if defined (__ACE_INLINE__)
00203 #include "ace/Service_Object.inl"
00204 #endif /* __ACE_INLINE__ */
00205 
00206 #include /**/ "ace/post.h"
00207 #endif /* ACE_SERVICE_OBJECT_H */

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