ACE_Service_Config Class Reference

Supplies common server operations for dynamic and static configuration of services. 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_Gestaltglobal (void)
ACE_Service_Gestaltcurrent (void)
ACE_Service_Gestaltinstance (void)
int open (const ACE_TCHAR program_name[], const ACE_TCHAR *logger_key=ACE_DEFAULT_LOGGER_KEY, int ignore_static_svcs=1, int ignore_default_svc_conf_file=0, int ignore_debug_flag=0)
int open (int argc, ACE_TCHAR *argv[], const ACE_TCHAR *logger_key=ACE_DEFAULT_LOGGER_KEY, int ignore_static_svcs=1, int ignore_default_svc_conf_file=0, int ignore_debug_flag=0)
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

ACE_Service_Gestaltcurrent (ACE_Service_Gestalt *)
 A mutator to set the "current" (TSS) gestalt instance.

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)

Private Member Functions

typedef ACE_TSS_TYPE (ACE_Service_Config::TSS_Resources) TSS_Service_Gestalt_Ptr

Static Private Member Functions

ACE_Service_Gestaltcurrent_i (ACE_Service_Gestalt *newcurrent)
 = Static interfaces

TSS_Service_Gestalt_Ptr *& impl_ (void)

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 services.

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 171 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 443 of file Service_Config.cpp.

References ACE_TRACE, ACE_Reactor::instance(), and signum_.

00446   : ACE_Service_Gestalt (size, false, ignore_static_svcs)
00447 {
00448   ACE_TRACE ("ACE_Service_Config::ACE_Service_Config");
00449 
00450   //  this->no_static_svcs_ = (ignore_static_svcs);
00451 
00452   ACE_Service_Config::signum_ = signum;
00453 
00454   // Initialize the Service Repository.
00455   //  ACE_Service_Repository::instance (static_cast<int> (size));
00456 
00457   // Initialize the ACE_Reactor (the ACE_Reactor should be the same
00458   // size as the ACE_Service_Repository).
00459   (void)ACE_Reactor::instance ();
00460 }

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 520 of file Service_Config.cpp.

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

00522   : ACE_Service_Gestalt (ACE_Service_Repository::DEFAULT_SIZE, false)
00523 {
00524   ACE_TRACE ("ACE_Service_Config::ACE_Service_Config");
00525 
00526   if (this->open (program_name,
00527                   logger_key) == -1 && errno != ENOENT)
00528     {
00529 
00530       // Only print out an error if it wasn't the svc.conf file that was
00531       // missing.
00532       ACE_ERROR ((LM_ERROR,
00533                   ACE_LIB_TEXT ("(%P|%t) SC failed to open: %p\n"),
00534                   program_name));
00535     }
00536 }

ACE_Service_Config::~ACE_Service_Config void   )  [virtual]
 

Perform user-specified close activities and remove dynamic memory.

Definition at line 617 of file Service_Config.cpp.

References ACE_TRACE.

00618 {
00619   ACE_TRACE ("ACE_Service_Config::~ACE_Service_Config");
00620 }


Member Function Documentation

typedef ACE_Service_Config::ACE_TSS_TYPE ACE_Service_Config::TSS_Resources   )  [private]
 

A type for the TSS-stored resources. The typedef helps to abstract from the particularities of single-threaded vs multi-threaded environments.

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 581 of file Service_Config.cpp.

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

Referenced by ACE_Object_Manager::fini().

00582 {
00583   return ACE_Service_Config::current ()->close ();
00584 }

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 587 of file Service_Config.cpp.

References ACE_TRACE, and ACE_Service_Repository::close_singleton().

00588 {
00589   ACE_TRACE ("ACE_Service_Config::close_svcs");
00590 
00591   ACE_Service_Repository::close_singleton ();
00592 
00593   return 0;
00594 }

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 479 of file Service_Config.cpp.

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

Referenced by ACE_Service_Type_Factory::make_service_type(), and ACE_Service_Gestalt::process_directive_i().

00484 {
00485   ACE_Service_Type_Impl *stp = 0;
00486 
00487   // Note, the only place we need to put a case statement.  This is
00488   // also the place where we'd put the RTTI tests, if the compiler
00489   // actually supported them!
00490 
00491   switch (type)
00492     {
00493     case ACE_Service_Type::SERVICE_OBJECT:
00494       ACE_NEW_RETURN (stp,
00495                       ACE_Service_Object_Type ((ACE_Service_Object *) symbol,
00496                                                name, flags,
00497                                                gobbler),
00498                       0);
00499       break;
00500     case ACE_Service_Type::MODULE:
00501       ACE_NEW_RETURN (stp,
00502                       ACE_Module_Type (symbol, name, flags),
00503                       0);
00504       break;
00505     case ACE_Service_Type::STREAM:
00506       ACE_NEW_RETURN (stp,
00507                       ACE_Stream_Type (symbol, name, flags),
00508                       0);
00509       break;
00510     default:
00511       ACE_ERROR ((LM_ERROR,
00512                   ACE_LIB_TEXT ("unknown case\n")));
00513       break;
00514     }
00515   return stp;
00516 
00517 }

ACE_Service_Gestalt * ACE_Service_Config::current void   )  [static]
 

Accessor for the "current" service repository through a pointer held in TSS.

Definition at line 325 of file Service_Config.cpp.

References ACE_GUARD_RETURN, ACE_TSS_GET, current_i(), global(), and impl_().

Referenced by ACE_Service_Config_Guard::ACE_Service_Config_Guard(), close(), initialize(), insert(), instance(), open(), parse_args(), process_directive(), process_directives(), static_svcs(), and ACE_Service_Config_Guard::~ACE_Service_Config_Guard().

00326 {
00327 
00328   if (ACE_Service_Config::impl_ () != 0)
00329     {
00330       // TSS already initialized, but a new thread may need its own
00331       // ptr to the process-wide gestalt.
00332       if (ACE_TSS_GET (ACE_Service_Config::impl_ (), TSS_Resources)->ptr_ == 0)
00333         return current_i (global ());
00334 
00335       return ACE_TSS_GET (ACE_Service_Config::impl_ (), TSS_Resources)->ptr_;
00336     }
00337   else
00338     {
00339       // TSS not initialized yet - first thread to hit this, so doing
00340       // the double-checked locking thing
00341       ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00342                                 *ACE_Static_Object_Lock::instance (), 0));
00343 
00344       if (ACE_Service_Config::impl_ () != 0)
00345         {
00346           // Another thread snuck in and initialized the TSS, but we
00347           // still need ow own ptr to the process-wide gestalt.
00348           if (ACE_TSS_GET (ACE_Service_Config::impl_ (), TSS_Resources)->ptr_ == 0)
00349             return current_i (global ());
00350 
00351           return ACE_TSS_GET (ACE_Service_Config::impl_ (), TSS_Resources)->ptr_;
00352         }
00353 
00354       return current_i (global ());
00355     }
00356 }

ACE_Service_Gestalt * ACE_Service_Config::current ACE_Service_Gestalt  )  [static, protected]
 

A mutator to set the "current" (TSS) gestalt instance.

Mutator to set the (TSS) global instance. Intended for use by helper classes, like ACE_Service_Config_Guard which when instantiated on the stack, can temporarily change which gestalt instance is viewed as global from the point of view of the static initializers in DLLs.

Definition at line 360 of file Service_Config.cpp.

References ACE_GUARD_RETURN, and current_i().

00361 {
00362    ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00363                              *ACE_Static_Object_Lock::instance (), 0));
00364 
00365   return current_i (newcurrent);
00366 }

ACE_Service_Gestalt * ACE_Service_Config::current_i ACE_Service_Gestalt newcurrent  )  [static, private]
 

= Static interfaces

A private, non-locking mutator to set the "current" (TSS) gestalt instance. Make sure to call with the proper locks held!

Definition at line 371 of file Service_Config.cpp.

References ACE_NEW_RETURN, ACE_TSS_GET, and impl_().

Referenced by current().

00372 {
00373   if (ACE_Service_Config::impl_ () == 0)
00374     {
00375       ACE_NEW_RETURN (ACE_Service_Config::impl_ (), TSS_Service_Gestalt_Ptr, 0);
00376     }
00377 
00378   ACE_TSS_GET (ACE_Service_Config::impl_ (), TSS_Resources)->ptr_ = newcurrent;
00379   return newcurrent;
00380 }

void ACE_Service_Config::dump void   )  const
 

Dump the state of an object.

Reimplemented from ACE_Service_Gestalt.

Definition at line 88 of file Service_Config.cpp.

References ACE_TRACE.

00089 {
00090 #if defined (ACE_HAS_DUMP)
00091   ACE_TRACE ("ACE_Service_Config::dump");
00092 #endif /* ACE_HAS_DUMP */
00093 }

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 597 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().

00598 {
00599   ACE_TRACE ("ACE_Service_Config::fini_svcs");
00600 
00601   // Clear the LM_DEBUG bit from log messages if appropriate
00602   if (ACE::debug ())
00603     ACE_Log_Msg::disable_debug_messages ();
00604 
00605   int result = 0;
00606   if (ACE_Service_Repository::instance () != 0)
00607     result = ACE_Service_Repository::instance ()->fini ();
00608 
00609   if (ACE::debug ())
00610     ACE_Log_Msg::enable_debug_messages ();
00611 
00612   return result;
00613 }

ACE_Service_Gestalt * ACE_Service_Config::global void   )  [static]
 

If not yet initialized, creates a process-wide instance global instance, which is registered with the ACE_Object_Manager, via ACE_Singleton. Note that this is allways the same instance, in contrast with current (), which may be different instance at different times, dependent on the context.

Definition at line 282 of file Service_Config.cpp.

References ACE_Singleton< TYPE, ACE_LOCK >::instance().

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

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

Handles signals to trigger reconfigurations.

Definition at line 541 of file Service_Config.cpp.

References ACE_ASSERT, reconfig_occurred_, signum_, and ucontext_t.

00544 {
00545 #if defined (ACE_NDEBUG)
00546   ACE_UNUSED_ARG (sig);
00547 #else  /* ! ACE_NDEBUG */
00548   ACE_ASSERT (ACE_Service_Config::signum_ == sig);
00549 #endif /* ! ACE_NDEBUG */
00550 
00551   ACE_Service_Config::reconfig_occurred_ = 1;
00552 }

ACE_Service_Config::TSS_Service_Gestalt_Ptr *& ACE_Service_Config::impl_ void   )  [static, private]
 

Provides access to the static ptr, containing the TSS accessor. Ensures the desired order of initialization, even when other static initializers need the value.

A "straight" static ptr does not work in static builds, because some static initializer may call current() method and assign value to instance_ *before* the startup code has had a chance to initialize it . This results in instance_ being "zeroed" out after it was assigned the correct value. Having a method scoped static guarantees that the first time the method is invoked, the instance_ will be initialized before returning.

Definition at line 304 of file Service_Config.cpp.

Referenced by current(), and current_i().

00305 {
00306   /// A "straight" static ptr does not work in static builds, because
00307   /// some static initializer may call current() method and assign
00308   /// value to instance_ *before* the startup code has had a chance to
00309   /// initialize it . This results in instance_ being "zeroed" out
00310   /// after it was assigned the correct value. Having a method scoped
00311   /// static guarantees that the first time the method is invoked, the
00312   /// instance_ will be initialized before returning.
00313 
00314   static TSS_Service_Gestalt_Ptr *instance_ = 0;
00315 
00316   return instance_;
00317 }

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 79 of file Service_Config.inl.

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

00081 {
00082   ACE_TRACE ("ACE_Service_Config::initialize");
00083   return ACE_Service_Config::current ()->initialize (svc_name,
00084                                                      parameters);
00085 }

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 91 of file Service_Config.inl.

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

00093 {
00094   ACE_TRACE ("ACE_Service_Config::initialize");
00095   return ACE_Service_Config::current ()->initialize (sr,
00096                                                      parameters);
00097 }

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 399 of file Service_Config.cpp.

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

00400 {
00401   return ACE_Service_Config::current ()->insert (stsd);
00402 }

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 keep interface changes to a minimum this method merely forwards to current(). Thus it is possible to temporarily replace what those initializers think is the global service repository, for instance when dynamically loading a service from a DLL, which in turn, contains its own static services.

Definition at line 290 of file Service_Config.cpp.

References current().

00291 {
00292   return  ACE_Service_Config::current ();
00293 }

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,
int  ignore_static_svcs = 1,
int  ignore_default_svc_conf_file = 0,
int  ignore_debug_flag = 0
[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,
int  ignore_static_svcs = 1,
int  ignore_default_svc_conf_file = 0,
int  ignore_debug_flag = 0
[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 138 of file Service_Config.cpp.

References ACE_DEBUG, ACE_DEFAULT_LOGGER_KEY, ACE_DEFAULT_SVC_CONF, ACE_ERROR, ACE_ERROR_RETURN, ACE_LIB_TEXT, 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().

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

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 96 of file Service_Config.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TCHAR, ACE_TRACE, 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_.

00097 {
00098   ACE_TRACE ("ACE_Service_Config::parse_args_i");
00099   ACE_Get_Opt getopt (argc,
00100                       argv,
00101                       ACE_LIB_TEXT ("bs:p:"),
00102                       1); // Start at argv[1].
00103 
00104   for (int c; (c = getopt ()) != -1; )
00105     switch (c)
00106       {
00107       case 'p':
00108         ACE_Service_Config::pid_file_name_ = getopt.opt_arg ();
00109         break;
00110       case 'b':
00111         ACE_Service_Config::be_a_daemon_ = 1;
00112         break;
00113       case 's':
00114         {
00115           // There's no point in dealing with this on NT since it
00116           // doesn't really support signals very well...
00117 #if !defined (ACE_LACKS_UNIX_SIGNALS)
00118           ACE_Service_Config::signum_ =
00119             ACE_OS::atoi (getopt.opt_arg ());
00120 
00121           if (ACE_Reactor::instance ()->register_handler
00122               (ACE_Service_Config::signum_,
00123                ACE_Service_Config::signal_handler_) == -1)
00124             ACE_ERROR_RETURN ((LM_ERROR,
00125                                ACE_LIB_TEXT ("cannot obtain signal handler\n")),
00126                               -1);
00127 #endif /* ACE_LACKS_UNIX_SIGNALS */
00128           break;
00129         }
00130       }
00131 
00132   return ACE_Service_Gestalt::parse_args_i (argc, argv);
00133 
00134 } /* 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 115 of file Service_Config.inl.

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

00117 {
00118   return ACE_Service_Config::current ()->process_directive (ssd,
00119                                                             force_replace);
00120 }

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 101 of file Service_Config.inl.

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

Referenced by ACE_Service_Manager::process_request().

00102 {
00103   return ACE_Service_Config::current ()->process_directive (directive);
00104 }

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 109 of file Service_Config.inl.

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

Referenced by reconfigure().

00110 {
00111   return ACE_Service_Config::current ()->process_directives ();
00112 }

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.

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.

void ACE_Service_Config::reconfig_occurred int   )  [static]
 

Indicate that reconfiguration occurred.

Definition at line 633 of file Service_Config.cpp.

References ACE_TRACE, and reconfig_occurred_.

00634 {
00635   ACE_TRACE ("ACE_Service_Config::reconfig_occurred");
00636   ACE_Service_Config::reconfig_occurred_ = config_occurred;
00637 }

int ACE_Service_Config::reconfig_occurred void   )  [static]
 

True if reconfiguration occurred.

Definition at line 626 of file Service_Config.cpp.

References ACE_TRACE, and reconfig_occurred_.

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

00627 {
00628   ACE_TRACE ("ACE_Service_Config::reconfig_occurred");
00629   return ACE_Service_Config::reconfig_occurred_ != 0;
00630 }

void ACE_Service_Config::reconfigure void   )  [static]
 

Perform the reconfiguration process.

Definition at line 557 of file Service_Config.cpp.

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

Referenced by ACE_Reactor::check_reconfiguration(), and ACE_Proactor::check_reconfiguration().

00558 {
00559   ACE_TRACE ("ACE_Service_Config::reconfigure");
00560 
00561   ACE_Service_Config::reconfig_occurred_ = 0;
00562 
00563   if (ACE::debug ())
00564     {
00565 #if !defined (ACE_NLOGGING)
00566       time_t t = ACE_OS::time (0);
00567 #endif /* ! ACE_NLOGGING */
00568       if (ACE::debug ())
00569         ACE_DEBUG ((LM_DEBUG,
00570                     ACE_LIB_TEXT ("beginning reconfiguration at %s"),
00571                     ACE_OS::ctime (&t)));
00572     }
00573   if (ACE_Service_Config::process_directives () == -1)
00574     ACE_ERROR ((LM_ERROR,
00575                 ACE_LIB_TEXT ("%p\n"),
00576                 ACE_LIB_TEXT ("process_directives")));
00577 }

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 409 of file Service_Config.cpp.

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

00410 {
00411   ACE_TRACE ("ACE_Service_Config::remove");
00412   return ACE_Service_Repository::instance ()->remove (svc_name);
00413 }

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 432 of file Service_Config.cpp.

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

00433 {
00434   ACE_TRACE ("ACE_Service_Config::resume");
00435   return ACE_Service_Repository::instance ()->resume (svc_name);
00436 }

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 71 of file Service_Config.inl.

References signal_handler_.

Referenced by ACE_Object_Manager::init().

00072 {
00073   signal_handler_ = signal_handler;
00074 }

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 392 of file Service_Config.cpp.

References current().

Referenced by ACE_Object_Manager_Preallocations::ACE_Object_Manager_Preallocations().

00393 {
00394   return ACE_Service_Config::current ();
00395 }

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 422 of file Service_Config.cpp.

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

00423 {
00424   ACE_TRACE ("ACE_Service_Config::suspend");
00425   return ACE_Service_Repository::instance ()->suspend (svc_name);
00426 }


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 589 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 460 of file Service_Config.h.

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

Shall we become a daemon process?

Definition at line 81 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 78 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 73 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 70 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 84 of file Service_Config.cpp.

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


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:28:59 2006 for ACE by doxygen 1.3.6