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

◆ ConversationObserver()

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

Definition at line 26 of file conversation.cpp.

27 {}

◆ ~ConversationObserver()

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

◆ getConversationIdsOfObservables()

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

Get the conversation ids of observables

Definition at line 74 of file conversation.cpp.

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

◆ getNextEvent()

bool fipa::acl::ConversationObserver::getNextEvent ( conversation::Event &  msg)

Retrieve next event

Definition at line 59 of file conversation.cpp.

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

◆ hasEvents()

bool fipa::acl::ConversationObserver::hasEvents ( ) const

Check if there is a next message

Definition at line 29 of file conversation.cpp.

30 {
31  boost::unique_lock<boost::mutex> lock(mEventsMutex);
32  return !mEvents.empty();
33 }

◆ waitForNextEvent()

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 42 of file conversation.cpp.

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

Friends And Related Function Documentation

◆ ConversationObservable

friend class ConversationObservable
friend

Definition at line 97 of file conversation.h.


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