Log_Record.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Log_Record.h
00006  *
00007  *  Log_Record.h,v 4.56 2006/05/27 15:52:26 schmidt Exp
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 // These need to go outside of the #ifdef to avoid problems with
00014 // circular dependencies...
00015 
00016 #include "ace/Log_Priority.h"
00017 
00018 #ifndef ACE_LOG_RECORD_H
00019 #define ACE_LOG_RECORD_H
00020 #include /**/ "ace/pre.h"
00021 
00022 #include "ace/ACE_export.h"
00023 
00024 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00025 # pragma once
00026 #endif /* ACE_LACKS_PRAGMA_ONCE */
00027 
00028 #include "ace/Default_Constants.h"
00029 #include "ace/Basic_Types.h"
00030 #include "ace/iosfwd.h"
00031 
00032 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00033 
00034 class ACE_Time_Value;
00035 
00036 /// Defines the structure of an ACE logging record.
00037 class ACE_Export ACE_Log_Record
00038 {
00039 public:
00040   enum
00041   {
00042     /// Maximum size of a logging message.
00043     MAXLOGMSGLEN = ACE_MAXLOGMSGLEN+1,
00044 
00045     /// Most restrictive alignment.
00046     ALIGN_WORDB  = 8,
00047 
00048     /// Size used by verbose mode.
00049     /// 20 (date) + 15 (host_name) + 10 (pid) + 10 (type)
00050     ///           + 4 (@) ... + ? (progname)
00051     VERBOSE_LEN = 128,
00052 
00053     /// Maximum size of a logging message with the verbose headers
00054     MAXVERBOSELOGMSGLEN = VERBOSE_LEN + MAXLOGMSGLEN
00055   };
00056 
00057   // = Initialization
00058   /**
00059    * Create a <Log_Record> and set its priority, time stamp, and
00060    * process id.
00061    */
00062   ACE_Log_Record (void);
00063   ACE_Log_Record (ACE_Log_Priority lp,
00064                   long time_stamp,
00065                   long pid);
00066   ACE_Log_Record (ACE_Log_Priority lp,
00067                   const ACE_Time_Value &time_stamp,
00068                   long pid);
00069 
00070   /// Default dtor.
00071   ~ACE_Log_Record (void);
00072 
00073 
00074   /// Write the contents of the logging record to the appropriate
00075   /// <FILE> iff the corresponding type is enabled.
00076   int print (const ACE_TCHAR host_name[],
00077              u_long verbose_flag,
00078 #if !defined (ACE_HAS_WINCE)
00079              FILE *fp = stderr);
00080 #else
00081              FILE *fp);
00082 #endif /* ACE_HAS_WINCE */
00083 
00084 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
00085   /// Write the contents of the logging record to the appropriate
00086   /// <ostream> iff the corresponding type is enabled.
00087   int print (const ACE_TCHAR host_name[],
00088              u_long verbose_flag,
00089              ACE_OSTREAM_TYPE &stream);
00090 #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */
00091 
00092   int format_msg (const ACE_TCHAR host_name[],
00093                   u_long verbose_flag,
00094                   ACE_TCHAR *verbose_msg);
00095 
00096   /**
00097    * Returns a character array with the string form of the
00098    * <ACE_Log_Priority> parameter.  This is used for the verbose
00099    * printing format.
00100    */
00101   static const ACE_TCHAR *priority_name (ACE_Log_Priority p);
00102 
00103   // IMPORTANT: <name> must be a statically allocated const ACE_TCHAR*
00104   static void priority_name (ACE_Log_Priority p,
00105                              const ACE_TCHAR *name);
00106 
00107   // = Marshall/demarshall
00108   /// Encode the <Log_Record> for transmission on the network.
00109   void encode (void);
00110 
00111   /// Decode the <Log_Record> received from the network.
00112   void decode (void);
00113 
00114   // = Set/get methods
00115 
00116   /// Get the type of the <Log_Record>.
00117   ACE_UINT32 type (void) const;
00118 
00119   /// Set the type of the <Log_Record>.
00120   void type (ACE_UINT32);
00121 
00122   /**
00123    * Get the priority of the <Log_Record> <type_>.  This is computed
00124    * as the base 2 logarithm of <type_> (which must be a power of 2,
00125    * as defined by the enums in <ACE_Log_Priority>).
00126    */
00127   u_long priority (void) const;
00128 
00129   /// Set the priority of the <Log_Record> <type_> (which must be a
00130   /// power of 2, as defined by the enums in <ACE_Log_Priority>).
00131   void priority (u_long num);
00132 
00133   /// Get the length of the <Log_Record>.
00134   long length (void) const;
00135 
00136   /// Set the length of the <Log_Record>.
00137   void length (long);
00138 
00139   /// Get the time stamp of the <Log_Record>.
00140   ACE_Time_Value time_stamp (void) const;
00141 
00142   /// Set the time stamp of the <Log_Record>.
00143   void time_stamp (const ACE_Time_Value &ts);
00144 
00145   /// Get the process id of the <Log_Record>.
00146   long pid (void) const;
00147 
00148   /// Set the process id of the <Log_Record>.
00149   void pid (long);
00150 
00151   /// Get the message data of the <Log_Record>.
00152   const ACE_TCHAR *msg_data (void) const;
00153 
00154   /// Set the message data pointer 
00155   void set_msg_data_ptr (ACE_TCHAR *data);
00156 
00157   /// Set the message data of the <Log_Record>.
00158   void msg_data (const ACE_TCHAR *data);
00159 
00160   /// Get the size of the message data of the <Log_Record>, including
00161   /// a byte for the NUL.
00162   size_t msg_data_len (void) const;
00163 
00164   /// Dump the state of an object.
00165   void dump (void) const;
00166 
00167   /// Declare the dynamic allocation hooks.
00168   ACE_ALLOC_HOOK_DECLARE;
00169 
00170 private:
00171   /// Round up to the alignment restrictions.
00172   void round_up (void);
00173 
00174   /**
00175    * Total length of the logging record in bytes.  This field *must*
00176    * come first in order for various IPC framing mechanisms to work
00177    * correctly.  In addition, the field must be an ACE_INT32 in order
00178    * to be passed portably across platforms.
00179    */
00180   ACE_INT32 length_;
00181 
00182   /// Type of logging record.
00183   ACE_UINT32 type_;
00184 
00185   /// Time that the logging record was generated.
00186   ACE_UINT32 secs_;
00187   ACE_UINT32 usecs_;
00188 
00189   /// Id of process that generated the logging record.
00190   ACE_UINT32 pid_;
00191 
00192   /// Logging record data
00193   ACE_TCHAR *msg_data_; // Add one for NUL-terminator.
00194 
00195 };
00196 
00197 // Forward decls.
00198 class ACE_InputCDR;
00199 class ACE_OutputCDR;
00200 
00201 // iostream operators for ACE_Log_Record.
00202 ACE_Export int operator>> (ACE_InputCDR &cdr, ACE_Log_Record &log_record);
00203 ACE_Export int operator<< (ACE_OutputCDR &cdr, const ACE_Log_Record &log_record);
00204 
00205 ACE_END_VERSIONED_NAMESPACE_DECL
00206 
00207 #if defined (__ACE_INLINE__)
00208 #include "ace/Log_Record.inl"
00209 #endif /* __ACE_INLINE__ */
00210 
00211 #include /**/ "ace/post.h"
00212 #endif /* ACE_LOG_RECORD_H */

Generated on Thu Nov 9 09:41:53 2006 for ACE by doxygen 1.3.6