*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// -*- C++ -*-
|
||||
|
||||
//=============================================================================
|
||||
/**
|
||||
* @file Log_Msg.h
|
||||
@@ -8,9 +9,11 @@
|
||||
* @author Douglas C. Schmidt <[email protected]>
|
||||
*/
|
||||
//=============================================================================
|
||||
|
||||
#ifndef ACE_LOG_MSG_H
|
||||
#define ACE_LOG_MSG_H
|
||||
#include /**/ "ace/pre.h"
|
||||
|
||||
// This stuff must come first to avoid problems with circular
|
||||
// headers...
|
||||
// ... but ACE_NDEBUG and ACE_NLOGGING can come from the config.h file, so
|
||||
@@ -21,9 +24,11 @@
|
||||
#include "ace/Default_Constants.h"
|
||||
#include "ace/Log_Priority.h"
|
||||
#include "ace/os_include/os_limits.h"
|
||||
|
||||
// The ACE_ASSERT macro used to be defined here, include ace/Assert.h
|
||||
// for backwards compatibility.
|
||||
#include "ace/Assert.h"
|
||||
|
||||
#if defined (ACE_NLOGGING)
|
||||
#define ACE_HEX_DUMP(X) do {} while (0)
|
||||
#define ACE_RETURN(Y) do { return (Y); } while (0)
|
||||
@@ -91,28 +96,39 @@
|
||||
#define ACE_ERROR_BREAK(X) { ACE_ERROR (X); break; }
|
||||
#endif
|
||||
#endif /* ACE_NLOGGING */
|
||||
|
||||
#include "ace/OS_Log_Msg_Attributes.h"
|
||||
|
||||
#if !defined (ACE_LACKS_PRAGMA_ONCE)
|
||||
# pragma once
|
||||
#endif /* ACE_LACKS_PRAGMA_ONCE */
|
||||
|
||||
// These workarounds are necessary for nasty libraries or platforms
|
||||
// that #define STDERR or THREAD (e.g. LynxOS). We simply #undef
|
||||
// these macros as there is no way to save the macro definition using
|
||||
// the pre-processor. See Bugzilla Bug #299 for more info.
|
||||
|
||||
#if defined (STDERR)
|
||||
# undef STDERR
|
||||
#endif /* STDERR */
|
||||
|
||||
#if defined (THREAD)
|
||||
# undef THREAD
|
||||
#endif /* THREAD */
|
||||
|
||||
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
class ACE_Log_Msg_Callback;
|
||||
class ACE_Log_Msg_Backend;
|
||||
|
||||
// ****************************************************************
|
||||
|
||||
#define ACE_LOG_MSG ACE_Log_Msg::instance ()
|
||||
|
||||
// Forward declaration
|
||||
class ACE_Thread_Descriptor;
|
||||
class ACE_Log_Record;
|
||||
|
||||
/**
|
||||
* @class ACE_Log_Msg
|
||||
*
|
||||
@@ -171,25 +187,35 @@ public:
|
||||
/// Write messages to the user provided backend
|
||||
CUSTOM = 256
|
||||
};
|
||||
|
||||
// = Initialization and termination routines.
|
||||
|
||||
/// Returns a pointer to the Singleton.
|
||||
static ACE_Log_Msg *instance (void);
|
||||
|
||||
/// Returns last error.
|
||||
static int last_error_adapter (void);
|
||||
|
||||
/// Returns non-null if an ACE_Log_Msg exists for the calling thread.
|
||||
static int exists (void);
|
||||
|
||||
/// Returns the current program name used for logging.
|
||||
static const ACE_TCHAR * program_name (void);
|
||||
|
||||
/// Clears the flag from the default priority mask used to
|
||||
/// initialize ACE_Log_Msg instances.
|
||||
static void disable_debug_messages (ACE_Log_Priority priority = LM_DEBUG);
|
||||
|
||||
/// Sets the flag in the default priority mask used to initialize
|
||||
/// ACE_Log_Msg instances.
|
||||
static void enable_debug_messages (ACE_Log_Priority priority = LM_DEBUG);
|
||||
|
||||
/// Initialize logger.
|
||||
ACE_Log_Msg (void);
|
||||
|
||||
/// cleanup logger.
|
||||
~ACE_Log_Msg (void);
|
||||
|
||||
/// Initialize the ACE logging facility.
|
||||
/**
|
||||
* Initialize the ACE logging facility. Supplies the program name
|
||||
@@ -212,19 +238,24 @@ public:
|
||||
int open (const ACE_TCHAR *prog_name,
|
||||
u_long options_flags = ACE_Log_Msg::STDERR,
|
||||
const ACE_TCHAR *logger_key = 0);
|
||||
|
||||
// = Set/get the options flags.
|
||||
|
||||
/**
|
||||
* Enable the bits in the logger's options flags.
|
||||
*/
|
||||
void set_flags (u_long f);
|
||||
|
||||
/**
|
||||
* Disable the bits in the logger's options flags.
|
||||
*/
|
||||
void clr_flags (u_long f);
|
||||
|
||||
/**
|
||||
* Return the bits in the logger's options flags.
|
||||
*/
|
||||
u_long flags (void);
|
||||
|
||||
/** @name Allow apps to acquire and release internal synchronization
|
||||
* lock
|
||||
*
|
||||
@@ -233,59 +264,80 @@ public:
|
||||
* lock atomically over a number of calls to ACE_Log_Msg.
|
||||
*/
|
||||
//@{
|
||||
|
||||
/// Acquire the internal lock.
|
||||
int acquire (void);
|
||||
|
||||
/// Release the internal lock.
|
||||
int release (void);
|
||||
//@}
|
||||
|
||||
/// Call after doing a @c fork() to resynchronize the process id and
|
||||
/// @c program_name_ variables.
|
||||
void sync (const ACE_TCHAR *program_name);
|
||||
|
||||
// = Set/get methods. Note that these are non-static and thus will
|
||||
// be thread-specific.
|
||||
|
||||
/// Set the result of the operation status (by convention, -1 means
|
||||
/// error).
|
||||
void op_status (int status);
|
||||
|
||||
/// Get the result of the operation status (by convention, -1 means
|
||||
/// error).
|
||||
int op_status (void) const;
|
||||
|
||||
/// Set the value of the errnum (by convention this corresponds to
|
||||
/// errno).
|
||||
void errnum (int);
|
||||
|
||||
/// Get the value of the errnum (by convention this corresponds to
|
||||
/// errno).
|
||||
int errnum (void) const;
|
||||
|
||||
/// Set the line number where an error occurred.
|
||||
void linenum (int);
|
||||
|
||||
/// Get the line number where an error occurred.
|
||||
int linenum (void) const;
|
||||
|
||||
/// Set the file name where an error occurred.
|
||||
void file (const char *);
|
||||
|
||||
/// Get the file name where an error occurred.
|
||||
const char *file (void);
|
||||
|
||||
/// Set the message that describes what type of error occurred.
|
||||
void msg (const ACE_TCHAR *);
|
||||
|
||||
/// Get the message that describes what type of error occurred.
|
||||
const ACE_TCHAR *msg (void);
|
||||
|
||||
/// Set the field that indicates whether interrupted calls should be
|
||||
/// restarted.
|
||||
void restart (int);
|
||||
|
||||
/// Get the field that indicates whether interrupted calls should be
|
||||
/// restarted.
|
||||
int restart (void) const;
|
||||
|
||||
// = Notice that the following two function is equivalent to
|
||||
// "void msg_ostream (HANDLE)" and "HANDLE msg_ostream (void)"
|
||||
// on Windows CE. There is no <iostream.h> support on CE.
|
||||
|
||||
/// Update the ostream without overwriting the delete_ostream_ flag.
|
||||
void msg_ostream (ACE_OSTREAM_TYPE *);
|
||||
|
||||
/**
|
||||
* delete_stream == true, forces Log_Msg.h to delete the stream in
|
||||
* its own ~dtor (assumes control of the stream)
|
||||
* use only with proper ostream (eg: fstream), not (cout, cerr)
|
||||
*/
|
||||
void msg_ostream (ACE_OSTREAM_TYPE *, bool delete_ostream);
|
||||
|
||||
/// Get the ostream that is used to print error messages.
|
||||
ACE_OSTREAM_TYPE *msg_ostream (void) const;
|
||||
|
||||
/**
|
||||
* Set a new callback object and return the existing callback to
|
||||
* allow "chaining". Note that ACE_Log_Msg_Callback objects are not
|
||||
@@ -294,6 +346,7 @@ public:
|
||||
*/
|
||||
ACE_Log_Msg_Callback *msg_callback (ACE_Log_Msg_Callback *c);
|
||||
ACE_Log_Msg_Callback *msg_callback (void) const;
|
||||
|
||||
/**
|
||||
* Set a new backend object and return the existing backend to
|
||||
* allow "chaining". Note that as opposed to ACE_Log_Msg_Callback,
|
||||
@@ -306,26 +359,35 @@ public:
|
||||
*/
|
||||
static ACE_Log_Msg_Backend *msg_backend (ACE_Log_Msg_Backend *b);
|
||||
static ACE_Log_Msg_Backend *msg_backend (void);
|
||||
|
||||
/// Nesting depth increment.
|
||||
int inc (void);
|
||||
|
||||
/// Nesting depth decrement.
|
||||
int dec (void);
|
||||
|
||||
/// Get trace depth.
|
||||
int trace_depth (void) const;
|
||||
|
||||
/// Set trace depth.
|
||||
void trace_depth (int);
|
||||
|
||||
/// Get trace active status.
|
||||
bool trace_active (void) const;
|
||||
|
||||
/// Set trace active status.
|
||||
void trace_active (bool value);
|
||||
|
||||
/// Get the TSS thread descriptor.
|
||||
ACE_Thread_Descriptor *thr_desc (void) const;
|
||||
|
||||
/**
|
||||
* Set the TSS thread descriptor. This method will call
|
||||
* td->acquire_release to block execution until this call
|
||||
* return.
|
||||
*/
|
||||
void thr_desc (ACE_Thread_Descriptor *td);
|
||||
|
||||
#if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) && defined(ACE_LEGACY_MODE)
|
||||
// These functions are disabled without ACE_LEGACY_MODE
|
||||
// because the *semantics* have changed (the objects are no longer
|
||||
@@ -333,38 +395,50 @@ public:
|
||||
/// Get TSS exception action.
|
||||
/// @note The action is no longer TSS, they are global!
|
||||
ACE_SEH_EXCEPT_HANDLER seh_except_selector (void);
|
||||
|
||||
/// Set TSS exception action.
|
||||
/// @note The action is no longer TSS, they are global!
|
||||
ACE_SEH_EXCEPT_HANDLER seh_except_selector (ACE_SEH_EXCEPT_HANDLER);
|
||||
|
||||
/// Get TSS exception handler.
|
||||
/// @note The handler is no longer TSS, they are global!
|
||||
ACE_SEH_EXCEPT_HANDLER seh_except_handler (void);
|
||||
|
||||
/// Set TSS exception handler.
|
||||
/// @note The handler is no longer TSS, they are global!
|
||||
ACE_SEH_EXCEPT_HANDLER seh_except_handler (ACE_SEH_EXCEPT_HANDLER);
|
||||
#endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS && ACE_LEGACY_MODE */
|
||||
|
||||
/// Stop tracing status on a per-thread basis...
|
||||
void stop_tracing (void);
|
||||
|
||||
/// Start tracing status on a per-thread basis...
|
||||
void start_tracing (void);
|
||||
|
||||
/// Query tracing status on a per-thread basis...
|
||||
bool tracing_enabled (void) const;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PROCESS = 0,
|
||||
THREAD = 1
|
||||
} MASK_TYPE;
|
||||
|
||||
// = Get/set the priority mask.
|
||||
/// Get the current ACE_Log_Priority mask.
|
||||
u_long priority_mask (MASK_TYPE = THREAD);
|
||||
|
||||
/// Set the ACE_Log_Priority mask, returns original mask.
|
||||
u_long priority_mask (u_long, MASK_TYPE = THREAD);
|
||||
|
||||
/// Return true if the requested priority is enabled.
|
||||
int log_priority_enabled (ACE_Log_Priority log_priority);
|
||||
|
||||
/// Return true if the requested priority is enabled.
|
||||
int log_priority_enabled (ACE_Log_Priority log_priority,
|
||||
const char *,
|
||||
...);
|
||||
|
||||
#if defined (ACE_USES_WCHAR)
|
||||
// We are not using ACE_TCHAR for this since ACE_HEX_DUMP
|
||||
// doesn't take in a ACE_TCHAR. log_hexdump takes in a char
|
||||
@@ -375,13 +449,17 @@ public:
|
||||
const wchar_t *,
|
||||
...);
|
||||
#endif /* ACE_USES_WCHAR */
|
||||
|
||||
/// Optimize reading of the pid (avoids a system call if the value is
|
||||
/// cached...).
|
||||
pid_t getpid (void) const;
|
||||
|
||||
/// Get the name of the local host.
|
||||
const ACE_TCHAR *local_host (void) const;
|
||||
|
||||
/// Set the name of the local host.
|
||||
void local_host (const ACE_TCHAR *);
|
||||
|
||||
/**
|
||||
* Set the line number, file name, operational status, error number,
|
||||
* restart flag, ostream, and the callback object. This combines
|
||||
@@ -394,12 +472,14 @@ public:
|
||||
int restart = 1,
|
||||
ACE_OSTREAM_TYPE *os = 0,
|
||||
ACE_Log_Msg_Callback *c = 0);
|
||||
|
||||
/// These values are only actually set if the requested priority is
|
||||
/// enabled.
|
||||
void conditional_set (const char *file,
|
||||
int line,
|
||||
int op_status,
|
||||
int errnum);
|
||||
|
||||
/**
|
||||
* Format a message to the thread-safe ACE logging mechanism. Valid
|
||||
* options (prefixed by '%', as in printf format strings) include:
|
||||
@@ -447,9 +527,11 @@ public:
|
||||
* - '?': print out stack trace (see Stack_Trace.h header comments)
|
||||
*/
|
||||
ssize_t log (ACE_Log_Priority priority, const ACE_TCHAR *format, ...);
|
||||
|
||||
#if defined (ACE_HAS_WCHAR)
|
||||
ssize_t log (ACE_Log_Priority priority, const ACE_ANTI_TCHAR *format, ...);
|
||||
#endif /* ACE_HAS_WCHAR */
|
||||
|
||||
/**
|
||||
* An alternative logging mechanism that makes it possible to
|
||||
* integrate variable argument lists from other logging mechanisms
|
||||
@@ -458,10 +540,12 @@ public:
|
||||
ssize_t log (const ACE_TCHAR *format,
|
||||
ACE_Log_Priority priority,
|
||||
va_list argp);
|
||||
|
||||
/// Log a custom built log record to the currently enabled logging
|
||||
/// sinks.
|
||||
ssize_t log (ACE_Log_Record &log_record,
|
||||
int suppress_stderr = 0);
|
||||
|
||||
/**
|
||||
* Method to log hex dump. This is useful for debugging. Calls
|
||||
* log() to do the actual print, but formats first to make the chars
|
||||
@@ -471,6 +555,7 @@ public:
|
||||
const char *buffer,
|
||||
size_t size,
|
||||
const ACE_TCHAR *text = 0);
|
||||
|
||||
static void init_hook (ACE_OS_Log_Msg_Attributes &attributes
|
||||
# if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
|
||||
, ACE_SEH_EXCEPT_HANDLER selector = 0
|
||||
@@ -482,6 +567,7 @@ public:
|
||||
* @a attributes argument
|
||||
*/
|
||||
);
|
||||
|
||||
/**
|
||||
* Inherit hook, the @a attributes field is a ACE_OS_Log_Msg_Attributes
|
||||
* object, invoke the inherit_log_msg() method on it, then destroy
|
||||
@@ -489,38 +575,53 @@ public:
|
||||
*/
|
||||
static void inherit_hook (ACE_OS_Thread_Descriptor *thr_desc,
|
||||
ACE_OS_Log_Msg_Attributes &attributes);
|
||||
|
||||
/// Dump the state of an object.
|
||||
void dump (void) const;
|
||||
|
||||
/// Declare the dynamic allocation hooks.
|
||||
ACE_ALLOC_HOOK_DECLARE;
|
||||
|
||||
private:
|
||||
/// Status of operation (-1 means failure, >= 0 means success).
|
||||
int status_;
|
||||
|
||||
/// Type of error that occurred (see <sys/errno.h>).
|
||||
int errnum_;
|
||||
|
||||
/// Line number where the error occurred.
|
||||
int linenum_;
|
||||
|
||||
/// File where the error occurred.
|
||||
char file_[MAXPATHLEN + 1];
|
||||
|
||||
/// The log message, which resides in thread-specific storage. Note
|
||||
/// that only the current log message is stored here -- it will be
|
||||
/// overwritten by the subsequent call to log().
|
||||
ACE_TCHAR* msg_; // Add one for NUL-terminator.
|
||||
|
||||
/// Indicates whether we should restart system calls that are
|
||||
/// interrupted.
|
||||
int restart_;
|
||||
|
||||
/// The ostream where logging messages can be written.
|
||||
ACE_OSTREAM_TYPE *ostream_;
|
||||
|
||||
/// The callback object.
|
||||
ACE_Log_Msg_Callback *msg_callback_;
|
||||
|
||||
/// Depth of the nesting for printing traces.
|
||||
int trace_depth_;
|
||||
|
||||
/// Are we already within an ACE_Trace constructor call?
|
||||
bool trace_active_;
|
||||
|
||||
/// Are we allowing tracing in this thread?
|
||||
bool tracing_enabled_;
|
||||
|
||||
/// Are we deleting this ostream?
|
||||
bool delete_ostream_;
|
||||
|
||||
/**
|
||||
* If we're running in the context of an ACE_Thread_Manager this
|
||||
* will point to the thread descriptor adapter which holds the
|
||||
@@ -528,42 +629,55 @@ private:
|
||||
* access all thread data kept in ACE_Thread_Descriptor.
|
||||
*/
|
||||
ACE_Thread_Descriptor *thr_desc_;
|
||||
|
||||
/**
|
||||
* Keeps track of all the per-thread ACE_Log_Priority values that
|
||||
* are currently enabled. Default is for all logging priorities to
|
||||
* be disabled.
|
||||
*/
|
||||
u_long priority_mask_;
|
||||
|
||||
/// Always timestamp?
|
||||
int timestamp_;
|
||||
|
||||
// = The following fields are *not* kept in thread-specific storage.
|
||||
|
||||
// We only want one instance for the entire process!
|
||||
|
||||
/**
|
||||
* Keeps track of all the per-process ACE_Log_Priority values that
|
||||
* are currently enabled. Default is for all logging priorities to
|
||||
* be enabled.
|
||||
*/
|
||||
static u_long process_priority_mask_;
|
||||
|
||||
/// Records the program name.
|
||||
static const ACE_TCHAR *program_name_;
|
||||
|
||||
/// Name of the local host (used when printing messages).
|
||||
static const ACE_TCHAR *local_host_;
|
||||
|
||||
/// Process id of the current process.
|
||||
static pid_t pid_;
|
||||
|
||||
/// Options flags used to hold the logger flag options, e.g.,
|
||||
/// STDERR, LOGGER, OSTREAM, MSG_CALLBACK, etc.
|
||||
static u_long flags_;
|
||||
|
||||
/// Offset of msg_[].
|
||||
static ptrdiff_t msg_off_;
|
||||
|
||||
/**
|
||||
* Number of existing ACE_Log_Msg instances; when 0, delete program/host
|
||||
* names
|
||||
*/
|
||||
static int instance_count_;
|
||||
|
||||
/**
|
||||
* Priority mask to use for each new instance
|
||||
*/
|
||||
static u_long default_priority_mask_;
|
||||
|
||||
/// Anonymous struct since there will only be one instance. This
|
||||
/// struct keeps information stored away in case we actually end up
|
||||
/// calling log() if the log priority is correct.
|
||||
@@ -575,21 +689,29 @@ private:
|
||||
int op_status_;
|
||||
int errnum_;
|
||||
} conditional_values_;
|
||||
|
||||
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
|
||||
static bool key_created_;
|
||||
#endif /* ACE_MT_SAFE */
|
||||
|
||||
/// For cleanup, at program termination.
|
||||
static void close (void);
|
||||
|
||||
/// Decouple the OS layer from the ACE_Log_Msg layer.
|
||||
static void sync_hook (const ACE_TCHAR *prg_name);
|
||||
|
||||
/// Return the TSS singleton thread descriptor
|
||||
static ACE_OS_Thread_Descriptor *thr_desc_hook (void);
|
||||
|
||||
//friend void ACE_OS::cleanup_tss (const u_int);
|
||||
|
||||
// = Disallow these operations.
|
||||
ACE_Log_Msg &operator= (const ACE_Log_Msg &);
|
||||
ACE_Log_Msg (const ACE_Log_Msg &);
|
||||
};
|
||||
|
||||
ACE_END_VERSIONED_NAMESPACE_DECL
|
||||
|
||||
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
|
||||
# if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \
|
||||
defined (ACE_HAS_TSS_EMULATION)
|
||||
@@ -599,23 +721,28 @@ ACE_END_VERSIONED_NAMESPACE_DECL
|
||||
# else
|
||||
# define LOCAL_EXTERN_PREFIX
|
||||
# endif /* ACE_HAS_THR_C_DEST */
|
||||
|
||||
#if (defined (ACE_HAS_VERSIONED_NAMESPACE) && ACE_HAS_VERSIONED_NAMESPACE == 1)
|
||||
# define ACE_TSS_CLEANUP_NAME ACE_PREPROC_CONCATENATE(ACE_,ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _TSS_cleanup))
|
||||
#else
|
||||
# define ACE_TSS_CLEANUP_NAME ACE_TSS_cleanup
|
||||
#endif /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
|
||||
|
||||
|
||||
LOCAL_EXTERN_PREFIX
|
||||
void
|
||||
ACE_TSS_CLEANUP_NAME (void *ptr);
|
||||
# endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */
|
||||
#endif /* ACE_MT_SAFE */
|
||||
|
||||
#if defined(ACE_LEGACY_MODE)
|
||||
#include "ace/Log_Msg_Callback.h"
|
||||
#endif /* ACE_LEGACY_MODE */
|
||||
|
||||
#if defined (__ACE_INLINE__)
|
||||
#include "ace/Log_Msg.inl"
|
||||
#endif /* __ACE_INLINE__ */
|
||||
|
||||
#include /**/ "ace/post.h"
|
||||
#endif /* ACE_LOG_MSG_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user