Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxLogThread.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXLOGTHREAD_H
34 #define CXLOGTHREAD_H
35 
36 #include "cxResourceExport.h"
37 
38 #include <QMetaType>
39 #include <QObject>
40 #include <QMutex>
41 #include <QDateTime>
42 #include <QFile>
43 #include <QPointer>
44 #include "boost/shared_ptr.hpp"
45 #include "boost/function.hpp"
46 #include "cxDefinitions.h"
47 #include "cxAudio.h"
48 #include <sstream>
49 #include "cxTypeConversions.h"
50 #include "cxLogger.h"
51 #include "cxLogMessage.h"
52 #include <QList>
53 #include <QThread>
54 #include <QFileSystemWatcher>
55 
56 class QString;
57 class QDomNode;
58 class QDomDocument;
59 class QFile;
60 class QTextStream;
61 
68 namespace cx
69 {
70 typedef boost::shared_ptr<class MessageObserver> MessageObserverPtr;
71 typedef boost::shared_ptr<class MessageRepository> MessageRepositoryPtr;
72 class LogFile;
73 
74 
79 class ThreadMethodInvoker : public QObject
80 {
81  Q_OBJECT
82 
83 public:
84  typedef boost::function<void()> ActionType;
85 
86  ThreadMethodInvoker(QObject* parent);
87  void callInLogThread(ActionType action);
88 
89 private slots:
90  void pendingAction();
91 
92 private:
93  QMutex mActionsMutex;
94  QList<ActionType> mPendingActions;
95 
96  bool executeAction();
97  ActionType popAction();
98  void invokePendingAction();
99 };
100 
105 class LogThread : public QObject
106 {
107  Q_OBJECT
108  typedef boost::function<void()> ActionType;
109 
110 public:
111  LogThread(QObject* parent = NULL);
112  virtual ~LogThread() {}
113  virtual void setLoggingFolder(QString absoluteLoggingFolderPath);
114  virtual void installObserver(MessageObserverPtr observer, bool resend);
115  virtual void uninstallObserver(MessageObserverPtr observer);
116 
117 signals:
118  void emittedMessage(Message message);
119 public slots:
120  virtual void logMessage(Message msg) {} // default impl do nothing (should be removed)
121 
122 protected:
123  virtual void executeSetLoggingFolder(QString absoluteLoggingFolderPath) = 0;
125  Message cleanupMessage(Message message);
127 
128 protected slots:
129  void processMessage(Message msg);
130 
131 private:
132  QPointer<ThreadMethodInvoker> mQueue;
133 
134  int getDefaultTimeout(MESSAGE_LEVEL messageLevel) const;
135 };
136 
137 } //namespace cx
138 
143 #endif // CXLOGTHREAD_H
virtual void logMessage(Message msg)
Definition: cxLogThread.h:120
virtual void installObserver(MessageObserverPtr observer, bool resend)
ThreadMethodInvoker(QObject *parent)
Definition: cxLogThread.cpp:41
virtual void uninstallObserver(MessageObserverPtr observer)
virtual void setLoggingFolder(QString absoluteLoggingFolderPath)
call during startup, will fail if called when running
LogThread(QObject *parent=NULL)
Definition: cxLogThread.cpp:96
MessageRepositoryPtr mRepository
Definition: cxLogThread.h:126
virtual void executeSetLoggingFolder(QString absoluteLoggingFolderPath)=0
virtual ~LogThread()
Definition: cxLogThread.h:112
void emittedMessage(Message message)
emitted for each new message, in addition to writing to observer.
boost::shared_ptr< class MessageObserver > MessageObserverPtr
Definition: cxLog.h:65
boost::function< void()> ActionType
Definition: cxLogThread.h:84
void callInLogThread(ThreadMethodInvoker::ActionType action)
void callInLogThread(ActionType action)
Definition: cxLogThread.cpp:46
void processMessage(Message msg)
boost::shared_ptr< class MessageRepository > MessageRepositoryPtr
Definition: cxLogThread.h:71
Message cleanupMessage(Message message)