00001 /****************************************************************************** 00002 * 00003 * package: Log4Qt 00004 * file: configuratorhelper.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_HELPERS_CONFIGURATORHELPER_H 00026 #define LOG4QT_HELPERS_CONFIGURATORHELPER_H 00027 00028 00029 /****************************************************************************** 00030 * Dependencies 00031 ******************************************************************************/ 00032 00033 #include <QtCore/QObject> 00034 00035 #include <QtCore/QList> 00036 #include <QtCore/QMutex> 00037 #include "log4qt/loggingevent.h" 00038 00039 00040 /****************************************************************************** 00041 * Declarations 00042 ******************************************************************************/ 00043 00044 class QFileSystemWatcher; 00045 00046 00047 namespace Log4Qt 00048 { 00049 00062 class ConfiguratorHelper : public QObject 00063 { 00064 Q_OBJECT 00065 00066 public: 00075 typedef bool (*ConfigureFunc)(const QString &rFileName); 00076 00077 private: 00078 ConfiguratorHelper(); 00079 ConfiguratorHelper(const ConfiguratorHelper &rOther); // Not implemented 00080 virtual ~ConfiguratorHelper(); 00081 ConfiguratorHelper &operator=(const ConfiguratorHelper &rOther); // Not implemented 00082 00083 public: 00084 00094 static QList<LoggingEvent> configureError(); 00095 00101 static QString configurationFile(); 00102 00106 static ConfiguratorHelper *instance(); 00107 00114 static void setConfigureError(const QList<LoggingEvent> &rConfigureError); 00115 00126 static void setConfigurationFile(const QString &rFileName = QString(), 00127 ConfigureFunc pConfigureFunc = 0); 00128 00129 signals: 00136 void configurationFileChanged(const QString &rFileName, 00137 bool error); 00138 00139 private slots: 00140 void doConfigurationFileChanged(const QString &rFileName); 00141 00142 private: 00143 void doSetConfigurationFile(const QString &rFileName, 00144 ConfigureFunc pConfigureFunc); 00145 00146 private: 00147 mutable QMutex mObjectGuard; 00148 QString mConfigurationFile; 00149 ConfigureFunc mpConfigureFunc; 00150 QFileSystemWatcher *mpConfigurationFileWatch; 00151 QList<LoggingEvent> mConfigureError; 00152 00153 #ifndef QT_NO_DEBUG_STREAM 00154 // Needs to be friend to access details 00155 friend QDebug operator<<(QDebug debug, 00156 const ConfiguratorHelper &rConfiguratorHelper); 00157 #endif // QT_NO_DEBUG_STREAM 00158 }; 00159 00160 00161 /************************************************************************** 00162 * Operators, Helper 00163 **************************************************************************/ 00164 00165 #ifndef QT_NO_DEBUG_STREAM 00166 00178 QDebug operator<<(QDebug debug, 00179 const ConfiguratorHelper &rConfiguratorHelper); 00180 #endif // QT_NO_DEBUG_STREAM 00181 00182 00183 00184 /************************************************************************** 00185 * Inline 00186 **************************************************************************/ 00187 00188 inline QList<LoggingEvent> ConfiguratorHelper::configureError() 00189 { QMutexLocker locker(&instance()->mObjectGuard); 00190 return instance()->mConfigureError; } 00191 00192 inline QString ConfiguratorHelper::configurationFile() 00193 { QMutexLocker locker(&instance()->mObjectGuard); 00194 return instance()->mConfigurationFile; } 00195 00196 inline void ConfiguratorHelper::setConfigureError(const QList<LoggingEvent> &rConfigureError) 00197 { QMutexLocker locker(&instance()->mObjectGuard); 00198 instance()->mConfigureError = rConfigureError; } 00199 00200 inline void ConfiguratorHelper::setConfigurationFile(const QString &rFileName, 00201 ConfigureFunc pConfigureFunc) 00202 { instance()->doSetConfigurationFile(rFileName, pConfigureFunc); } 00203 00204 } // namespace Log4Qt 00205 00206 00207 // Q_DECLARE_TYPEINFO(Log4Qt::ConfiguratorHelper, Q_COMPLEX_TYPE); // use default 00208 00209 00210 #endif // LOG4QT_HELPERS_CONFIGURATORHELPER_H