fipa_acl  1.4
Public Member Functions | Friends | List of all members
fipa::acl::ConversationObserver Class Reference

#include <conversation.h>

Public Member Functions

 ConversationObserver ()
 
virtual ~ConversationObserver ()
 
bool hasEvents () const
 
conversation::Event waitForNextEvent ()
 
bool getNextEvent (conversation::Event &msg)
 
std::vector
< fipa::acl::ConversationID
getConversationIdsOfObservables () const
 

Friends

class ConversationObservable
 

Detailed Description

Observer of a conversation The observer can either operate in a non-blocking fashion relying on hasEvents and getNextEvent or block using waitForNextEvent

Definition at line 95 of file conversation.h.

Constructor & Destructor Documentation

fipa::acl::ConversationObserver::ConversationObserver ( )

Definition at line 27 of file conversation.cpp.

28 {}
virtual fipa::acl::ConversationObserver::~ConversationObserver ( )
inlinevirtual

Desconstructor marked virtual to create polymorphic class At least one virtual method required to allow compile to take care of polymorphism

Definition at line 106 of file conversation.h.

106 {}

Member Function Documentation

std::vector< fipa::acl::ConversationID > fipa::acl::ConversationObserver::getConversationIdsOfObservables ( ) const

Get the conversation ids of observables

Definition at line 75 of file conversation.cpp.

76 {
77  std::vector<fipa::acl::ConversationID> conversationIds;
78 
79  boost::unique_lock<boost::mutex> lock(mObservablesMutex);
80  std::vector<ConversationObservablePtr>::const_iterator it = mObservables.begin();
81  for(; it != mObservables.end(); ++it)
82  {
83  conversationIds.push_back((*it)->getConversationId());
84  }
85 
86  return conversationIds;
87 }
bool fipa::acl::ConversationObserver::getNextEvent ( conversation::Event msg)

Retrieve next event

Definition at line 60 of file conversation.cpp.

61 {
62  boost::unique_lock<boost::mutex> lock(mEventsMutex);
63  if(mEvents.empty())
64  {
65  return false;
66  }
67 
68  event = mEvents.front();
69  mEvents.erase(mEvents.begin());
70 
71  LOG_INFO("Retrieve event: type: '%s', msg content: '%s'", conversation::EventTypeTxt[event.type].c_str(), event.msg.getContent().c_str());
72  return true;
73 }
bool fipa::acl::ConversationObserver::hasEvents ( ) const

Check if there is a next message

Definition at line 30 of file conversation.cpp.

31 {
32  boost::unique_lock<boost::mutex> lock(mEventsMutex);
33  return !mEvents.empty();
34 }
conversation::Event fipa::acl::ConversationObserver::waitForNextEvent ( )

Block this thread until a new message arrives

Returns
Next message as soon as it arrives

Definition at line 43 of file conversation.cpp.

44 {
45  boost::mutex mutex;
46  {
47  boost::unique_lock<boost::mutex> lock(mutex);
48  while(!hasEvents())
49  {
50  mCondition.wait(lock);
51  }
52  }
53 
54  conversation::Event event;
55  assert(getNextEvent(event));
56 
57  return event;
58 }
bool getNextEvent(conversation::Event &msg)

Friends And Related Function Documentation

friend class ConversationObservable
friend

Definition at line 97 of file conversation.h.


The documentation for this class was generated from the following files: