Correct feature names
[ACE_TAO.git] / ACE / ace / Service_Object.cpp
bloba16b9af04f234c5ec8ad89cb99dd2b1e5ad9faca
1 #include "ace/config-all.h"
3 #include "ace/Service_Object.h"
4 #if defined (ACE_HAS_ALLOC_HOOKS)
5 # include "ace/Malloc_Base.h"
6 #endif /* ACE_HAS_ALLOC_HOOKS */
8 #if !defined (__ACE_INLINE__)
9 #include "ace/Service_Object.inl"
10 #endif /* __ACE_INLINE__ */
12 #include "ace/OS_NS_stdio.h"
13 #include "ace/Service_Types.h"
14 #include "ace/DLL.h"
15 #include "ace/ACE.h"
16 #include "ace/Log_Category.h"
17 #if defined (ACE_OPENVMS)
18 # include "ace/Lib_Find.h"
19 #endif
21 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
23 ACE_ALLOC_HOOK_DEFINE(ACE_Service_Object)
24 ACE_ALLOC_HOOK_DEFINE(ACE_Service_Type)
26 void
27 ACE_Service_Type::dump (void) const
29 #if defined (ACE_HAS_DUMP)
30 ACE_TRACE ("ACE_Service_Type::dump");
31 #endif /* ACE_HAS_DUMP */
33 // Using printf, since the log facility may not have been
34 // initialized yet. Using a "//" prefix, in case the executable
35 // happens to be a code generator and the output gets embedded in
36 // the generated C++ code.
37 #ifndef ACE_LACKS_STDERR
38 ACE_OS::fprintf(stderr,
39 "// [ST] dump, this=%p, name=%s, type=%p, so=%p, active=%d\n",
40 static_cast<void const *> (this),
41 ACE_TEXT_ALWAYS_CHAR (this->name_),
42 static_cast<void const *> (this->type_),
43 (this->type_ != 0) ? this->type_->object () : 0,
44 this->active_);
45 #endif
48 ACE_Service_Type::ACE_Service_Type (const ACE_TCHAR *n,
49 ACE_Service_Type_Impl *t,
50 const ACE_DLL &dll,
51 bool active)
52 : name_ (0),
53 type_ (t),
54 dll_ (dll),
55 active_ (active),
56 fini_already_called_ (false)
58 ACE_TRACE ("ACE_Service_Type::ACE_Service_Type");
59 this->name (n);
62 ACE_Service_Type::ACE_Service_Type (const ACE_TCHAR *n,
63 ACE_Service_Type_Impl *t,
64 ACE_SHLIB_HANDLE handle,
65 bool active)
66 : name_ (0),
67 type_ (t),
68 active_ (active),
69 fini_already_called_ (false)
71 ACE_TRACE ("ACE_Service_Type::ACE_Service_Type");
72 this->dll_.set_handle (handle);
73 this->name (n);
76 ACE_Service_Type::~ACE_Service_Type (void)
78 ACE_TRACE ("ACE_Service_Type::~ACE_Service_Type");
79 this->fini ();
81 #if defined (ACE_HAS_ALLOC_HOOKS)
82 ACE_Allocator::instance()->free(const_cast <ACE_TCHAR *> (this->name_));
83 #else
84 delete [] const_cast <ACE_TCHAR *> (this->name_);
85 #endif /* ACE_HAS_ALLOC_HOOKS */
88 int
89 ACE_Service_Type::fini (void)
91 if (ACE::debug ())
92 ACELIB_DEBUG ((LM_DEBUG,
93 ACE_TEXT ("ACE (%P|%t) ST::fini - destroying name=%s, dll=%s\n"),
94 this->name_,
95 this->dll_.dll_name_));
97 if (this->fini_already_called_)
98 return 0;
100 this->fini_already_called_ = true;
102 if (this->type_ == 0)
104 // Returning 1 currently only makes sense for dummy instances, used
105 // to "reserve" a spot (kind of like forward-declarations) for a
106 // dynamic service. This is necessary to help enforce the correct
107 // finalization order, when such service also has any (dependent)
108 // static services
110 return 1; // No implementation was found.
113 int ret = this->type_->fini ();
115 // Ensure type is 0 to prevent invalid access after call to fini.
116 this->type_ = 0;
118 // Ensure that closing the DLL is done after type_->fini() as it may
119 // require access to the code for the service object destructor,
120 // which resides in the DLL
122 return (ret | this->dll_.close ());
126 ACE_Service_Type::suspend (void) const
128 ACE_TRACE ("ACE_Service_Type::suspend");
129 (const_cast<ACE_Service_Type *> (this))->active_ = false;
130 return this->type_->suspend ();
134 ACE_Service_Type::resume (void) const
136 ACE_TRACE ("ACE_Service_Type::resume");
137 (const_cast<ACE_Service_Type *> (this))->active_ = true;
138 return this->type_->resume ();
141 ACE_Service_Object::ACE_Service_Object (ACE_Reactor *r)
142 : ACE_Event_Handler (r)
144 ACE_TRACE ("ACE_Service_Object::ACE_Service_Object");
147 ACE_Service_Object::~ACE_Service_Object (void)
149 ACE_TRACE ("ACE_Service_Object::~ACE_Service_Object");
153 ACE_Service_Object::suspend (void)
155 ACE_TRACE ("ACE_Service_Object::suspend");
156 return 0;
160 ACE_Service_Object::resume (void)
162 ACE_TRACE ("ACE_Service_Object::resume");
163 return 0;
166 void
167 ACE_Service_Type::name (const ACE_TCHAR *n)
169 ACE_TRACE ("ACE_Service_Type::name");
171 #if defined (ACE_HAS_ALLOC_HOOKS)
172 ACE_Allocator::instance()->free(const_cast <ACE_TCHAR *> (this->name_));
173 #else
174 delete [] const_cast <ACE_TCHAR *> (this->name_);
175 #endif /* ACE_HAS_ALLOC_HOOKS */
177 this->name_ = ACE::strnew (n);
180 #if defined (ACE_OPENVMS)
181 ACE_Dynamic_Svc_Registrar::ACE_Dynamic_Svc_Registrar (const ACE_TCHAR* alloc_name,
182 void* svc_allocator)
184 // register service allocator function by full name in ACE singleton registry
185 ACE::ldregister (alloc_name, svc_allocator);
187 #endif
189 ACE_END_VERSIONED_NAMESPACE_DECL