1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
// -*- C++ -*- $Id$
#include "Svcconf_Handler.h"
#include "ace/ACE.h"
#include "ace/Log_Msg.h"
#include "ace/Service_Config.h"
#include "ace/Service_Types.h"
#include "ace/Service_Repository.h"
#include "ace/DLL.h"
#include "ace/ARGV.h"
#include "ace/Module.h"
#if (ACE_USES_CLASSIC_SVC_CONF == 0)
#if !defined (__ACEXML_INLINE__)
# include "Svcconf_Handler.i"
#endif /* __ACEXML_INLINE__ */
ACEXML_Svcconf_Handler::ACEXML_Svcconf_Handler (void)
: in_stream_def_ (0),
in_module_ (0),
stream_svc_type_ (0),
stream_ (0)
{
// no-op
}
ACEXML_Svcconf_Handler::~ACEXML_Svcconf_Handler (void)
{
// no-op
}
void
ACEXML_Svcconf_Handler::characters (const ACEXML_Char *,
int,
int ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// no-op
}
void
ACEXML_Svcconf_Handler::endDocument ( ACEXML_ENV_SINGLE_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// no-op
}
void
ACEXML_Svcconf_Handler::endElement (const ACEXML_Char *,
const ACEXML_Char *,
const ACEXML_Char *qName ACEXML_ENV_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
if (ACE_OS_String::strcmp (qName, ACE_TEXT ("dynamic")) == 0)
{
ACE_Parsed_Info *active_info = (this->in_stream_def_ == 0 ?
&this->parsed_info_ :
&this->stream_info_);
ACE_DLL svc_dll;
if (svc_dll.open (active_info->path ()) == -1)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("Cannot locate DLL\n")));
}
void *(*func) (ACE_Service_Object_Exterminator *) = 0;
ACE_Service_Object_Exterminator gobbler = 0;
void *symbol = 0;
long temp_ptr =
ACE_reinterpret_cast(long, svc_dll.symbol (active_info->init_func ()));
func = ACE_reinterpret_cast(void *(*)(ACE_Service_Object_Exterminator *),
temp_ptr);
if (func == 0)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Cannot locate init function\n")));
}
symbol = (*func)(&gobbler); // target object created in the loaded DLL.
ACE_Service_Type_Impl *stp = ACE_Service_Config::create_service_type_impl
(active_info->name (),
active_info->service_type (),
symbol,
ACE_Service_Type::DELETE_THIS |
ACE_Service_Type::DELETE_OBJ,
gobbler);
if (this->in_stream_def_)
{
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Create dynamic %s for stream\n"),
// this->stream_info_.name ()));
if (active_info->service_type () == ACE_Service_Type::STREAM)
{
this->stream_ = (ACE_Stream_Type *) stp;
}
else
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Expecting Stream type in stream header\n")));
}
this->stream_svc_type_ =
ACE_Service_Config::create_service_type (this->stream_info_.name (),
this->stream_,
svc_dll,
this->stream_info_.active ());
}
else
{
if (this->in_module_)
{
ACE_ARGV args (active_info->init_params ());
ACE_Module_Type *mt = (ACE_Module_Type *) stp;
ACE_Module<ACE_SYNCH> *mp = (ACE_Module<ACE_SYNCH> *) mt->object ();
if (ACE_OS::strcmp (mp->name (), active_info->name ()) != 0)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("warning: assigning Module_Type name %s to Module %s since names differ\n"),
active_info->name (),
mp->name ()));
mp->name (active_info->name ());
}
if (mt->init (args.argc (), args.argv ()) == -1
|| this->stream_->push (mt) == -1)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Error initializing module")));
}
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Push dynamic %s into stream %s\n"),
// this->parsed_info_.name (),
// this->stream_info_.name ()));
}
else
{
ACE_Service_Type *stype =
ACE_Service_Config::create_service_type (active_info->name (),
stp,
svc_dll,
active_info->active ());
// @@ Check error here.
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Apply dynamic %s\n"),
// this->parsed_info_.name ()));
if (ACE_Service_Config::initialize (stype,
active_info->init_params ()) == -1)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Failed to initialize dynamic service\n")));
}
}
this->parsed_info_.reset ();
}
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("static")) == 0)
{
if (this->in_stream_def_)
{
// @@ Couldn't make sense out of the original Svc_Conf.y.
ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Create static %s for stream\n"),
this->stream_info_.name ()));
}
else
{
if (this->in_module_)
{
// @@ Couldn't make sense out of the original Svc_Conf.y.
ACE_DEBUG ((LM_ERROR, ACE_TEXT ("Push static %s into stream %s\n"),
this->parsed_info_.name (),
this->stream_info_.name ()));
}
else
{
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Apply static %s\n"),
// this->parsed_info_.name ()));
if (ACE_Service_Config::initialize (this->parsed_info_.name (),
this->parsed_info_.init_params ()) == -1)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Failed to initialize static service\n")));
}
}
this->parsed_info_.reset ();
}
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("module")) == 0)
{
this->in_module_ = 0;
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("streamdef")) == 0)
{
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Apply stream %s of type %s\n"),
// this->stream_info_.name (),
// this->stream_info_.name ()));
ACE_Service_Config::initialize (this->stream_svc_type_,
this->stream_info_.init_params ());
this->stream_info_.reset ();
this->stream_svc_type_ = 0;
this->stream_ = 0;
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("stream")) == 0)
{
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Apply stream %s of type %s\n"),
// this->stream_info_.name (),
// this->stream_info_.name ()));
this->stream_info_.reset ();
}
else
{
}
}
void
ACEXML_Svcconf_Handler::endPrefixMapping (const ACEXML_Char * ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// no-op
}
void
ACEXML_Svcconf_Handler::ignorableWhitespace (const ACEXML_Char *,
int,
int ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// no-op
}
void
ACEXML_Svcconf_Handler::processingInstruction (const ACEXML_Char *,
const ACEXML_Char * ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// no-op
}
void
ACEXML_Svcconf_Handler::setDocumentLocator (ACEXML_Locator* locator)
{
this->locator_ = locator;
}
void
ACEXML_Svcconf_Handler::skippedEntity (const ACEXML_Char * ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// no-op
}
void
ACEXML_Svcconf_Handler::startDocument ( ACEXML_ENV_SINGLE_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// no-op
}
void
ACEXML_Svcconf_Handler::startElement (const ACEXML_Char *,
const ACEXML_Char *,
const ACEXML_Char *qName,
ACEXML_Attributes *alist ACEXML_ENV_ARG_DECL)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
if (ACE_OS_String::strcmp (qName, ACE_TEXT ("dynamic")) == 0)
{
this->get_dynamic_attrs (alist ACEXML_ENV_ARG_PARAMETER);
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("initializer")) == 0)
{
this->get_initializer_attrs (alist ACEXML_ENV_ARG_PARAMETER);
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("static")) == 0)
{
this->get_static_attrs (alist ACEXML_ENV_ARG_PARAMETER);
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("stream")) == 0)
{
this->get_stream_id (alist ACEXML_ENV_ARG_PARAMETER);
if (ACE_Service_Repository::instance()->find
(this->stream_info_.name (),
(const ACE_Service_Type **) &this->stream_svc_type_) == -1)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Cannot find stream\n")));
}
this->stream_ = this->stream_svc_type_ == 0
? 0
: ACE_dynamic_cast (ACE_Stream_Type *,
ACE_const_cast (ACE_Service_Type_Impl *,
this->stream_svc_type_->type ()));
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Retrieve stream %s from repository\n"),
// this->stream_info_.name ()));
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("streamdef")) == 0)
{
this->in_stream_def_ = 1;
// @@ Set up stream service object
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("module")) == 0)
{
this->in_stream_def_ = 0;
this->in_module_ = 1;
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("resume")) == 0)
{
this->get_id (alist ACEXML_ENV_ARG_PARAMETER);
if (this->in_module_)
{
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Resume %s in stream %s\n"),
// this->parsed_info_.name (),
// this->stream_info_.name ()));
ACE_Module_Type *mt = (this->stream_ == 0)
? 0
: this->stream_->find (this->parsed_info_.name ());
if (mt == 0)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Can't locate module\n")));
}
mt->resume ();
}
else
{
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Resume %s\n"),
// this->parsed_info_.name ()));
if (ACE_Service_Config::resume (this->parsed_info_.name ()) == -1)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Resume fail\n")));
}
}
this->parsed_info_.reset ();
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("suspend")) == 0)
{
this->get_id (alist ACEXML_ENV_ARG_PARAMETER);
if (this->in_module_)
{
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Suspend %s in stream %s\n"),
// this->parsed_info_.name (),
// this->stream_info_.name ()));
ACE_Module_Type *mt = (this->stream_ == 0)
? 0
: this->stream_->find (this->parsed_info_.name ());
if (mt == 0)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Can't locate module\n")));
}
mt->suspend ();
}
else
{
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Suspend %s\n"),
// this->parsed_info_.name ()));
if (ACE_Service_Config::suspend (this->parsed_info_.name ()) == -1)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Suspend failed\n")));
}
}
this->parsed_info_.reset ();
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("remove")) == 0)
{
this->get_id (alist ACEXML_ENV_ARG_PARAMETER);
if (this->in_module_)
{
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Remove %s in stream %s\n"),
// this->parsed_info_.name (),
// this->stream_info_.name ()));
ACE_Module_Type *mt = (this->stream_ == 0)
? 0
: this->stream_->find (this->parsed_info_.name ());
if (mt == 0)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Can't locate module\n")));
}
this->stream_->remove (mt);
}
else
{
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("Remove %s\n"),
// this->parsed_info_.name ()));
if (ACE_Service_Config::remove (this->parsed_info_.name ()) == -1)
{
ACEXML_THROW (ACEXML_SAXException (ACE_TEXT ("Remove failed\n")));
}
}
this->parsed_info_.reset ();
}
else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("ACE_Svc_Conf")) == 0)
{
// Main document tag. no-op.
// ACE_DEBUG ((LM_INFO, ACE_TEXT ("ACE_Svc_Conf tag\n")));
}
else
{
// @@ Error. Perhaps we should relay to user event handler here, if available.
}
return;
}
void
ACEXML_Svcconf_Handler::startPrefixMapping (const ACEXML_Char *,
const ACEXML_Char * ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// No-op.
}
// *** Methods inherit from ACEXML_DTDHandler.
void
ACEXML_Svcconf_Handler::notationDecl (const ACEXML_Char *,
const ACEXML_Char *,
const ACEXML_Char * ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// No-op.
}
void
ACEXML_Svcconf_Handler::unparsedEntityDecl (const ACEXML_Char *,
const ACEXML_Char *,
const ACEXML_Char *,
const ACEXML_Char * ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// No-op.
}
// Methods inherit from ACEXML_EnitityResolver.
ACEXML_InputSource *
ACEXML_Svcconf_Handler::resolveEntity (const ACEXML_Char *,
const ACEXML_Char * ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
// No-op.
return 0;
}
// Methods inherit from ACEXML_ErrorHandler.
/*
* Receive notification of a recoverable error.
*/
void
ACEXML_Svcconf_Handler::error (ACEXML_SAXParseException& ex ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
ACE_DEBUG ((LM_DEBUG, "%s: line :%d col: %d ", this->locator_->getSystemId(),
this->locator_->getLineNumber(),
this->locator_->getColumnNumber()));
ex.print();
}
void
ACEXML_Svcconf_Handler::fatalError (ACEXML_SAXParseException& ex ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
ACE_DEBUG ((LM_DEBUG, "%s: line :%d col: %d ", this->locator_->getSystemId(),
this->locator_->getLineNumber(),
this->locator_->getColumnNumber()));
ex.print();
}
void
ACEXML_Svcconf_Handler::warning (ACEXML_SAXParseException& ex ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
ACE_DEBUG ((LM_DEBUG, "%s: line :%d col: %d ", this->locator_->getSystemId(),
this->locator_->getLineNumber(),
this->locator_->getColumnNumber()));
ex.print();
}
int
ACEXML_Svcconf_Handler::get_stream_id (ACEXML_Attributes *alist ACEXML_ENV_ARG_DECL)
{
if (alist != 0)
for (size_t i = 0; i < alist->getLength (); ++i)
{
if (ACE_OS_String::strcmp (alist->getQName (i), ACE_TEXT ("id")) == 0)
{
this->stream_info_.name (alist->getValue (i));
}
else
{
ACEXML_THROW_RETURN (ACEXML_SAXException (ACE_TEXT ("Invalid stream attribute\n")),
-1);
}
}
return 0;
}
int
ACEXML_Svcconf_Handler::get_id (ACEXML_Attributes *alist ACEXML_ENV_ARG_DECL)
{
if (alist != 0)
for (size_t i = 0; i < alist->getLength (); ++i)
{
if (ACE_OS_String::strcmp (alist->getQName (i), ACE_TEXT ("id")) == 0)
{
this->parsed_info_.name (alist->getValue (i));
}
else
{
ACEXML_THROW_RETURN (ACEXML_SAXException (ACE_TEXT ("Invalid attribute, expecting 'id'\n")), -1);
}
}
return 0;
}
int
ACEXML_Svcconf_Handler::get_dynamic_attrs (ACEXML_Attributes *alist ACEXML_ENV_ARG_DECL)
{
if (alist != 0)
{
ACE_Parsed_Info *info = (this->in_stream_def_ == 0 ?
&this->parsed_info_ :
&this->stream_info_);
for (size_t i = 0; i < alist->getLength (); ++i)
{
if (ACE_OS_String::strcmp (alist->getQName (i), ACE_TEXT ("id")) == 0)
{
info->name (alist->getValue (i));
}
else if (ACE_OS_String::strcmp (alist->getQName (i), ACE_TEXT ("status")) == 0)
{
if (ACE_OS_String::strcmp (alist->getValue (i), ACE_TEXT ("inactive")) == 0)
{
info->active (0);
}
else if (ACE_OS_String::strcmp (alist->getValue (i), ACE_TEXT ("active")) == 0)
{
info->active (1);
}
else
{
ACEXML_THROW_RETURN (ACEXML_SAXException (ACE_TEXT ("Invalid attribute value, expecting 'active' or 'inactive'\n")), -1);
}
}
else if (ACE_OS_String::strcmp (alist->getQName (i), ACE_TEXT ("type")) == 0)
{
if (ACE_OS_String::strcasecmp (alist->getValue (i), ACE_TEXT ("service_object")) == 0)
{
info->service_type (ACE_Service_Type::SERVICE_OBJECT);
}
else if (ACE_OS_String::strcasecmp (alist->getValue (i), ACE_TEXT ("stream")) == 0)
{
info->service_type (ACE_Service_Type::STREAM);
}
else if (ACE_OS_String::strcasecmp (alist->getValue (i), ACE_TEXT ("module")) == 0)
{
info->service_type (ACE_Service_Type::MODULE);
}
else
{
ACEXML_THROW_RETURN (ACEXML_SAXException (ACE_TEXT ("Invalid Service_Object attribute value\n")), -1);
}
}
else
{
ACEXML_THROW_RETURN(ACEXML_SAXException(ACE_TEXT ("Invalid attribute\n")), -1);
}
}
}
return 0;
}
int
ACEXML_Svcconf_Handler::get_initializer_attrs (ACEXML_Attributes *alist ACEXML_ENV_ARG_DECL)
{
if (alist != 0)
{
ACE_Parsed_Info *info = (this->in_stream_def_ == 0 ?
&this->parsed_info_ :
&this->stream_info_);
for (size_t i = 0; i < alist->getLength (); ++i)
{
if (ACE_OS_String::strcmp (alist->getQName (i), ACE_TEXT ("init")) == 0)
{
info->init_func (alist->getValue (i));
}
else if (ACE_OS_String::strcmp (alist->getQName (i), ACE_TEXT ("path")) == 0)
{
info->path (alist->getValue (i));
}
else if (ACE_OS_String::strcmp (alist->getQName (i), ACE_TEXT ("params")) == 0)
{
info->init_params (alist->getValue (i));
}
else
{
ACEXML_THROW_RETURN (ACEXML_SAXException (ACE_TEXT ("Invalid initializer attribute.\n")), -1);
}
}
}
return 0;
}
int
ACEXML_Svcconf_Handler::get_static_attrs (ACEXML_Attributes *alist ACEXML_ENV_ARG_DECL)
{
if (alist != 0)
{
ACE_Parsed_Info *info = (this->in_stream_def_ == 0 ?
&this->parsed_info_ :
&this->stream_info_);
for (size_t i = 0; i < alist->getLength (); ++i)
{
if (ACE_OS_String::strcmp (alist->getQName (i), ACE_TEXT ("id")) == 0)
{
info->name (alist->getValue (i));
}
else if (ACE_OS_String::strcmp (alist->getQName (i), ACE_TEXT ("params")) == 0)
{
info->init_params (alist->getValue (i));
}
else
{
ACEXML_THROW_RETURN (ACEXML_SAXException (ACE_TEXT ("Invalid static attribute.\n")), -1);
}
}
}
return 0;
}
#endif /* ACE_USES_CLASSIC_SVC_CONF == 0 */
|