Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Service_Object.h
blob287391e52021a9083d8ec5cea11be2f928d845c9
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Service_Object.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
9 //=============================================================================
11 #ifndef ACE_SERVICE_OBJECT_H
12 #define ACE_SERVICE_OBJECT_H
13 #include /**/ "ace/pre.h"
15 #include "ace/Shared_Object.h"
16 #include "ace/Svc_Conf_Tokens.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ace/Event_Handler.h"
23 #include "ace/DLL.h"
25 #include "ace/Service_Gestalt.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
29 #define ACE_Component ACE_Service_Object
31 /**
32 * @class ACE_Service_Object
34 * @brief Provide the abstract base class common to all service
35 * implementations.
37 * Classes that inherit from ACE_Service_Objects are capable
38 * of being registered with the ACE_Reactor (due to the
39 * ACE_Event_Handler, as well as being dynamically linked by
40 * the ACE_Service_Config (due to the ACE_Shared_Object).
42 class ACE_Export ACE_Service_Object
43 : public ACE_Event_Handler,
44 public ACE_Shared_Object
46 public:
47 /// Constructor.
48 ACE_Service_Object (ACE_Reactor * = 0);
50 /// Destructor.
51 virtual ~ACE_Service_Object ();
53 /// Temporarily disable a service without removing it completely.
54 virtual int suspend ();
56 /// Re-enable a previously suspended service.
57 virtual int resume ();
59 /// Declare the dynamic allocation hooks.
60 ACE_ALLOC_HOOK_DECLARE;
63 // Forward decl.
64 class ACE_Service_Type_Impl;
66 /**
67 * @class ACE_Service_Type
69 * @brief Keeps track of information related to the various
70 * ACE_Service_Type_Impl subclasses.
72 * This class acts as the interface of the "Bridge" pattern.
74 class ACE_Export ACE_Service_Type
76 public:
77 enum
79 /// Delete the payload object.
80 DELETE_OBJ = 1,
82 /// Delete the enclosing object.
83 DELETE_THIS = 2
86 enum
88 SERVICE_OBJECT = ACE_SVC_OBJ_T,
89 MODULE = ACE_MODULE_T,
90 STREAM = ACE_STREAM_T,
91 INVALID_TYPE = -1
94 ACE_Service_Type (const ACE_TCHAR *n,
95 ACE_Service_Type_Impl *o,
96 const ACE_DLL &dll,
97 bool active);
98 ACE_Service_Type (const ACE_TCHAR *n,
99 ACE_Service_Type_Impl *o,
100 ACE_SHLIB_HANDLE handle,
101 bool active);
102 ~ACE_Service_Type ();
104 const ACE_TCHAR *name () const;
105 void name (const ACE_TCHAR *);
107 const ACE_Service_Type_Impl *type () const;
108 void type (const ACE_Service_Type_Impl *, bool active = true);
110 /// Is this just a stub for the real thing?
111 bool is_forward_declaration () const;
113 int suspend () const;
114 int resume () const;
115 bool active () const;
116 void active (bool turnon);
118 /// Calls @c fini on @c type_
119 int fini ();
121 /// Check if the service has been fini'ed.
122 bool fini_called () const;
124 /// Dump the state of an object.
125 void dump () const;
127 /// Get to the DLL's implentation
128 const ACE_DLL & dll () const;
130 /// Sets the DLL
131 void dll (const ACE_DLL&);
133 /// Declare the dynamic allocation hooks.
134 ACE_ALLOC_HOOK_DECLARE;
136 private:
137 /// Humanly readible name of svc.
138 const ACE_TCHAR *name_;
140 /// Pointer to C++ object that implements the svc.
141 const ACE_Service_Type_Impl *type_;
143 /// ACE_DLL representing the shared object file (non-zero if
144 /// dynamically linked).
145 mutable ACE_DLL dll_;
147 /// true if svc is currently active, otherwise false.
148 bool active_;
150 /// true if @c fini on @c type_ has already been called, otherwise false.
151 bool fini_already_called_;
155 * @class ACE_Service_Object_Ptr
157 * @brief This is a smart pointer that holds onto the associated
158 * ACE_Service_Object * until the current scope is left, at
159 * which point the object's fini() hook is called and the
160 * service_object_ gets deleted.
162 * This class is similar to the Standard C++ Library class
163 * auto_ptr. It is used in conjunction with statically linked
164 * ACE_Service_Objects, as shown in the ./netsvcs/server/main.cpp example.
166 class ACE_Export ACE_Service_Object_Ptr
168 public:
169 /// Acquire ownership of the @a so.
170 ACE_Service_Object_Ptr (ACE_Service_Object *so);
172 /// Release the held ACE_Service_Object by calling its fini() hook.
173 ~ACE_Service_Object_Ptr ();
175 /// Smart pointer to access the underlying ACE_Service_Object.
176 ACE_Service_Object *operator-> ();
178 private:
179 /// Holds the service object until we're done.
180 ACE_Service_Object *service_object_;
183 ACE_END_VERSIONED_NAMESPACE_DECL
185 #if defined (__ACE_INLINE__)
186 #include "ace/Service_Object.inl"
187 #endif /* __ACE_INLINE__ */
189 #include /**/ "ace/post.h"
190 #endif /* ACE_SERVICE_OBJECT_H */