2 #include <base-logging/Logging.hpp> 10 LOG_DEBUG(
"Creating conversation monitor for agent: '%s'",
self.getName().c_str());
11 if(!protocolDirectory.empty())
13 LOG_DEBUG(
"Setting protocol resource directory: '%s'",protocolDirectory.c_str());
23 boost::unique_lock<boost::mutex> lock(mMutex);
24 std::map<std::string, ConversationPtr>::iterator it;
26 it = mActiveConversations.find(conversationId);
28 if(it != mActiveConversations.end())
30 bool conversationEnded =
false;
32 conversationEnded = it->second->hasEnded();
33 }
catch(
const std::runtime_error& e)
38 std::string errorMsg =
"Trying to update already completed conversation: " + conversationId +
" performative: '" + msg.
getPerformative() +
"' content: '" + msg.
getContent() +
"'";
41 LOG_INFO(
"Update existing conversation '%p' with conversation id '%s'",
this, it->second->getConversationId().c_str());
42 it->second->update(msg);
47 throw conversation::InvalidOperation(
"Can only update an existing conversation. Possibly the corresponding conversation did already end and this message does not conform to the respective protocol");
52 boost::unique_lock<boost::mutex> lock(mMutex);
53 bool success = mActiveConversations.erase(conversationId);
59 boost::unique_lock<boost::mutex> lock(mMutex);
62 mActiveConversations.insert(std::pair<std::string, ConversationPtr>(conversation->getConversationId(), conversation));
69 boost::unique_lock<boost::mutex> lock(mMutex);
70 std::map<fipa::acl::ConversationID, ConversationPtr>::iterator it = mActiveConversations.find(conversationId);
71 if(it != mActiveConversations.end())
81 boost::unique_lock<boost::mutex> lock(mMutex);
82 std::map<fipa::acl::ConversationID, ConversationPtr>::iterator it = mActiveConversations.find(conversationId);
83 if(it != mActiveConversations.end())
88 mActiveConversations.insert(std::pair<fipa::acl::ConversationID, ConversationPtr>(conversationId, conversation));
89 LOG_INFO(
"Create new conversation '%p' with conversation id '%s'",
this, conversationId.c_str());
95 LOG_DEBUG_S <<
"Cleaning up conversation monitor.";
96 boost::unique_lock<boost::mutex> lock(mMutex);
98 std::map<fipa::acl::ConversationID, ConversationPtr>::iterator it = mActiveConversations.begin();
99 std::vector<fipa::acl::ConversationID> endedConversations;
100 std::vector<fipa::acl::ConversationID>::iterator eit;
104 for(; it != mActiveConversations.end(); ++it)
106 LOG_DEBUG_S <<
"Cleaning up conversation monitor: Processing conversation " << it->first;
109 if(conversation->hasEnded())
111 LOG_DEBUG_S <<
"Detaching observers from ended conversation " << it->first;
112 conversation->detachObservers();
113 endedConversations.push_back(it->first);
117 LOG_DEBUG_S <<
"Erasing ended conversations from active conversations.";
118 for( eit = endedConversations.begin(); eit != endedConversations.end(); ++eit)
120 LOG_DEBUG_S <<
"Erasing ended conversation " << *eit <<
" from active conversations.";
121 mActiveConversations.erase(*eit);
127 boost::unique_lock<boost::mutex> lock(mMutex);
128 std::map<fipa::acl::ConversationID, ConversationPtr>::iterator it = mActiveConversations.begin();
129 std::vector<fipa::acl::ConversationID> activeConversations;
131 for(; it != mActiveConversations.end(); it++)
133 activeConversations.push_back(it->first);
136 return activeConversations;
std::string ConversationID
std::string getConversationID() const
static fipa::acl::ConversationID generateConversationID(const std::string &topic="")
ConversationPtr getConversation(const fipa::acl::ConversationID &conversationId)
boost::shared_ptr< Conversation > ConversationPtr
bool removeConversation(const fipa::acl::ConversationID &conversationId)
ConversationMonitor(const AgentID &self, const std::string &protocolDirectory="")
ConversationPtr getOrCreateConversation(const fipa::acl::ConversationID &conversationId)
std::string getContent() const
std::vector< fipa::acl::ConversationID > getActiveConversations()
const std::string & getName() const
setter and getter methods for all fields; they do not result in deep-copies assignments/retreivals, but this can be easily changed if needed through the overloaded operator which do
static void setProtocolResourceDir(const std::string &resourceDir)
std::string getPerformative() const
ConversationPtr updateConversation(const fipa::acl::ACLMessage &msg)
This class provides a representation of a message conforming to the FIPA specification SC00061...
ConversationPtr startConversation(const std::string &topic)
Implements the general AgentID functionality, which is present throughout the fipa specifications(FIP...
Foundation of Physical Intelligent Agents.
virtual ~ConversationMonitor()