CustusX  15.4.0-beta
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 "boost/shared_ptr.hpp"
44 #include "boost/function.hpp"
45 #include "cxDefinitions.h"
46 #include "cxAudio.h"
47 #include <sstream>
48 #include "cxTypeConversions.h"
49 #include "cxLogger.h"
50 #include "cxLogMessage.h"
51 #include <QList>
52 #include <QThread>
53 #include <QFileSystemWatcher>
54 
55 class QString;
56 class QDomNode;
57 class QDomDocument;
58 class QFile;
59 class QTextStream;
60 
67 namespace cx
68 {
69 typedef boost::shared_ptr<class MessageObserver> MessageObserverPtr;
70 typedef boost::shared_ptr<class MessageRepository> MessageRepositoryPtr;
71 class LogFile;
72 
77 class LogThread : public QObject
78 {
79  Q_OBJECT
80  typedef boost::function<void()> PendingActionType;
81 
82 public:
83  LogThread(QObject* parent = NULL);
84  virtual ~LogThread() {}
85  virtual void setLoggingFolder(QString absoluteLoggingFolderPath);
86  virtual void installObserver(MessageObserverPtr observer, bool resend);
87  virtual void uninstallObserver(MessageObserverPtr observer);
88 
89 signals:
90  void emittedMessage(Message message);
91 public slots:
92  void pendingAction();
93  virtual void logMessage(Message msg) {} // default impl do nothing (should be removed)
94 
95 protected:
96  virtual void executeSetLoggingFolder(QString absoluteLoggingFolderPath) = 0;
97  void callInLogThread(PendingActionType& action);
100 
101 protected slots:
102  void processMessage(Message msg);
103 
104 private:
105  QMutex mActionsMutex;
106  QList<PendingActionType> mPendingActions;
107 
108  bool executeAction();
109  PendingActionType popAction();
110  void invokePendingAction();
111  int getDefaultTimeout(MESSAGE_LEVEL messageLevel) const;
112 };
113 
114 } //namespace cx
115 
120 #endif // CXLOGTHREAD_H
void callInLogThread(PendingActionType &action)
Definition: cxLogThread.cpp:65
void pendingAction()
Definition: cxLogThread.cpp:79
virtual void logMessage(Message msg)
Definition: cxLogThread.h:93
virtual void installObserver(MessageObserverPtr observer, bool resend)
Definition: cxLogThread.cpp:47
virtual void uninstallObserver(MessageObserverPtr observer)
Definition: cxLogThread.cpp:53
virtual void setLoggingFolder(QString absoluteLoggingFolderPath)
call during startup, will fail if called when running
Definition: cxLogThread.cpp:59
LogThread(QObject *parent=NULL)
Definition: cxLogThread.cpp:41
MessageRepositoryPtr mRepository
Definition: cxLogThread.h:99
virtual void executeSetLoggingFolder(QString absoluteLoggingFolderPath)=0
virtual ~LogThread()
Definition: cxLogThread.h:84
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
void processMessage(Message msg)
boost::shared_ptr< class MessageRepository > MessageRepositoryPtr
Definition: cxLogThread.h:70
Message cleanupMessage(Message message)