Fraxinus  22.09
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 namespace cx
23 {
24 
34 class MessageObserver : public QObject
35 {
36  Q_OBJECT
37 public:
41  void sendMessage(const Message& message);
47  void installFilter(MessageFilterPtr filter);
48 
49 signals:
50  void newMessage(Message message);
51  void newChannel(QString channel);
52 private:
53  bool testFilter(const Message &msg) const;
54 
55  MessageFilterPtr mFilter;
56  QStringList mChannels;
57  QMutex mMutex;
58 };
59 
60 typedef boost::shared_ptr<class MessageObserver> MessageObserverPtr;
61 typedef boost::shared_ptr<class MessageListener> MessageListenerPtr;
62 typedef boost::shared_ptr<class MessageRepository> MessageRepositoryPtr;
63 
74 class MessageRepository : public QObject
75 {
76 public:
77  static MessageRepositoryPtr create();
79  void setMessage(Message message);
80 
81  void install(MessageObserverPtr observer, bool resend);
82  void uninstall(MessageObserverPtr observer);
83 
84  void setMessageQueueMaxSize(int count);
85  int getMessageQueueMaxSize() const; // <0 means infinite
86  void clearQueue();
87 
88 private:
90  void limitQueueSize();
91  void emitThroughFilter(const Message& message);
92  QList<Message> mMessages;
93  std::vector<MessageObserverPtr> mObservers;
94  int mMessageHistoryMaxSize;
95  bool exists(MessageObserverPtr observer);
96 };
97 
98 
99 } // namespace cx
100 
101 #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)