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