---
name: "ACE_Service_Config"
section: "3"
platform: "linux"
package: "libace-doc"
version: "5.0.7-4"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/ACE_Service_Config"
---

# ACE\_Service\_Config(3)

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

## NAME

ACE\_Service\_Config -  Supplies common server operations for dynamic and static configuration of services.

## SYNOPSIS

```
#include <ace/Service_Config.h>
class ACE_Service_Config
{
  public:
    enum { MAX_SERVICES = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE };
    ACE_Service_Config (
        int ignore_static_svcs = 1,
        size_t size = ACE_Service_Config::MAX_SERVICES,
        int signum = SIGHUP
        );
    ACE_Service_Config (
        const ASYS_TCHAR program_name[],
        LPCTSTR logger_key = ACE_DEFAULT_LOGGER_KEY
        );
    static int open_i (
        const ASYS_TCHAR program_name[],
        LPCTSTR logger_key = ACE_DEFAULT_LOGGER_KEY,
        int ignore_default_svc_conf_file = 0
        );
    static int open (
        const ASYS_TCHAR program_name[],
        LPCTSTR logger_key = ACE_DEFAULT_LOGGER_KEY,
        int ignore_static_svcs = 1,
        int ignore_default_svc_conf_file = 0
        );
    static int open (
        int argc,
        ASYS_TCHAR *argv[],
        LPCTSTR logger_key = ACE_DEFAULT_LOGGER_KEY,
        int ignore_static_svcs = 1,
        int ignore_default_svc_conf = 0
        );
    virtual ~ACE_Service_Config (void);
    static int close (void);
    static int fini_svcs (void);
    static int close_svcs (void);
    static int close_singletons (void);
    static int run_reactor_event_loop (void);
    static int run_reactor_event_loop (ACE_Time_Value &tv);
    static int end_reactor_event_loop (void);
    static int reactor_event_loop_done (void);
    static int reconfig_occurred (void);
    static void reconfig_occurred (int);
    static void reconfigure (void);
    static ACE_STATIC_SVCS *static_svcs (void);
    static ACE_Reactor *reactor (void);
    static ACE_Reactor *reactor (ACE_Reactor *);
    static ACE_Service_Repository *svc_rep (void);
    static ACE_Service_Repository *svc_rep (ACE_Service_Repository *);
    static ACE_Thread_Manager *thr_mgr (void);
    static ACE_Thread_Manager *thr_mgr (ACE_Thread_Manager *);
    static ACE_Allocator *alloc (void);
    static ACE_Allocator *alloc (ACE_Allocator *);
    static int initialize (
        const ACE_Service_Type *,
        ASYS_TCHAR parameters[]
        );
    static int initialize (
        const ASYS_TCHAR svc_name[],
        ASYS_TCHAR parameters[]
        );
    static int resume (const ASYS_TCHAR svc_name[]);
    static int suspend (const ASYS_TCHAR svc_name[]);
    static int remove (const ASYS_TCHAR svc_name[]);
    static int initialize (
        const ACE_Service_Type *,
        char parameters[]
        );
    static int initialize (const char svc_name[], char parameters[]);
    static int resume (const char svc_name[]);
    static int suspend (const char svc_name[]);
    static int remove (const char svc_name[]);
    void dump (void) const;
    static ACE_INLINE void signal_handler (ACE_Sig_Adapter *);
    ACE_ALLOC_HOOK_DECLARE;
    static int process_directive (const ASYS_TCHAR directive[]);
    static int process_directives (void);
    static void handle_signal (int sig, siginfo_t *, ucontext_t *);
  protected:
    static int process_commandline_directives (void);
    static int process_directives_i (void);
    static int parse_args (int, ASYS_TCHAR *argv[]);
    static int start_daemon (void);
    static int load_static_svcs (void);
  private:
    static LPCTSTR logger_key_;
    static ACE_STATIC_SVCS *static_svcs_;
    static ACE_SVC_QUEUE *svc_queue_;
    static ACE_SVC_QUEUE *svc_conf_file_queue_;
    static int init_svc_conf_file_queue (void);
    static sig_atomic_t reconfig_occurred_;
    static char be_a_daemon_;
    static char no_static_svcs_;
    static int signum_;
    static ACE_Sig_Adapter *signal_handler_;
    static int is_initialized_;
};
```

## DESCRIPTION

The ACE\_Service\_Config uses the Monostate pattern.  Therefore, you can only have one of these instantiated per-process.

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.

## Initialization and termination methods.

```
ACE_Service_Config (
    int ignore_static_svcs = 1,
    size_t size = ACE_Service_Config::MAX_SERVICES,
    int signum = SIGHUP
    );
```

Initialize the Service Repository.

```
ACE_Service_Config (
    const ASYS_TCHAR program_name[],
    LPCTSTR logger_key = ACE_DEFAULT_LOGGER_KEY
    );
```

Performs an open without parsing command-line arguments.

```
static int open_i (
    const ASYS_TCHAR program_name[],
    LPCTSTR logger_key = ACE_DEFAULT_LOGGER_KEY,
    int ignore_default_svc_conf_file = 0
    );
```

Performs an open without parsing command-line arguments.  If ignore\_default\_svc\_conf\_file is non-0 then the "svc.conf" file will be ignored.  Returns number of errors that occurred on failure and 0 otherwise.

```
static int open (
    const ASYS_TCHAR program_name[],
    LPCTSTR logger_key = ACE_DEFAULT_LOGGER_KEY,
    int ignore_static_svcs = 1,
    int ignore_default_svc_conf_file = 0
    );
```

Performs an open without parsing command-line arguments.  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.

```
static int open (
    int argc,
    ASYS_TCHAR *argv[],
    LPCTSTR logger_key = ACE_DEFAULT_LOGGER_KEY,
    int ignore_static_svcs = 1,
    int ignore_default_svc_conf = 0
    );
```

This is the primary entry point into the ACE\_Service\_Config (the constructor just handles simple initializations).  It parses arguments passed in from the command-line.  The arguments that are valid in a call to this method include:

       be written\
        A static service repostory will be constructed if the flag\
        is used.  Use this flag to override the default\
        ignore\_static\_svcs flag at run-time.\
        eliminates the need to construct the static service repository.\
        Please observe the difference between options '-f' that looks\
        for a list of files and here a list of services.

Returns number of errors that occurred on failure and 0 otherwise.

```
virtual ~ACE_Service_Config (void);
```

Perform user-specified close activities and remove dynamic memory.

```
static int close (void);
```

Tidy up and perform last rites when ACE\_Service\_Config is shut down.  This method calls close\_svcs and close\_singletons. Returns 0.

```
static int fini_svcs (void);
```

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

```
static int close_svcs (void);
```

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

```
static int close_singletons (void);
```

Delete the dynamically allocated Singletons (i.e., the Reactor, Proactor, ReactorEx, Thread\_Manager, and Allocator). Returns 0.

## Reactor event loop management methods.

```
static int run_reactor_event_loop (void);
```

Run the event loop until the ACE\_Reactor::handle\_events method returns -1 or the end\_reactor\_event\_loop method is invoked. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Reactor::run\_event\_loop instead.

```
static int run_reactor_event_loop (ACE_Time_Value &tv);
```

Run the event loop until the ACE\_Reactor::handle\_events method returns -1, the end\_reactor\_event\_loop method is invoked, or the ACE\_Time\_Value expires. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Reactor::run\_event\_loop instead.

```
static int end_reactor_event_loop (void);
```

Instruct the ACE\_Service\_Config to terminate its event loop and notifies the ACE\_Reactor::instance so that it can wake up and close down gracefully. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Reactor::end\_event\_loop instead.

```
static int reactor_event_loop_done (void);
```

Report if the Reactor's event loop is finished. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Reactor::event\_loop\_done instead.

```
static int reconfig_occurred (void);
```

True if reconfiguration occurred.

```
static void reconfig_occurred (int);
```

Indicate that reconfiguration occurred.

```
static void reconfigure (void);
```

Perform the reconfiguration process.

## The following methods are static in order to enforce Singleton

semantics for the Reactor, Service\_Repository, Thread\_Manager, and Acceptor/Connector Strategy factory.  Other portions of the system may need to access them at some point or another...

## Accessors and mutators for process-wide Singletons.

```
static ACE_STATIC_SVCS *static_svcs (void);
```

Returns a pointer to the list of statically linked services.

```
static ACE_Reactor *reactor (void);
```

Get pointer to a process-wide ACE\_Reactor. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Reactor::instance instead.

```
static ACE_Reactor *reactor (ACE_Reactor *);
```

Set pointer to a process-wide ACE\_Reactor and return existing pointer. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Reactor::instance instead.

```
static ACE_Service_Repository *svc_rep (void);
```

Get pointer to a process-wide ACE\_Service\_Repository. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Service\_Repository::instance instead.

```
static ACE_Service_Repository *svc_rep (ACE_Service_Repository *);
```

Set pointer to a process-wide ACE\_Service\_Repository and return existing pointer. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Service\_Repository::instance instead.

```
static ACE_Thread_Manager *thr_mgr (void);
```

Get pointer to a process-wide ACE\_Thread\_Manager. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Thread\_Manager::instance instead.

```
static ACE_Thread_Manager *thr_mgr (ACE_Thread_Manager *);
```

Set pointer to a process-wide ACE\_Thread\_Manager and return existing pointer. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Thread\_Manager::instance instead.

```
static ACE_Allocator *alloc (void);
```

Get pointer to a default ACE\_Allocator. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Allocator::instance instead.

```
static ACE_Allocator *alloc (ACE_Allocator *);
```

Set pointer to a process-wide ACE\_Allocator and return existing pointer. DO NOT USE THIS METHOD. It may be unsupported in future releases. Use ACE\_Allocator::instance instead.

## Utility methods.

```
static int initialize (
    const ACE_Service_Type *,
    ASYS_TCHAR parameters[]
    );
```

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

```
static int initialize (
    const ASYS_TCHAR svc_name[],
    ASYS_TCHAR parameters[]
    );
```

Initialize and activate a statically svc\_name service.

```
static int resume (const ASYS_TCHAR svc_name[]);
```

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

```
static int suspend (const ASYS_TCHAR svc_name[]);
```

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 suspend member function on the appropriate ACE\_Service\_Object.  A service can be resumed later on by calling the RESUME member function...

```
static int remove (const ASYS_TCHAR svc_name[]);
```

Totally remove svc\_name from the daemon by removing it from the ACE\_Reactor, and unlinking it if necessary.

We must provide these function to bridge the Svc\_Conf parser with ACE.

```
static int initialize (const ACE_Service_Type *, char parameters[]);
```

```
static int initialize (const char svc_name[], char parameters[]);
```

```
static int resume (const char svc_name[]);
```

```
static int suspend (const char svc_name[]);
```

```
static int remove (const char svc_name[]);
```

```
void dump (void) const;
```

Dump the state of an object.

```
static ACE_INLINE void signal_handler (ACE_Sig_Adapter *);
```

Set the signal\_handler;for internal use by ACE\_Object\_Manager only.

```
ACE_ALLOC_HOOK_DECLARE;
```

Declare the dynamic allocation hooks.

```
static int process_directive (const ASYS_TCHAR directive[]);
```

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

```
static int process_directives (void);
```

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

```
static void handle_signal (int sig, siginfo_t *, ucontext_t *);
```

Handles signals to trigger reconfigurations.

## Set by command-line options.

```
static char be_a_daemon_;
```

Shall we become a daemon process?

```
static char no_static_svcs_;
```

Should we avoid loading the static services?

```
static int signum_;
```

Number of the signal used to trigger reconfiguration.

```
static ACE_Sig_Adapter *signal_handler_;
```

Handles the reconfiguration signals.

```
static int is_initialized_;
```

Keep track of whether the ACE\_Service\_Config is already initialized.  If so, we can't allow yyparse to be called since it's not reentrant.  This variable is incremented by the ACE\_Service\_Config::open method and decremented by the ACE\_Service\_Config::close method.

## AUTHOR

Doug Schmidt

## LIBRARY

ace
