Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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,v 1.1.1.4 2003/02/21 18:36:32 chad 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 #define ACE_Component ACE_Service_Object
00028 /**
00029  * @class ACE_Service_Object
00030  *
00031  * @brief Provide the abstract base class common to all service
00032  * implementations.
00033  *
00034  * Classes that inherit from <ACE_Service_Objects> are capable
00035  * of being registered with the <ACE_Reactor> (due to the
00036  * <ACE_Event_Handler>, as well as being dynamically linked by
00037  * the <ACE_Service_Config> (due to the <ACE_Shared_Object>).
00038  */
00039 class ACE_Export ACE_Service_Object : public ACE_Event_Handler, public ACE_Shared_Object
00040 {
00041 public:
00042   // = Initialization and termination methods.
00043   /// Constructor.
00044   ACE_Service_Object (ACE_Reactor * = 0);
00045 
00046   /// Destructor.
00047   virtual ~ACE_Service_Object (void);
00048 
00049     /// Temporarily disable a service without removing it completely.
00050   virtual int suspend (void);
00051 
00052     /// Re-enable a previously suspended service.
00053   virtual int resume (void);
00054 };
00055 
00056 // Forward decl.
00057 class ACE_Service_Type_Impl;
00058 class ACE_DLL;
00059 
00060 /**
00061  * @class ACE_Service_Type
00062  *
00063  * @brief Keeps track of information related to the various
00064  * <ACE_Service_Type_Impl> subclasses.
00065  *
00066  * This class acts as the interface of the "Bridge" pattern.
00067  */
00068 class ACE_Export ACE_Service_Type
00069 {
00070 public:
00071   enum
00072   {
00073     /// Delete the payload object.
00074     DELETE_OBJ = 1,
00075 
00076     /// Delete the enclosing object.
00077     DELETE_THIS = 2
00078   };
00079 
00080   enum
00081     {
00082       SERVICE_OBJECT = ACE_SVC_OBJ_T,
00083       MODULE = ACE_MODULE_T,
00084       STREAM = ACE_STREAM_T,
00085       INVALID_TYPE = -1
00086     };
00087 
00088   // = Initialization and termination methods.
00089   ACE_Service_Type (const ACE_TCHAR *n,
00090                     ACE_Service_Type_Impl *o,
00091                     const ACE_DLL &dll,
00092                     int active);
00093   ~ACE_Service_Type (void);
00094 
00095   const ACE_TCHAR *name (void) const;
00096   void name (const ACE_TCHAR *);
00097 
00098   const ACE_Service_Type_Impl *type (void) const;
00099   void type (const ACE_Service_Type_Impl *,
00100              int active = 1);
00101 
00102   int suspend (void) const;
00103   int resume (void) const;
00104   int  active (void) const;
00105   void active (int);
00106 
00107   /// Calls <fini> on <type_>
00108   int fini (void);
00109 
00110   /// Check if the service has been fini'ed.
00111   int fini_called (void) const;
00112 
00113   /// Dump the state of an object.
00114   void dump (void) const;
00115 
00116   /// Declare the dynamic allocation hooks.
00117   ACE_ALLOC_HOOK_DECLARE;
00118 
00119 private:
00120   /// Humanly readible name of svc.
00121   const ACE_TCHAR *name_;
00122 
00123   /// Pointer to C++ object that implements the svc.
00124   const ACE_Service_Type_Impl *type_;
00125 
00126   /// ACE_DLL representing the shared object file (non-zero if dynamically linked).
00127   ACE_DLL dll_;
00128 
00129   /// 1 if svc is currently active, otherwise 0.
00130   int active_;
00131 
00132   /// 1 if <fini> on <type_> has already been called, otherwise 0.
00133   int fini_already_called_;
00134 };
00135 
00136 /**
00137  * @class ACE_Service_Object_Ptr
00138  *
00139  * @brief This is a smart pointer that holds onto the associated
00140  * <ACE_Service_Object> * until the current scope is left, at
00141  * which point the object's <fini> hook is called and the
00142  * service_object_ gets deleted.
00143  *
00144  * This class is similar to the Standard C++ Library class
00145  * <auto_ptr>.  It is used in conjunction with statically linked
00146  * <ACE_Service_Objects>, as shown in the
00147  * ./netsvcs/server/main.cpp example.
00148  */
00149 class ACE_Export ACE_Service_Object_Ptr
00150 {
00151 public:
00152   // = Initialization and termination methods.
00153   /// Acquire ownership of the <so>.
00154   ACE_Service_Object_Ptr (ACE_Service_Object *so);
00155 
00156   /// Release the held <ACE_Service_Object> by calling its <fini> hook.
00157   ~ACE_Service_Object_Ptr (void);
00158 
00159   /// Smart pointer to access the underlying <ACE_Service_Object>.
00160   ACE_Service_Object *operator-> ();
00161 
00162 private:
00163   /// Holds the service object until we're done.
00164   ACE_Service_Object *service_object_;
00165 };
00166 
00167 #if defined (__ACE_INLINE__)
00168 #include "ace/Service_Object.i"
00169 #endif /* __ACE_INLINE__ */
00170 
00171 #include "ace/post.h"
00172 #endif /* ACE_SERVICE_OBJECT_H */

Generated on Mon Jun 16 11:21:11 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002