Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Service_Config.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: Service_Config.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:22 chad Exp $
00003 
00004 #include "ace/Svc_Conf.h"
00005 #include "ace/Get_Opt.h"
00006 #include "ace/ARGV.h"
00007 #include "ace/Malloc.h"
00008 #include "ace/Service_Manager.h"
00009 #include "ace/Service_Repository.h"
00010 #include "ace/Service_Types.h"
00011 #include "ace/Containers.h"
00012 #include "ace/Auto_Ptr.h"
00013 #include "ace/Reactor.h"
00014 #include "ace/Thread_Manager.h"
00015 #include "ace/DLL.h"
00016 
00017 #include "ace/Service_Config.h"
00018 #include "ace/XML_Svc_Conf.h"
00019 
00020 #if !defined (__ACE_INLINE__)
00021 #include "ace/Service_Config.i"
00022 #endif /* __ACE_INLINE__ */
00023 
00024 ACE_RCSID (ace,
00025            Service_Config,
00026            "$Id: Service_Config.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:22 chad Exp $")
00027 
00028 ACE_ALLOC_HOOK_DEFINE (ACE_Service_Config)
00029 
00030 void
00031 ACE_Service_Config::dump (void) const
00032 {
00033   ACE_TRACE ("ACE_Service_Config::dump");
00034 }
00035 
00036 // All the factory functions that allocate default statically linked
00037 // services should be placed below.
00038 
00039 // Allocate a Service Manager.
00040 
00041 ACE_FACTORY_DEFINE (ACE, ACE_Service_Manager)
00042 
00043 // ----------------------------------------
00044 
00045 // Set the signal handler to point to the handle_signal() function.
00046 ACE_Sig_Adapter *ACE_Service_Config::signal_handler_ = 0;
00047 
00048 // Trigger a reconfiguration.
00049 sig_atomic_t ACE_Service_Config::reconfig_occurred_ = 0;
00050 
00051   // = Set by command-line options.
00052 int ACE_Service_Config::be_a_daemon_ = 0;
00053 int ACE_Service_Config::no_static_svcs_ = 1;
00054 
00055 // Number of the signal used to trigger reconfiguration.
00056 int ACE_Service_Config::signum_ = SIGHUP;
00057 
00058 // Indicates where to write the logging output.  This is typically
00059 // either a STREAM pipe or a socket address.
00060 const ACE_TCHAR *ACE_Service_Config::logger_key_ = ACE_DEFAULT_LOGGER_KEY;
00061 
00062 // The ACE_Service_Manager static service object is now defined by the
00063 // ACE_Object_Manager, in Object_Manager.cpp.
00064 
00065 // Are we initialized already?
00066 int ACE_Service_Config::is_initialized_ = 0;
00067 
00068 // List of statically configured services.
00069 
00070 ACE_STATIC_SVCS *ACE_Service_Config::static_svcs_ = 0;
00071 ACE_SVC_QUEUE *ACE_Service_Config::svc_queue_ = 0;
00072 ACE_SVC_QUEUE *ACE_Service_Config::svc_conf_file_queue_ = 0;
00073 
00074 ACE_STATIC_SVCS *
00075 ACE_Service_Config::static_svcs (void)
00076 {
00077   if (ACE_Service_Config::static_svcs_ == 0)
00078     ACE_NEW_RETURN (ACE_Service_Config::static_svcs_,
00079                     ACE_STATIC_SVCS,
00080                     0);
00081   return ACE_Service_Config::static_svcs_;
00082 }
00083 
00084 // Totally remove <svc_name> from the daemon by removing it from the
00085 // ACE_Reactor, and unlinking it if necessary.
00086 
00087 int
00088 ACE_Service_Config::remove (const ACE_TCHAR svc_name[])
00089 {
00090   ACE_TRACE ("ACE_Service_Config::remove");
00091   return ACE_Service_Repository::instance ()->remove (svc_name);
00092 }
00093 
00094 // Suspend <svc_name>.  Note that this will not unlink the service
00095 // from the daemon if it was dynamically linked, it will mark it as
00096 // being suspended in the Service Repository and call the <suspend>
00097 // member function on the appropriate <ACE_Service_Object>.  A service
00098 // can be resumed later on by calling the <resume> method...
00099 
00100 int
00101 ACE_Service_Config::suspend (const ACE_TCHAR svc_name[])
00102 {
00103   ACE_TRACE ("ACE_Service_Config::suspend");
00104   return ACE_Service_Repository::instance ()->suspend (svc_name);
00105 }
00106 
00107 // Resume a SVC_NAME that was previously suspended or has not yet
00108 // been resumed (e.g., a static service).
00109 
00110 int
00111 ACE_Service_Config::resume (const ACE_TCHAR svc_name[])
00112 {
00113   ACE_TRACE ("ACE_Service_Config::resume");
00114   return ACE_Service_Repository::instance ()->resume (svc_name);
00115 }
00116 
00117 // Initialize the Service Repository.  Note that this *must* be
00118 // performed in the constructor (rather than <open>) since otherwise
00119 // the repository will not be properly initialized to allow static
00120 // configuration of services...
00121 
00122 ACE_Service_Config::ACE_Service_Config (int ignore_static_svcs,
00123                                         size_t size,
00124                                         int signum)
00125 {
00126   ACE_TRACE ("ACE_Service_Config::ACE_Service_Config");
00127   ACE_Service_Config::no_static_svcs_ = ignore_static_svcs;
00128   ACE_Service_Config::signum_ = signum;
00129 
00130   // Initialize the Service Repository.
00131   ACE_Service_Repository::instance (ACE_static_cast (int, size));
00132 
00133   // Initialize the ACE_Reactor (the ACE_Reactor should be the same
00134   // size as the ACE_Service_Repository).
00135   ACE_Reactor::instance ();
00136 }
00137 
00138 int
00139 ACE_Service_Config::init_svc_conf_file_queue (void)
00140 {
00141   if (ACE_Service_Config::svc_conf_file_queue_ == 0)
00142       ACE_NEW_RETURN (ACE_Service_Config::svc_conf_file_queue_,
00143                       ACE_SVC_QUEUE,
00144                       -1);
00145   return 0;
00146 }
00147 
00148 // Handle the command-line options intended for the
00149 // ACE_Service_Config.
00150 
00151 int
00152 ACE_Service_Config::parse_args (int argc, ACE_TCHAR *argv[])
00153 {
00154   ACE_TRACE ("ACE_Service_Config::parse_args");
00155   ACE_Get_Opt getopt (argc,
00156                       argv,
00157                       ACE_LIB_TEXT ("bdf:k:nys:S:"),
00158                       1); // Start at argv[1].
00159 
00160   if (ACE_Service_Config::init_svc_conf_file_queue () == -1)
00161     return -1;
00162 
00163   for (int c; (c = getopt ()) != -1; )
00164     switch (c)
00165       {
00166       case 'b':
00167         ACE_Service_Config::be_a_daemon_ = 1;
00168         break;
00169       case 'd':
00170         ACE::debug (1);
00171         break;
00172       case 'f':
00173         if (ACE_Service_Config::svc_conf_file_queue_->enqueue_tail
00174             (ACE_TString (getopt.opt_arg ())) == -1)
00175           ACE_ERROR_RETURN ((LM_ERROR,
00176                              ACE_LIB_TEXT ("%p\n"),
00177                              "enqueue_tail"),
00178                             -1);
00179         break;
00180       case 'k':
00181         ACE_Service_Config::logger_key_ = getopt.opt_arg ();
00182         break;
00183       case 'n':
00184         ACE_Service_Config::no_static_svcs_ = 1;
00185         break;
00186       case 'y':
00187         ACE_Service_Config::no_static_svcs_ = 0;
00188         break;
00189       case 's':
00190         {
00191           // There's no point in dealing with this on NT since it
00192           // doesn't really support signals very well...
00193 #if !defined (ACE_LACKS_UNIX_SIGNALS)
00194           ACE_Service_Config::signum_ =
00195             ACE_OS::atoi (getopt.opt_arg ());
00196 
00197           if (ACE_Reactor::instance ()->register_handler
00198               (ACE_Service_Config::signum_,
00199                ACE_Service_Config::signal_handler_) == -1)
00200             ACE_ERROR_RETURN ((LM_ERROR,
00201                                ACE_LIB_TEXT ("cannot obtain signal handler\n")),
00202                               -1);
00203 #endif /* ACE_LACKS_UNIX_SIGNALS */
00204           break;
00205         }
00206       case 'S':
00207         if (ACE_Service_Config::svc_queue_ == 0)
00208           ACE_NEW_RETURN (ACE_Service_Config::svc_queue_,
00209                           ACE_SVC_QUEUE,
00210                           -1);
00211         if (ACE_Service_Config::svc_queue_->enqueue_tail
00212             (ACE_TString (getopt.opt_arg ())) == -1)
00213           ACE_ERROR_RETURN ((LM_ERROR,
00214                              ACE_LIB_TEXT ("%p\n"),
00215                              "enqueue_tail"),
00216                             -1);
00217         break;
00218       default:
00219         if (ACE::debug () > 0)
00220           ACE_DEBUG ((LM_DEBUG,
00221                       ACE_LIB_TEXT ("%c is not a ACE_Service_Config option\n"),
00222                       c));
00223       }
00224 
00225   return 0;
00226 }
00227 
00228 #if (ACE_USES_CLASSIC_SVC_CONF == 0)
00229 ACE_Service_Type *
00230 ACE_Service_Config::create_service_type  (const ACE_TCHAR *n,
00231                                           ACE_Service_Type_Impl *o,
00232                                           ACE_DLL &dll,
00233                                           int active)
00234 {
00235   ACE_Service_Type *sp = 0;
00236   ACE_NEW_RETURN (sp,
00237                   ACE_Service_Type (n, o, dll, active),
00238                   0);
00239   return sp;
00240 }
00241 #endif /* ACE_USES_CLASSIC_SVC_CONF == 0 */
00242 
00243 ACE_Service_Type_Impl *
00244 ACE_Service_Config::create_service_type_impl (const ACE_TCHAR *name,
00245                                               int type,
00246                                               void *symbol,
00247                                               u_int flags,
00248                                               ACE_Service_Object_Exterminator gobbler)
00249 {
00250   ACE_Service_Type_Impl *stp = 0;
00251 
00252   // Note, the only place we need to put a case statement.  This is
00253   // also the place where we'd put the RTTI tests, if the compiler
00254   // actually supported them!
00255 
00256   switch (type)
00257     {
00258     case ACE_Service_Type::SERVICE_OBJECT:
00259       ACE_NEW_RETURN (stp,
00260                       ACE_Service_Object_Type ((ACE_Service_Object *) symbol,
00261                                                name, flags,
00262                                                gobbler),
00263                       0);
00264       break;
00265     case ACE_Service_Type::MODULE:
00266       ACE_NEW_RETURN (stp,
00267                       ACE_Module_Type (symbol, name, flags),
00268                       0);
00269       break;
00270     case ACE_Service_Type::STREAM:
00271       ACE_NEW_RETURN (stp,
00272                       ACE_Stream_Type (symbol, name, flags),
00273                       0);
00274       break;
00275     default:
00276       ACE_ERROR ((LM_ERROR,
00277                   ACE_LIB_TEXT ("unknown case\n")));
00278       break;
00279     }
00280   return stp;
00281 
00282 }
00283 
00284 // Initialize and activate a statically linked service.
00285 
00286 int
00287 ACE_Service_Config::initialize (const ACE_TCHAR *svc_name,
00288                                 const ACE_TCHAR *parameters)
00289 {
00290   ACE_TRACE ("ACE_Service_Config::initialize");
00291   ACE_ARGV args (parameters);
00292   ACE_Service_Type *srp = 0;
00293 
00294   if (ACE::debug ())
00295     ACE_DEBUG ((LM_DEBUG,
00296                 ACE_LIB_TEXT ("opening static service %s\n"),
00297                 svc_name));
00298 
00299   if (ACE_Service_Repository::instance ()->find
00300       (svc_name,
00301        (const ACE_Service_Type **) &srp) == -1)
00302     ACE_ERROR_RETURN ((LM_ERROR,
00303                        ACE_LIB_TEXT ("%s not found\n"),
00304                        svc_name),
00305                       -1);
00306   else if (srp->type ()->init (args.argc (),
00307                                args.argv ()) == -1)
00308     {
00309       // Remove this entry.
00310       ACE_ERROR ((LM_ERROR,
00311                          ACE_LIB_TEXT ("static initialization failed, %p\n"),
00312                          svc_name));
00313       ACE_Service_Repository::instance ()->remove (svc_name);
00314       return -1;
00315     }
00316   else
00317     {
00318       srp->active (1);
00319       return 0;
00320     }
00321 }
00322 
00323 // Dynamically link the shared object file and retrieve a pointer to
00324 // the designated shared object in this file.
00325 
00326 int
00327 ACE_Service_Config::initialize (const ACE_Service_Type *sr,
00328                                 const ACE_TCHAR *parameters)
00329 {
00330   ACE_TRACE ("ACE_Service_Config::initialize");
00331   ACE_ARGV args (parameters);
00332 
00333   if (ACE::debug ())
00334     ACE_DEBUG ((LM_DEBUG,
00335                 ACE_LIB_TEXT ("opening dynamic service %s\n"),
00336                 sr->name ()));
00337 
00338   if (sr->type ()->init (args.argc (),
00339                          args.argv ()) == -1)
00340     {
00341       ACE_ERROR ((LM_ERROR,
00342                   ACE_LIB_TEXT ("dynamic initialization failed for %s\n"),
00343                   sr->name ()));
00344       return -1;
00345     }
00346   else
00347     {
00348       if (ACE_Service_Repository::instance ()->insert (sr) == -1)
00349         ACE_ERROR_RETURN ((LM_ERROR,
00350                            ACE_LIB_TEXT ("insertion failed, %p\n"),
00351                            sr->name ()),
00352                           -1);
00353       return 0;
00354     }
00355 }
00356 
00357 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00358 int
00359 ACE_Service_Config::process_directives_i (ACE_Svc_Conf_Param *param)
00360 {
00361   // AC 970827 Skip the heap check because yacc allocates a buffer
00362   // here which will be reported as a memory leak for some reason.
00363   
00364 
00365 ACE_NO_HEAP_CHECK  ::ace_yyparse (param);
00366 
00367   if (param->yyerrno > 0)
00368     {
00369       // This is a hack, better errors should be provided...
00370       errno = EINVAL;
00371       return param->yyerrno;
00372     }
00373   else
00374     return 0;
00375 }
00376 #else
00377 ACE_XML_Svc_Conf *
00378 ACE_Service_Config::get_xml_svc_conf (ACE_DLL &xmldll)
00379 {
00380   if (xmldll.open (ACE_LIB_TEXT ("ACEXML_XML_Svc_Conf_Parser")) == -1)
00381     ACE_ERROR_RETURN ((LM_ERROR,
00382                        ACE_LIB_TEXT ("Fail to open ACEXML_XML_Svc_Conf_Parser: %p\n"),
00383                        "ACE_Service_Config::get_xml_svc_conf"),
00384                       0);
00385 
00386   void *foo;
00387   foo = xmldll.symbol (ACE_LIB_TEXT ("_ACEXML_create_XML_Svc_Conf_Object"));
00388 
00389   // Cast the void* to long first.
00390   long tmp = ACE_reinterpret_cast (long, foo);
00391   ACE_XML_Svc_Conf::Factory factory =
00392     ACE_reinterpret_cast (ACE_XML_Svc_Conf::Factory, tmp);
00393   if (factory == 0)
00394     ACE_ERROR_RETURN ((LM_ERROR,
00395                        ACE_TEXT ("Unable to resolve factory: %p\n"),
00396                        xmldll.error ()),
00397                       0);
00398 
00399   return factory ();
00400 }
00401 #endif /* ACE_USES_CLASSIC_SVC_CONF == 1 */
00402 
00403 int
00404 ACE_Service_Config::process_file (const ACE_TCHAR file[])
00405 {
00406   ACE_TRACE ("ACE_Service_Config::process_file");
00407 
00408 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00409   int result = 0;
00410 
00411   FILE *fp = ACE_OS::fopen (file,
00412                             ACE_LIB_TEXT ("r"));
00413 
00414   if (fp == 0)
00415     {
00416       // Invalid svc.conf file.  We'll report it here and break out of
00417       // the method.
00418       if (ACE::debug ())
00419         ACE_DEBUG ((LM_DEBUG,
00420                     ACE_LIB_TEXT ("%p\n"),
00421                     file));
00422 
00423       errno = ENOENT;
00424       result = -1;
00425     }
00426   else
00427     {
00428       ACE_Svc_Conf_Param f (fp);
00429 
00430       // Keep track of the number of errors.
00431       result = ACE_Service_Config::process_directives_i (&f);
00432 
00433       (void) ACE_OS::fclose (fp);
00434     }
00435   return result;
00436 #else
00437   ACE_DLL dll;
00438 
00439   auto_ptr<ACE_XML_Svc_Conf>
00440     xml_svc_conf (ACE_Service_Config::get_xml_svc_conf (dll));
00441 
00442   if (xml_svc_conf.get () == 0)
00443     return -1;
00444 
00445   return xml_svc_conf->parse_file (file);
00446 #endif /* ACE_USES_CLASSIC_SVC_CONF == 1 */
00447 }
00448 
00449 int
00450 ACE_Service_Config::process_directive (const ACE_TCHAR directive[])
00451 {
00452   ACE_TRACE ("ACE_Service_Config::process_directive");
00453 
00454   if (ACE::debug ())
00455     ACE_DEBUG ((LM_DEBUG,
00456                 ACE_LIB_TEXT ("Service_Config::process_directive - %s\n"),
00457                 directive));
00458 
00459 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00460   ACE_UNUSED_ARG (directive);
00461 
00462   ACE_Svc_Conf_Param d (directive);
00463 
00464   int result = ACE_Service_Config::process_directives_i (&d);
00465 
00466   return result;
00467 #else
00468   ACE_DLL dll;
00469 
00470   auto_ptr<ACE_XML_Svc_Conf>
00471     xml_svc_conf (ACE_Service_Config::get_xml_svc_conf (dll));
00472 
00473   if (xml_svc_conf.get () == 0)
00474     return -1;
00475 
00476   return xml_svc_conf->parse_string (directive);
00477 #endif /* ACE_USES_CLASSIC_SVC_CONF == 1 */
00478 }
00479 
00480 // Process service configuration requests as indicated in the queue of
00481 // svc.conf files.
00482 int
00483 ACE_Service_Config::process_directives (void)
00484 {
00485   ACE_TRACE ("ACE_Service_Config::process_directives");
00486 
00487   int result = 0;
00488 
00489   if (ACE_Service_Config::svc_conf_file_queue_ != 0)
00490     {
00491       ACE_TString *sptr = 0;
00492       ACE_SVC_QUEUE &queue = *ACE_Service_Config::svc_conf_file_queue_;
00493 
00494       // Iterate through all the svc.conf files.
00495       for (ACE_SVC_QUEUE_ITERATOR iter (queue);
00496            iter.next (sptr) != 0;
00497            iter.advance ())
00498         {
00499           int r = ACE_Service_Config::process_file (sptr->fast_rep ());
00500 
00501           if (r < 0)
00502             {
00503               result = r;
00504               break;
00505             }
00506 
00507           result += r;
00508         }
00509     }
00510 
00511   return result;
00512 }
00513 
00514 int
00515 ACE_Service_Config::process_commandline_directives (void)
00516 {
00517   int result = 0;
00518 
00519   if (ACE_Service_Config::svc_queue_ != 0)
00520     {
00521       ACE_TString *sptr = 0;
00522       ACE_SVC_QUEUE &queue = *ACE_Service_Config::svc_queue_;
00523 
00524       for (ACE_SVC_QUEUE_ITERATOR iter (queue);
00525            iter.next (sptr) != 0;
00526            iter.advance ())
00527         {
00528           // Process just a single directive.
00529           if (ACE_Service_Config::process_directive (sptr->fast_rep ()) != 0)
00530             {
00531               ACE_ERROR ((LM_ERROR,
00532                           ACE_LIB_TEXT ("%p\n"),
00533                           ACE_LIB_TEXT ("process_directive")));
00534               result = -1;
00535             }
00536         }
00537 
00538       delete ACE_Service_Config::svc_queue_;
00539       ACE_Service_Config::svc_queue_ = 0;
00540     }
00541 
00542   return result;
00543 }
00544 
00545 int
00546 ACE_Service_Config::process_directive (const ACE_Static_Svc_Descriptor &ssd,
00547                                        int force_replace)
00548 {
00549   if (!force_replace)
00550     {
00551       if (ACE_Service_Repository::instance ()->find (ssd.name_,
00552                                                      0, 0) >= 0)
00553         {
00554           // The service is already there, just return
00555           return 0;
00556         }
00557     }
00558 
00559   ACE_Service_Object_Exterminator gobbler;
00560   void *sym = (ssd.alloc_)(&gobbler);
00561 
00562   ACE_Service_Type_Impl *stp =
00563     ACE_Service_Config::create_service_type_impl (ssd.name_,
00564                                                   ssd.type_,
00565                                                   sym,
00566                                                   ssd.flags_,
00567                                                   gobbler);
00568   if (stp == 0)
00569     return 0;
00570 
00571 
00572   ACE_Service_Type *service_type;
00573   ACE_NEW_RETURN (service_type,
00574                   ACE_Service_Type (ssd.name_,
00575                                     stp,
00576                                     0,
00577                                     ssd.active_),
00578                   -1);
00579 
00580   return ACE_Service_Repository::instance ()->insert (service_type);
00581 }
00582 
00583 // Add the default statically-linked services to the Service
00584 // Repository.
00585 
00586 int
00587 ACE_Service_Config::load_static_svcs (void)
00588 {
00589   ACE_TRACE ("ACE_Service_Config::load_static_svcs");
00590 
00591   ACE_Static_Svc_Descriptor **ssdp = 0;
00592   ACE_STATIC_SVCS &svcs = *ACE_Service_Config::static_svcs ();
00593 
00594   for (ACE_STATIC_SVCS_ITERATOR iter (svcs);
00595        iter.next (ssdp) != 0;
00596        iter.advance ())
00597     {
00598       ACE_Static_Svc_Descriptor *ssd = *ssdp;
00599 
00600       if (ACE_Service_Config::process_directive (*ssd, 1) == -1)
00601         return -1;
00602     }
00603   return 0;
00604 }
00605 
00606 // Performs an open without parsing command-line arguments.
00607 
00608 int
00609 ACE_Service_Config::open_i (const ACE_TCHAR program_name[],
00610                             const ACE_TCHAR *logger_key,
00611                             int ignore_default_svc_conf_file,
00612                             int ignore_debug_flag)
00613 {
00614   int result = 0;
00615   ACE_TRACE ("ACE_Service_Config::open_i");
00616   ACE_Log_Msg *log_msg = ACE_LOG_MSG;
00617 
00618   // Record the current log setting upon entering this thread.
00619   u_long old_process_mask = log_msg->priority_mask
00620     (ACE_Log_Msg::PROCESS);
00621   u_long old_thread_mask = log_msg->priority_mask
00622     (ACE_Log_Msg::THREAD);
00623 
00624   if (ACE_Service_Config::is_initialized_ != 0)
00625     // Guard against reentrant processing!
00626     return 0;
00627   else
00628     ACE_Service_Config::is_initialized_++;
00629 
00630   if (ACE_Service_Config::init_svc_conf_file_queue () == -1)
00631     return -1;
00632   else if (!ignore_default_svc_conf_file
00633       && ACE_Service_Config::svc_conf_file_queue_->is_empty ()
00634       // Load the default "svc.conf" entry here if there weren't
00635       // overriding -f arguments in <parse_args>.
00636       && ACE_Service_Config::svc_conf_file_queue_->enqueue_tail
00637            (ACE_TString (ACE_DEFAULT_SVC_CONF)) == -1)
00638     ACE_ERROR_RETURN ((LM_ERROR,
00639                        ACE_LIB_TEXT ("%p\n"),
00640                        "enqueue_tail"),
00641                       -1);
00642 
00643   if (ignore_debug_flag == 0)
00644     {
00645       // If -d was included as a startup parameter, the user wants debug
00646       // information printed during service initialization.
00647       if (ACE::debug ())
00648         ACE_Log_Msg::enable_debug_messages ();
00649       else
00650         // The user has requested no debugging info.
00651         ACE_Log_Msg::disable_debug_messages ();
00652     }
00653 
00654   // Become a daemon before doing anything else.
00655   if (ACE_Service_Config::be_a_daemon_)
00656     ACE_Service_Config::start_daemon ();
00657 
00658   u_long flags = log_msg->flags ();
00659 
00660   if (flags == 0)
00661     // Only use STDERR if the caller hasn't already set the flags.
00662     flags = (u_long) ACE_Log_Msg::STDERR;
00663 
00664   const ACE_TCHAR *key = logger_key;
00665 
00666   if (key == 0 || ACE_OS::strcmp (key, ACE_DEFAULT_LOGGER_KEY) == 0)
00667     // Only use the static <logger_key_> if the caller doesn't
00668     // override it in the parameter list or if the key supplied is
00669     // equal to the default static logger key.
00670     key = ACE_Service_Config::logger_key_;
00671   else
00672     ACE_SET_BITS (flags, ACE_Log_Msg::LOGGER);
00673 
00674   if (log_msg->open (program_name,
00675                      flags,
00676                      key) == -1)
00677     result = -1;
00678   else
00679     {
00680       if (ACE::debug ())
00681         ACE_DEBUG ((LM_STARTUP,
00682                     ACE_LIB_TEXT ("starting up daemon %n\n")));
00683 
00684       // Initialize the Service Repository (this will still work if
00685       // user forgets to define an object of type ACE_Service_Config).
00686       ACE_Service_Repository::instance (ACE_Service_Config::MAX_SERVICES);
00687 
00688       // Initialize the ACE_Reactor (the ACE_Reactor should be the
00689       // same size as the ACE_Service_Repository).
00690       ACE_Reactor::instance ();
00691 
00692       // There's no point in dealing with this on NT since it doesn't
00693       // really support signals very well...
00694 #if !defined (ACE_LACKS_UNIX_SIGNALS)
00695       // @@ This really ought to be a Singleton.
00696       if (ACE_Reactor::instance ()->register_handler
00697           (ACE_Service_Config::signum_,
00698            ACE_Service_Config::signal_handler_) == -1)
00699         ACE_ERROR ((LM_ERROR,
00700                     ACE_LIB_TEXT ("can't register signal handler\n")));
00701 #endif /* ACE_LACKS_UNIX_SIGNALS */
00702 
00703       // See if we need to load the static services.
00704       if (ACE_Service_Config::no_static_svcs_ == 0
00705           && ACE_Service_Config::load_static_svcs () == -1)
00706         result = -1;
00707       else
00708         {
00709           if (ACE_Service_Config::process_commandline_directives () == -1)
00710             result = -1;
00711           else
00712             result = ACE_Service_Config::process_directives ();
00713         }
00714     }
00715 
00716   {
00717     // Make sure to save/restore errno properly.
00718     ACE_Errno_Guard error (errno);
00719 
00720     if (ignore_debug_flag == 0)
00721       {
00722         // Reset debugging back to the way it was when we came into
00723         // into <open_i>.
00724         log_msg->priority_mask (old_process_mask, ACE_Log_Msg::PROCESS);
00725         log_msg->priority_mask (old_thread_mask, ACE_Log_Msg::THREAD);
00726       }
00727   }
00728 
00729   return result;
00730 }
00731 
00732 ACE_Service_Config::ACE_Service_Config (const ACE_TCHAR program_name[],
00733                                         const ACE_TCHAR *logger_key)
00734 {
00735   ACE_TRACE ("ACE_Service_Config::ACE_Service_Config");
00736 
00737   if (this->open (program_name,
00738                   logger_key) == -1
00739       && errno != ENOENT)
00740     // Only print out an error if it wasn't the svc.conf file that was
00741     // missing.
00742     ACE_ERROR ((LM_ERROR,
00743                 ACE_LIB_TEXT ("%p\n"),
00744                 program_name));
00745 }
00746 
00747 // Signal handling API to trigger dynamic reconfiguration.
00748 
00749 void
00750 ACE_Service_Config::handle_signal (int sig,
00751                                    siginfo_t *,
00752                                    ucontext_t *)
00753 {
00754 #if defined (ACE_NDEBUG)
00755   ACE_UNUSED_ARG (sig);
00756 #else  /* ! ACE_NDEBUG */
00757   ACE_ASSERT (ACE_Service_Config::signum_ == sig);
00758 #endif /* ! ACE_NDEBUG */
00759 
00760   ACE_Service_Config::reconfig_occurred_ = 1;
00761 }
00762 
00763 // Trigger the reconfiguration process.
00764 
00765 void
00766 ACE_Service_Config::reconfigure (void)
00767 {
00768   ACE_TRACE ("ACE_Service_Config::reconfigure");
00769 
00770   ACE_Service_Config::reconfig_occurred_ = 0;
00771 
00772   if (ACE::debug ())
00773     {
00774 #if !defined (ACE_NLOGGING)
00775       time_t t = ACE_OS::time (0);
00776 #endif /* ! ACE_NLOGGING */
00777       if (ACE::debug ())
00778         ACE_DEBUG ((LM_DEBUG,
00779                     ACE_LIB_TEXT ("beginning reconfiguration at %s"),
00780                     ACE_OS::ctime (&t)));
00781     }
00782   if (ACE_Service_Config::process_directives () == -1)
00783     ACE_ERROR ((LM_ERROR,
00784                 ACE_LIB_TEXT ("%p\n"),
00785                 ACE_LIB_TEXT ("process_directives")));
00786 }
00787 
00788 // Tidy up and perform last rites on a terminating ACE_Service_Config.
00789 int
00790 ACE_Service_Config::close (void)
00791 {
00792   ACE_TRACE ("ACE_Service_Config::close");
00793 
00794   ACE_Service_Config::is_initialized_--;
00795   if (ACE_Service_Config::is_initialized_ > 0)
00796     return 0;
00797 
00798   // Delete the service repository.  All the objects inside the
00799   // service repository should already have been finalized.
00800   ACE_Service_Config::close_svcs ();
00801 
00802   // Delete the list fo svc.conf files
00803   delete ACE_Service_Config::svc_conf_file_queue_;
00804   ACE_Service_Config::svc_conf_file_queue_ = 0;
00805 
00806   // Delete the dynamically allocated static_svcs instance.
00807   delete ACE_Service_Config::static_svcs_;
00808   ACE_Service_Config::static_svcs_ = 0;
00809 
00810   return 0;
00811 }
00812 
00813 int
00814 ACE_Service_Config::close_svcs (void)
00815 {
00816   ACE_TRACE ("ACE_Service_Config::close_svcs");
00817 
00818   ACE_Service_Repository::close_singleton ();
00819 
00820   return 0;
00821 }
00822 
00823 int
00824 ACE_Service_Config::fini_svcs (void)
00825 {
00826   ACE_TRACE ("ACE_Service_Config::fini_svcs");
00827 
00828   // Clear the LM_DEBUG bit from log messages if appropriate
00829   if (ACE::debug ())
00830     ACE_Log_Msg::disable_debug_messages ();
00831 
00832   int result = 0;
00833   if (ACE_Service_Repository::instance () != 0)
00834     result = ACE_Service_Repository::instance ()->fini ();
00835 
00836   if (ACE::debug ())
00837     ACE_Log_Msg::enable_debug_messages ();
00838 
00839   return result;
00840 }
00841 
00842 // Perform user-specified close activities and remove dynamic memory.
00843 
00844 ACE_Service_Config::~ACE_Service_Config (void)
00845 {
00846   ACE_TRACE ("ACE_Service_Config::~ACE_Service_Config");
00847 }
00848 
00849 // ************************************************************
00850 
00851 /* static */
00852 int
00853 ACE_Service_Config::reconfig_occurred (void)
00854 {
00855   ACE_TRACE ("ACE_Service_Config::reconfig_occurred");
00856   return ACE_Service_Config::reconfig_occurred_ != 0;
00857 }
00858 
00859 void
00860 ACE_Service_Config::reconfig_occurred (int config_occurred)
00861 {
00862   ACE_TRACE ("ACE_Service_Config::reconfig_occurred");
00863   ACE_Service_Config::reconfig_occurred_ = config_occurred;
00864 }
00865 
00866 // Become a daemon (i.e., run as a "background" process).
00867 
00868 int
00869 ACE_Service_Config::start_daemon (void)
00870 {
00871   ACE_TRACE ("ACE_Service_Config::start_daemon");
00872   return ACE::daemonize ();
00873 }

Generated on Mon Jun 16 11:21:10 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002