00001 /****************************************************************************** 00002 * 00003 * package: Log4Qt 00004 * file: appenderskeleton.h 00005 * created: September 2007 00006 * author: Martin Heinrich 00007 * 00008 * 00009 * Copyright 2007 Martin Heinrich 00010 * 00011 * Licensed under the Apache License, Version 2.0 (the "License"); 00012 * you may not use this file except in compliance with the License. 00013 * You may obtain a copy of the License at 00014 * 00015 * http://www.apache.org/licenses/LICENSE-2.0 00016 * 00017 * Unless required by applicable law or agreed to in writing, software 00018 * distributed under the License is distributed on an "AS IS" BASIS, 00019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 * See the License for the specific language governing permissions and 00021 * limitations under the License. 00022 * 00023 ******************************************************************************/ 00024 00025 #ifndef LOG4QT_APPENDERSKELETON_H 00026 #define LOG4QT_APPENDERSKELETON_H 00027 00028 00029 /****************************************************************************** 00030 * Dependencies 00031 ******************************************************************************/ 00032 00033 #include "log4qt/appender.h" 00034 00035 #include <QtCore/QMutex> 00036 #include "log4qt/helpers/logobjectptr.h" 00037 00038 00039 /****************************************************************************** 00040 * Declarations 00041 ******************************************************************************/ 00042 00043 namespace Log4Qt 00044 { 00045 00046 class Filter; 00047 class Layout; 00048 class Logger; 00049 class LoggingEvent; 00050 00059 class AppenderSkeleton : public Appender 00060 { 00061 Q_OBJECT 00062 00068 Q_PROPERTY(bool isActive READ isActive) 00069 00070 00075 Q_PROPERTY(bool isClosed READ isClosed) 00076 00082 Q_PROPERTY(Level threshold READ threshold WRITE setThreshold) 00083 00084 public: 00085 AppenderSkeleton(QObject *pParent = 0); 00086 protected: 00087 AppenderSkeleton(const bool isActive, 00088 QObject *pParent = 0); 00089 public: 00090 // virtual ~AppenderSkeleton(); Use compiler default 00091 private: 00092 AppenderSkeleton(const AppenderSkeleton &rOther); // Not implemented 00093 AppenderSkeleton &operator=(const AppenderSkeleton &rOther); // Not implemented 00094 00095 public: 00096 // JAVA: ErrorHandler* errorHandler(); 00097 virtual Filter *filter() const; 00098 virtual Layout *layout() const; 00099 bool isActive() const; 00100 bool isClosed() const; 00101 virtual QString name() const; 00102 Level threshold() const; 00103 // JAVA: void setErrorHandler(ErrorHandler *pErrorHandler); 00104 virtual void setLayout(Layout *pLayout); 00105 virtual void setName(const QString &rName); 00106 void setThreshold(Level level); 00107 00108 virtual void activateOptions(); 00109 virtual void addFilter(Filter *pFilter); 00110 virtual void clearFilters(); 00111 virtual void close(); 00112 00119 virtual void doAppend(const LoggingEvent &rEvent); 00120 00121 // JAVA: void finalize(); 00122 Filter* firstFilter() const; 00123 bool isAsSevereAsThreshold(Level level) const; 00124 00125 protected: 00126 virtual void append(const LoggingEvent &rEvent) = 0; 00127 00150 virtual bool checkEntryConditions() const; 00151 00152 protected: 00153 mutable QMutex mObjectGuard; 00154 private: 00155 bool mAppendRecursionGuard; 00156 volatile bool mIsActive; 00157 volatile bool mIsClosed; 00158 LogObjectPtr<Layout> mpLayout; 00159 Level mThreshold; 00160 LogObjectPtr<Filter> mpHeadFilter; 00161 LogObjectPtr<Filter> mpTailFilter; 00162 }; 00163 00164 00165 /************************************************************************** 00166 * Operators, Helper 00167 **************************************************************************/ 00168 00169 00170 /************************************************************************** 00171 * Inline 00172 **************************************************************************/ 00173 00174 inline Filter *AppenderSkeleton::filter() const 00175 { QMutexLocker locker(&mObjectGuard); 00176 return mpHeadFilter; } 00177 00178 inline Layout *AppenderSkeleton::layout() const 00179 { QMutexLocker locker(&mObjectGuard); 00180 return mpLayout; } 00181 00182 inline QString AppenderSkeleton::name() const 00183 { QMutexLocker locker(&mObjectGuard); 00184 return objectName(); } 00185 00186 inline Level AppenderSkeleton::threshold() const 00187 { // QMutexLocker locker(&mObjectGuard); // Level is threadsafe 00188 return mThreshold; } 00189 00190 inline void AppenderSkeleton::setLayout(Layout *pLayout) 00191 { QMutexLocker locker(&mObjectGuard); 00192 mpLayout = pLayout; } 00193 00194 inline void AppenderSkeleton::setName(const QString &rName) 00195 { QMutexLocker locker(&mObjectGuard); 00196 setObjectName(rName); } 00197 00198 inline void AppenderSkeleton::setThreshold(Level level) 00199 { // QMutexLocker locker(&mObjectGuard); // Level is threadsafe 00200 mThreshold = level; } 00201 00202 inline bool AppenderSkeleton::isActive() const 00203 { // QMutexLocker locker(&mObjectGuard); // Read/Write of int is safe 00204 return mIsActive; } 00205 00206 inline bool AppenderSkeleton::isClosed() const 00207 { // QMutexLocker locker(&mObjectGuard); // Read/Write of int is safe 00208 return mIsClosed; } 00209 00210 inline Filter *AppenderSkeleton::firstFilter() const 00211 { QMutexLocker locker(&mObjectGuard); 00212 return filter(); } 00213 00214 inline bool AppenderSkeleton::isAsSevereAsThreshold(Level level) const 00215 { // QMutexLocker locker(&mObjectGuard); // Level is threadsafe 00216 return (mThreshold <= level); } 00217 00218 00219 } // namespace Log4Qt 00220 00221 00222 // Q_DECLARE_TYPEINFO(Log4Qt::AppenderSkeleton, Q_COMPLEX_TYPE); // Use default 00223 00224 00225 #endif // LOG4QT_APPENDERSKELETON_H