44 QMutexLocker locker(&mMutex);
45 if (!mChannels.contains(message.
mChannel))
53 if (this->testFilter(message))
61 bool MessageObserver::testFilter(
const Message &msg)
const
65 return (*mFilter)(msg);
70 QMutexLocker locker(&mMutex);
73 mFilter = filter->clone();
87 MessageRepository::MessageRepository() :
88 mMessageHistoryMaxSize(3000)
98 mMessages.push_back(message);
99 this->limitQueueSize();
100 this->emitThroughFilter(message);
103 void MessageRepository::limitQueueSize()
105 if (mMessageHistoryMaxSize<0)
108 while (mMessages.size() > mMessageHistoryMaxSize)
109 mMessages.pop_front();
112 void MessageRepository::emitThroughFilter(
const Message& message)
114 for (
unsigned i=0; i<mObservers.size(); ++i)
116 mObservers[i]->sendMessage(message);
122 if(!this->exists(observer))
123 mObservers.push_back(observer);
127 for (
unsigned i = 0; i < mMessages.size(); ++i)
128 observer->sendMessage(mMessages[i]);
135 if (std::count(mObservers.begin(), mObservers.end(), observer))
142 if (!this->exists(observer))
144 mObservers.erase(std::find(mObservers.begin(), mObservers.end(), observer));
149 mMessageHistoryMaxSize = count;
150 this->limitQueueSize();
155 return mMessageHistoryMaxSize;
void sendMessage(const Message &message)
void uninstall(MessageObserverPtr observer)
static MessageRepositoryPtr create()
void setMessageQueueMaxSize(int count)
boost::shared_ptr< class MessageFilter > MessageFilterPtr
void setMessage(Message message)
void newChannel(QString channel)
void installFilter(MessageFilterPtr filter)
void install(MessageObserverPtr observer, bool resend)
boost::shared_ptr< class MessageObserver > MessageObserverPtr
int getMessageQueueMaxSize() const
boost::shared_ptr< class MessageRepository > MessageRepositoryPtr
void newMessage(Message message)