• 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.14 2010/03/25 22:07:23 javarias 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 
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         // MWCW lacks template friends, hence the following kludge
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         // Data
00229         unsigned int* pCount_;
00230     };  
00231 
00232 #ifdef MAKE_VXWORKS
00233 // we have to define (copy from loki) our own RefCountedMT for VxWorks since the one for loki is too compley for VxWorks compiler
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                 // *pCount_ = 1;
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             //MWCW lacks template friends, hence the following kludge
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             // Data
00288             CountPtrType pCount_;
00289         };
00290 #endif //MAKE_VXWORKS
00291 };
00292 
00293 #endif 

Generated on Thu Jan 12 2012 23:13:51 for ACS-10.0 C++ API by  doxygen 1.7.0