NorMIT-nav  18.04
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 #include "cxEnumConverter.h"
21 
22 namespace cx
23 {
24 
25 typedef boost::shared_ptr<class MessageFilter> MessageFilterPtr;
26 typedef boost::shared_ptr<class MessageObserver> MessageObserverPtr;
27 typedef boost::shared_ptr<class MessageListener> MessageListenerPtr;
28 typedef boost::shared_ptr<class Log> LogPtr;
29 
40 class cxResource_EXPORT MessageListener : public QObject
41 {
42  Q_OBJECT
43 public:
44  static MessageListenerPtr create(LogPtr log=LogPtr());
45  static MessageListenerPtr createWithQueue(LogPtr log=LogPtr(), int size=1000);
46  MessageListenerPtr clone();
47  ~MessageListener();
48  bool containsErrors() const;
49  bool containsText(const QString text) const;
50  QList<Message> getMessages() const;
51 
52  void restart(); // emit all messages in queue, then continue emitting new incoming messages
53 
54  void installFilter(MessageFilterPtr);
55  void setMessageQueueMaxSize(int count);
56  int getMessageQueueMaxSize() const; // <0 means infinite
57 
58 signals:
59  void newMessage(Message message);
60  void newChannel(QString channel);
61 
62 private slots:
63  void messageReceived(Message message);
64 private:
65  MessageListener(LogPtr log);
66  bool isError(MESSAGE_LEVEL level) const;
67  void limitQueueSize();
68  QList<Message> mMessages;
69  LogPtr mManager;
70  int mMessageHistoryMaxSize;
71 
72  MessageObserverPtr mObserver;
73 };
74 
75 
76 } // namespace cx
77 
78 
79 #endif // CXMESSAGELISTENER_H
boost::shared_ptr< class MessageFilter > MessageFilterPtr
boost::shared_ptr< class Log > LogPtr
Definition: cxLog.h:47
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.