00001
00002
00003 #include "ace/Svc_Conf.h"
00004 #include "ace/Get_Opt.h"
00005 #include "ace/ARGV.h"
00006 #include "ace/Malloc.h"
00007 #include "ace/Service_Manager.h"
00008 #include "ace/Service_Types.h"
00009 #include "ace/Containers.h"
00010 #include "ace/Auto_Ptr.h"
00011 #include "ace/Reactor.h"
00012 #include "ace/Thread_Manager.h"
00013 #include "ace/DLL.h"
00014 #include "ace/XML_Svc_Conf.h"
00015 #include "ace/SString.h"
00016
00017 #ifndef ACE_LACKS_UNIX_SIGNALS
00018 # include "ace/Signal.h"
00019 #endif
00020
00021 #include "ace/OS_NS_stdio.h"
00022 #include "ace/OS_NS_string.h"
00023 #include "ace/OS_NS_time.h"
00024 #include "ace/OS_NS_unistd.h"
00025 #include "ace/OS_NS_sys_stat.h"
00026
00027 #include "ace/TSS_T.h"
00028 #include "ace/Service_Gestalt.h"
00029
00030 #include "ace/Svc_Conf_Param.h"
00031
00032 ACE_RCSID (ace,
00033 Service_Gestalt,
00034 "$Id: Service_Gestalt.cpp 91158 2010-07-21 15:54:12Z mesnier_p $")
00035
00036 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00037
00038 ACE_Service_Type_Dynamic_Guard::ACE_Service_Type_Dynamic_Guard
00039 (ACE_Service_Repository &r, const ACE_TCHAR *name)
00040 : repo_ (r)
00041
00042 , repo_begin_ (r.current_size ())
00043 , name_ (name)
00044 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 , repo_monitor_ (r.lock_)
00062 #endif
00063 {
00064 if (ACE::debug ())
00065 ACE_DEBUG ((LM_DEBUG,
00066 ACE_TEXT ("ACE (%P|%t) STDG::<ctor>, repo=%@")
00067 ACE_TEXT(", name=%s - begining at [%d]\n"),
00068 &this->repo_,
00069 this->name_,
00070 this->repo_begin_));
00071
00072 ACE_ASSERT (this->name_ != 0);
00073 }
00074
00075
00076
00077 ACE_Service_Type_Dynamic_Guard::~ACE_Service_Type_Dynamic_Guard (void)
00078 {
00079 const ACE_Service_Type *tmp = 0;
00080
00081
00082
00083
00084 size_t slot = 0;
00085 int const ret = this->repo_.find_i (this->name_, slot, &tmp, false);
00086
00087
00088 if ((ret < 0 && ret != -2) || tmp == 0)
00089 {
00090 if (ACE::debug ())
00091 ACE_ERROR ((LM_WARNING,
00092 ACE_TEXT ("ACE (%P|%t) STDG::<dtor> - Failed (%d) to find %s -> %@\n"),
00093 ret, this->name_, tmp));
00094 return;
00095 }
00096
00097 if (tmp->type () != 0)
00098 {
00099
00100
00101
00102 if (ACE::debug ())
00103 ACE_DEBUG ((LM_DEBUG,
00104 ACE_TEXT ("ACE (%P|%t) STDG::<dtor>, repo=%@ [%d], ")
00105 ACE_TEXT ("name=%s - updating dependents [%d - %d)\n"),
00106 &this->repo_,
00107 slot,
00108 this->name_,
00109 this->repo_begin_,
00110 this->repo_.current_size ()));
00111
00112
00113
00114
00115
00116 this->repo_.relocate_i (this->repo_begin_, this->repo_.current_size (), tmp->dll());
00117
00118 if (ACE::debug ())
00119 ACE_DEBUG ((LM_DEBUG,
00120 ACE_TEXT ("ACE (%P|%t) STDG::<dtor>, repo=%@ [%d], ")
00121 ACE_TEXT ("name=%s - loaded (type=%@, impl=%@, object=%@, active=%d)\n"),
00122 &this->repo_,
00123 slot,
00124 this->name_,
00125 tmp,
00126 tmp->type (),
00127 tmp->type ()->object (),
00128 tmp->active ()));
00129 }
00130 }
00131
00132
00133
00134
00135
00136 ACE_Service_Gestalt::Processed_Static_Svc::
00137 Processed_Static_Svc (const ACE_Static_Svc_Descriptor *assd)
00138 :name_(0),
00139 assd_(assd)
00140 {
00141 ACE_NEW_NORETURN (name_, ACE_TCHAR[ACE_OS::strlen(assd->name_)+1]);
00142 ACE_OS::strcpy(name_,assd->name_);
00143 }
00144
00145 ACE_Service_Gestalt::Processed_Static_Svc::~Processed_Static_Svc (void)
00146 {
00147 delete [] name_;
00148 }
00149
00150 void
00151 ACE_Service_Gestalt::intrusive_add_ref (ACE_Service_Gestalt* g)
00152 {
00153 if (g != 0)
00154 {
00155 ++g->refcnt_;
00156 ACE_ASSERT (g->refcnt_ > 0);
00157 }
00158 }
00159
00160 void
00161 ACE_Service_Gestalt::intrusive_remove_ref (ACE_Service_Gestalt* g)
00162 {
00163 if (g != 0)
00164 {
00165 long tmp = --g->refcnt_;
00166 if (tmp <= 0) delete g;
00167 ACE_ASSERT (tmp >= 0);
00168 }
00169 }
00170
00171
00172 ACE_Service_Gestalt::~ACE_Service_Gestalt (void)
00173 {
00174
00175 if (this->svc_repo_is_owned_)
00176 delete this->repo_;
00177
00178 this->repo_ =0;
00179
00180 delete this->static_svcs_;
00181 this->static_svcs_ = 0;
00182
00183
00184 #ifndef ACE_NLOGGING
00185 if (ACE::debug ())
00186 ACE_DEBUG ((LM_DEBUG,
00187 ACE_TEXT ("ACE (%P|%t) SG::~SG - this=%@, pss = %@\n"),
00188 this, this->processed_static_svcs_));
00189 #endif
00190
00191 if (this->processed_static_svcs_ &&
00192 !this->processed_static_svcs_->is_empty())
00193 {
00194 Processed_Static_Svc **pss = 0;
00195 for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
00196 iter.next (pss) != 0;
00197 iter.advance ())
00198 {
00199 delete *pss;
00200 }
00201 }
00202
00203 delete this->processed_static_svcs_;
00204 this->processed_static_svcs_ = 0;
00205
00206 delete this->svc_conf_file_queue_;
00207 this->svc_conf_file_queue_ = 0;
00208 }
00209
00210 ACE_Service_Gestalt::ACE_Service_Gestalt (size_t size,
00211 bool svc_repo_is_owned,
00212 bool no_static_svcs)
00213 : svc_repo_is_owned_ (svc_repo_is_owned)
00214 , svc_repo_size_ (size)
00215 , is_opened_ (0)
00216 , logger_key_ (ACE_DEFAULT_LOGGER_KEY)
00217 , no_static_svcs_ (no_static_svcs)
00218 , svc_queue_ (0)
00219 , svc_conf_file_queue_ (0)
00220 , repo_ (0)
00221 , static_svcs_ (0)
00222 , processed_static_svcs_ (0)
00223 , refcnt_ (0)
00224 {
00225 (void)this->init_i ();
00226
00227 #ifndef ACE_NLOGGING
00228 if (ACE::debug ())
00229 ACE_DEBUG ((LM_DEBUG,
00230 ACE_TEXT ("ACE (%P|%t) SG::ctor - this = %@, pss = %@\n"),
00231 this, this->processed_static_svcs_));
00232 #endif
00233 }
00234
00235
00236
00237
00238 int
00239 ACE_Service_Gestalt::init_i (void)
00240 {
00241
00242
00243
00244 if (this->repo_ == 0)
00245 {
00246 if (this->svc_repo_is_owned_)
00247 {
00248 ACE_NEW_RETURN (this->repo_,
00249 ACE_Service_Repository (this->svc_repo_size_),
00250 -1);
00251 }
00252 else
00253 {
00254 this->repo_ =
00255 ACE_Service_Repository::instance (this->svc_repo_size_);
00256 }
00257 }
00258
00259 if (init_svc_conf_file_queue () == -1)
00260 return -1;
00261
00262 return 0;
00263 }
00264
00265
00266
00267
00268 int
00269 ACE_Service_Gestalt::load_static_svcs (void)
00270 {
00271 ACE_TRACE ("ACE_Service_Gestalt::load_static_svcs");
00272
00273 if (this->static_svcs_ == 0)
00274 return 0;
00275
00276 ACE_Static_Svc_Descriptor **ssdp = 0;
00277 for (ACE_STATIC_SVCS_ITERATOR iter (*this->static_svcs_);
00278 iter.next (ssdp) != 0;
00279 iter.advance ())
00280 {
00281 ACE_Static_Svc_Descriptor *ssd = *ssdp;
00282
00283 if (this->process_directive (*ssd, 1) == -1)
00284 return -1;
00285 }
00286 return 0;
00287
00288 }
00289
00290
00291
00292
00293 int
00294 ACE_Service_Gestalt::find_static_svc_descriptor (const ACE_TCHAR* name,
00295 ACE_Static_Svc_Descriptor **ssd) const
00296 {
00297 ACE_TRACE ("ACE_Service_Gestalt::find_static_svc_descriptor");
00298
00299 if (this->static_svcs_ == 0)
00300 return -1;
00301
00302 ACE_Static_Svc_Descriptor **ssdp = 0;
00303 for (ACE_STATIC_SVCS_ITERATOR iter ( *this->static_svcs_);
00304 iter.next (ssdp) != 0;
00305 iter.advance ())
00306 {
00307 if (ACE_OS::strcmp ((*ssdp)->name_, name) == 0)
00308 {
00309 if (ssd != 0)
00310 *ssd = *ssdp;
00311
00312 return 0;
00313 }
00314 }
00315
00316 return -1;
00317 }
00318
00319
00320 const ACE_Static_Svc_Descriptor*
00321 ACE_Service_Gestalt::find_processed_static_svc (const ACE_TCHAR* name)
00322 {
00323 if (this->processed_static_svcs_ == 0 || name == 0)
00324 return 0;
00325
00326 Processed_Static_Svc **pss = 0;
00327 for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
00328 iter.next (pss) != 0;
00329 iter.advance ())
00330 {
00331 if (ACE_OS::strcmp ((*pss)->name_, name) == 0)
00332 return (*pss)->assd_;
00333 }
00334 return 0;
00335 }
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 void
00346 ACE_Service_Gestalt::add_processed_static_svc
00347 (const ACE_Static_Svc_Descriptor *assd)
00348 {
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365 if (this->processed_static_svcs_ == 0)
00366 ACE_NEW (this->processed_static_svcs_,
00367 ACE_PROCESSED_STATIC_SVCS);
00368
00369 Processed_Static_Svc **pss = 0;
00370 for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
00371 iter.next (pss) != 0;
00372 iter.advance ())
00373 {
00374 if (ACE_OS::strcmp ((*pss)->name_, assd->name_) == 0)
00375 {
00376 (*pss)->assd_ = assd;
00377 return;
00378 }
00379 }
00380 Processed_Static_Svc *tmp = 0;
00381 ACE_NEW (tmp,Processed_Static_Svc(assd));
00382 this->processed_static_svcs_->insert(tmp);
00383
00384 if (ACE::debug ())
00385 ACE_DEBUG ((LM_DEBUG,
00386 ACE_TEXT ("ACE (%P|%t) SG::add_processed_static_svc, ")
00387 ACE_TEXT ("repo=%@ - %s\n"),
00388 this->repo_,
00389 assd->name_));
00390 }
00391
00392
00393
00394
00395
00396
00397
00398 int
00399 ACE_Service_Gestalt::insert (ACE_Static_Svc_Descriptor *stsd)
00400 {
00401 if (this->static_svcs_ == 0)
00402 ACE_NEW_RETURN (this->static_svcs_,
00403 ACE_STATIC_SVCS,
00404 -1);
00405
00406 return this->static_svcs_->insert (stsd);
00407 }
00408
00409
00410 ACE_ALLOC_HOOK_DEFINE (ACE_Service_Gestalt)
00411
00412
00413 void
00414 ACE_Service_Gestalt::dump (void) const
00415 {
00416 #if defined (ACE_HAS_DUMP)
00417 ACE_TRACE ("ACE_Service_Gestalt::dump");
00418 #endif
00419 }
00420
00421 int
00422 ACE_Service_Gestalt::initialize (const ACE_TCHAR *svc_name,
00423 const ACE_TCHAR *parameters)
00424 {
00425 ACE_TRACE ("ACE_Service_Gestalt_Base::initialize (repo)");
00426 ACE_ARGV args (parameters);
00427
00428 #ifndef ACE_NLOGGING
00429 if (ACE::debug ())
00430 {
00431 ACE_DEBUG ((LM_DEBUG,
00432 ACE_TEXT ("ACE (%P|%t) SG::initialize - () repo=%@, ")
00433 ACE_TEXT ("looking up static ")
00434 ACE_TEXT ("service \'%s\' to initialize\n"),
00435 this->repo_,
00436 svc_name));
00437 }
00438 #endif
00439
00440 const ACE_Service_Type *srp = 0;
00441 for (int i = 0; this->find (svc_name, &srp) == -1 && i < 2; i++)
00442
00443 {
00444 const ACE_Static_Svc_Descriptor *assd =
00445 ACE_Service_Config::global()->find_processed_static_svc(svc_name);
00446 if (assd != 0)
00447 {
00448 this->process_directive_i(*assd, 0);
00449 }
00450 else
00451 {
00452 ACE_ERROR_RETURN ((LM_ERROR,
00453 ACE_TEXT ("ACE (%P|%t) ERROR: SG::initialize - service \'%s\'")
00454 ACE_TEXT (" was not located.\n"),
00455 svc_name),
00456 -1);
00457 }
00458 }
00459 if (srp == 0)
00460 ACE_ERROR_RETURN ((LM_ERROR,
00461 ACE_TEXT ("ACE (%P|%t) ERROR: SG::initialize - service \'%s\'")
00462 ACE_TEXT (" was not located.\n"),
00463 svc_name),
00464 -1);
00465
00466
00467 if (srp->type ()->init (args.argc (),
00468 args.argv ()) == -1)
00469 {
00470
00471 ACE_ERROR ((LM_ERROR,
00472 ACE_TEXT ("ACE (%P|%t) ERROR: SG::initialize - static init of \'%s\'")
00473 ACE_TEXT (" failed (%p)\n"),
00474 svc_name, ACE_TEXT ("error")));
00475 this->repo_->remove (svc_name);
00476 return -1;
00477 }
00478
00479
00480 const_cast<ACE_Service_Type *>(srp)->active (1);
00481 return 0;
00482 }
00483
00484
00485 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00486 int
00487 ACE_Service_Gestalt::initialize (const ACE_Service_Type_Factory *stf,
00488 const ACE_TCHAR *parameters)
00489 {
00490 ACE_TRACE ("ACE_Service_Gestalt::initialize");
00491
00492 #ifndef ACE_NLOGGING
00493 if (ACE::debug ())
00494 ACE_DEBUG ((LM_DEBUG,
00495 ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, name=%s")
00496 ACE_TEXT (" - looking up in the repo\n"),
00497 this->repo_,
00498 stf->name ()));
00499 #endif
00500
00501 ACE_Service_Type *srp = 0;
00502 int const retv = this->repo_->find (stf->name (),
00503 (const ACE_Service_Type **) &srp);
00504
00505
00506
00507 if (retv >= 0)
00508 {
00509 #ifndef ACE_NLOGGING
00510 if (ACE::debug ())
00511 ACE_DEBUG ((LM_WARNING,
00512 ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@,")
00513 ACE_TEXT (" name=%s - removing a pre-existing namesake.\n"),
00514 this->repo_,
00515 stf->name ()));
00516 #endif
00517 this->repo_->remove (stf->name ());
00518 }
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530 if (retv == -2 && srp->type () == 0)
00531 ACE_ERROR_RETURN ((LM_WARNING,
00532 ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@,")
00533 ACE_TEXT (" name=%s - forward-declared; ")
00534 ACE_TEXT (" recursive initialization requests are")
00535 ACE_TEXT (" ignored.\n"),
00536 this->repo_,
00537 stf->name ()),
00538 -1);
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548 ACE_Service_Type_Dynamic_Guard dummy (*this->repo_,
00549 stf->name ());
00550
00551
00552
00553 ACE_Auto_Ptr<ACE_Service_Type> tmp (stf->make_service_type (this));
00554
00555 if (tmp.get () != 0 &&
00556 this->initialize_i (tmp.get (), parameters) == 0)
00557 {
00558
00559
00560
00561 tmp.release ();
00562 return 0;
00563 }
00564
00565 return -1;
00566 }
00567 #endif
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580 int
00581 ACE_Service_Gestalt::initialize (const ACE_Service_Type *sr,
00582 const ACE_TCHAR *parameters)
00583 {
00584 ACE_TRACE ("ACE_Service_Gestalt::initialize");
00585
00586 if (ACE::debug ())
00587 ACE_DEBUG ((LM_DEBUG,
00588 ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, name=%s")
00589 ACE_TEXT (" - looking up in the repo\n"),
00590 this->repo_,
00591 sr->name ()));
00592
00593 ACE_Service_Type *srp = 0;
00594 if (this->repo_->find (sr->name (),
00595 (const ACE_Service_Type **) &srp) >= 0)
00596 {
00597 #ifndef ACE_NLOGGING
00598 ACE_DEBUG ((LM_WARNING,
00599 ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, name=%s")
00600 ACE_TEXT (" - removing a pre-existing namesake.\n"),
00601 this->repo_,
00602 sr->name ()));
00603 #endif
00604 this->repo_->remove (sr->name ());
00605 }
00606
00607 return this->initialize_i (sr, parameters);
00608
00609 }
00610
00611
00612
00613 int
00614 ACE_Service_Gestalt::initialize_i (const ACE_Service_Type *sr,
00615 const ACE_TCHAR *parameters)
00616 {
00617 ACE_TRACE ("ACE_Service_Gestalt::initialize_i");
00618 ACE_ARGV args (parameters);
00619 if (sr->type ()->init (args.argc (),
00620 args.argv ()) == -1)
00621 {
00622
00623 ACE_Service_Type *ps = 0;
00624 this->repo_->remove (sr->name (), &ps);
00625
00626 #ifndef ACE_NLOGGING
00627
00628 if (ACE::debug ())
00629 ACE_ERROR_RETURN ((LM_WARNING,
00630 ACE_TEXT ("ACE (%P|%t) SG::initialize_i -")
00631 ACE_TEXT (" repo=%@, name=%s - remove failed: %m\n"),
00632 this->repo_,
00633 sr->name ()),
00634 -1);
00635 #endif
00636 return -1;
00637 }
00638
00639 if (this->repo_->insert (sr) == -1)
00640 {
00641 #ifndef ACE_NLOGGING
00642
00643 if (ACE::debug ())
00644 ACE_ERROR_RETURN ((LM_WARNING,
00645 ACE_TEXT ("ACE (%P|%t) SG::initialize_i -")
00646 ACE_TEXT (" repo=%@, name=%s - insert failed: %m\n"),
00647 this->repo_,
00648 sr->name ()),
00649 -1);
00650 #endif
00651 return -1;
00652 }
00653
00654 return 0;
00655 }
00656
00657
00658
00659
00660 int
00661 ACE_Service_Gestalt::remove (const ACE_TCHAR svc_name[])
00662 {
00663 ACE_TRACE ("ACE_Service_Gestalt::remove");
00664 if (this->repo_ == 0)
00665 return -1;
00666
00667 return this->repo_->remove (svc_name);
00668 }
00669
00670
00671
00672
00673
00674
00675 int
00676 ACE_Service_Gestalt::suspend (const ACE_TCHAR svc_name[])
00677 {
00678 ACE_TRACE ("ACE_Service_Gestalt::suspend");
00679 if (this->repo_ == 0)
00680 return -1;
00681
00682 return this->repo_->suspend (svc_name);
00683 }
00684
00685
00686
00687
00688 int
00689 ACE_Service_Gestalt::resume (const ACE_TCHAR svc_name[])
00690 {
00691 ACE_TRACE ("ACE_Service_Gestalt::resume");
00692 if (this->repo_ == 0)
00693 return -1;
00694
00695 return this->repo_->resume (svc_name);
00696 }
00697
00698
00699 int
00700 ACE_Service_Gestalt::process_directive (const ACE_Static_Svc_Descriptor &ssd,
00701 bool force_replace)
00702 {
00703 int const result = process_directive_i (ssd, force_replace);
00704 if (result == 0)
00705 {
00706 this->add_processed_static_svc(&ssd);
00707 }
00708 return result;
00709 }
00710
00711 int
00712 ACE_Service_Gestalt::process_directive_i (const ACE_Static_Svc_Descriptor &ssd,
00713 bool force_replace)
00714 {
00715 if (this->repo_ == 0)
00716 return -1;
00717
00718 if (!force_replace)
00719 {
00720 if (this->repo_->find (ssd.name_, 0, 0) >= 0)
00721 {
00722
00723 return 0;
00724 }
00725 }
00726
00727
00728 ACE_Service_Object_Exterminator gobbler;
00729 void *sym = (ssd.alloc_)(&gobbler);
00730
00731 ACE_Service_Type_Impl *stp =
00732 ACE_Service_Config::create_service_type_impl (ssd.name_,
00733 ssd.type_,
00734 sym,
00735 ssd.flags_,
00736 gobbler);
00737 if (stp == 0)
00738 return 0;
00739
00740 ACE_Service_Type *service_type = 0;
00741
00742
00743
00744
00745
00746 ACE_DLL tmp_dll;
00747
00748 ACE_NEW_RETURN (service_type,
00749 ACE_Service_Type (ssd.name_,
00750 stp,
00751 tmp_dll,
00752 ssd.active_),
00753 -1);
00754
00755 #ifndef ACE_NLOGGING
00756 if (ACE::debug ())
00757 ACE_DEBUG ((LM_DEBUG,
00758 ACE_TEXT ("ACE (%P|%t) SG::process_directive_i, ")
00759 ACE_TEXT ("repo=%@ - %s, dll=%s, force=%d\n"),
00760 this->repo_,
00761 ssd.name_,
00762 (tmp_dll.dll_name_ == 0) ? ACE_TEXT ("<null>") : tmp_dll.dll_name_,
00763 force_replace));
00764 #endif
00765
00766 return this->repo_->insert (service_type);
00767 }
00768
00769 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00770
00771 int
00772 ACE_Service_Gestalt::process_directives_i (ACE_Svc_Conf_Param *param)
00773 {
00774 #ifndef ACE_NLOGGING
00775 if (ACE::debug ())
00776 ACE_DEBUG ((LM_DEBUG,
00777 ACE_TEXT ("ACE (%P|%t) SG::process_directives_i, ")
00778 ACE_TEXT ("repo=%@ - %s\n"),
00779 this->repo_,
00780 (param->type == ACE_Svc_Conf_Param::SVC_CONF_FILE)
00781 ? ACE_TEXT ("<from file>")
00782 : param->source.directive));
00783 #endif
00784
00785
00786
00787 ACE_NO_HEAP_CHECK
00788
00789
00790 ACE_ASSERT (this == param->config);
00791
00792
00793
00794
00795
00796
00797
00798
00799 ACE_Service_Config_Guard guard (this);
00800
00801 ::ace_yyparse (param);
00802
00803
00804 if (param->yyerrno > 0)
00805 {
00806
00807
00808
00809 ACE_OS::last_error (EINVAL);
00810 return param->yyerrno;
00811 }
00812 else
00813 return 0;
00814 }
00815
00816 #else
00817
00818 ACE_XML_Svc_Conf *
00819 ACE_Service_Gestalt::get_xml_svc_conf (ACE_DLL &xmldll)
00820 {
00821 if (xmldll.open (ACE_TEXT ("ACEXML_XML_Svc_Conf_Parser")) == -1)
00822 ACE_ERROR_RETURN ((LM_ERROR,
00823 ACE_TEXT ("ACE (%P|%t) Failure to open ACEXML_XML_Svc_Conf_Parser: %p\n"),
00824 ACE_TEXT("ACE_Service_Config::get_xml_svc_conf")),
00825 0);
00826
00827 void * foo =
00828 xmldll.symbol (ACE_TEXT ("_ACEXML_create_XML_Svc_Conf_Object"));
00829
00830 #if defined (ACE_OPENVMS) && (!defined (__INITIAL_POINTER_SIZE) || (__INITIAL_POINTER_SIZE < 64))
00831 int const temp_p = reinterpret_cast<int> (foo);
00832 #else
00833 intptr_t const temp_p = reinterpret_cast<intptr_t> (foo);
00834 #endif
00835
00836 ACE_XML_Svc_Conf::Factory factory = reinterpret_cast<ACE_XML_Svc_Conf::Factory> (temp_p);
00837
00838 if (factory == 0)
00839 ACE_ERROR_RETURN ((LM_ERROR,
00840 ACE_TEXT ("ACE (%P|%t) Unable to resolve factory: %p\n"),
00841 xmldll.error ()),
00842 0);
00843
00844 return factory ();
00845 }
00846 #endif
00847
00848 int
00849 ACE_Service_Gestalt::process_file (const ACE_TCHAR file[])
00850 {
00851 ACE_TRACE ("ACE_Service_Gestalt::process_file");
00852
00853
00854
00855
00856
00857
00858 if (this->repo_->find (file, 0, 0) >=0)
00859 {
00860 ACE_DEBUG ((LM_WARNING,
00861 ACE_TEXT ("ACE (%P|%t) Configuration file %s is currently")
00862 ACE_TEXT (" being processed. Ignoring recursive process_file().\n"),
00863 file));
00864 return 0;
00865 }
00866
00867
00868
00869 ACE_Service_Type_Dynamic_Guard recursion_guard (*this->repo_,
00870 file);
00871
00872
00873
00874
00875 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00876 int result = 0;
00877
00878 FILE *fp = ACE_OS::fopen (file,
00879 ACE_TEXT ("r"));
00880
00881 if (fp == 0)
00882 {
00883
00884
00885 if (ACE::debug ())
00886 ACE_DEBUG ((LM_ERROR,
00887 ACE_TEXT ("ACE (%P|%t): %p\n"),
00888 file));
00889
00890
00891
00892 ACE_stat exists;
00893 if (ACE_OS::stat (file, &exists) == 0)
00894
00895
00896 errno = EPERM;
00897 else
00898 errno = ENOENT;
00899 result = -1;
00900 }
00901 else
00902 {
00903 ACE_Svc_Conf_Param f (this, fp);
00904
00905
00906 result = this->process_directives_i (&f);
00907
00908 (void) ACE_OS::fclose (fp);
00909 }
00910 return result;
00911 #else
00912 ACE_DLL dll;
00913
00914 auto_ptr<ACE_XML_Svc_Conf> xml_svc_conf (this->get_xml_svc_conf (dll));
00915
00916 if (xml_svc_conf.get () == 0)
00917 return -1;
00918
00919 return xml_svc_conf->parse_file (file);
00920 #endif
00921 }
00922
00923 int
00924 ACE_Service_Gestalt::process_directive (const ACE_TCHAR directive[])
00925 {
00926 ACE_TRACE ("ACE_Service_Gestalt::process_directive");
00927
00928 #ifndef ACE_NLOGGING
00929 if (ACE::debug ())
00930 ACE_DEBUG ((LM_DEBUG,
00931 ACE_TEXT ("ACE (%P|%t) SG::process_directive, repo=%@ - %s\n"),
00932 this->repo_,
00933 directive));
00934 #endif
00935
00936 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00937 ACE_UNUSED_ARG (directive);
00938
00939 ACE_Svc_Conf_Param d (this, directive);
00940
00941 return this->process_directives_i (&d);
00942 #else
00943 ACE_DLL dll;
00944
00945 auto_ptr<ACE_XML_Svc_Conf>
00946 xml_svc_conf (this->get_xml_svc_conf (dll));
00947
00948 if (xml_svc_conf.get () == 0)
00949 return -1;
00950
00951
00952
00953
00954
00955
00956
00957 ACE_Service_Config_Guard guard (this);
00958
00959 return xml_svc_conf->parse_string (directive);
00960 #endif
00961
00962 }
00963
00964
00965 int
00966 ACE_Service_Gestalt::init_svc_conf_file_queue (void)
00967 {
00968 if (this->svc_conf_file_queue_ == 0)
00969 {
00970 ACE_SVC_QUEUE *tmp = 0;
00971 ACE_NEW_RETURN (tmp,
00972 ACE_SVC_QUEUE,
00973 -1);
00974 this->svc_conf_file_queue_ = tmp;
00975 }
00976
00977 #ifndef ACE_NLOGGING
00978 if (ACE::debug ())
00979 ACE_DEBUG ((LM_DEBUG,
00980 ACE_TEXT ("ACE (%P|%t) SG::init_svc_conf_file_queue ")
00981 ACE_TEXT ("- this=%@, repo=%@\n"),
00982 this, this->repo_));
00983 #endif
00984
00985 return 0;
00986
00987 }
00988
00989
00990 int
00991 ACE_Service_Gestalt::open_i (const ACE_TCHAR program_name[],
00992 const ACE_TCHAR* logger_key,
00993 bool ignore_static_svcs,
00994 bool ignore_default_svc_conf_file,
00995 bool ignore_debug_flag)
00996 {
00997 ACE_TRACE ("ACE_Service_Gestalt::open_i");
00998 int result = 0;
00999 ACE_Log_Msg *log_msg = ACE_LOG_MSG;
01000
01001 this->no_static_svcs_ = ignore_static_svcs;
01002
01003
01004 u_long old_process_mask = log_msg->priority_mask
01005 (ACE_Log_Msg::PROCESS);
01006
01007 u_long old_thread_mask = log_msg->priority_mask
01008 (ACE_Log_Msg::THREAD);
01009
01010 #ifndef ACE_NLOGGING
01011 if (ACE::debug ())
01012 ACE_DEBUG ((LM_DEBUG,
01013 ACE_TEXT ("ACE (%P|%t) SG::open_i - this=%@, ")
01014 ACE_TEXT ("opened=%d, loadstatics=%d\n"),
01015 this, this->is_opened_, this->no_static_svcs_));
01016 #endif
01017
01018
01019
01020
01021 if (this->is_opened_++ != 0)
01022 return 0;
01023
01024 if (this->init_i () != 0)
01025 return -1;
01026
01027 u_long flags = log_msg->flags ();
01028
01029
01030 if (flags == 0)
01031 flags = (u_long) ACE_Log_Msg::STDERR;
01032
01033 const ACE_TCHAR *key = logger_key;
01034
01035 if (key == 0 || ACE_OS::strcmp (key, ACE_DEFAULT_LOGGER_KEY) == 0)
01036 {
01037
01038
01039
01040 key = this->logger_key_;
01041 }
01042 else
01043 {
01044 ACE_SET_BITS (flags, ACE_Log_Msg::LOGGER);
01045 }
01046
01047 if (log_msg->open (program_name,
01048 flags,
01049 key) == -1)
01050 return -1;
01051
01052 if (!ignore_debug_flag)
01053 {
01054
01055
01056 if (ACE::debug ())
01057 ACE_Log_Msg::enable_debug_messages ();
01058 else
01059
01060 ACE_Log_Msg::disable_debug_messages ();
01061 }
01062
01063 if (!ignore_default_svc_conf_file)
01064 {
01065 bool add_default = true;
01066 bool has_files = this->svc_conf_file_queue_ &&
01067 !this->svc_conf_file_queue_->is_empty ();
01068 bool has_cmdline = this->svc_queue_ && !this->svc_queue_->is_empty ();
01069 if (has_files || has_cmdline)
01070 {
01071
01072 ACE_TString *sptr = 0;
01073 ACE_TString default_svc_conf (ACE_DEFAULT_SVC_CONF);
01074
01075 for (ACE_SVC_QUEUE_ITERATOR iter (*this->svc_conf_file_queue_);
01076 iter.next (sptr) != 0 && add_default;
01077 iter.advance ())
01078 {
01079 add_default = (*sptr != default_svc_conf);
01080 }
01081
01082 if (add_default)
01083 {
01084 FILE *fp = ACE_OS::fopen (ACE_DEFAULT_SVC_CONF, ACE_TEXT ("r"));
01085 if (fp != 0)
01086 ACE_OS::fclose(fp);
01087 else
01088 add_default = false;
01089
01090 }
01091 }
01092
01093
01094
01095 if (add_default && svc_conf_file_queue_->enqueue_head
01096 (ACE_TString (ACE_DEFAULT_SVC_CONF)) == -1)
01097 {
01098 errno = ENOENT;
01099 ACE_ERROR_RETURN ((LM_ERROR,
01100 ACE_TEXT ("%p\n"),
01101 ACE_TEXT ("enqueuing ")
01102 ACE_DEFAULT_SVC_CONF
01103 ACE_TEXT(" file")),
01104 -1);
01105 }
01106 }
01107
01108
01109 if (this->no_static_svcs_ == 0
01110 && this->load_static_svcs () == -1)
01111 result = -1;
01112 else
01113 {
01114 result = this->process_directives ();
01115 if (result != -1 || errno == ENOENT)
01116 result = this->process_commandline_directives ();
01117 }
01118
01119
01120
01121 {
01122
01123 ACE_Errno_Guard error (errno);
01124
01125 if (!ignore_debug_flag)
01126 {
01127 log_msg->priority_mask (old_process_mask, ACE_Log_Msg::PROCESS);
01128 log_msg->priority_mask (old_thread_mask, ACE_Log_Msg::THREAD);
01129 }
01130 }
01131
01132 return result;
01133 }
01134
01135
01136 int
01137 ACE_Service_Gestalt::is_opened (void)
01138 {
01139 return this->is_opened_;
01140 }
01141
01142 int
01143 ACE_Service_Gestalt::process_commandline_directives (void)
01144 {
01145 int result = 0;
01146 if (this->svc_queue_ != 0)
01147 {
01148 ACE_TString *sptr = 0;
01149 for (ACE_SVC_QUEUE_ITERATOR iter (*this->svc_queue_);
01150 iter.next (sptr) != 0;
01151 iter.advance ())
01152 {
01153
01154 if (this->process_directive ((sptr->fast_rep ())) != 0)
01155 {
01156 ACE_ERROR ((LM_ERROR,
01157 ACE_TEXT ("ACE (%P|%t) %p\n"),
01158 ACE_TEXT ("process_directive")));
01159 result = -1;
01160 }
01161 }
01162
01163 delete this->svc_queue_;
01164 this->svc_queue_ = 0;
01165 }
01166
01167 return result;
01168
01169 }
01170
01171
01172 int
01173 ACE_Service_Gestalt::parse_args (int argc, ACE_TCHAR *argv[])
01174 {
01175 ACE_TRACE ("ACE_Service_Gestalt::parse_args");
01176 bool unused_ignore_default_svc_conf = true;
01177 return parse_args_i (argc, argv, unused_ignore_default_svc_conf);
01178 }
01179
01180 int
01181 ACE_Service_Gestalt::parse_args_i (int argc,
01182 ACE_TCHAR *argv[],
01183 bool &ignore_default_svc_conf_file)
01184 {
01185 ACE_TRACE ("ACE_Service_Gestalt::parse_args_i");
01186 ACE_Get_Opt get_opt (argc,
01187 argv,
01188 ACE_TEXT ("df:k:nyS:"),
01189 1);
01190
01191 if (this->init_svc_conf_file_queue () == -1)
01192 return -1;
01193
01194 for (int c; (argc != 0) && ((c = get_opt ()) != -1); )
01195 switch (c)
01196 {
01197 case 'd':
01198 ACE::debug (1);
01199 break;
01200 case 'f':
01201 if (this->svc_conf_file_queue_->enqueue_tail (ACE_TString (get_opt.opt_arg ())) == -1)
01202 ACE_ERROR_RETURN ((LM_ERROR,
01203 ACE_TEXT ("%p\n"),
01204 ACE_TEXT ("enqueue_tail")),
01205 -1);
01206 ignore_default_svc_conf_file = true;
01207 break;
01208 case 'k':
01209
01210
01211
01212
01213 this->logger_key_ = get_opt.opt_arg ();
01214 break;
01215 case 'n':
01216 this->no_static_svcs_ = 1;
01217 break;
01218 case 'y':
01219 this->no_static_svcs_ = 0;
01220 break;
01221 case 'S':
01222 if (this->svc_queue_ == 0)
01223 {
01224 ACE_NEW_RETURN (this->svc_queue_,
01225 ACE_SVC_QUEUE,
01226 -1);
01227 }
01228
01229 if (this->svc_queue_->enqueue_tail (ACE_TString (get_opt.opt_arg ())) == -1)
01230 ACE_ERROR_RETURN ((LM_ERROR,
01231 ACE_TEXT ("%p\n"),
01232 ACE_TEXT ("enqueue_tail")),
01233 -1);
01234 break;
01235 default:
01236 if (ACE::debug ())
01237 ACE_DEBUG ((LM_DEBUG,
01238 ACE_TEXT ("ACE (%P|%t) %c is not a ACE_Service_Config option\n"),
01239 c));
01240 }
01241
01242 return 0;
01243 }
01244
01245
01246
01247
01248
01249 int
01250 ACE_Service_Gestalt::process_directives (bool )
01251 {
01252 ACE_TRACE ("ACE_Service_Gestalt::process_directives");
01253 if (this->svc_conf_file_queue_ == 0
01254 || this->svc_conf_file_queue_->is_empty ())
01255 {
01256 return 0;
01257 }
01258
01259 ACE_TString *sptr = 0;
01260 int failed = 0;
01261
01262
01263 for (ACE_SVC_QUEUE_ITERATOR iter (*this->svc_conf_file_queue_);
01264 iter.next (sptr) != 0;
01265 iter.advance ())
01266 {
01267 int result = this->process_file (sptr->fast_rep ());
01268 if (result < 0)
01269 return result;
01270 failed += result;
01271 }
01272
01273 return failed;
01274
01275 }
01276
01277
01278 int
01279 ACE_Service_Gestalt::close (void)
01280 {
01281 ACE_TRACE ("ACE_Service_Gestalt::close");
01282
01283 if (!this->is_opened_ || --this->is_opened_ != 0)
01284 return 0;
01285
01286
01287 delete this->svc_conf_file_queue_;
01288 this->svc_conf_file_queue_ = 0;
01289
01290 if (this->processed_static_svcs_ &&
01291 !this->processed_static_svcs_->is_empty())
01292 {
01293 Processed_Static_Svc **pss = 0;
01294 for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
01295 iter.next (pss) != 0;
01296 iter.advance ())
01297 {
01298 delete *pss;
01299 }
01300 }
01301 delete this->processed_static_svcs_;
01302 this->processed_static_svcs_ = 0;
01303
01304 #ifndef ACE_NLOGGING
01305 if (ACE::debug ())
01306 ACE_DEBUG ((LM_DEBUG,
01307 ACE_TEXT ("ACE (%P|%t) SG::close - complete this=%@, repo=%@, owned=%d\n"),
01308 this, this->repo_, this->svc_repo_is_owned_));
01309 #endif
01310
01311 if (this->svc_repo_is_owned_)
01312 delete this->repo_;
01313
01314 this->repo_ = 0;
01315
01316 return 0;
01317 }
01318
01319
01320 ACE_END_VERSIONED_NAMESPACE_DECL
01321
01322 #if !defined (__ACE_INLINE__)
01323 #include "ace/Service_Gestalt.inl"
01324 #endif
01325
01326
01327 ACE_FACTORY_DEFINE (ACE, ACE_Service_Manager)