Fraxinus  18.10
An IGT application
cxReporterMessageRepository.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 CXREPORTERMESSAGEREPOSITORY_H
12 #define CXREPORTERMESSAGEREPOSITORY_H
13 
14 #include "cxResourceExport.h"
15 #include "cxReporter.h"
16 #include "cxMessageListener.h"
17 
18 
19 #include <vector>
20 #include <QPointer>
21 
22 #include "cxEnumConverter.h"
23 
24 namespace cx
25 {
26 
36 class MessageObserver : public QObject
37 {
38  Q_OBJECT
39 public:
43  void sendMessage(const Message& message);
49  void installFilter(MessageFilterPtr filter);
50 
51 signals:
52  void newMessage(Message message);
53  void newChannel(QString channel);
54 private:
55  bool testFilter(const Message &msg) const;
56 
57  MessageFilterPtr mFilter;
58  QStringList mChannels;
59  QMutex mMutex;
60 };
61 
62 typedef boost::shared_ptr<class MessageObserver> MessageObserverPtr;
63 typedef boost::shared_ptr<class MessageListener> MessageListenerPtr;
64 typedef boost::shared_ptr<class MessageRepository> MessageRepositoryPtr;
65 
76 class MessageRepository : public QObject
77 {
78 public:
79  static MessageRepositoryPtr create();
81  void setMessage(Message message);
82 
83  void install(MessageObserverPtr observer, bool resend);
84  void uninstall(MessageObserverPtr observer);
85 
86  void setMessageQueueMaxSize(int count);
87  int getMessageQueueMaxSize() const; // <0 means infinite
88  void clearQueue();
89 
90 private:
92  void limitQueueSize();
93  void emitThroughFilter(const Message& message);
94  QList<Message> mMessages;
95  std::vector<MessageObserverPtr> mObservers;
96  int mMessageHistoryMaxSize;
97  bool exists(MessageObserverPtr observer);
98 };
99 
100 
101 } // namespace cx
102 
103 #endif // CXREPORTERMESSAGEREPOSITORY_H
void sendMessage(const Message &message)
boost::shared_ptr< class MessageFilter > MessageFilterPtr
void newChannel(QString channel)
void installFilter(MessageFilterPtr filter)
boost::shared_ptr< class MessageObserver > MessageObserverPtr
Definition: cxLog.h:44
boost::shared_ptr< class MessageRepository > MessageRepositoryPtr
Definition: cxLogThread.h:50
boost::shared_ptr< class MessageListener > MessageListenerPtr
Definition: cxLog.h:45
Namespace for all CustusX production code.
void newMessage(Message message)