Go to the documentation of this file.00001 #ifndef logging_base_log_H
00002 #define logging_base_log_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00032 #ifndef __cplusplus
00033 #error This is a C++ include file and cannot be used from plain C
00034 #endif
00035
00036 #include <string>
00037 #include <lokiSmartPtr.h>
00038 #include "loggingBaseExport.h"
00039 #include "acsutilTimeStamp.h"
00040 #include "loggingStatistics.h"
00041
00042 namespace Logging
00043 {
00044
00049 class loggingBase_EXPORT BaseLog
00050 {
00051 public:
00052
00053 BaseLog();
00054
00055
00056 virtual ~BaseLog(){}
00057
00058
00059 loggingStatistics stats;
00060
00066 enum Priority
00067 {
00068 LM_SHUTDOWN = 01,
00070 LM_TRACE = 02,
00071
00072 LM_DELOUSE = 03,
00073
00076 LM_DEBUG = 04,
00077
00079 LM_INFO = 010,
00080
00083 LM_NOTICE = 020,
00084
00086 LM_WARNING = 040,
00087
00089 LM_ERROR = 0200,
00090
00092 LM_CRITICAL = 0400,
00093
00096 LM_ALERT = 01000,
00097
00099 LM_EMERGENCY = 02000
00100 };
00101
00115 struct LogRecord {
00116 Priority priority;
00117 std::string message;
00118 std::string file;
00119 unsigned long line;
00120 std::string method;
00121 unsigned long long timeStamp;
00122 };
00123
00124
00135 virtual void
00136 log(Priority priority,
00137 const std::string &message,
00138 const std::string &file,
00139 unsigned long line,
00140 const std::string &method);
00141
00149 virtual void
00150 log(const LogRecord &lr) = 0;
00151
00157 virtual std::string
00158 getName() const = 0;
00159
00164 static const std::string FIELD_UNAVAILABLE;
00165
00169 static const std::string GLOBAL_LOGGER_NAME;
00170
00174 static const std::string ANONYMOUS_LOGGER_NAME;
00175
00180 static const std::string STATIC_LOGGER_NAME;
00181
00182 };
00183
00193 template <class P>
00194 class RefCounted
00195 {
00196 public:
00197 RefCounted()
00198 {
00199 pCount_ = new unsigned int();
00200 assert(pCount_);
00201 *pCount_ = 1;
00202 }
00203
00204 RefCounted(const RefCounted& rhs)
00205 : pCount_(rhs.pCount_)
00206 {}
00207
00208
00209 template <typename P1>
00210 RefCounted(const RefCounted<P1>& rhs)
00211 : pCount_(reinterpret_cast<const RefCounted&>(rhs).pCount_)
00212 {}
00213
00214 P Clone(const P& val)
00215 {
00216 ++*pCount_;
00217 return val;
00218 }
00219
00220 bool Release(const P&)
00221 {
00222 if (!--*pCount_)
00223 {
00224 delete pCount_;
00225 return true;
00226 }
00227 return false;
00228 }
00229
00230 void Swap(RefCounted& rhs)
00231 { std::swap(pCount_, rhs.pCount_); }
00232
00233 enum { destructiveCopy = false };
00234
00235 private:
00236
00237 unsigned int* pCount_;
00238 };
00239
00240 #ifdef MAKE_VXWORKS
00241
00242 template <class P>
00243 class RefCountedMT : public Loki::ObjectLevelLockable<RefCountedMT<P>, LOKI_DEFAULT_MUTEX >
00244 {
00245 typedef Loki::ObjectLevelLockable<RefCountedMT<P>, LOKI_DEFAULT_MUTEX > base_type;
00246 typedef typename base_type::IntType CountType;
00247 typedef volatile CountType *CountPtrType;
00248
00249 public:
00250 RefCountedMT()
00251 {
00252 pCount_ = reinterpret_cast<CountPtrType>(
00253 Loki::SmallObject<LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL>::operator new(
00254 sizeof(*pCount_)));
00255 assert(pCount_);
00256
00257 Loki::ObjectLevelLockable<RefCountedMT, LOKI_DEFAULT_MUTEX>::AtomicAssign(*pCount_, 1);
00258 }
00259
00260 RefCountedMT(const RefCountedMT& rhs) :
00261 Loki::ObjectLevelLockable<RefCountedMT<P>, LOKI_DEFAULT_MUTEX>( rhs ),
00262 pCount_(rhs.pCount_)
00263 {}
00264
00265
00266 template <typename P1>
00267 RefCountedMT(const RefCountedMT<P1>& rhs)
00268 : pCount_(reinterpret_cast<const RefCountedMT<P>&>(rhs).pCount_)
00269 {}
00270
00271 P Clone(const P& val)
00272 {
00273 Loki::ObjectLevelLockable<RefCountedMT, LOKI_DEFAULT_MUTEX>::AtomicIncrement(*pCount_);
00274 return val;
00275 }
00276
00277 bool Release(const P&)
00278 {
00279 if (! Loki::ObjectLevelLockable<RefCountedMT, LOKI_DEFAULT_MUTEX>::AtomicDecrement(*pCount_))
00280 {
00281 Loki::SmallObject<LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL>::operator delete(
00282 const_cast<CountType *>(pCount_),
00283 sizeof(*pCount_));
00284 return true;
00285 }
00286 return false;
00287 }
00288
00289 void Swap(RefCountedMT& rhs)
00290 { std::swap(pCount_, rhs.pCount_); }
00291
00292 enum { destructiveCopy = false };
00293
00294 private:
00295
00296 CountPtrType pCount_;
00297 };
00298 #endif //MAKE_VXWORKS
00299 };
00300
00301 #endif