00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Log_Record.h 00006 * 00007 * $Id: Log_Record.h 79340 2007-08-14 17:58:34Z schmidt $ 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 time_t 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: @a 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 /// @deprecated The encode() and decode() metods are deprecated; please use 00110 /// the CDR insertion and extraction operators to properly encode and decode 00111 /// ACE_Log_Record objects. 00112 void encode (void); 00113 00114 /// Decode the <Log_Record> received from the network. 00115 /// @deprecated The encode() and decode() metods are deprecated; please use 00116 /// the CDR insertion and extraction operators to properly encode and decode 00117 /// ACE_Log_Record objects. 00118 void decode (void); 00119 00120 // = Set/get methods 00121 00122 /// Get the type of the <Log_Record>. 00123 ACE_UINT32 type (void) const; 00124 00125 /// Set the type of the <Log_Record>. 00126 void type (ACE_UINT32); 00127 00128 /** 00129 * Get the priority of the <Log_Record> <type_>. This is computed 00130 * as the base 2 logarithm of <type_> (which must be a power of 2, 00131 * as defined by the enums in <ACE_Log_Priority>). 00132 */ 00133 u_long priority (void) const; 00134 00135 /// Set the priority of the <Log_Record> <type_> (which must be a 00136 /// power of 2, as defined by the enums in <ACE_Log_Priority>). 00137 void priority (u_long num); 00138 00139 /// Get the total length of the <Log_Record>, which includes the 00140 /// size of the various data member fields. 00141 long length (void) const; 00142 00143 /// Set the total length of the <Log_Record>, which needs to account for 00144 /// the size of the various data member fields. 00145 void length (long); 00146 00147 /// Get the time stamp of the <Log_Record>. 00148 ACE_Time_Value time_stamp (void) const; 00149 00150 /// Set the time stamp of the <Log_Record>. 00151 void time_stamp (const ACE_Time_Value &ts); 00152 00153 /// Get the process id of the <Log_Record>. 00154 long pid (void) const; 00155 00156 /// Set the process id of the <Log_Record>. 00157 void pid (long); 00158 00159 /// Get the message data of the <Log_Record>. 00160 const ACE_TCHAR *msg_data (void) const; 00161 00162 /// Set the message data of the record. If @a data is longer than the 00163 /// current msg_data_ buffer, a new msg_data_ buffer is allocated to 00164 /// fit. If such a reallocation faisl, this method returns -1, else 0. 00165 int msg_data (const ACE_TCHAR *data); 00166 00167 /// Get the size of the message data of the <Log_Record>, including 00168 /// a byte for the NUL. 00169 size_t msg_data_len (void) const; 00170 00171 /// Dump the state of an object. 00172 void dump (void) const; 00173 00174 /// Declare the dynamic allocation hooks. 00175 ACE_ALLOC_HOOK_DECLARE; 00176 00177 private: 00178 /// Round up to the alignment restrictions. 00179 void round_up (void); 00180 00181 /** 00182 * Total length of the logging record in bytes. This field *must* 00183 * come first in order for various IPC framing mechanisms to work 00184 * correctly. In addition, the field must be an ACE_INT32 in order 00185 * to be passed portably across platforms. 00186 */ 00187 ACE_INT32 length_; 00188 00189 /// Type of logging record. 00190 ACE_UINT32 type_; 00191 00192 /// Time that the logging record was generated. 00193 time_t secs_; 00194 ACE_UINT32 usecs_; 00195 00196 /// Id of process that generated the logging record. 00197 ACE_UINT32 pid_; 00198 00199 /// Logging record data 00200 ACE_TCHAR *msg_data_; // Heap-allocated text message area 00201 size_t msg_data_size_; // Allocated size of msg_data_ in ACE_TCHARs 00202 00203 /// disallow copying... 00204 ACE_Log_Record (const ACE_Log_Record& rhs); 00205 ACE_Log_Record& operator= (const ACE_Log_Record& rhs); 00206 }; 00207 00208 // Forward decls. 00209 class ACE_InputCDR; 00210 class ACE_OutputCDR; 00211 00212 // iostream operators for ACE_Log_Record. 00213 ACE_Export int operator>> (ACE_InputCDR &cdr, ACE_Log_Record &log_record); 00214 ACE_Export int operator<< (ACE_OutputCDR &cdr, const ACE_Log_Record &log_record); 00215 00216 ACE_END_VERSIONED_NAMESPACE_DECL 00217 00218 #if defined (__ACE_INLINE__) 00219 #include "ace/Log_Record.inl" 00220 #endif /* __ACE_INLINE__ */ 00221 00222 #include /**/ "ace/post.h" 00223 #endif /* ACE_LOG_RECORD_H */