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"
16 #include "ace/Log_Category.h"
18 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
20 ACE_ALLOC_HOOK_DEFINE(ACE_Service_Object
)
21 ACE_ALLOC_HOOK_DEFINE(ACE_Service_Type
)
24 ACE_Service_Type::dump () const
26 #if defined (ACE_HAS_DUMP)
27 ACE_TRACE ("ACE_Service_Type::dump");
28 #endif /* ACE_HAS_DUMP */
30 // Using printf, since the log facility may not have been
31 // initialized yet. Using a "//" prefix, in case the executable
32 // happens to be a code generator and the output gets embedded in
33 // the generated C++ code.
34 #ifndef ACE_LACKS_STDERR
35 ACE_OS::fprintf(stderr
,
36 "// [ST] dump, this=%p, name=%s, type=%p, so=%p, active=%d\n",
37 static_cast<void const *> (this),
38 ACE_TEXT_ALWAYS_CHAR (this->name_
),
39 static_cast<void const *> (this->type_
),
40 (this->type_
!= 0) ? this->type_
->object () : 0,
45 ACE_Service_Type::ACE_Service_Type (const ACE_TCHAR
*n
,
46 ACE_Service_Type_Impl
*t
,
53 fini_already_called_ (false)
55 ACE_TRACE ("ACE_Service_Type::ACE_Service_Type");
59 ACE_Service_Type::ACE_Service_Type (const ACE_TCHAR
*n
,
60 ACE_Service_Type_Impl
*t
,
61 ACE_SHLIB_HANDLE handle
,
66 fini_already_called_ (false)
68 ACE_TRACE ("ACE_Service_Type::ACE_Service_Type");
69 this->dll_
.set_handle (handle
);
73 ACE_Service_Type::~ACE_Service_Type ()
75 ACE_TRACE ("ACE_Service_Type::~ACE_Service_Type");
78 #if defined (ACE_HAS_ALLOC_HOOKS)
79 ACE_Allocator::instance()->free(const_cast <ACE_TCHAR
*> (this->name_
));
81 delete [] const_cast <ACE_TCHAR
*> (this->name_
);
82 #endif /* ACE_HAS_ALLOC_HOOKS */
86 ACE_Service_Type::fini ()
89 ACELIB_DEBUG ((LM_DEBUG
,
90 ACE_TEXT ("ACE (%P|%t) ST::fini - destroying name=%s, dll=%s\n"),
92 this->dll_
.dll_name_
));
94 if (this->fini_already_called_
)
97 this->fini_already_called_
= true;
101 // Returning 1 currently only makes sense for dummy instances, used
102 // to "reserve" a spot (kind of like forward-declarations) for a
103 // dynamic service. This is necessary to help enforce the correct
104 // finalization order, when such service also has any (dependent)
107 return 1; // No implementation was found.
110 int const ret
= this->type_
->fini ();
112 // Ensure type is 0 to prevent invalid access after call to fini.
115 // Ensure that closing the DLL is done after type_->fini() as it may
116 // require access to the code for the service object destructor,
117 // which resides in the DLL
119 return (ret
| this->dll_
.close ());
123 ACE_Service_Type::suspend () const
125 ACE_TRACE ("ACE_Service_Type::suspend");
126 (const_cast<ACE_Service_Type
*> (this))->active_
= false;
127 return this->type_
->suspend ();
131 ACE_Service_Type::resume () const
133 ACE_TRACE ("ACE_Service_Type::resume");
134 (const_cast<ACE_Service_Type
*> (this))->active_
= true;
135 return this->type_
->resume ();
138 ACE_Service_Object::ACE_Service_Object (ACE_Reactor
*r
)
139 : ACE_Event_Handler (r
)
141 ACE_TRACE ("ACE_Service_Object::ACE_Service_Object");
144 ACE_Service_Object::~ACE_Service_Object ()
146 ACE_TRACE ("ACE_Service_Object::~ACE_Service_Object");
150 ACE_Service_Object::suspend ()
152 ACE_TRACE ("ACE_Service_Object::suspend");
157 ACE_Service_Object::resume ()
159 ACE_TRACE ("ACE_Service_Object::resume");
164 ACE_Service_Type::name (const ACE_TCHAR
*n
)
166 ACE_TRACE ("ACE_Service_Type::name");
168 #if defined (ACE_HAS_ALLOC_HOOKS)
169 ACE_Allocator::instance()->free(const_cast <ACE_TCHAR
*> (this->name_
));
171 delete [] const_cast <ACE_TCHAR
*> (this->name_
);
172 #endif /* ACE_HAS_ALLOC_HOOKS */
174 this->name_
= ACE::strnew (n
);
177 ACE_END_VERSIONED_NAMESPACE_DECL