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
00040 namespace Logging
00041 {
00042
00047 class loggingBase_EXPORT BaseLog
00048 {
00049 public:
00050
00051 virtual ~BaseLog(){}
00052
00058 enum Priority
00059 {
00060 LM_SHUTDOWN = 01,
00062 LM_TRACE = 02,
00063
00064 LM_DELOUSE = 03,
00065
00068 LM_DEBUG = 04,
00069
00071 LM_INFO = 010,
00072
00075 LM_NOTICE = 020,
00076
00078 LM_WARNING = 040,
00079
00081 LM_ERROR = 0200,
00082
00084 LM_CRITICAL = 0400,
00085
00088 LM_ALERT = 01000,
00089
00091 LM_EMERGENCY = 02000
00092 };
00093
00094
00108 struct LogRecord {
00109 Priority priority;
00110 std::string message;
00111 std::string file;
00112 unsigned long line;
00113 std::string method;
00114 unsigned long long timeStamp;
00115 };
00116
00117
00128 virtual void
00129 log(Priority priority,
00130 const std::string &message,
00131 const std::string &file,
00132 unsigned long line,
00133 const std::string &method);
00134
00142 virtual void
00143 log(const LogRecord &lr) = 0;
00144
00145
00151 virtual std::string
00152 getName() const = 0;
00153
00158 static const std::string FIELD_UNAVAILABLE;
00159
00163 static const std::string GLOBAL_LOGGER_NAME;
00164
00168 static const std::string ANONYMOUS_LOGGER_NAME;
00169
00174 static const std::string STATIC_LOGGER_NAME;
00175 };
00176
00186 template <class P>
00187 class RefCounted
00188 {
00189 public:
00190 RefCounted()
00191 {
00192 pCount_ = new unsigned int();
00193 assert(pCount_);
00194 *pCount_ = 1;
00195 }
00196
00197 RefCounted(const RefCounted& rhs)
00198 : pCount_(rhs.pCount_)
00199 {}
00200
00201
00202 template <typename P1>
00203 RefCounted(const RefCounted<P1>& rhs)
00204 : pCount_(reinterpret_cast<const RefCounted&>(rhs).pCount_)
00205 {}
00206
00207 P Clone(const P& val)
00208 {
00209 ++*pCount_;
00210 return val;
00211 }
00212
00213 bool Release(const P&)
00214 {
00215 if (!--*pCount_)
00216 {
00217 delete pCount_;
00218 return true;
00219 }
00220 return false;
00221 }
00222
00223 void Swap(RefCounted& rhs)
00224 { std::swap(pCount_, rhs.pCount_); }
00225
00226 enum { destructiveCopy = false };
00227
00228 private:
00229
00230 unsigned int* pCount_;
00231 };
00232
00233 #ifdef MAKE_VXWORKS
00234
00235 template <class P>
00236 class RefCountedMT : public Loki::ObjectLevelLockable<RefCountedMT<P>, LOKI_DEFAULT_MUTEX >
00237 {
00238 typedef Loki::ObjectLevelLockable<RefCountedMT<P>, LOKI_DEFAULT_MUTEX > base_type;
00239 typedef typename base_type::IntType CountType;
00240 typedef volatile CountType *CountPtrType;
00241
00242 public:
00243 RefCountedMT()
00244 {
00245 pCount_ = reinterpret_cast<CountPtrType>(
00246 Loki::SmallObject<LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL>::operator new(
00247 sizeof(*pCount_)));
00248 assert(pCount_);
00249
00250 Loki::ObjectLevelLockable<RefCountedMT, LOKI_DEFAULT_MUTEX>::AtomicAssign(*pCount_, 1);
00251 }
00252
00253 RefCountedMT(const RefCountedMT& rhs) :
00254 Loki::ObjectLevelLockable<RefCountedMT<P>, LOKI_DEFAULT_MUTEX>( rhs ),
00255 pCount_(rhs.pCount_)
00256 {}
00257
00258
00259 template <typename P1>
00260 RefCountedMT(const RefCountedMT<P1>& rhs)
00261 : pCount_(reinterpret_cast<const RefCountedMT<P>&>(rhs).pCount_)
00262 {}
00263
00264 P Clone(const P& val)
00265 {
00266 Loki::ObjectLevelLockable<RefCountedMT, LOKI_DEFAULT_MUTEX>::AtomicIncrement(*pCount_);
00267 return val;
00268 }
00269
00270 bool Release(const P&)
00271 {
00272 if (! Loki::ObjectLevelLockable<RefCountedMT, LOKI_DEFAULT_MUTEX>::AtomicDecrement(*pCount_))
00273 {
00274 Loki::SmallObject<LOKI_DEFAULT_THREADING_NO_OBJ_LEVEL>::operator delete(
00275 const_cast<CountType *>(pCount_),
00276 sizeof(*pCount_));
00277 return true;
00278 }
00279 return false;
00280 }
00281
00282 void Swap(RefCountedMT& rhs)
00283 { std::swap(pCount_, rhs.pCount_); }
00284
00285 enum { destructiveCopy = false };
00286
00287 private:
00288
00289 CountPtrType pCount_;
00290 };
00291 #endif //MAKE_VXWORKS
00292 };
00293
00294 #endif