NorMIT-nav  2023.01.05-dev+develop.0da12
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);
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
cx::LogThread::mRepository
MessageRepositoryPtr mRepository
Definition: cxLogThread.h:105
cxLogger.h
cx::LogThread::executeSetLoggingFolder
virtual void executeSetLoggingFolder(QString absoluteLoggingFolderPath)=0
cx::LogThread::processMessage
void processMessage(Message msg)
Definition: cxLogThread.cpp:105
cx::LogThread::setLoggingFolder
virtual void setLoggingFolder(QString absoluteLoggingFolderPath)
call during startup, will fail if called when running
Definition: cxLogThread.cpp:94
cx::Message
Definition: cxLogMessage.h:54
cx::ThreadMethodInvoker::ActionType
boost::function< void()> ActionType
Definition: cxLogThread.h:63
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::LogThread::~LogThread
virtual ~LogThread()
Definition: cxLogThread.h:91
cx::LogFile
Definition: cxLogFile.h:25
cx::LogThread::logMessage
virtual void logMessage(Message msg)
Definition: cxLogThread.h:99
cx::LogThread::installObserver
virtual void installObserver(MessageObserverPtr observer, bool resend)
Definition: cxLogThread.cpp:82
cxAudio.h
cxDefinitions.h
cxLogMessage.h
cx::LogThread::LogThread
LogThread(QObject *parent=NULL)
Definition: cxLogThread.cpp:75
cx::MessageObserverPtr
boost::shared_ptr< class MessageObserver > MessageObserverPtr
Definition: cxLog.h:44
cxTypeConversions.h
cx::LogThread::cleanupMessage
Message cleanupMessage(Message message)
Definition: cxLogThread.cpp:115
cx::LogThread
Definition: cxLogThread.h:84
cx::ThreadMethodInvoker::callInLogThread
void callInLogThread(ActionType action)
Definition: cxLogThread.cpp:25
cx::LogThread::emittedMessage
void emittedMessage(Message message)
emitted for each new message, in addition to writing to observer.
cx::ThreadMethodInvoker::ThreadMethodInvoker
ThreadMethodInvoker(QObject *parent)
Definition: cxLogThread.cpp:20
cx::ThreadMethodInvoker
Definition: cxLogThread.h:58
cx::LogThread::callInLogThread
void callInLogThread(ThreadMethodInvoker::ActionType action)
Definition: cxLogThread.cpp:100
cx::LogThread::uninstallObserver
virtual void uninstallObserver(MessageObserverPtr observer)
Definition: cxLogThread.cpp:88
cx::MessageRepositoryPtr
boost::shared_ptr< class MessageRepository > MessageRepositoryPtr
Definition: cxLogThread.h:50