Service_Object.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Service_Object.h
00006  *
00007  *  Service_Object.h,v 4.43 2006/04/26 21:19:42 jeliazkov_i Exp
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                     int active);
00099   ACE_Service_Type (const ACE_TCHAR *n,
00100                     ACE_Service_Type_Impl *o,
00101                     ACE_SHLIB_HANDLE handle,
00102                     int 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 *, int active = 1);
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   int  active (void) const;
00117   void active (int);
00118 
00119   /// Calls <fini> on <type_>
00120   int fini (void);
00121 
00122   /// Check if the service has been fini'ed.
00123   int 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 () const;
00130 
00131   /// Declare the dynamic allocation hooks.
00132   ACE_ALLOC_HOOK_DECLARE;
00133 
00134 private:
00135   /// Humanly readible name of svc.
00136   const ACE_TCHAR *name_;
00137 
00138   /// Pointer to C++ object that implements the svc.
00139   const ACE_Service_Type_Impl *type_;
00140 
00141   /// ACE_DLL representing the shared object file (non-zero if
00142   /// dynamically linked).
00143   mutable ACE_DLL dll_;
00144 
00145   /// 1 if svc is currently active, otherwise 0.
00146   int active_;
00147 
00148   /// 1 if <fini> on <type_> has already been called, otherwise 0.
00149   int fini_already_called_;
00150 };
00151 
00152 /**
00153  * @class ACE_Service_Object_Ptr
00154  *
00155  * @brief This is a smart pointer that holds onto the associated
00156  * ACE_Service_Object * until the current scope is left, at
00157  * which point the object's <fini> hook is called and the
00158  * service_object_ gets deleted.
00159  *
00160  * This class is similar to the Standard C++ Library class
00161  * <auto_ptr>.  It is used in conjunction with statically linked
00162  * <ACE_Service_Objects>, as shown in the
00163  * ./netsvcs/server/main.cpp example.
00164  */
00165 class ACE_Export ACE_Service_Object_Ptr
00166 {
00167 public:
00168   // = Initialization and termination methods.
00169   /// Acquire ownership of the @a so.
00170   ACE_Service_Object_Ptr (ACE_Service_Object *so);
00171 
00172   /// Release the held ACE_Service_Object by calling its <fini> hook.
00173   ~ACE_Service_Object_Ptr (void);
00174 
00175   /// Smart pointer to access the underlying ACE_Service_Object.
00176   ACE_Service_Object *operator-> ();
00177 
00178 private:
00179   /// Holds the service object until we're done.
00180   ACE_Service_Object *service_object_;
00181 };
00182 
00183 ACE_END_VERSIONED_NAMESPACE_DECL
00184 
00185 #if defined (__ACE_INLINE__)
00186 #include "ace/Service_Object.inl"
00187 #endif /* __ACE_INLINE__ */
00188 
00189 #include /**/ "ace/post.h"
00190 #endif /* ACE_SERVICE_OBJECT_H */

Generated on Thu Nov 9 09:42:03 2006 for ACE by doxygen 1.3.6