CustusX  22.04-rc5
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXLOGTHREAD_H
13 #define CXLOGTHREAD_H
14 
15 #include "cxResourceExport.h"
16 
17 #include <QMetaType>
18 #include <QObject>
19 #include <QMutex>
20 #include <QDateTime>
21 #include <QFile>
22 #include <QPointer>
23 #include "boost/shared_ptr.hpp"
24 #include "boost/function.hpp"
25 #include "cxDefinitions.h"
26 #include "cxAudio.h"
27 #include <sstream>
28 #include "cxTypeConversions.h"
29 #include "cxLogger.h"
30 #include "cxLogMessage.h"
31 #include <QList>
32 #include <QThread>
33 #include <QFileSystemWatcher>
34 
35 class QString;
36 class QDomNode;
37 class QDomDocument;
38 class QFile;
39 class QTextStream;
40 
47 namespace cx
48 {
49 typedef boost::shared_ptr<class MessageObserver> MessageObserverPtr;
50 typedef boost::shared_ptr<class MessageRepository> MessageRepositoryPtr;
51 class LogFile;
52 
53 
58 class ThreadMethodInvoker : public QObject
59 {
60  Q_OBJECT
61 
62 public:
63  typedef boost::function<void()> ActionType;
64 
65  ThreadMethodInvoker(QObject* parent);
66  void callInLogThread(ActionType action);
67 
68 private slots:
69  void pendingAction();
70 
71 private:
72  QMutex mActionsMutex;
73  QList<ActionType> mPendingActions;
74 
75  bool executeAction();
76  ActionType popAction();
77  void invokePendingAction();
78 };
79 
84 class LogThread : public QObject
85 {
86  Q_OBJECT
87  typedef boost::function<void()> ActionType;
88 
89 public:
90  LogThread(QObject* parent = NULL);
91  virtual ~LogThread() {}
92  virtual void setLoggingFolder(QString absoluteLoggingFolderPath);
93  virtual void installObserver(MessageObserverPtr observer, bool resend);
94  virtual void uninstallObserver(MessageObserverPtr observer);
95 
96 signals:
97  void emittedMessage(Message message);
98 public slots:
99  virtual void logMessage(Message msg) {} // default impl do nothing (should be removed)
100 
101 protected:
102  virtual void executeSetLoggingFolder(QString absoluteLoggingFolderPath) = 0;
104  Message cleanupMessage(Message message);
105  MessageRepositoryPtr mRepository;
106 
107 protected slots:
108  void processMessage(Message msg);
109 
110 private:
111  QPointer<ThreadMethodInvoker> mQueue;
112 
113  int getDefaultTimeout(MESSAGE_LEVEL messageLevel) const;
114 };
115 
116 } //namespace cx
117 
122 #endif // CXLOGTHREAD_H
virtual void logMessage(Message msg)
Definition: cxLogThread.h:99
ThreadMethodInvoker(QObject *parent)
Definition: cxLogThread.cpp:20
MessageRepositoryPtr mRepository
Definition: cxLogThread.h:105
virtual ~LogThread()
Definition: cxLogThread.h:91
boost::shared_ptr< class MessageObserver > MessageObserverPtr
Definition: cxLog.h:44
boost::function< void()> ActionType
Definition: cxLogThread.h:63
void callInLogThread(ActionType action)
Definition: cxLogThread.cpp:25
boost::shared_ptr< class MessageRepository > MessageRepositoryPtr
Definition: cxLogThread.h:50
Namespace for all CustusX production code.