Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / Service_Object.cpp
blob79060626410e0b7dbff63b66fe550f92c8b528eb
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"
18 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
20 ACE_ALLOC_HOOK_DEFINE(ACE_Service_Object)
21 ACE_ALLOC_HOOK_DEFINE(ACE_Service_Type)
23 void
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,
41 this->active_);
42 #endif
45 ACE_Service_Type::ACE_Service_Type (const ACE_TCHAR *n,
46 ACE_Service_Type_Impl *t,
47 const ACE_DLL &dll,
48 bool active)
49 : name_ (0),
50 type_ (t),
51 dll_ (dll),
52 active_ (active),
53 fini_already_called_ (false)
55 ACE_TRACE ("ACE_Service_Type::ACE_Service_Type");
56 this->name (n);
59 ACE_Service_Type::ACE_Service_Type (const ACE_TCHAR *n,
60 ACE_Service_Type_Impl *t,
61 ACE_SHLIB_HANDLE handle,
62 bool active)
63 : name_ (0),
64 type_ (t),
65 active_ (active),
66 fini_already_called_ (false)
68 ACE_TRACE ("ACE_Service_Type::ACE_Service_Type");
69 this->dll_.set_handle (handle);
70 this->name (n);
73 ACE_Service_Type::~ACE_Service_Type ()
75 ACE_TRACE ("ACE_Service_Type::~ACE_Service_Type");
76 this->fini ();
78 #if defined (ACE_HAS_ALLOC_HOOKS)
79 ACE_Allocator::instance()->free(const_cast <ACE_TCHAR *> (this->name_));
80 #else
81 delete [] const_cast <ACE_TCHAR *> (this->name_);
82 #endif /* ACE_HAS_ALLOC_HOOKS */
85 int
86 ACE_Service_Type::fini ()
88 if (ACE::debug ())
89 ACELIB_DEBUG ((LM_DEBUG,
90 ACE_TEXT ("ACE (%P|%t) ST::fini - destroying name=%s, dll=%s\n"),
91 this->name_,
92 this->dll_.dll_name_));
94 if (this->fini_already_called_)
95 return 0;
97 this->fini_already_called_ = true;
99 if (this->type_ == 0)
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)
105 // static services
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.
113 this->type_ = 0;
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");
153 return 0;
157 ACE_Service_Object::resume ()
159 ACE_TRACE ("ACE_Service_Object::resume");
160 return 0;
163 void
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_));
170 #else
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