ACE_Service_Config Class Reference

Supplies common server operations for dynamic and static configuration of service. More...

#include <Service_Config.h>

Inheritance diagram for ACE_Service_Config:

Inheritance graph
[legend]
Collaboration diagram for ACE_Service_Config:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Service_Config (int ignore_static_svcs=1, size_t size=ACE_Service_Gestalt::MAX_SERVICES, int signum=SIGHUP)
 ACE_Service_Config (const ACE_TCHAR program_name[], const ACE_TCHAR *logger_key=ACE_DEFAULT_LOGGER_KEY)
virtual ~ACE_Service_Config (void)
void dump (void) const
 Dump the state of an object.


Static Public Member Functions

ACE_Service_Gestaltcurrent (ACE_Service_Gestalt *)
 = Static interfaces

ACE_Service_Configglobal (void)
ACE_Service_Gestaltcurrent (void)
 Accessor for the "current" service gestalt.

ACE_Service_Gestaltinstance (void)
int open (const ACE_TCHAR program_name[], const ACE_TCHAR *logger_key=ACE_DEFAULT_LOGGER_KEY, bool ignore_static_svcs=true, bool ignore_default_svc_conf_file=false, bool ignore_debug_flag=false)
int open (int argc, ACE_TCHAR *argv[], const ACE_TCHAR *logger_key=ACE_DEFAULT_LOGGER_KEY, bool ignore_static_svcs=true, bool ignore_default_svc_conf_file=false, bool ignore_debug_flag=false)
int close (void)
int fini_svcs (void)
int close_svcs (void)
int reconfig_occurred (void)
 True if reconfiguration occurred.

void reconfig_occurred (int)
 Indicate that reconfiguration occurred.

void reconfigure (void)
 Perform the reconfiguration process.

ACE_Service_Gestaltstatic_svcs (void)
int insert (ACE_Static_Svc_Descriptor *svc)
int initialize (const ACE_Service_Type *, const ACE_TCHAR *parameters)
int initialize (const ACE_TCHAR *svc_name, const ACE_TCHAR *parameters)
 Initialize and activate a statically svc_name service.

int resume (const ACE_TCHAR svc_name[])
int suspend (const ACE_TCHAR svc_name[])
int remove (const ACE_TCHAR svc_name[])
ACE_INLINE void signal_handler (ACE_Sig_Adapter *)
 Set the signal_handler;for internal use by ACE_Object_Manager only.

int process_file (const ACE_TCHAR file[])
int process_directive (const ACE_TCHAR directive[])
int process_directive (const ACE_Static_Svc_Descriptor &ssd, int force_replace=0)
 Process one static service definition.

int process_directives (void)
void handle_signal (int sig, siginfo_t *, ucontext_t *)
 Handles signals to trigger reconfigurations.

int parse_args (int, ACE_TCHAR *argv[])
ACE_Service_Type_Implcreate_service_type_impl (const ACE_TCHAR *name, int type, void *symbol, u_int flags, ACE_Service_Object_Exterminator gobbler)

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Protected Member Functions

virtual int open_i (const ACE_TCHAR program_name[], const ACE_TCHAR *logger_key, bool ignore_static_svcs, bool ignore_default_svc_conf_file, bool ignore_debug_flag)
virtual int parse_args_i (int argc, ACE_TCHAR *argv[])

Static Protected Member Functions

int process_commandline_directives (void)
int process_directives_i (ACE_Svc_Conf_Param *param)
int start_daemon (void)
 Become a daemon.

int load_static_svcs (void)

Protected Attributes

ACE_TSS< ACE_Service_Gestalttss_

Static Private Attributes

sig_atomic_t reconfig_occurred_ = 0
 True if reconfiguration occurred.

int be_a_daemon_ = 0
 Shall we become a daemon process?

ACE_TCHARpid_file_name_ = 0
 Pathname of file to write process id.

int signum_ = SIGHUP
 Number of the signal used to trigger reconfiguration.

ACE_Sig_Adaptersignal_handler_ = 0
 Handles the reconfiguration signals.


Friends

class ACE_Service_Config_Guard

Detailed Description

Supplies common server operations for dynamic and static configuration of service.

The ACE_Service_Config uses the Monostate pattern. Therefore, you can only have one of these instantiated per-process. It represents the process-wide collection of services, which is typicaly shared among all other configurable entities. The only ACE_Service_Config instance is registered with and owned by the ACE_Object_Manager.

By contrast, the ACE_Service_Gestalt represents the collection of services, pertaining to a configurable entity. Typicaly, a "configurable entity" is an instance, which owns an instance of ACE_Service_Gestalt in order to ensure full controll over the services it needs.

Another facet of ACE_Service_Config is that for a given thread, it provides access to its current, process-global ACE_Service_Gestalt instance through its curent() method.

Note:
The signal_handler_ static member is allocated by the ACE_Object_Manager. The ACE_Service_Config constructor uses signal_handler_. Therefore, if the program has any static ACE_Service_Config objects, there might be initialization order problems. They can be minimized, but not eliminated, by _not_ #defining ACE_HAS_NONSTATIC_OBJECT_MANAGER.

Definition at line 203 of file Service_Config.h.


Constructor & Destructor Documentation

ACE_Service_Config::ACE_Service_Config int  ignore_static_svcs = 1,
size_t  size = ACE_Service_Gestalt::MAX_SERVICES,
int  signum = SIGHUP
 

Initialize the Service Repository. Note that initialising signum to a negative number will prevent a signal handler being registered when the repository is opened.

Definition at line 377 of file Service_Config.cpp.

References ACE_TRACE, and signum_.

00380   : ACE_Service_Gestalt (size, false, ignore_static_svcs)
00381   , tss_ (this)
00382 {
00383   ACE_TRACE ("ACE_Service_Config::ACE_Service_Config");
00384   ACE_Service_Config::signum_ = signum;
00385 }

ACE_Service_Config::ACE_Service_Config const ACE_TCHAR  program_name[],
const ACE_TCHAR logger_key = ACE_DEFAULT_LOGGER_KEY
 

Performs an open without parsing command-line arguments. The logger_key indicates where to write the logging output, which is typically either a STREAM pipe or a socket address.

Definition at line 445 of file Service_Config.cpp.

References ACE_ERROR, ACE_TCHAR, ACE_TEXT, ACE_TRACE, LM_ERROR, and open().

00447   : ACE_Service_Gestalt (ACE_Service_Repository::DEFAULT_SIZE, false)
00448   , tss_ (this)
00449 {
00450   ACE_TRACE ("ACE_Service_Config::ACE_Service_Config");
00451 
00452   if (this->open (program_name,
00453                   logger_key) == -1 && errno != ENOENT)
00454     {
00455 
00456       // Only print out an error if it wasn't the svc.conf file that was
00457       // missing.
00458       ACE_ERROR ((LM_ERROR,
00459                   ACE_TEXT ("(%P|%t) SC failed to open: %p\n"),
00460                   program_name));
00461     }
00462 }

ACE_Service_Config::~ACE_Service_Config void   )  [virtual]
 

Perform user-specified close activities and remove dynamic memory.

Definition at line 552 of file Service_Config.cpp.

References ACE_TRACE.

00553 {
00554   ACE_TRACE ("ACE_Service_Config::~ACE_Service_Config");
00555 }


Member Function Documentation

int ACE_Service_Config::close void   )  [static]
 

Tidy up and perform last rites when ACE_Service_Config is shut down. This method calls . Returns 0.

Reimplemented from ACE_Service_Gestalt.

Definition at line 507 of file Service_Config.cpp.

References ACE_Service_Gestalt::close(), close_svcs(), and instance().

Referenced by ACE_Object_Manager::fini().

00508 {
00509   int result1 = ACE_Service_Config::instance ()->close ();
00510 
00511   // Delete the service repository.  All the objects inside the
00512   // service repository should already have been finalized.
00513   int result2 = ACE_Service_Config::close_svcs ();
00514 
00515   // Do away with the Singleton
00516   ACE_SERVICE_CONFIG_SINGLETON::close ();
00517 
00518   return (result1 | result2);
00519 }

int ACE_Service_Config::close_svcs void   )  [static]
 

Perform user-specified close hooks on all of the configured services in the Service_Repository, then delete the Service_Repository itself. Returns 0.

Definition at line 522 of file Service_Config.cpp.

References ACE_TRACE, ACE_Service_Repository::close_singleton(), current(), and global().

Referenced by close().

00523 {
00524   ACE_TRACE ("ACE_Service_Config::close_svcs");
00525 
00526   ACE_Service_Repository::close_singleton ();
00527   ACE_Service_Config::current (global ());
00528   return 0;
00529 }

ACE_Service_Type_Impl * ACE_Service_Config::create_service_type_impl const ACE_TCHAR name,
int  type,
void *  symbol,
u_int  flags,
ACE_Service_Object_Exterminator  gobbler
[static]
 

Definition at line 404 of file Service_Config.cpp.

References ACE_ERROR, ACE_NEW_RETURN, ACE_Service_Object_Exterminator, ACE_TCHAR, ACE_TEXT, and LM_ERROR.

Referenced by ACE_Service_Gestalt::process_directive_i().

00409 {
00410   ACE_Service_Type_Impl *stp = 0;
00411 
00412   // Note, the only place we need to put a case statement.  This is
00413   // also the place where we'd put the RTTI tests, if the compiler
00414   // actually supported them!
00415 
00416   switch (type)
00417     {
00418     case ACE_Service_Type::SERVICE_OBJECT:
00419       ACE_NEW_RETURN (stp,
00420                       ACE_Service_Object_Type ((ACE_Service_Object *) symbol,
00421                                                name, flags,
00422                                                gobbler),
00423                       0);
00424       break;
00425     case ACE_Service_Type::MODULE:
00426       ACE_NEW_RETURN (stp,
00427                       ACE_Module_Type (symbol, name, flags),
00428                       0);
00429       break;
00430     case ACE_Service_Type::STREAM:
00431       ACE_NEW_RETURN (stp,
00432                       ACE_Stream_Type (symbol, name, flags),
00433                       0);
00434       break;
00435     default:
00436       ACE_ERROR ((LM_ERROR,
00437                   ACE_TEXT ("unknown case\n")));
00438       break;
00439     }
00440   return stp;
00441 
00442 }

ACE_INLINE ACE_Service_Gestalt * ACE_Service_Config::current void   )  [static]
 

Accessor for the "current" service gestalt.

Return the configuration instance, considered "global" in the current thread. This may be the same as instance(), but on some occasions, it may be a different one. For example, ACE_Service_Config_Guard provides a way of temporarily replacing the "current" configuration instance in the context of a thread.

Definition at line 73 of file Service_Config.inl.

References global(), and tss_.

Referenced by ACE_Service_Config_Guard::ACE_Service_Config_Guard(), close_svcs(), initialize(), open(), parse_args(), process_directive(), process_directives(), process_file(), and ACE_Service_Config_Guard::~ACE_Service_Config_Guard().

00074 {
00075   return ACE_Service_Config::global ()->tss_;
00076 }

ACE_INLINE ACE_Service_Gestalt * ACE_Service_Config::current ACE_Service_Gestalt  )  [static]
 

= Static interfaces

Mutator to set the (TSS) global instance. Intended for use by helper classes like

See also:
ACE_Service_Config_Guard. Stack-based instances of it can temporarily change which Gestalt is considered global by any static initializer (especially those in DLLs, loaded at run-time).

Definition at line 80 of file Service_Config.inl.

References global(), ACE_TSS< ACE_Service_Gestalt >::ts_object(), and tss_.

00081 {
00082   return ACE_Service_Config::global ()->tss_.ts_object (newcurrent);
00083 }

void ACE_Service_Config::dump void   )  const
 

Dump the state of an object.

Reimplemented from ACE_Service_Gestalt.

Definition at line 96 of file Service_Config.cpp.

References ACE_TRACE.

00097 {
00098 #if defined (ACE_HAS_DUMP)
00099   ACE_TRACE ("ACE_Service_Config::dump");
00100 #endif /* ACE_HAS_DUMP */
00101 }

int ACE_Service_Config::fini_svcs void   )  [static]
 

Perform user-specified close hooks and possibly delete all of the configured services in the .

Definition at line 532 of file Service_Config.cpp.

References ACE_TRACE, ACE::debug(), ACE_Log_Msg::disable_debug_messages(), ACE_Log_Msg::enable_debug_messages(), ACE_Service_Repository::fini(), and ACE_Service_Repository::instance().

Referenced by ACE_Object_Manager::fini().

00533 {
00534   ACE_TRACE ("ACE_Service_Config::fini_svcs");
00535 
00536   // Clear the LM_DEBUG bit from log messages if appropriate
00537   if (ACE::debug ())
00538     ACE_Log_Msg::disable_debug_messages ();
00539 
00540   int result = 0;
00541   if (ACE_Service_Repository::instance () != 0)
00542     result = ACE_Service_Repository::instance ()->fini ();
00543 
00544   if (ACE::debug ())
00545     ACE_Log_Msg::enable_debug_messages ();
00546 
00547   return result;
00548 }

ACE_Service_Config * ACE_Service_Config::global void   )  [static]
 

Returns a process-wide global singleton instance in contrast with current (), which may return a different instance at different times, dependent on the context. Use of this method is discouraged as it allows circumvention of the mechanism for dynamically loading services. Use with extreme caution!

Definition at line 332 of file Service_Config.cpp.

Referenced by close_svcs(), current(), ACE_Dynamic_Service_Base::find_i(), ACE_Service_Gestalt::initialize(), and instance().

00333 {
00334   return ACE_SERVICE_CONFIG_SINGLETON::instance ();
00335 }

void ACE_Service_Config::handle_signal int  sig,
siginfo_t ,
ucontext_t
[static]
 

Handles signals to trigger reconfigurations.

Definition at line 467 of file Service_Config.cpp.

References ACE_ASSERT, reconfig_occurred_, signum_, and ucontext_t.

00470 {
00471 #if defined (ACE_NDEBUG)
00472   ACE_UNUSED_ARG (sig);
00473 #else  /* ! ACE_NDEBUG */
00474   ACE_ASSERT (ACE_Service_Config::signum_ == sig);
00475 #endif /* ! ACE_NDEBUG */
00476 
00477   ACE_Service_Config::reconfig_occurred_ = 1;
00478 }

ACE_INLINE int ACE_Service_Config::initialize const ACE_TCHAR svc_name,
const ACE_TCHAR parameters
[static]
 

Initialize and activate a statically svc_name service.

Reimplemented from ACE_Service_Gestalt.

Definition at line 111 of file Service_Config.inl.

References ACE_TCHAR, ACE_TRACE, current(), and ACE_Service_Gestalt::initialize().

00113 {
00114   ACE_TRACE ("ACE_Service_Config::initialize");
00115   return ACE_Service_Config::current ()->initialize (svc_name,
00116                                                      parameters);
00117 }

ACE_INLINE int ACE_Service_Config::initialize const ACE_Service_Type ,
const ACE_TCHAR parameters
[static]
 

Dynamically link the shared object file and retrieve a pointer to the designated shared object in this file.

Reimplemented from ACE_Service_Gestalt.

Definition at line 123 of file Service_Config.inl.

References ACE_TCHAR, ACE_TRACE, current(), and ACE_Service_Gestalt::initialize().

00125 {
00126   ACE_TRACE ("ACE_Service_Config::initialize");
00127   return ACE_Service_Config::current ()->initialize (sr,
00128                                                      parameters);
00129 }

int ACE_Service_Config::insert ACE_Static_Svc_Descriptor svc  )  [static]
 

Insert a static service descriptor for processing on open_i(). The corresponding ACE_STATIC_SVC_* macros were chaged to use this method instead of obtaining a ptr to a container. See the note on static_svcs(). Added to prevent exposing the internal storage representation of the services repository and provide a better way of debugging service loading and registration problems.

Reimplemented from ACE_Service_Gestalt.

Definition at line 338 of file Service_Config.cpp.

References ACE_Service_Gestalt::insert(), and instance().

00339 {
00340   return ACE_Service_Config::instance ()->insert (stsd);
00341 }

ACE_INLINE ACE_Service_Gestalt * ACE_Service_Config::instance void   )  [static]
 

This is what the static service initializators are hard-wired to use, so in order to avoid interface changes this method merely forwards to ACE_Service_Config::current. This enables us to enforce which Service Gestalt is used for services registering through static initializers. Especially important for DLL-based dynamic services, which can contain their own static services and static initializers.

Definition at line 61 of file Service_Config.inl.

References global(), and tss_.

Referenced by close(), insert(), and static_svcs().

00062 {
00063   return ACE_Service_Config::global ()->tss_;
00064 }

int ACE_Service_Config::load_static_svcs void   )  [static, protected]
 

Add the default statically-linked services to the ACE_Service_Repository.

Reimplemented from ACE_Service_Gestalt.

ACE_INLINE int ACE_Service_Config::open int  argc,
ACE_TCHAR argv[],
const ACE_TCHAR logger_key = ACE_DEFAULT_LOGGER_KEY,
bool  ignore_static_svcs = true,
bool  ignore_default_svc_conf_file = false,
bool  ignore_debug_flag = false
[static]
 

This is the primary entry point into the ACE_Service_Config (the constructor just handles simple initializations). It parses arguments passed in from argc and argv parameters. The arguments that are valid in a call to this method include:

  • '-b' Option to indicate that we should be a daemon. Note that when this option is used, the process will be daemonized before the service configuration file(s) are read. During daemonization, (on POSIX systems) the current directory will be changed to "/" so the caller should either fully specify the file names, or execute a chroot() to the appropriate directory.
    See also:
    ACE::daemonize().
  • '-d' Turn on debugging mode
  • '-f' Specifies a configuration file name other than the default svc.conf. Can be specified multiple times to use multiple files.
  • '-k' Specifies the rendezvous point to use for the ACE distributed logger.
  • '-y' Explicitly enables the use of static services. This flag overrides the ignore_static_svcs parameter value.
  • '-n' Explicitly disables the use of static services. This flag overrides the ignore_static_svcs parameter value.
  • '-p' Specifies a pathname which is used to store the process id.
  • '-s' Specifies a signal number other than SIGHUP to trigger reprocessing of the configuration file(s). Ignored for platforms that do not have POSIX signals, such as Windows.
  • '-S' Specifies a service directive string. Enclose the string in quotes and escape any embedded quotes with a backslash. This option specifies service directives without the need for a configuration file.

Parameters:
argc The number of commandline arguments.
argv The array with commandline arguments
logger_key Indicates where to write the logging output, which is typically either a STREAM pipe or a socket address.
ignore_static_svcs If 1 then static services are not loaded, otherwise, they are loaded.
ignore_default_svc_conf_file If non-0 then the svc.conf configuration file will be ignored.
ignore_debug_flag If non-0 then the application is responsible for setting the ACE_Log_Msg::priority_mask appropriately.
Return values:
-1 The configuration file is not found or cannot be opened (errno is set accordingly).
0 Success.
>0 The number of errors encountered while processing the service configuration file(s).

Reimplemented from ACE_Service_Gestalt.

Definition at line 29 of file Service_Config.inl.

References ACE_TCHAR, ACE_TRACE, current(), and ACE_Service_Gestalt::open().

00035 {
00036   ACE_TRACE ("ACE_Service_Config::open");
00037   return ACE_Service_Config::current()->open (argc,
00038                                               argv,
00039                                               logger_key,
00040                                               ignore_static_svcs,
00041                                               ignore_default_svc_conf,
00042                                               ignore_debug_flag);
00043 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_Service_Config::open const ACE_TCHAR  program_name[],
const ACE_TCHAR logger_key = ACE_DEFAULT_LOGGER_KEY,
bool  ignore_static_svcs = true,
bool  ignore_default_svc_conf_file = false,
bool  ignore_debug_flag = false
[static]
 

Performs an open without parsing command-line arguments. The logger_key indicates where to write the logging output, which is typically either a STREAM pipe or a socket address. If ignore_static_svcs is 1 then static services are not loaded, otherwise, they are loaded. If ignore_default_svc_conf_file is non-0 then the <svc.conf> configuration file will be ignored. Returns zero upon success, -1 if the file is not found or cannot be opened (errno is set accordingly), otherwise returns the number of errors encountered loading the services in the specified svc.conf configuration file. If ignore_debug_flag is non-0 then the application is responsible for setting the ACE_Log_Msg::priority_mask appropriately.

Reimplemented from ACE_Service_Gestalt.

Definition at line 13 of file Service_Config.inl.

References ACE_TCHAR, ACE_TRACE, current(), and ACE_Service_Gestalt::open().

Referenced by ACE_Service_Config().

00018 {
00019   ACE_TRACE ("ACE_Service_Config::open");
00020   return ACE_Service_Config::current()->open (program_name,
00021                                               logger_key,
00022                                               ignore_static_svcs,
00023                                               ignore_default_svc_conf,
00024                                               ignore_debug_flag);
00025 }

int ACE_Service_Config::open_i const ACE_TCHAR  program_name[],
const ACE_TCHAR logger_key,
bool  ignore_static_svcs,
bool  ignore_default_svc_conf_file,
bool  ignore_debug_flag
[protected, virtual]
 

Performs an open without parsing command-line arguments. Implements whats different in the opening sequence for this class, as opposed to the base class.

The logger_key indicates where to write the logging output, which is typically either a STREAM pipe or a socket address. If ignore_default_svc_conf_file is non-0 then the "svc.conf" file will be ignored. If ignore_debug_flag is non-0 then the application is responsible for setting the ACE_Log_Msg::priority_mask() appropriately. Returns number of errors that occurred on failure and 0 otherwise.

Reimplemented from ACE_Service_Gestalt.

Definition at line 170 of file Service_Config.cpp.

References ACE_DEBUG, ACE_DEFAULT_LOGGER_KEY, ACE_DEFAULT_SVC_CONF, ACE_ERROR, ACE_ERROR_RETURN, ACE_LOG_MSG, ACE_SET_BITS, ACE_TCHAR, ACE_TEXT, ACE_TRACE, ACE_TString, be_a_daemon_, ACE::daemonize(), ACE::debug(), ACE_OS::fclose(), ACE_Log_Msg::flags(), ACE_OS::fopen(), ACE_OS::fprintf(), ACE_Service_Gestalt::init_svc_conf_file_queue(), ACE_Reactor::instance(), ACE_Service_Repository::instance(), LM_DEBUG, LM_ERROR, LM_STARTUP, ACE_Log_Msg::open(), ACE_Service_Gestalt::open_i(), pid_file_name_, ACE_Reactor::register_handler(), ACE_Sig_Set::sig_add(), signal_handler_, signum_, and ACE_OS::strcmp().

00175 {
00176   int result = 0;
00177   ACE_TRACE ("ACE_Service_Config::open_i");
00178   ACE_Log_Msg *log_msg = ACE_LOG_MSG;
00179 
00180   if (ACE::debug ())
00181     ACE_DEBUG ((LM_DEBUG,
00182                 ACE_TEXT ("(%P|%t) SC::open_i - this=%@, opened=%d, ")
00183                 ACE_TEXT ("loadstatics=%d\n"),
00184                 this, this->is_opened_, this->no_static_svcs_));
00185 
00186   // Guard against reentrant processing. For example,
00187   // if the singleton gestalt (ubergestalt) was already open,
00188   // do not open it again...
00189   // The base class open_i increments this and we are
00190   // forwarding to it, so we don't have to increment here.
00191   if (this->is_opened_ != 0)
00192     return ACE_Service_Gestalt::open_i (program_name,
00193                                         logger_key,
00194                                         ignore_static_svcs,
00195                                         ignore_default_svc_conf_file,
00196                                         ignore_debug_flag);
00197 
00198   // Check for things we need to do on a per-process basis and which
00199   // may not be safe, or wise to do an a per instance basis
00200 
00201   // Override any defaults, if required
00202   this->no_static_svcs_ = ignore_static_svcs;
00203 
00204   // Become a daemon before doing anything else.
00205   if (this->be_a_daemon_)
00206     ACE::daemonize ();
00207 
00208   // Write process id to file.
00209   if (this->pid_file_name_ != 0)
00210     {
00211       FILE* pidf = ACE_OS::fopen (this->pid_file_name_,
00212                                   ACE_TEXT("w"));
00213 
00214       if (pidf != 0)
00215         {
00216           ACE_OS::fprintf (pidf,
00217                            "%ld\n",
00218                            static_cast<long> (ACE_OS::getpid()));
00219           ACE_OS::fclose (pidf);
00220         }
00221     }
00222 
00223   u_long flags = log_msg->flags ();
00224 
00225   // Only use STDERR if the caller hasn't already set the flags.
00226   if (flags == 0)
00227     flags = (u_long) ACE_Log_Msg::STDERR;
00228 
00229   const ACE_TCHAR *key = logger_key;
00230 
00231   if (key == 0 || ACE_OS::strcmp (key, ACE_DEFAULT_LOGGER_KEY) == 0)
00232     // Only use the static <logger_key_> if the caller doesn't
00233     // override it in the parameter list or if the key supplied is
00234     // equal to the default static logger key.
00235     key = this->logger_key_;
00236   else
00237     ACE_SET_BITS (flags, ACE_Log_Msg::LOGGER);
00238 
00239   if (log_msg->open (program_name,
00240                      flags,
00241                      key) == -1)
00242     result = -1;
00243   else
00244     {
00245       if (ACE::debug ())
00246         ACE_DEBUG ((LM_STARTUP,
00247                     ACE_TEXT ("starting up daemon %n\n")));
00248 
00249       // Initialize the Service Repository (this will still work if
00250       // user forgets to define an object of type ACE_Service_Config).
00251       ACE_Service_Repository::instance (ACE_Service_Config::MAX_SERVICES);
00252 
00253       // Initialize the ACE_Reactor (the ACE_Reactor should be the
00254       // same size as the ACE_Service_Repository).
00255       ACE_Reactor::instance ();
00256 
00257       // There's no point in dealing with this on NT since it doesn't
00258       // really support signals very well...
00259 #if !defined (ACE_LACKS_UNIX_SIGNALS)
00260       // Only attempt to register a signal handler for positive
00261       // signal numbers.
00262       if (ACE_Service_Config::signum_ > 0)
00263         {
00264           ACE_Sig_Set ss;
00265           ss.sig_add (ACE_Service_Config::signum_);
00266           if (ACE_Reactor::instance ()->register_handler
00267               (ss, ACE_Service_Config::signal_handler_) == -1)
00268             ACE_ERROR ((LM_ERROR,
00269                         ACE_TEXT ("can't register signal handler\n")));
00270         }
00271 #endif /* ACE_LACKS_UNIX_SIGNALS */
00272     }
00273 
00274   if (result == -1)
00275     return -1;
00276 
00277   if (this->init_svc_conf_file_queue () == -1)
00278     return -1;
00279 
00280   // Check if the default file exists before attempting to queue it
00281   // for processing
00282   if (!ignore_default_svc_conf_file)
00283     {
00284       FILE *fp = ACE_OS::fopen (ACE_DEFAULT_SVC_CONF,
00285                                 ACE_TEXT ("r"));
00286       ignore_default_svc_conf_file = (fp == 0);
00287       if (fp != 0)
00288         ACE_OS::fclose (fp);
00289     }
00290 
00291   if (!ignore_default_svc_conf_file
00292       && this->svc_conf_file_queue_->is_empty ())
00293     {
00294       // Load the default "svc.conf" entry here if there weren't
00295       // overriding -f arguments in <parse_args>.
00296       if (this->svc_conf_file_queue_->enqueue_tail
00297           (ACE_TString (ACE_DEFAULT_SVC_CONF)) == -1)
00298         {
00299           ACE_ERROR_RETURN ((LM_ERROR,
00300                              ACE_TEXT ("%p\n"),
00301                              ACE_TEXT ("enqueuing ")
00302                              ACE_DEFAULT_SVC_CONF
00303                              ACE_TEXT(" file")),
00304                             -1);
00305         }
00306     }
00307 
00308   return ACE_Service_Gestalt::open_i (program_name,
00309                                       logger_key,
00310                                       ignore_static_svcs,
00311                                       ignore_default_svc_conf_file,
00312                                       ignore_debug_flag);
00313 }

ACE_INLINE int ACE_Service_Config::parse_args int  ,
ACE_TCHAR argv[]
[static]
 

Handle the command-line options intended for the ACE_Service_Config. Note that argv[0] is assumed to be the program name. The arguments that are valid in a call to this method are

  • '-b' Option to indicate that we should be a daemon
  • '-d' Turn on debugging mode
  • '-f' Option to read in the list of svc.conf file names
  • '-k' Option to read a wide string where in the logger output can be written
  • '-y' Turn on the flag for a repository of statically linked services
  • '-n' Need not have a repository of statically linked services
  • '-S' Option to read in the list of services on the command-line Please observe the difference between options '-f' that looks for a list of files and here a list of services.

Reimplemented from ACE_Service_Gestalt.

Definition at line 49 of file Service_Config.inl.

References ACE_TCHAR, current(), and ACE_Service_Gestalt::parse_args().

00050 {
00051   return ACE_Service_Config::current ()->parse_args (argc, argv);
00052 }

int ACE_Service_Config::parse_args_i int  argc,
ACE_TCHAR argv[]
[protected, virtual]
 

Implements whats different in the command line parameter processing for this class, as opposed to the base class.

Reimplemented from ACE_Service_Gestalt.

Definition at line 104 of file Service_Config.cpp.

References ACE_ARGV, ACE_ERROR_RETURN, ACE_TCHAR, ACE_TEXT, ACE_TRACE, ACE_ARGV_T< CHAR_TYPE >::add(), ACE_ARGV_T< CHAR_TYPE >::argc(), ACE_ARGV_T< CHAR_TYPE >::argv(), ACE_OS::atoi(), be_a_daemon_, ACE_Reactor::instance(), LM_ERROR, ACE_Service_Gestalt::parse_args_i(), pid_file_name_, ACE_Reactor::register_handler(), signal_handler_, and signum_.

00105 {
00106   ACE_TRACE ("ACE_Service_Config::parse_args_i");
00107 
00108   // Using PERMUTE_ARGS (default) in order to have all
00109   // unrecognized options and their value arguments moved
00110   // to the end of the argument vector. We'll pick them up
00111   // after processing our options and pass them on to the
00112   // base class for further parsing.
00113   //FUZZ: disable check_for_lack_ACE_OS
00114   ACE_Get_Opt getopt (argc,
00115                       argv,
00116                       ACE_TEXT ("bs:p:"),
00117                       1  ,                       // Start at argv[1].
00118                       0,                       // Do not report errors
00119                       ACE_Get_Opt::RETURN_IN_ORDER);
00120   //FUZZ: enable check_for_lack_ACE_OS
00121 
00122   // Keep a list of all unknown arguments, begin with the
00123   // executable's name
00124   ACE_ARGV superargv;
00125   superargv.add (argv[0]);
00126 
00127   //FUZZ: disable check_for_lack_ACE_OS
00128   for (int c; (c = getopt ()) != -1; )
00129   //FUZZ: enable check_for_lack_ACE_OS
00130     switch (c)
00131       {
00132       case 'p':
00133         ACE_Service_Config::pid_file_name_ = getopt.opt_arg ();
00134         break;
00135       case 'b':
00136         ACE_Service_Config::be_a_daemon_ = 1;
00137         break;
00138       case 's':
00139         {
00140           // There's no point in dealing with this on NT since it
00141           // doesn't really support signals very well...
00142 #if !defined (ACE_LACKS_UNIX_SIGNALS)
00143           ACE_Service_Config::signum_ =
00144             ACE_OS::atoi (getopt.opt_arg ());
00145 
00146           if (ACE_Reactor::instance ()->register_handler
00147               (ACE_Service_Config::signum_,
00148                ACE_Service_Config::signal_handler_) == -1)
00149             ACE_ERROR_RETURN ((LM_ERROR,
00150                                ACE_TEXT ("cannot obtain signal handler\n")),
00151                               -1);
00152 #endif /* ACE_LACKS_UNIX_SIGNALS */
00153           break;
00154         }
00155       default:
00156         superargv.add ( argv[getopt.opt_ind () - 1],true);
00157       }
00158 
00159   // Collect any argumets that were left
00160   for (int c = getopt.opt_ind (); c < argc; c++)
00161       superargv.add (argv[c-1],true);
00162 
00163   return ACE_Service_Gestalt::parse_args_i (superargv.argc (),
00164                                             superargv.argv ());
00165 
00166 } /* parse_args_i () */

int ACE_Service_Config::process_commandline_directives void   )  [static, protected]
 

Process service configuration requests that were provided on the command-line. Returns the number of errors that occurred.

Reimplemented from ACE_Service_Gestalt.

ACE_INLINE int ACE_Service_Config::process_directive const ACE_Static_Svc_Descriptor ssd,
int  force_replace = 0
[static]
 

Process one static service definition.

Load a new static service into the ACE_Service_Repository.

Parameters:
ssd Service descriptor, see the document of ACE_Static_Svc_Descriptor for more details.
force_replace If set the new service descriptor replaces any previous instance in the ACE_Service_Repository.
Returns:
Returns -1 if the service cannot be 'loaded'.

Reimplemented from ACE_Service_Gestalt.

Definition at line 154 of file Service_Config.inl.

References current(), and ACE_Service_Gestalt::process_directive().

00156 {
00157   return ACE_Service_Config::current ()->process_directive (ssd,
00158                                                             force_replace);
00159 }

ACE_INLINE int ACE_Service_Config::process_directive const ACE_TCHAR  directive[]  )  [static]
 

Process one service configuration directive, which is passed as a string. Returns the number of errors that occurred.

Reimplemented from ACE_Service_Gestalt.

Definition at line 140 of file Service_Config.inl.

References ACE_TCHAR, current(), and ACE_Service_Gestalt::process_directive().

Referenced by ACE_Service_Manager::process_request().

00141 {
00142   return ACE_Service_Config::current ()->process_directive (directive);
00143 }

ACE_INLINE int ACE_Service_Config::process_directives void   )  [static]
 

Process (or re-process) service configuration requests that are provided in the svc.conf file(s). Returns the number of errors that occurred.

Reimplemented from ACE_Service_Gestalt.

Definition at line 148 of file Service_Config.inl.

References current(), and ACE_Service_Gestalt::process_directives().

Referenced by reconfigure().

00149 {
00150   return ACE_Service_Config::current ()->process_directives ();
00151 }

int ACE_Service_Config::process_directives_i ACE_Svc_Conf_Param param  )  [static, protected]
 

This is the implementation function that process_directives() and process_directive() both call. Returns the number of errors that occurred.

Reimplemented from ACE_Service_Gestalt.

ACE_INLINE int ACE_Service_Config::process_file const ACE_TCHAR  file[]  )  [static]
 

Process a file containing a list of service configuration directives.

Reimplemented from ACE_Service_Gestalt.

Definition at line 133 of file Service_Config.inl.

References ACE_INLINE, ACE_TCHAR, current(), and ACE_Service_Gestalt::process_file().

00134 {
00135   return ACE_Service_Config::current ()->process_file (file);
00136 }

void ACE_Service_Config::reconfig_occurred int   )  [static]
 

Indicate that reconfiguration occurred.

Definition at line 568 of file Service_Config.cpp.

References ACE_TRACE, and reconfig_occurred_.

00569 {
00570   ACE_TRACE ("ACE_Service_Config::reconfig_occurred");
00571   ACE_Service_Config::reconfig_occurred_ = config_occurred;
00572 }

int ACE_Service_Config::reconfig_occurred void   )  [static]
 

True if reconfiguration occurred.

Definition at line 561 of file Service_Config.cpp.

References ACE_TRACE, and reconfig_occurred_.

Referenced by ACE_Reactor::check_reconfiguration(), and ACE_Service_Manager::reconfigure_services().

00562 {
00563   ACE_TRACE ("ACE_Service_Config::reconfig_occurred");
00564   return ACE_Service_Config::reconfig_occurred_ != 0;
00565 }

void ACE_Service_Config::reconfigure void   )  [static]
 

Perform the reconfiguration process.

Definition at line 483 of file Service_Config.cpp.

References ACE_DEBUG, ACE_ERROR, ACE_TEXT, ACE_TRACE, ACE::debug(), LM_DEBUG, LM_ERROR, process_directives(), reconfig_occurred_, and ACE_OS::time().

Referenced by ACE_Reactor::check_reconfiguration().

00484 {
00485   ACE_TRACE ("ACE_Service_Config::reconfigure");
00486 
00487   ACE_Service_Config::reconfig_occurred_ = 0;
00488 
00489   if (ACE::debug ())
00490     {
00491 #if !defined (ACE_NLOGGING)
00492       time_t t = ACE_OS::time (0);
00493 #endif /* ! ACE_NLOGGING */
00494       if (ACE::debug ())
00495         ACE_DEBUG ((LM_DEBUG,
00496                     ACE_TEXT ("beginning reconfiguration at %s"),
00497                     ACE_OS::ctime (&t)));
00498     }
00499   if (ACE_Service_Config::process_directives () == -1)
00500     ACE_ERROR ((LM_ERROR,
00501                 ACE_TEXT ("%p\n"),
00502                 ACE_TEXT ("process_directives")));
00503 }

int ACE_Service_Config::remove const ACE_TCHAR  svc_name[]  )  [static]
 

Totally remove svc_name from the daemon by removing it from the ACE_Reactor, and unlinking it if necessary.

Reimplemented from ACE_Service_Gestalt.

Definition at line 347 of file Service_Config.cpp.

References ACE_TCHAR, ACE_TRACE, ACE_Service_Repository::instance(), and ACE_Service_Repository::remove().

00348 {
00349   ACE_TRACE ("ACE_Service_Config::remove");
00350   return ACE_Service_Repository::instance ()->remove (svc_name);
00351 }

int ACE_Service_Config::resume const ACE_TCHAR  svc_name[]  )  [static]
 

Resume a svc_name that was previously suspended or has not yet been resumed (e.g., a static service).

Reimplemented from ACE_Service_Gestalt.

Definition at line 370 of file Service_Config.cpp.

References ACE_TCHAR, ACE_TRACE, ACE_Service_Repository::instance(), and ACE_Service_Repository::resume().

00371 {
00372   ACE_TRACE ("ACE_Service_Config::resume");
00373   return ACE_Service_Repository::instance ()->resume (svc_name);
00374 }

ACE_INLINE void ACE_Service_Config::signal_handler ACE_Sig_Adapter  )  [static]
 

Set the signal_handler;for internal use by ACE_Object_Manager only.

Definition at line 103 of file Service_Config.inl.

References signal_handler_.

Referenced by ACE_Object_Manager::init().

00104 {
00105   signal_handler_ = signal_handler;
00106 }

int ACE_Service_Config::start_daemon void   )  [static, protected]
 

Become a daemon.

ACE_Service_Gestalt * ACE_Service_Config::static_svcs void   )  [static]
 

Returns a pointer to the list of statically linked services.

Deprecated:
  • Same as instance(), but still useful in legacy code, (notably, one that can not be easily modified) which uses the following idiom for registering static services:
ACE_Service_Config::static_svcs ()->insert (...);

Definition at line 324 of file Service_Config.cpp.

References instance().

Referenced by ACE_Object_Manager_Preallocations::ACE_Object_Manager_Preallocations().

00325 {
00326   return ACE_Service_Config::instance ();
00327 }

int ACE_Service_Config::suspend const ACE_TCHAR  svc_name[]  )  [static]
 

Suspend svc_name. Note that this will not unlink the service from the daemon if it was dynamically linked, it will mark it as being suspended in the Service Repository and call the member function on the appropriate ACE_Service_Object. A service can be resumed later on by calling the member function...

Reimplemented from ACE_Service_Gestalt.

Definition at line 360 of file Service_Config.cpp.

References ACE_TCHAR, ACE_TRACE, ACE_Service_Repository::instance(), and ACE_Service_Repository::suspend().

00361 {
00362   ACE_TRACE ("ACE_Service_Config::suspend");
00363   return ACE_Service_Repository::instance ()->suspend (svc_name);
00364 }


Friends And Related Function Documentation

friend class ACE_Service_Config_Guard [friend]
 

This class needs the intimate access to be able to swap the current TSS pointer for the global Gestalt.

Reimplemented from ACE_Service_Gestalt.

Definition at line 605 of file Service_Config.h.


Member Data Documentation

ACE_Service_Config::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented from ACE_Service_Gestalt.

Definition at line 480 of file Service_Config.h.

int ACE_Service_Config::be_a_daemon_ = 0 [static, private]
 

Shall we become a daemon process?

Definition at line 89 of file Service_Config.cpp.

Referenced by open_i(), and parse_args_i().

ACE_TCHAR * ACE_Service_Config::pid_file_name_ = 0 [static, private]
 

Pathname of file to write process id.

Definition at line 86 of file Service_Config.cpp.

Referenced by open_i(), and parse_args_i().

sig_atomic_t ACE_Service_Config::reconfig_occurred_ = 0 [static, private]
 

True if reconfiguration occurred.

Definition at line 81 of file Service_Config.cpp.

Referenced by handle_signal(), reconfig_occurred(), and reconfigure().

ACE_Sig_Adapter * ACE_Service_Config::signal_handler_ = 0 [static, private]
 

Handles the reconfiguration signals.

Definition at line 78 of file Service_Config.cpp.

Referenced by open_i(), parse_args_i(), and signal_handler().

int ACE_Service_Config::signum_ = SIGHUP [static, private]
 

Number of the signal used to trigger reconfiguration.

Definition at line 92 of file Service_Config.cpp.

Referenced by ACE_Service_Config(), handle_signal(), open_i(), and parse_args_i().

ACE_TSS<ACE_Service_Gestalt> ACE_Service_Config::tss_ [protected]
 

A Wrapper for the TSS-stored pointer to the "current" configuration Gestalt. Static initializers from any DLL loaded through the SC will find the SC instance through the TSS pointer, instead of the global singleton. This makes it possible to ensure that the new services are loaded in the correct Gestalt, independent of which thread is actually using the SC at the time to do so.

Definition at line 267 of file Service_Config.h.

Referenced by current(), and instance().


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 12:57:15 2008 for ACE by doxygen 1.3.6