1 #include "ace/Service_Types.h"
3 #if !defined (__ACE_INLINE__)
4 #include "ace/Service_Types.inl"
5 #endif /* __ACE_INLINE__ */
7 #include "ace/Stream_Modules.h"
8 #include "ace/Stream.h"
9 #include "ace/OS_NS_stdio.h"
10 #include "ace/OS_NS_string.h"
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 using MT_Stream
= ACE_Stream
<ACE_MT_SYNCH
>;
15 using MT_Module
= ACE_Module
<ACE_MT_SYNCH
>;
16 using MT_Task
= ACE_Task
<ACE_MT_SYNCH
>;
18 ACE_ALLOC_HOOK_DEFINE(ACE_Service_Type_Impl
)
21 ACE_Service_Type_Impl::dump () const
23 #if defined (ACE_HAS_DUMP)
24 ACE_TRACE ("ACE_Service_Type_Impl::dump");
25 #endif /* ACE_HAS_DUMP */
28 ACE_Service_Type_Impl::ACE_Service_Type_Impl (void *so
,
29 const ACE_TCHAR
*s_name
,
31 ACE_Service_Object_Exterminator gobbler
,
39 ACE_TRACE ("ACE_Service_Type_Impl::ACE_Service_Type_Impl");
43 ACE_Service_Type_Impl::~ACE_Service_Type_Impl ()
45 ACE_TRACE ("ACE_Service_Type_Impl::~ACE_Service_Type_Impl");
47 // It's ok to call this, even though we may have already deleted it
48 // in the fini() method since it would then be NULL.
49 #if defined (ACE_HAS_ALLOC_HOOKS)
50 ACE_Allocator::instance()->free(const_cast <ACE_TCHAR
*> (this->name_
));
52 delete [] const_cast <ACE_TCHAR
*> (this->name_
);
53 #endif /* ACE_HAS_ALLOC_HOOKS */
57 ACE_Service_Type_Impl::fini () const
59 ACE_TRACE ("ACE_Service_Type_Impl::fini");
61 #if defined (ACE_HAS_ALLOC_HOOKS)
62 ACE_Allocator::instance()->free(const_cast <ACE_TCHAR
*> (this->name_
));
64 delete [] const_cast <ACE_TCHAR
*> (this->name_
);
65 #endif /* ACE_HAS_ALLOC_HOOKS */
66 (const_cast <ACE_Service_Type_Impl
*> (this))->name_
= 0;
68 if (ACE_BIT_ENABLED (this->flags_
,
69 ACE_Service_Type::DELETE_OBJ
))
72 gobbler_ (this->object ());
74 // Cast to remove const-ness.
75 operator delete ((void *) this->object ());
78 if (ACE_BIT_ENABLED (this->flags_
,
79 ACE_Service_Type::DELETE_THIS
))
80 delete const_cast <ACE_Service_Type_Impl
*> (this);
85 ACE_Service_Object_Type::ACE_Service_Object_Type (void *so
,
86 const ACE_TCHAR
*s_name
,
88 ACE_Service_Object_Exterminator gobbler
,
90 : ACE_Service_Type_Impl (so
, s_name
, f
, gobbler
, stype
)
93 ACE_TRACE ("ACE_Service_Object_Type::ACE_Service_Object_Type");
97 ACE_Service_Object_Type::init (int argc
, ACE_TCHAR
*argv
[]) const
99 ACE_TRACE ("ACE_Service_Object_Type::init");
101 void * const obj
= this->object ();
103 ACE_Service_Object
* const so
=
104 static_cast<ACE_Service_Object
*> (obj
);
109 this->initialized_
= so
->init (argc
, argv
);
111 return this->initialized_
;
115 ACE_Service_Object_Type::fini () const
117 ACE_TRACE ("ACE_Service_Object_Type::fini");
119 void * const obj
= this->object ();
121 ACE_Service_Object
* const so
=
122 static_cast<ACE_Service_Object
*> (obj
);
124 // Call fini() if an only if, the object was successfully
125 // initialized, i.e. init() returned 0. This is necessary to
126 // maintain the ctor/dtor-like semantics for init/fini.
127 if (so
!= 0 && this->initialized_
== 0)
130 return ACE_Service_Type_Impl::fini ();
133 ACE_Service_Object_Type::~ACE_Service_Object_Type ()
135 ACE_TRACE ("ACE_Service_Object_Type::~ACE_Service_Object_Type");
139 ACE_Service_Object_Type::suspend () const
141 ACE_TRACE ("ACE_Service_Object_Type::suspend");
142 return static_cast<ACE_Service_Object
*> (this->object ())->suspend ();
146 ACE_Service_Object_Type::resume () const
148 ACE_TRACE ("ACE_Service_Object_Type::resume");
149 return static_cast<ACE_Service_Object
*> (this->object ())->resume ();
153 ACE_Service_Object_Type::info (ACE_TCHAR
**str
, size_t len
) const
155 ACE_TRACE ("ACE_Service_Object_Type::info");
156 return static_cast<ACE_Service_Object
*> (this->object ())->info (str
, len
);
159 ACE_ALLOC_HOOK_DEFINE(ACE_Module_Type
)
162 ACE_Module_Type::dump () const
164 #if defined (ACE_HAS_DUMP)
165 ACE_TRACE ("ACE_Module_Type::dump");
166 #endif /* ACE_HAS_DUMP */
169 ACE_Module_Type::ACE_Module_Type (void *m
,
170 const ACE_TCHAR
*m_name
,
173 : ACE_Service_Type_Impl (m
, m_name
, f
, 0, stype
)
176 ACE_TRACE ("ACE_Module_Type::ACE_Module_Type");
179 ACE_Module_Type::~ACE_Module_Type ()
181 ACE_TRACE ("ACE_Module_Type::~ACE_Module_Type");
185 ACE_Module_Type::init (int argc
, ACE_TCHAR
*argv
[]) const
187 ACE_TRACE ("ACE_Module_Type::init");
188 void *obj
= this->object ();
189 MT_Module
*mod
= (MT_Module
*) obj
;
191 // Change the Module's name to what's in the svc.conf file. We must
192 // do this so the names match up so everything shuts down properly
193 // during the call to ACE_Stream_Type::fini which calls
194 // MT_Stream::remove([name]) for all the modules. If the calls to
195 // remove fail, we end up with a double delete during
196 // shutdown. Bugzilla #3847
198 mod
->name (this->name_
);
199 MT_Task
*reader
= mod
->reader ();
200 MT_Task
*writer
= mod
->writer ();
202 if (reader
->init (argc
, argv
) == -1
203 || writer
->init (argc
, argv
) == -1)
210 ACE_Module_Type::suspend () const
212 ACE_TRACE ("ACE_Module_Type::suspend");
213 void *obj
= this->object ();
214 MT_Module
*mod
= (MT_Module
*) obj
;
215 MT_Task
*reader
= mod
->reader ();
216 MT_Task
*writer
= mod
->writer ();
218 if (reader
->suspend () == -1
219 || writer
->suspend () == -1)
226 ACE_Module_Type::resume () const
228 ACE_TRACE ("ACE_Module_Type::resume");
229 void *obj
= this->object ();
230 MT_Module
*mod
= (MT_Module
*) obj
;
231 MT_Task
*reader
= mod
->reader ();
232 MT_Task
*writer
= mod
->writer ();
234 if (reader
->resume () == -1
235 || writer
->resume () == -1)
241 // Note, these operations are somewhat too familiar with the
242 // implementation of ACE_Module and ACE_Module::close...
245 ACE_Module_Type::fini () const
247 ACE_TRACE ("ACE_Module_Type::fini");
248 void *obj
= this->object ();
249 MT_Module
*mod
= (MT_Module
*) obj
;
250 MT_Task
*reader
= mod
->reader ();
251 MT_Task
*writer
= mod
->writer ();
259 // Close the module and delete the memory.
260 mod
->close (MT_Module::M_DELETE
);
261 return ACE_Service_Type_Impl::fini ();
265 ACE_Module_Type::info (ACE_TCHAR
**str
, size_t len
) const
267 ACE_TRACE ("ACE_Module_Type::info");
268 ACE_TCHAR buf
[BUFSIZ
];
270 ACE_OS::snprintf (buf
, BUFSIZ
,
271 ACE_TEXT ("%s\t %s"),
273 ACE_TEXT ("# ACE_Module\n"));
275 if (*str
== 0 && (*str
= ACE_OS::strdup (buf
)) == 0)
278 ACE_OS::strsncpy (*str
, buf
, len
);
279 return static_cast<int> (ACE_OS::strlen (buf
));
283 ACE_Module_Type::link (ACE_Module_Type
*n
)
285 ACE_TRACE ("ACE_Module_Type::link");
290 ACE_Module_Type::link () const
292 ACE_TRACE ("ACE_Module_Type::link");
296 ACE_ALLOC_HOOK_DEFINE(ACE_Stream_Type
)
299 ACE_Stream_Type::dump () const
301 #if defined (ACE_HAS_DUMP)
302 ACE_TRACE ("ACE_Stream_Type::dump");
303 #endif /* ACE_HAS_DUMP */
307 ACE_Stream_Type::init (int, ACE_TCHAR
*[]) const
309 ACE_TRACE ("ACE_Stream_Type::init");
314 ACE_Stream_Type::suspend () const
316 ACE_TRACE ("ACE_Stream_Type::suspend");
318 for (ACE_Module_Type
*m
= this->head_
;
327 ACE_Stream_Type::resume () const
329 ACE_TRACE ("ACE_Stream_Type::resume");
331 for (ACE_Module_Type
*m
= this->head_
;
339 ACE_Stream_Type::ACE_Stream_Type (void *s
,
340 const ACE_TCHAR
*s_name
,
343 : ACE_Service_Type_Impl (s
, s_name
, f
, 0, stype
),
346 ACE_TRACE ("ACE_Stream_Type::ACE_Stream_Type");
349 ACE_Stream_Type::~ACE_Stream_Type ()
351 ACE_TRACE ("ACE_Stream_Type::~ACE_Stream_Type");
355 ACE_Stream_Type::info (ACE_TCHAR
**str
, size_t len
) const
357 ACE_TRACE ("ACE_Stream_Type::info");
358 ACE_TCHAR buf
[BUFSIZ
];
360 ACE_OS::snprintf (buf
, BUFSIZ
,
361 ACE_TEXT ("%s\t %s"),
363 ACE_TEXT ("# STREAM\n"));
365 if (*str
== 0 && (*str
= ACE_OS::strdup (buf
)) == 0)
368 ACE_OS::strsncpy (*str
, buf
, len
);
369 return static_cast<int> (ACE_OS::strlen (buf
));
373 ACE_Stream_Type::fini () const
375 ACE_TRACE ("ACE_Stream_Type::fini");
376 void *obj
= this->object ();
377 MT_Stream
*str
= (MT_Stream
*) obj
;
379 for (ACE_Module_Type
*m
= this->head_
; m
!= 0;)
381 ACE_Module_Type
*t
= m
->link ();
383 // Final arg is an indication to *not* delete the Module.
384 str
->remove (m
->name (),
385 MT_Module::M_DELETE_NONE
);
390 return ACE_Service_Type_Impl::fini ();
393 // Locate and remove <mod_name> from the ACE_Stream.
396 ACE_Stream_Type::remove (ACE_Module_Type
*mod
)
398 ACE_TRACE ("ACE_Stream_Type::remove");
400 ACE_Module_Type
*prev
= 0;
401 void *obj
= this->object ();
402 MT_Stream
*str
= (MT_Stream
*) obj
;
405 for (ACE_Module_Type
*m
= this->head_
; m
!= 0; )
407 // We need to do this first so we don't bomb out if we delete m!
408 ACE_Module_Type
*link
= m
->link ();
417 // Final arg is an indication to *not* delete the Module.
418 if (str
->remove (m
->name (),
419 MT_Module::M_DELETE_NONE
) == -1)
422 // Do not call m->fini (); as this will result in a double delete
423 // of the ACE_Module_type when ACE_Service_Repository::fini is called
435 ACE_Stream_Type::push (ACE_Module_Type
*new_module
)
437 ACE_TRACE ("ACE_Stream_Type::push");
438 void *obj
= this->object ();
439 MT_Stream
*str
= (MT_Stream
*) obj
;
441 new_module
->link (this->head_
);
442 this->head_
= new_module
;
443 obj
= new_module
->object ();
444 return str
->push ((MT_Module
*) obj
);
448 ACE_Stream_Type::find (const ACE_TCHAR
*module_name
) const
450 ACE_TRACE ("ACE_Stream_Type::find");
452 for (ACE_Module_Type
*m
= this->head_
;
455 if (ACE_OS::strcmp (m
->name (), module_name
) == 0)
461 // @@@ Eliminated ommented out explicit template instantiation code
463 ACE_END_VERSIONED_NAMESPACE_DECL