• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

loggingBaseLog.h

Go to the documentation of this file.
00001 #ifndef logging_base_log_H
00002 #define logging_base_log_H
00003 /*******************************************************************************
00004 * ALMA - Atacama Large Millimiter Array
00005 * (c) Associated Universities Inc., 2005 
00006 * 
00007 * This library is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU Lesser General Public
00009 * License as published by the Free Software Foundation; either
00010 * version 2.1 of the License, or (at your option) any later version.
00011 * 
00012 * This library is distributed in the hope that it will be useful,
00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 * Lesser General Public License for more details.
00016 * 
00017 * You should have received a copy of the GNU Lesser General Public
00018 * License along with this library; if not, write to the Free Software
00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 *
00021 * "@(#) $Id: loggingBaseLog.h,v 1.16 2012/02/29 12:50:09 tstaig Exp $"
00022 *
00023 * who       when      what
00024 * --------  --------  ----------------------------------------------
00025 * dfugate  2005-03-09  created
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         // Default constructor
00053         BaseLog();
00054 
00055         // Default constructor
00056         virtual ~BaseLog(){}
00057 
00058         // Statistics object
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                         // MWCW lacks template friends, hence the following kludge
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                         // Data
00237                         unsigned int* pCount_;
00238                 };
00239 
00240 #ifdef MAKE_VXWORKS
00241 // we have to define (copy from loki) our own RefCountedMT for VxWorks since the one for loki is too compley for VxWorks compiler
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                 // *pCount_ = 1;
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             //MWCW lacks template friends, hence the following kludge
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             // Data
00296             CountPtrType pCount_;
00297         };
00298 #endif //MAKE_VXWORKS
00299 };
00300 
00301 #endif 

Generated on Mon May 4 2015 08:27:43 for ACS-2015.4 C++ API by  doxygen 1.7.0