*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// -*- C++ -*-
|
||||
|
||||
//====================================================================
|
||||
/**
|
||||
* @file Service_Config.h
|
||||
@@ -8,19 +9,26 @@
|
||||
* @author Douglas C. Schmidt <[email protected]>
|
||||
*/
|
||||
//====================================================================
|
||||
|
||||
#ifndef ACE_SERVICE_CONFIG_H
|
||||
#define ACE_SERVICE_CONFIG_H
|
||||
|
||||
#include /**/ "ace/pre.h"
|
||||
|
||||
#include /**/ "ace/config-all.h"
|
||||
#include "ace/Default_Constants.h"
|
||||
#include "ace/Intrusive_Auto_Ptr.h"
|
||||
#include "ace/Service_Gestalt.h"
|
||||
#include "ace/Synch_Traits.h"
|
||||
|
||||
#if !defined (ACE_LACKS_PRAGMA_ONCE)
|
||||
# pragma once
|
||||
#endif /* ACE_LACKS_PRAGMA_ONCE */
|
||||
|
||||
#include "ace/OS_NS_signal.h"
|
||||
|
||||
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
// Forward decl.
|
||||
class ACE_Service_Object;
|
||||
class ACE_Service_Type;
|
||||
@@ -31,6 +39,7 @@ class ACE_Allocator;
|
||||
class ACE_Reactor;
|
||||
class ACE_Thread_Manager;
|
||||
class ACE_DLL;
|
||||
|
||||
#if (ACE_USES_CLASSIC_SVC_CONF == 1)
|
||||
#define ACE_STATIC_SERVICE_DIRECTIVE(ident, parameters) \
|
||||
ACE_TEXT ("static ") \
|
||||
@@ -77,12 +86,16 @@ class ACE_Svc_Conf_Param;
|
||||
ACE_TEXT ("\"></remove></ACE_Svc_Conf>")
|
||||
class ACE_XML_Svc_Conf;
|
||||
#endif /* ACE_USES_CLASSIC_SVC_CONF == 1 */
|
||||
|
||||
ACE_END_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef ACE_Service_Object *(*ACE_SERVICE_ALLOCATOR) (ACE_Service_Object_Exterminator *);
|
||||
}
|
||||
|
||||
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
/**
|
||||
* @class ACE_Static_Svc_Descriptor
|
||||
*
|
||||
@@ -94,25 +107,34 @@ class ACE_Static_Svc_Descriptor
|
||||
public:
|
||||
/// Name of the service.
|
||||
const ACE_TCHAR *name_;
|
||||
|
||||
/// Type of service.
|
||||
int type_;
|
||||
|
||||
/// Factory function that allocates the service.
|
||||
ACE_SERVICE_ALLOCATOR alloc_;
|
||||
|
||||
/// Bitmask flags indicating how the framework should delete memory.
|
||||
u_int flags_;
|
||||
|
||||
/// Flag indicating whether the service starts out active.
|
||||
int active_;
|
||||
|
||||
/// Dump the state of an object.
|
||||
void dump (void) const;
|
||||
|
||||
/// Declare the dynamic allocation hooks.
|
||||
ACE_ALLOC_HOOK_DECLARE;
|
||||
|
||||
public:
|
||||
/// Compare two service descriptors for equality.
|
||||
bool operator== (ACE_Static_Svc_Descriptor &) const;
|
||||
|
||||
/// Compare two service descriptors for inequality.
|
||||
bool operator!= (ACE_Static_Svc_Descriptor &) const;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @class ACE_Threading_Helper
|
||||
*
|
||||
@@ -129,6 +151,7 @@ template <typename LOCK>
|
||||
class ACE_Threading_Helper
|
||||
{
|
||||
};
|
||||
|
||||
/*
|
||||
* Specialization for a multi threaded program
|
||||
*/
|
||||
@@ -138,13 +161,16 @@ class ACE_Export ACE_Threading_Helper<ACE_Thread_Mutex>
|
||||
public:
|
||||
ACE_Threading_Helper ();
|
||||
~ACE_Threading_Helper ();
|
||||
|
||||
void set (void*);
|
||||
void* get (void);
|
||||
|
||||
private:
|
||||
/// Key for the thread-specific data, which is a simple pointer to
|
||||
/// the thread's (currently-) global configuration context.
|
||||
ACE_thread_key_t key_;
|
||||
};
|
||||
|
||||
/*
|
||||
* Specialization for a single threaded program
|
||||
*/
|
||||
@@ -154,10 +180,13 @@ class ACE_Export ACE_Threading_Helper<ACE_Null_Mutex>
|
||||
public:
|
||||
ACE_Threading_Helper ();
|
||||
~ACE_Threading_Helper ();
|
||||
|
||||
void set (void*);
|
||||
void* get (void);
|
||||
};
|
||||
|
||||
#define ACE_Component_Config ACE_Service_Config
|
||||
|
||||
/**
|
||||
* @class ACE_Service_Config
|
||||
*
|
||||
@@ -191,18 +220,23 @@ public:
|
||||
*/
|
||||
class ACE_Export ACE_Service_Config
|
||||
{
|
||||
|
||||
/// The Instance, or the global (default) configuration context.
|
||||
/// The monostate would forward the calls to that instance. The TSS
|
||||
/// will point here
|
||||
ACE_Intrusive_Auto_Ptr<ACE_Service_Gestalt> instance_;
|
||||
|
||||
/// A helper instance to manage thread-specific key creation.
|
||||
/// Dependent on the syncronization mutex ACE uses, the corresponding
|
||||
/// partial template instantiation will perform the right services
|
||||
/// that have to do with managing thread-specific storage. Note that,
|
||||
/// for single-threaded builds they would do (next to) nothing.
|
||||
ACE_Threading_Helper<ACE_SYNCH_MUTEX> threadkey_;
|
||||
|
||||
public:
|
||||
|
||||
// = Initialization and termination methods.
|
||||
|
||||
/**
|
||||
* Initialize the Service Repository. Note that initialising @a
|
||||
* signum to a negative number will prevent a signal handler being
|
||||
@@ -211,6 +245,7 @@ public:
|
||||
ACE_Service_Config (bool ignore_static_svcs = true,
|
||||
size_t size = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE,
|
||||
int signum = SIGHUP);
|
||||
|
||||
/**
|
||||
* Performs an open without parsing command-line arguments. The
|
||||
* @a logger_key indicates where to write the logging output, which
|
||||
@@ -218,10 +253,13 @@ public:
|
||||
*/
|
||||
ACE_Service_Config (const ACE_TCHAR program_name[],
|
||||
const ACE_TCHAR *logger_key = ACE_DEFAULT_LOGGER_KEY);
|
||||
|
||||
/// Perform user-specified close activities and remove dynamic
|
||||
/// memory.
|
||||
virtual ~ACE_Service_Config (void);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Performs an open without parsing command-line arguments.
|
||||
* Implements whats different in the opening sequence
|
||||
@@ -240,18 +278,22 @@ private:
|
||||
bool ignore_static_svcs,
|
||||
bool ignore_default_svc_conf_file,
|
||||
bool ignore_debug_flag);
|
||||
|
||||
/**
|
||||
* Implements whats different in the command line parameter processing
|
||||
* for this class, as opposed to the base class.
|
||||
*/
|
||||
virtual int parse_args_i (int argc, ACE_TCHAR *argv[]);
|
||||
|
||||
/// = Static interfaces
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns the process-wide global singleton instance. It would
|
||||
* have been created and will be managed by the Object Manager.
|
||||
*/
|
||||
static ACE_Service_Config* singleton (void);
|
||||
|
||||
/**
|
||||
* Mutator for the currently active configuration context instance
|
||||
* (gestalt). Intended for use by helper classes like @see
|
||||
@@ -260,10 +302,12 @@ private:
|
||||
* initializers (especially those in DLLs loaded at run-time).
|
||||
*/
|
||||
static void current (ACE_Service_Gestalt*);
|
||||
|
||||
/**
|
||||
* Accessor for the "current" service gestalt
|
||||
*/
|
||||
static ACE_Service_Gestalt* current (void);
|
||||
|
||||
/**
|
||||
* This is what the static service initializators are hard-wired to
|
||||
* use, so in order to avoid interface changes this method merely
|
||||
@@ -276,6 +320,7 @@ private:
|
||||
* @deprecated Use current() instead.
|
||||
*/
|
||||
static ACE_Service_Gestalt* instance (void);
|
||||
|
||||
/**
|
||||
* Returns a process-wide global singleton instance in contrast with
|
||||
* current (), which may return a different instance at different
|
||||
@@ -285,6 +330,7 @@ private:
|
||||
* caution!
|
||||
*/
|
||||
static ACE_Service_Gestalt* global (void);
|
||||
|
||||
/**
|
||||
* Performs an open without parsing command-line arguments. The
|
||||
* @a logger_key indicates where to write the logging output, which
|
||||
@@ -304,6 +350,7 @@ private:
|
||||
bool ignore_static_svcs = true,
|
||||
bool ignore_default_svc_conf_file = false,
|
||||
bool ignore_debug_flag = false);
|
||||
|
||||
/**
|
||||
* This is the primary entry point into the ACE_Service_Config (the
|
||||
* constructor just handles simple initializations). It parses
|
||||
@@ -360,28 +407,37 @@ private:
|
||||
bool ignore_static_svcs = true,
|
||||
bool ignore_default_svc_conf_file = false,
|
||||
bool ignore_debug_flag = false);
|
||||
|
||||
/// Tidy up and perform last rites when ACE_Service_Config is shut
|
||||
/// down. This method calls close_svcs(). Returns 0.
|
||||
static int close (void);
|
||||
|
||||
/// Perform user-specified close hooks and possibly delete all of the
|
||||
/// configured services in the <Service_Repository>.
|
||||
static int fini_svcs (void);
|
||||
|
||||
/// True if reconfiguration occurred.
|
||||
static int reconfig_occurred (void);
|
||||
|
||||
/// Indicate that reconfiguration occurred.
|
||||
static void reconfig_occurred (int);
|
||||
|
||||
/// Perform the reconfiguration process.
|
||||
static void reconfigure (void);
|
||||
|
||||
// = 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...
|
||||
|
||||
// = This is not strictly needed, anymore since the service configurator
|
||||
// has been refactored to allow multiple service configuration
|
||||
// instances (called gestalts). The interfaces, however were retained in for
|
||||
// the sake of maintaining source-code compatibility.
|
||||
|
||||
|
||||
// = Accessors and mutators for process-wide Singletons.
|
||||
|
||||
/// Returns a pointer to the list of statically linked services.
|
||||
///
|
||||
/// @deprecated - Same as instance(), but still useful in legacy code,
|
||||
@@ -390,6 +446,7 @@ private:
|
||||
///
|
||||
/// ACE_Service_Config::static_svcs ()->insert (...);
|
||||
static ACE_Service_Gestalt* static_svcs (void);
|
||||
|
||||
/// 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().
|
||||
@@ -397,17 +454,21 @@ private:
|
||||
/// services repository and provide a better way of debugging service
|
||||
/// loading and registration problems.
|
||||
static int insert (ACE_Static_Svc_Descriptor *svc);
|
||||
|
||||
// = Utility methods.
|
||||
/// Dynamically link the shared object file and retrieve a pointer to
|
||||
/// the designated shared object in this file.
|
||||
static int initialize (const ACE_Service_Type *,
|
||||
const ACE_TCHAR *parameters);
|
||||
|
||||
/// Initialize and activate a statically @a svc_name service.
|
||||
static int initialize (const ACE_TCHAR *svc_name,
|
||||
const ACE_TCHAR *parameters);
|
||||
|
||||
/// Resume a @a svc_name that was previously suspended or has not yet
|
||||
/// been resumed (e.g., a static service).
|
||||
static int resume (const ACE_TCHAR svc_name[]);
|
||||
|
||||
/**
|
||||
* Suspend @a svc_name. Note that this will not unlink the service
|
||||
* from the daemon if it was dynamically linked, it will mark it as
|
||||
@@ -417,9 +478,11 @@ private:
|
||||
* function...
|
||||
*/
|
||||
static int suspend (const ACE_TCHAR svc_name[]);
|
||||
|
||||
/// Totally remove @a svc_name from the daemon by removing it
|
||||
/// from the ACE_Reactor, and unlinking it if necessary.
|
||||
static int remove (const ACE_TCHAR svc_name[]);
|
||||
|
||||
#if defined (ACE_HAS_WINCE) && defined (ACE_USES_WCHAR)
|
||||
// We must provide these function to bridge the Svc_Conf parser
|
||||
// with ACE.
|
||||
@@ -429,18 +492,24 @@ private:
|
||||
static int suspend (const ACE_ANTI_TCHAR svc_name[]);
|
||||
static int remove (const ACE_ANTI_TCHAR svc_name[]);
|
||||
#endif /* ACE_HAS_WINCE */
|
||||
|
||||
/// Dump the state of an object.
|
||||
void dump (void) const;
|
||||
|
||||
/// Set the signal_handler;for internal use by ACE_Object_Manager only.
|
||||
static ACE_INLINE void signal_handler (ACE_Sig_Adapter *);
|
||||
|
||||
/// Declare the dynamic allocation hooks.
|
||||
ACE_ALLOC_HOOK_DECLARE;
|
||||
|
||||
/// Process a file containing a list of service configuration
|
||||
/// directives.
|
||||
static int process_file (const ACE_TCHAR file[]);
|
||||
|
||||
/// Process one service configuration @a directive, which is passed as
|
||||
/// a string. Returns the number of errors that occurred.
|
||||
static int process_directive (const ACE_TCHAR directive[]);
|
||||
|
||||
/**
|
||||
* Process one static service definition. Load a new static service
|
||||
* into the ACE_Service_Repository.
|
||||
@@ -455,14 +524,17 @@ private:
|
||||
*/
|
||||
static int process_directive (const ACE_Static_Svc_Descriptor &ssd,
|
||||
bool force_replace = false);
|
||||
|
||||
/**
|
||||
* Process (or re-process) service configuration requests that are
|
||||
* provided in the svc.conf file(s). Returns the number of errors
|
||||
* that occurred.
|
||||
*/
|
||||
static int process_directives (void);
|
||||
|
||||
/// Handles signals to trigger reconfigurations.
|
||||
static void handle_signal (int sig, siginfo_t *, ucontext_t *);
|
||||
|
||||
/**
|
||||
* Handle the command-line options intended for the
|
||||
* ACE_Service_Config. Note that @c argv[0] is assumed to be the
|
||||
@@ -481,29 +553,36 @@ private:
|
||||
* for a list of files and here a list of services.
|
||||
*/
|
||||
static int parse_args (int, ACE_TCHAR *argv[]);
|
||||
|
||||
#if (ACE_USES_CLASSIC_SVC_CONF == 0)
|
||||
static ACE_Service_Type *create_service_type (const ACE_TCHAR *n,
|
||||
ACE_Service_Type_Impl *o,
|
||||
ACE_DLL &dll,
|
||||
int active);
|
||||
#endif /* ACE_USES_CLASSIC_SVC_CONF == 0 */
|
||||
|
||||
static ACE_Service_Type_Impl *
|
||||
create_service_type_impl (const ACE_TCHAR *name,
|
||||
int type,
|
||||
void *symbol,
|
||||
u_int flags,
|
||||
ACE_Service_Object_Exterminator gobbler);
|
||||
|
||||
/// @deprecated
|
||||
/// Process service configuration requests that were provided on the
|
||||
/// command-line. Returns the number of errors that occurred.
|
||||
static int process_commandline_directives (void);
|
||||
|
||||
/// Become a daemon.
|
||||
static int start_daemon (void);
|
||||
|
||||
// @deprecated
|
||||
// Add the default statically-linked services to the
|
||||
// ACE_Service_Repository.
|
||||
static int load_static_svcs (void);
|
||||
|
||||
protected:
|
||||
|
||||
#if (ACE_USES_CLASSIC_SVC_CONF == 1)
|
||||
/// @deprecated
|
||||
/// This is the implementation function that process_directives()
|
||||
@@ -512,25 +591,35 @@ protected:
|
||||
static int process_directives_i (ACE_Svc_Conf_Param *param);
|
||||
#endif /* ACE_USES_CLASSIC_SVC_CONF == 1 */
|
||||
|
||||
|
||||
// = Process-wide state.
|
||||
|
||||
private:
|
||||
|
||||
/// Have we called ACE_Service_Config::open() yet?
|
||||
bool is_opened_;
|
||||
|
||||
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
|
||||
/// Synchronization variable for open, etc.
|
||||
mutable ACE_SYNCH_MUTEX lock_;
|
||||
#endif /* ACE_MT_SAFE */
|
||||
|
||||
/// True if reconfiguration occurred.
|
||||
static sig_atomic_t reconfig_occurred_;
|
||||
|
||||
// = Set by command-line options.
|
||||
/// Shall we become a daemon process?
|
||||
static bool be_a_daemon_;
|
||||
|
||||
/// Pathname of file to write process id.
|
||||
static ACE_TCHAR *pid_file_name_;
|
||||
|
||||
/// Number of the signal used to trigger reconfiguration.
|
||||
static int signum_;
|
||||
|
||||
/// Handles the reconfiguration signals.
|
||||
static ACE_Sig_Adapter *signal_handler_;
|
||||
|
||||
/// Pointer to the Singleton (ACE_Cleanup) Gestalt instance.
|
||||
/// There is thread-specific global instance pointer, which is used to
|
||||
/// temporarily change which Gestalt instance is used for static service
|
||||
@@ -547,13 +636,16 @@ private:
|
||||
/// deallocated, but the global service repository will still "think"
|
||||
/// it must finalize the (DLL's) static services - with disastrous
|
||||
/// consequences, occurring in the post-main code (at_exit()).
|
||||
|
||||
/// This class needs the intimate access to be able to swap the
|
||||
/// current TSS pointer for the global Gestalt.
|
||||
friend class ACE_Service_Config_Guard;
|
||||
|
||||
/// The helper needs intimate access (when building with no threads)
|
||||
friend class ACE_Threading_Helper <ACE_Thread_Mutex>;
|
||||
friend class ACE_Threading_Helper <ACE_Null_Mutex>;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class ACE_Service_Config_Guard
|
||||
*
|
||||
@@ -570,18 +662,24 @@ class ACE_Export ACE_Service_Config_Guard
|
||||
public:
|
||||
ACE_Service_Config_Guard (ACE_Service_Gestalt* psg);
|
||||
~ACE_Service_Config_Guard (void);
|
||||
|
||||
private:
|
||||
// Private AND not implemented to disable copying
|
||||
ACE_Service_Config_Guard(const ACE_Service_Config_Guard&);
|
||||
ACE_Service_Config_Guard& operator= (const ACE_Service_Config_Guard&);
|
||||
|
||||
private:
|
||||
ACE_Intrusive_Auto_Ptr<ACE_Service_Gestalt> saved_;
|
||||
};
|
||||
|
||||
|
||||
ACE_END_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
#if defined (__ACE_INLINE__)
|
||||
#include "ace/Service_Config.inl"
|
||||
#endif /* __ACE_INLINE__ */
|
||||
|
||||
#include /**/ "ace/post.h"
|
||||
|
||||
#endif /* ACE_SERVICE_CONFIG_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user