/** Write from local copy into BlackBoard memory. * @exception InterfaceInvalidException thrown if the interface has * been marked invalid */ void Interface::write() { if ( ! __write_access ) { throw InterfaceWriteDeniedException(__type, __id, "Cannot write."); } __rwlock->lock_for_write(); __data_mutex->lock(); if ( __valid ) { if (data_changed) { if (__auto_timestamping) __timestamp->stamp(); long sec = 0, usec = 0; __timestamp->get_timestamp(sec, usec); data_ts->timestamp_sec = sec; data_ts->timestamp_usec = usec; data_changed = false; } memcpy(__mem_data_ptr, data_ptr, data_size); } else { __data_mutex->unlock(); __rwlock->unlock(); throw InterfaceInvalidException(this, "write()"); } __data_mutex->unlock(); __rwlock->unlock(); __interface_mediator->notify_of_data_change(this); }
/** Get the first message from the message queue. * * This can only be called on a writing interface instance. * * @return first message in queue or NULL if there is none */ Message * Interface::msgq_first() { if ( ! __write_access ) { throw InterfaceWriteDeniedException(__type, __id, "Cannot work on message queue on " "reading instance of an interface (first)."); } return __message_queue->first(); }
/** Remove message from queue. * Removes the given message from the queue. Note that if you * unref()ed the message after insertion this will most likely delete * the object. It is not safe to use the message after removing it * from the queue in general. * * This can only be called on a writing interface instance. * * @param message Message to remove. */ void Interface::msgq_remove(Message *message) { if ( ! __write_access ) { throw InterfaceWriteDeniedException(__type, __id, "Cannot work on message queue on " "reading instance of an interface (remove msg)."); } return __message_queue->remove(message); }
/** Erase first message from queue. * This can only be called on a writing interface instance. */ void Interface::msgq_pop() { if ( ! __write_access ) { throw InterfaceWriteDeniedException(__type, __id, "Cannot work on message queue on " "reading instance of an interface (pop)."); } __message_queue->pop(); }
/** Get start iterator for message queue. * Not that you must have locked the queue before this operation! * * This can only be called on a writing interface instance. * * @return iterator to begin of message queue. * @exception NotLockedException thrown if message queue is not locked * during this operation. */ MessageQueue::MessageIterator Interface::msgq_begin() { if ( ! __write_access ) { throw InterfaceWriteDeniedException(__type, __id, "Cannot work on message queue on " "reading instance of an interface (begin)."); } return __message_queue->begin(); }
/** Get size of message queue. * This can only be called on a writing interface instance. * @return number of messages in queue. */ unsigned int Interface::msgq_size() { if ( ! __write_access ) { throw InterfaceWriteDeniedException(__type, __id, "Cannot work on message queue on " "reading instance of an interface (size)."); } return __message_queue->size(); }
/** Enqueue message. * This will enqueue the message without transmitting it via the * message mediator. It can be useful, for example, to enqueue the * message from an event callback. * * This can only be called on a writing interface instance. * * @param message message to enqueue, reference count will be incremented. */ void Interface::msgq_append(Message *message) { if ( ! __write_access ) { throw InterfaceWriteDeniedException(__type, __id, "Cannot work on message queue on " "reading instance of an interface (append)."); } message->ref(); __message_queue->append(message); }
/** Try to lock message queue. * Try to lock the message queue. Returns immediately and does not * wait for lock. * * This can only be called on a writing interface instance. * @return true, if the lock has been aquired, false otherwise. * @see lock() */ bool Interface::msgq_try_lock() { if ( ! __write_access ) { throw InterfaceWriteDeniedException(__type, __id, "Cannot work on message queue on " "reading instance of an interface " "(msgq_try_lock)."); } return __message_queue->try_lock(); }