Skip to content
Snippets Groups Projects
Commit e7a1ac34 authored by jpbl's avatar jpbl
Browse files

*** empty log message ***

parent a3133d0a
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <stdexcept> #include <stdexcept>
#include "requesterimpl.h" #include "requesterimpl.h"
#include "sessionio.h"
RequesterImpl::RequesterImpl() RequesterImpl::RequesterImpl()
: mCallIdCount(0) : mCallIdCount(0)
...@@ -45,7 +46,7 @@ RequesterImpl::sendCallCommand(const std::string &sessionId, ...@@ -45,7 +46,7 @@ RequesterImpl::sendCallCommand(const std::string &sessionId,
const std::string &command) const std::string &command)
{ {
// We retreive the internal of a session. // We retreive the internal of a session.
SessionSender *session = getSessionSender(sessionId); SessionIO *session = getSessionIO(sessionId);
// We ask the factory to create the request. // We ask the factory to create the request.
Request *request = mCallRequestFactory.create(command, sequenceId, callId) Request *request = mCallRequestFactory.create(command, sequenceId, callId)
...@@ -58,7 +59,68 @@ RequesterImpl::sendCallCommand(const std::string &sessionId, ...@@ -58,7 +59,68 @@ RequesterImpl::sendCallCommand(const std::string &sessionId,
} }
void void
RequesterImpl::receiveCallCommand RequesterImpl::registerRequest(const std::string &sessionId,
const std::string &sequenceId,
Request *request)
{
if(mRequests.find(sequenceId) != mRequests.end()) {
throw std::logic_error("Registering an already know sequence ID");
}
mRequests.insert(std::make_pair(sequenceId, request));
}
void
RequesterImpl::receiveAnswer(const std::string &answer)
{
std::string code;
std::string seq;
std::string message;
std::istream s(answer);
s >> code >> seq;
getline(s, message);
receiveAnswer(code, seq, message);
}
int
RequesterImpl::getCodeCategory(const std::string &code)
{
int c;
std::istream s(code);
s >> c;
return c / 100;
}
void
RequesterImpl::receiveAnswer(const std::string &code,
const std::string &sequence,
const std::string &message)
{
c = getCodeCategory(code);
std::map< std::string, Request * >::iterator pos;
pos = mRequests.find(sequence);
if(pos == mRequests.end()) {
std::cerr << "We received an answer with an unknown sequence" << std::endl;
return;
}
if(c <= 1) {
//Other answers will come for this request.
(*pos)->onEntry(code, message);
}
else{
//This is the final answer of this request.
if(c == 2) {
(*pos)->onSuccess(code, message);
}
else {
(*pos)->onError(code, message);
}
delete(*pos);
mRequests.erase(pos);
}
}
std::string std::string
RequesterImpl::generateCallId() RequesterImpl::generateCallId()
......
...@@ -41,7 +41,7 @@ class RequesterImpl ...@@ -41,7 +41,7 @@ class RequesterImpl
const std::string &callId, const std::string &callId,
char *command); char *command);
static int getCodeCategory(const std::string &code);
private: private:
/** /**
...@@ -64,9 +64,15 @@ class RequesterImpl ...@@ -64,9 +64,15 @@ class RequesterImpl
*/ */
std::string generateSequenceId(); std::string generateSequenceId();
/**
* Return the SessionIO instance related to
* the session ID.
*/
SessionIO *getSessionIO(const std::string &sessionId);
private: private:
std::map< std::string, SessionIO * > mSessions; std::map< std::string, SessionIO * > mSessions;
std::map< std::string, Request * > mRequests;
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment