24 #include <interface/message_queue.h> 25 #include <interface/message.h> 27 #include <core/threading/mutex.h> 28 #include <core/exceptions/software.h> 45 :
Exception(
"Message already enqueued in another MessageQueue.")
65 __mutex =
new Mutex();
85 msg_list_t *l = __list;
111 if ( __list == NULL ) {
112 __list = (msg_list_t *)malloc(
sizeof(msg_list_t));
115 __list->msg_id = msg->
id();
118 msg_list_t *l = (msg_list_t *)malloc(
sizeof(msg_list_t));
121 l->msg_id = msg->
id();
142 if ( __mutex->try_lock() ) {
144 throw NotLockedException(
"Message queue must be locked to insert messages after iterator.");
146 if ( it.cur == NULL ) {
153 msg_list_t *l = (msg_list_t *)malloc(
sizeof(msg_list_t));
154 l->next = it.cur->next;
156 l->msg_id = msg->
id();
158 if ( l->next == NULL ) {
171 msg_list_t *l = __list;
172 msg_list_t *p = NULL;
174 if ( l->msg == msg ) {
193 msg_list_t *l = __list;
194 msg_list_t *p = NULL;
196 if ( l->msg_id == msg_id ) {
215 if ( __mutex->try_lock() ) {
238 msg_list_t *l = __list;
256 bool rv = ( __list == NULL );
285 return __mutex->try_lock();
319 remove(__list, NULL);
332 if ( __mutex->try_lock() ) {
347 if ( __mutex->try_lock() ) {
444 for (
unsigned int j = 0; (cur != NULL) && (j < i); ++j) {
460 for (
unsigned int j = 0; (cur != NULL) && (j < i); ++j) {
475 return (cur == c.cur);
487 return (cur != c.cur);
499 return ( cur != NULL ) ? cur->msg : NULL;
533 if ( cur == NULL )
return 0;
Base class for all messages passed through interfaces in Fawkes BlackBoard.
unsigned int id() const
Get message ID.
void mark_enqueued()
Mark message as being enqueued.
void insert_after(const MessageIterator &it, Message *msg)
Enqueue message after given iterator.
unsigned int id() const
Get ID of current element or 0 if element is end.
MessageIterator & operator+=(unsigned int i)
Advance by a certain amount.
MessageIterator end()
Get iterator to element beyond end of message queue list.
Fawkes library namespace.
MessageQueue()
Constructor.
Message * operator*() const
Get memory pointer of chunk.
MessageAlreadyQueuedException()
Constructor.
A NULL pointer was supplied where not allowed.
MessageIterator()
Constructor.
bool enqueued() const
Check is message has been enqueued.
MessageIterator & operator+(unsigned int i)
Advance by a certain amount.
MessageIterator & operator++()
Increment iterator.
Base class for exceptions in Fawkes.
virtual ~MessageQueue()
Destructor.
void flush()
Delete all messages from queue.
bool operator!=(const MessageIterator &c) const
Check inequality of two iterators.
unsigned int size() const
Get number of messages in queue.
bool try_lock()
Try to lock message queue.
bool operator==(const MessageIterator &c) const
Check equality of two iterators.
Message * operator->() const
Act on current message.
MessageIterator begin()
Get iterator to first element in message queue.
void append(Message *msg)
Append message to queue.
bool empty() const
Check if message queue is empty.
Operation on unlocked object.
void remove(const Message *msg)
Remove message from queue.
void pop()
Erase first message from queue.
void unlock()
Unlock message queue.
Message * first()
Get first message from queue.
Mutex mutual exclusion lock.
void lock()
Lock message queue.
MessageIterator & operator=(const MessageIterator &c)
Assign iterator.