1 #include "Svcconf_Handler.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/Service_Config.h"
5 #include "ace/Service_Types.h"
6 #include "ace/Service_Repository.h"
7 #include "ace/Service_Gestalt.h"
10 #include "ace/Module.h"
11 #include "ace/OS_NS_strings.h"
12 #include "ace/SString.h"
14 #if (ACE_USES_CLASSIC_SVC_CONF == 0)
16 #if !defined (__ACEXML_INLINE__)
17 # include "Svcconf_Handler.inl"
18 #endif /* __ACEXML_INLINE__ */
20 ACEXML_Svcconf_Handler::ACEXML_Svcconf_Handler ()
28 ACEXML_Svcconf_Handler::~ACEXML_Svcconf_Handler ()
33 ACEXML_Svcconf_Handler::characters (const ACEXML_Char
*,
40 ACEXML_Svcconf_Handler::endDocument ()
45 ACEXML_Svcconf_Handler::endElement (const ACEXML_Char
*,
47 const ACEXML_Char
*qName
)
49 if (ACE_OS::strcmp (qName
, ACE_TEXT ("dynamic")) == 0)
51 ACE_Parsed_Info
*active_info
= (this->in_stream_def_
== 0 ?
55 // We must allocate a string here to ensure that the
56 // name is still available by the time the
57 // ACE_Service_Type_Dynamic_Guard is destructed.
58 ACE_TString name
= active_info
->name ();
59 ACE_Service_Type_Dynamic_Guard
dummy (
60 *ACE_Service_Config::current ()->current_service_repository (),
64 if (svc_dll
.open (active_info
->path ()) == -1)
66 // build the error message
67 ACE_TString
msg (ACE_TEXT ("Cannot locate DLL: '"));
68 msg
+= ACE_TString (active_info
->path ());
69 msg
+= ACE_TString (ACE_TEXT ("' for entity '"));
70 msg
+= ACE_TString (active_info
->name ());
71 msg
+= ACE_TString (ACE_TEXT ("'\n"));
73 throw ACEXML_SAXException (msg
.c_str ());
76 void *(*func
) (ACE_Service_Object_Exterminator
*) = 0;
77 ACE_Service_Object_Exterminator gobbler
= 0;
81 reinterpret_cast<long> (svc_dll
.symbol (active_info
->init_func ()));
82 func
= reinterpret_cast<void *(*)(ACE_Service_Object_Exterminator
*)> (temp_ptr
);
86 // build the error message
87 ACE_TString
msg (ACE_TEXT ("Cannot locate init function: '"));
88 msg
+= ACE_TString (active_info
->init_func ());
89 msg
+= ACE_TString (ACE_TEXT ("' for entity '"));
90 msg
+= ACE_TString (active_info
->name ());
91 msg
+= ACE_TString (ACE_TEXT ("'\n"));
93 throw ACEXML_SAXException (msg
.c_str ());
95 symbol
= (*func
)(&gobbler
); // target object created in the loaded DLL.
97 ACE_Service_Type_Impl
*stp
= ACE_Service_Config::create_service_type_impl
98 (active_info
->name (),
99 active_info
->service_type (),
101 ACE_Service_Type::DELETE_THIS
|
102 ACE_Service_Type::DELETE_OBJ
,
105 if (this->in_stream_def_
)
107 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Create dynamic %s for stream\n"),
108 // this->stream_info_.name ()));
109 if (active_info
->service_type () == ACE_Service_Type::STREAM
)
111 this->stream_
= (ACE_Stream_Type
*) stp
;
115 // We will not retain this stream
118 // build the error message
119 ACE_TString
msg (ACE_TEXT ("Expecting Stream type in stream header"));
120 msg
+= ACE_TString (ACE_TEXT (" for entity '"));
121 msg
+= ACE_TString (active_info
->name ());
122 msg
+= ACE_TString (ACE_TEXT ("'\n"));
124 throw ACEXML_SAXException (msg
.c_str ());
127 this->stream_svc_type_
=
128 ACE_Service_Config::create_service_type (this->stream_info_
.name (),
131 this->stream_info_
.active ());
135 if (this->in_module_
)
137 ACE_ARGV
args (active_info
->init_params ());
139 ACE_Module_Type
*mt
= (ACE_Module_Type
*) stp
;
141 ACE_Module
<ACE_SYNCH
> *mp
= (ACE_Module
<ACE_SYNCH
> *) mt
->object ();
143 if (ACE_OS::strcmp (mp
->name (), active_info
->name ()) != 0)
145 ACE_DEBUG ((LM_DEBUG
,
146 ACE_TEXT ("warning: assigning Module_Type name %s to Module %s since names differ\n"),
147 active_info
->name (),
149 mp
->name (active_info
->name ());
152 if (mt
->init (args
.argc (), args
.argv ()) == -1
153 || this->stream_
->push (mt
) == -1)
155 // build the error message
156 ACE_TString
msg (ACE_TEXT ("Error initializing module"));
157 msg
+= ACE_TString (ACE_TEXT (" for entity '"));
158 msg
+= ACE_TString (active_info
->name ());
159 msg
+= ACE_TString (ACE_TEXT ("'\n"));
161 throw ACEXML_SAXException (msg
.c_str ());
165 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Push dynamic %s into stream %s\n"),
166 // this->parsed_info_.name (),
167 // this->stream_info_.name ()));
171 ACE_Service_Type
*stype
=
172 ACE_Service_Config::create_service_type (active_info
->name (),
175 active_info
->active ());
176 // @@ Check error here.
178 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Apply dynamic %s\n"),
179 // this->parsed_info_.name ()));
180 if (ACE_Service_Config::initialize (stype
,
181 active_info
->init_params ()) == -1)
183 // If it did not initialize correctly, the
184 // ACE_Service_Config doesn't own this object
187 // build the error message
188 ACE_TString
msg (ACE_TEXT ("Failed to initialize dynamic service"));
189 msg
+= ACE_TString (ACE_TEXT (" for entity '"));
190 msg
+= ACE_TString (active_info
->name ());
191 msg
+= ACE_TString (ACE_TEXT ("'\n"));
193 throw ACEXML_SAXException (msg
.c_str ());
196 this->parsed_info_
.reset ();
199 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("static")) == 0)
201 if (this->in_stream_def_
)
203 // @@ Couldn't make sense out of the original Svc_Conf.y.
204 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("Create static %s for stream\n"),
205 this->stream_info_
.name ()));
209 if (this->in_module_
)
211 // @@ Couldn't make sense out of the original Svc_Conf.y.
212 ACE_DEBUG ((LM_ERROR
, ACE_TEXT ("Push static %s into stream %s\n"),
213 this->parsed_info_
.name (),
214 this->stream_info_
.name ()));
218 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Apply static %s\n"),
219 // this->parsed_info_.name ()));
220 if (ACE_Service_Config::initialize (this->parsed_info_
.name (),
221 this->parsed_info_
.init_params ()) == -1)
223 // build the error message
224 ACE_TString
msg (ACE_TEXT ("Failed to initialize static service"));
225 msg
+= ACE_TString (ACE_TEXT (" for entity '"));
226 msg
+= ACE_TString (this->parsed_info_
.name ());
227 msg
+= ACE_TString (ACE_TEXT ("'\n"));
229 throw ACEXML_SAXException (msg
.c_str ());
232 this->parsed_info_
.reset ();
235 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("module")) == 0)
237 this->in_module_
= 0;
239 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("streamdef")) == 0)
241 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Apply stream %s of type %s\n"),
242 // this->stream_info_.name (),
243 // this->stream_info_.name ()));
244 ACE_Service_Config::initialize (this->stream_svc_type_
,
245 this->stream_info_
.init_params ());
247 this->stream_info_
.reset ();
248 this->stream_svc_type_
= 0;
251 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("stream")) == 0)
253 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Apply stream %s of type %s\n"),
254 // this->stream_info_.name (),
255 // this->stream_info_.name ()));
256 this->stream_info_
.reset ();
264 ACEXML_Svcconf_Handler::endPrefixMapping (const ACEXML_Char
*)
269 ACEXML_Svcconf_Handler::ignorableWhitespace (const ACEXML_Char
*,
276 ACEXML_Svcconf_Handler::processingInstruction (const ACEXML_Char
*,
282 ACEXML_Svcconf_Handler::setDocumentLocator (ACEXML_Locator
* locator
)
284 this->locator_
= locator
;
288 ACEXML_Svcconf_Handler::skippedEntity (const ACEXML_Char
*)
293 ACEXML_Svcconf_Handler::startDocument ()
298 ACEXML_Svcconf_Handler::startElement (const ACEXML_Char
*,
300 const ACEXML_Char
*qName
,
301 ACEXML_Attributes
*alist
)
303 if (ACE_OS::strcmp (qName
, ACE_TEXT ("dynamic")) == 0)
305 this->get_dynamic_attrs (alist
);
307 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("initializer")) == 0)
309 this->get_initializer_attrs (alist
);
311 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("static")) == 0)
313 this->get_static_attrs (alist
);
315 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("stream")) == 0)
317 this->get_stream_id (alist
);
319 if (ACE_Service_Repository::instance()->find
320 (this->stream_info_
.name (),
321 (const ACE_Service_Type
**) &this->stream_svc_type_
) == -1)
323 // build the error message
324 ACE_TString
msg (ACE_TEXT ("Cannot find stream '"));
325 msg
+= ACE_TString (this->stream_info_
.name ());
326 msg
+= ACE_TString (ACE_TEXT ("'\n"));
328 throw ACEXML_SAXException (msg
.c_str ());
330 this->stream_
= this->stream_svc_type_
== 0
332 : dynamic_cast<ACE_Stream_Type
*> (const_cast<ACE_Service_Type_Impl
*> (this->stream_svc_type_
->type ()));
334 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Retrieve stream %s from repository\n"),
335 // this->stream_info_.name ()));
337 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("streamdef")) == 0)
339 this->in_stream_def_
= 1;
340 // @@ Set up stream service object
342 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("module")) == 0)
344 this->in_stream_def_
= 0;
345 this->in_module_
= 1;
347 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("resume")) == 0)
349 this->get_id (alist
);
350 if (this->in_module_
)
352 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Resume %s in stream %s\n"),
353 // this->parsed_info_.name (),
354 // this->stream_info_.name ()));
355 ACE_Module_Type
*mt
= (this->stream_
== 0)
357 : this->stream_
->find (this->parsed_info_
.name ());
361 // build the error message
362 ACE_TString
msg (ACE_TEXT ("Can't locate module '"));
363 msg
+= ACE_TString (this->parsed_info_
.name ());
364 msg
+= ACE_TString (ACE_TEXT ("'\n"));
366 throw ACEXML_SAXException (msg
.c_str ());
373 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Resume %s\n"),
374 // this->parsed_info_.name ()));
375 if (ACE_Service_Config::resume (this->parsed_info_
.name ()) == -1)
377 // build the error message
378 ACE_TString
msg (ACE_TEXT ("Resume failed"));
379 msg
+= ACE_TString (ACE_TEXT (" for entity '"));
380 msg
+= ACE_TString (this->parsed_info_
.name ());
381 msg
+= ACE_TString (ACE_TEXT ("'\n"));
383 throw ACEXML_SAXException (msg
.c_str ());
386 this->parsed_info_
.reset ();
388 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("suspend")) == 0)
390 this->get_id (alist
);
391 if (this->in_module_
)
393 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Suspend %s in stream %s\n"),
394 // this->parsed_info_.name (),
395 // this->stream_info_.name ()));
396 ACE_Module_Type
*mt
= (this->stream_
== 0)
398 : this->stream_
->find (this->parsed_info_
.name ());
402 // build the error message
403 ACE_TString
msg (ACE_TEXT ("Can't locate module '"));
404 msg
+= ACE_TString (this->parsed_info_
.name ());
405 msg
+= ACE_TString (ACE_TEXT ("'\n"));
407 throw ACEXML_SAXException (msg
.c_str ());
414 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Suspend %s\n"),
415 // this->parsed_info_.name ()));
416 if (ACE_Service_Config::suspend (this->parsed_info_
.name ()) == -1)
418 // build the error message
419 ACE_TString
msg (ACE_TEXT ("Suspend failed"));
420 msg
+= ACE_TString (ACE_TEXT (" for entity '"));
421 msg
+= ACE_TString (this->parsed_info_
.name ());
422 msg
+= ACE_TString (ACE_TEXT ("'\n"));
424 throw ACEXML_SAXException (msg
.c_str ());
427 this->parsed_info_
.reset ();
429 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("remove")) == 0)
431 this->get_id (alist
);
432 if (this->in_module_
)
434 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Remove %s in stream %s\n"),
435 // this->parsed_info_.name (),
436 // this->stream_info_.name ()));
437 ACE_Module_Type
*mt
= (this->stream_
== 0)
439 : this->stream_
->find (this->parsed_info_
.name ());
443 // build the error message
444 ACE_TString
msg (ACE_TEXT ("Can't locate module '"));
445 msg
+= ACE_TString (this->parsed_info_
.name ());
446 msg
+= ACE_TString (ACE_TEXT ("'\n"));
448 throw ACEXML_SAXException (msg
.c_str ());
451 this->stream_
->remove (mt
);
455 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("Remove %s\n"),
456 // this->parsed_info_.name ()));
457 if (ACE_Service_Config::remove (this->parsed_info_
.name ()) == -1)
459 // build the error message
460 ACE_TString
msg (ACE_TEXT ("Remove failed"));
461 msg
+= ACE_TString (ACE_TEXT (" for entity '"));
462 msg
+= ACE_TString (this->parsed_info_
.name ());
463 msg
+= ACE_TString (ACE_TEXT ("'\n"));
465 throw ACEXML_SAXException (msg
.c_str ());
468 this->parsed_info_
.reset ();
470 else if (ACE_OS::strcmp (qName
, ACE_TEXT ("ACE_Svc_Conf")) == 0)
472 // Main document tag. no-op.
473 // ACE_DEBUG ((LM_INFO, ACE_TEXT ("ACE_Svc_Conf tag\n")));
477 // @@ Error. Perhaps we should relay to user event handler here, if available.
484 ACEXML_Svcconf_Handler::startPrefixMapping (const ACEXML_Char
*,
490 // *** Methods inherit from ACEXML_DTDHandler.
493 ACEXML_Svcconf_Handler::notationDecl (const ACEXML_Char
*,
501 ACEXML_Svcconf_Handler::unparsedEntityDecl (const ACEXML_Char
*,
509 // Methods inherit from ACEXML_EnitityResolver.
512 ACEXML_Svcconf_Handler::resolveEntity (const ACEXML_Char
*,
519 // Methods inherit from ACEXML_ErrorHandler.
522 * Receive notification of a recoverable error.
525 ACEXML_Svcconf_Handler::error (ACEXML_SAXParseException
& ex
)
527 ACE_DEBUG ((LM_DEBUG
, "%s: line :%d col: %d ", this->locator_
->getSystemId(),
528 this->locator_
->getLineNumber(),
529 this->locator_
->getColumnNumber()));
534 ACEXML_Svcconf_Handler::fatalError (ACEXML_SAXParseException
& ex
)
536 ACE_DEBUG ((LM_DEBUG
, "%s: line :%d col: %d ", this->locator_
->getSystemId(),
537 this->locator_
->getLineNumber(),
538 this->locator_
->getColumnNumber()));
543 ACEXML_Svcconf_Handler::warning (ACEXML_SAXParseException
& ex
)
545 ACE_DEBUG ((LM_DEBUG
, "%s: line :%d col: %d ", this->locator_
->getSystemId(),
546 this->locator_
->getLineNumber(),
547 this->locator_
->getColumnNumber()));
552 ACEXML_Svcconf_Handler::get_stream_id (ACEXML_Attributes
*alist
)
555 for (size_t i
= 0; i
< alist
->getLength (); ++i
)
557 if (ACE_OS::strcmp (alist
->getQName (i
), ACE_TEXT ("id")) == 0)
559 this->stream_info_
.name (alist
->getValue (i
));
563 // build the error message
564 ACE_TString
msg (ACE_TEXT ("Invalid stream attribute '"));
565 msg
+= ACE_TString (alist
->getQName (i
));
566 msg
+= ACE_TString (ACE_TEXT ("' for entity '"));
567 msg
+= ACE_TString (this->stream_info_
.name ());
568 msg
+= ACE_TString (ACE_TEXT ("'\n"));
570 throw ACEXML_SAXException (msg
.c_str ());
577 ACEXML_Svcconf_Handler::get_id (ACEXML_Attributes
*alist
)
580 for (size_t i
= 0; i
< alist
->getLength (); ++i
)
582 if (ACE_OS::strcmp (alist
->getQName (i
), ACE_TEXT ("id")) == 0)
584 this->parsed_info_
.name (alist
->getValue (i
));
588 // build the error message
589 ACE_TString
msg (ACE_TEXT ("Invalid attribute '"));
590 msg
+= ACE_TString (alist
->getQName (i
));
591 msg
+= ACE_TString (ACE_TEXT ("', expecting 'id'"));
592 msg
+= ACE_TString (ACE_TEXT (" for entity '"));
593 msg
+= ACE_TString (this->parsed_info_
.name ());
594 msg
+= ACE_TString (ACE_TEXT ("'\n"));
596 throw ACEXML_SAXException (msg
.c_str ());
603 ACEXML_Svcconf_Handler::get_dynamic_attrs (ACEXML_Attributes
*alist
)
607 ACE_Parsed_Info
*info
= (this->in_stream_def_
== 0 ?
608 &this->parsed_info_
:
609 &this->stream_info_
);
610 for (size_t i
= 0; i
< alist
->getLength (); ++i
)
612 if (ACE_OS::strcmp (alist
->getQName (i
), ACE_TEXT ("id")) == 0)
614 info
->name (alist
->getValue (i
));
616 else if (ACE_OS::strcmp (alist
->getQName (i
), ACE_TEXT ("status")) == 0)
618 if (ACE_OS::strcmp (alist
->getValue (i
), ACE_TEXT ("inactive")) == 0)
622 else if (ACE_OS::strcmp (alist
->getValue (i
), ACE_TEXT ("active")) == 0)
628 // build the error message
629 ACE_TString
msg (ACE_TEXT ("Invalid attribute value '"));
630 msg
+= ACE_TString (alist
->getQName (i
));
631 msg
+= ACE_TString (ACE_TEXT ("', expecting 'active' or 'inactive'"));
632 msg
+= ACE_TString (ACE_TEXT (" for entity '"));
633 msg
+= ACE_TString (info
->name ());
634 msg
+= ACE_TString (ACE_TEXT ("'\n"));
636 throw ACEXML_SAXException (msg
.c_str ());
639 else if (ACE_OS::strcmp (alist
->getQName (i
), ACE_TEXT ("type")) == 0)
641 if (ACE_OS::strcasecmp (alist
->getValue (i
), ACE_TEXT ("service_object")) == 0)
643 info
->service_type (ACE_Service_Type::SERVICE_OBJECT
);
645 else if (ACE_OS::strcasecmp (alist
->getValue (i
), ACE_TEXT ("stream")) == 0)
647 info
->service_type (ACE_Service_Type::STREAM
);
649 else if (ACE_OS::strcasecmp (alist
->getValue (i
), ACE_TEXT ("module")) == 0)
651 info
->service_type (ACE_Service_Type::MODULE
);
655 // build the error message
656 ACE_TString
msg (ACE_TEXT ("Invalid Service_Object attribute value'"));
657 msg
+= ACE_TString (alist
->getQName (i
));
658 msg
+= ACE_TString (ACE_TEXT ("' for entity '"));
659 msg
+= ACE_TString (info
->name ());
660 msg
+= ACE_TString (ACE_TEXT ("'\n"));
662 throw ACEXML_SAXException (msg
.c_str ());
667 // build the error message
668 ACE_TString
msg (ACE_TEXT ("Invalid attribute'"));
669 msg
+= ACE_TString (alist
->getQName (i
));
670 msg
+= ACE_TString (ACE_TEXT ("' for entity '"));
671 msg
+= ACE_TString (info
->name ());
672 msg
+= ACE_TString (ACE_TEXT ("'\n"));
674 throw ACEXML_SAXException (msg
.c_str ());
682 ACEXML_Svcconf_Handler::get_initializer_attrs (ACEXML_Attributes
*alist
)
686 ACE_Parsed_Info
*info
= (this->in_stream_def_
== 0 ?
687 &this->parsed_info_
:
688 &this->stream_info_
);
689 for (size_t i
= 0; i
< alist
->getLength (); ++i
)
691 if (ACE_OS::strcmp (alist
->getQName (i
), ACE_TEXT ("init")) == 0)
693 info
->init_func (alist
->getValue (i
));
695 else if (ACE_OS::strcmp (alist
->getQName (i
), ACE_TEXT ("path")) == 0)
697 info
->path (alist
->getValue (i
));
699 else if (ACE_OS::strcmp (alist
->getQName (i
), ACE_TEXT ("params")) == 0)
701 info
->init_params (alist
->getValue (i
));
705 // build the error message
706 ACE_TString
msg (ACE_TEXT ("Invalid initializer attribute'"));
707 msg
+= ACE_TString (alist
->getQName (i
));
708 msg
+= ACE_TString (ACE_TEXT ("' for entity '"));
709 msg
+= ACE_TString (info
->name ());
710 msg
+= ACE_TString (ACE_TEXT ("'\n"));
712 throw ACEXML_SAXException (msg
.c_str ());
720 ACEXML_Svcconf_Handler::get_static_attrs (ACEXML_Attributes
*alist
)
724 ACE_Parsed_Info
*info
= (this->in_stream_def_
== 0 ?
725 &this->parsed_info_
:
726 &this->stream_info_
);
727 for (size_t i
= 0; i
< alist
->getLength (); ++i
)
729 if (ACE_OS::strcmp (alist
->getQName (i
), ACE_TEXT ("id")) == 0)
731 info
->name (alist
->getValue (i
));
733 else if (ACE_OS::strcmp (alist
->getQName (i
), ACE_TEXT ("params")) == 0)
735 info
->init_params (alist
->getValue (i
));
739 // build the error message
740 ACE_TString
msg (ACE_TEXT ("Invalid static attribute '"));
741 msg
+= ACE_TString (alist
->getQName (i
));
742 msg
+= ACE_TString (ACE_TEXT ("' for entity '"));
743 msg
+= ACE_TString (info
->name ());
744 msg
+= ACE_TString (ACE_TEXT ("'\n"));
746 throw ACEXML_SAXException (msg
.c_str ());
753 #endif /* ACE_USES_CLASSIC_SVC_CONF == 0 */