Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Log_Record.h

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

Generated on Mon Jun 16 11:20:01 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002