CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxMessageListener.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 #ifndef CXMESSAGELISTENER_H
12 #define CXMESSAGELISTENER_H
13 
14 #include "cxResourceExport.h"
15 #include "cxReporter.h"
16 
17 #include <vector>
18 #include <QPointer>
19 
20 namespace cx
21 {
22 
23 typedef boost::shared_ptr<class MessageFilter> MessageFilterPtr;
24 typedef boost::shared_ptr<class MessageObserver> MessageObserverPtr;
25 typedef boost::shared_ptr<class MessageListener> MessageListenerPtr;
26 typedef boost::shared_ptr<class Log> LogPtr;
27 
38 class cxResource_EXPORT MessageListener : public QObject
39 {
40  Q_OBJECT
41 public:
42  static MessageListenerPtr create(LogPtr log=LogPtr());
43  static MessageListenerPtr createWithQueue(LogPtr log=LogPtr(), int size=1000);
44  MessageListenerPtr clone();
45  ~MessageListener();
46  bool containsErrors() const;
47  bool containsText(const QString text) const;
48  QList<Message> getMessages() const;
49 
50  void restart(); // emit all messages in queue, then continue emitting new incoming messages
51 
52  void installFilter(MessageFilterPtr);
53  void setMessageQueueMaxSize(int count);
54  int getMessageQueueMaxSize() const; // <0 means infinite
55 
56 signals:
57  void newMessage(Message message);
58  void newChannel(QString channel);
59 
60 private slots:
61  void messageReceived(Message message);
62 private:
63  MessageListener(LogPtr log);
64  bool isError(MESSAGE_LEVEL level) const;
65  void limitQueueSize();
66  QList<Message> mMessages;
67  LogPtr mManager;
68  int mMessageHistoryMaxSize;
69 
70  MessageObserverPtr mObserver;
71 };
72 
73 
74 } // namespace cx
75 
76 
77 #endif // CXMESSAGELISTENER_H
boost::shared_ptr< class MessageFilter > MessageFilterPtr
boost::shared_ptr< class Log > LogPtr
Definition: cxLog.h:48
boost::shared_ptr< class MessageObserver > MessageObserverPtr
Definition: cxLog.h:44
boost::shared_ptr< class MessageListener > MessageListenerPtr
Definition: cxLog.h:45
Namespace for all CustusX production code.