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