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

*** empty log message ***

parent 08d7036a
No related branches found
No related tags found
Loading
......@@ -21,6 +21,7 @@
#ifndef SFLPHONEGUI_OBJECTPOOL_H
#define SFLPHONEGUI_OBJECTPOOL_H
#include <list>
#include <string>
#include <qmutex.h>
#include <qwaitcondition.h>
......
......@@ -35,6 +35,10 @@ void
Request::onError(const std::string &, const std::string &)
{}
void
Request::onEntry(const std::string &, const std::string &)
{}
void
Request::onSuccess(const std::string &, const std::string &)
{}
......@@ -71,7 +75,20 @@ CallRequest::onError(const std::string &code, const std::string &message)
}
void
CallRequest::onError(Call , const std::string &, const std::string &)
CallRequest::onError(Call, const std::string &, const std::string &)
{}
void
CallRequest::onEntry(const std::string &code, const std::string &message)
{
onEntry(Call(Requester::instance().getSessionIdFromSequenceId(getSequenceId()),
mCallId),
code,
message);
}
void
CallRequest::onEntry(Call, const std::string &, const std::string &)
{}
void
......
......@@ -80,7 +80,6 @@ class Request
private:
const std::string mSequenceId;
const std::string mSessionId;
const std::string mCommand;
const std::list< std::string > mArgs;
};
......@@ -129,6 +128,15 @@ class CallRequest : public Request
virtual void onError(const std::string &code,
const std::string &message);
/**
* This function will be called when the request
* receive its answer, if the there's other answer to
* come. This function will call the onEntry, but with
* the call linked to this request.
*/
virtual void onEntry(const std::string &code,
const std::string &message);
/**
* This function will be called when the request
* receive its answer, if the request successfully
......
......@@ -19,6 +19,7 @@
*/
#include <stdexcept>
#include <sstream>
#include "requesterimpl.h"
#include "sessionio.h"
......@@ -53,7 +54,7 @@ RequesterImpl::send(const std::string &sessionId,
Request *request = mRequestFactory.create(command, sequenceId, args);
registerRequest(sessionId, sequenceId, request);
s->send(request.toString());
session->send(request->toString());
return sequenceId;
}
......@@ -84,33 +85,34 @@ RequesterImpl::registerSession(const std::string &id,
s->start();
}
int
RequesterImpl::getCodeCategory(const std::string &code)
{
int c;
std::istringstream s(code);
s >> c;
return c / 100;
}
void
RequesterImpl::receiveAnswer(const std::string &answer)
{
std::string code;
std::string seq;
std::string message;
std::istream s(answer);
std::istringstream 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);
int c = getCodeCategory(code);
std::map< std::string, Request * >::iterator pos;
pos = mRequests.find(sequence);
......@@ -121,17 +123,17 @@ RequesterImpl::receiveAnswer(const std::string &code,
if(c <= 1) {
//Other answers will come for this request.
(*pos)->onEntry(code, message);
pos->second->onEntry(code, message);
}
else{
//This is the final answer of this request.
if(c == 2) {
(*pos)->onSuccess(code, message);
pos->second->onSuccess(code, message);
}
else {
(*pos)->onError(code, message);
pos->second->onError(code, message);
}
delete(*pos);
delete pos->second;
mRequests.erase(pos);
}
}
......@@ -139,7 +141,7 @@ RequesterImpl::receiveAnswer(const std::string &code,
std::string
RequesterImpl::generateCallId()
{
std::ostream id;
std::ostringstream id;
id << "cCallID:" << mCallIdCount;
mCallIdCount++;
return id.str();
......@@ -148,7 +150,7 @@ RequesterImpl::generateCallId()
std::string
RequesterImpl::generateSessionId()
{
std::ostream id;
std::ostringstream id;
id << "cSessionID:" << mSessionIdCount;
mSessionIdCount++;
return id.str();
......@@ -157,7 +159,7 @@ RequesterImpl::generateSessionId()
std::string
RequesterImpl::generateSequenceId()
{
std::ostream id;
std::ostringstream id;
id << "cSequenceID:" << mSequenceIdCount;
mSequenceIdCount++;
return id.str();
......
......@@ -41,6 +41,12 @@ class RequesterImpl
const std::string &command,
const std::list< std::string > &args);
void receiveAnswer(const std::string &answer);
void receiveAnswer(const std::string &code,
const std::string &sequence,
const std::string &message);
static int getCodeCategory(const std::string &code);
/**
......@@ -67,6 +73,11 @@ class RequesterImpl
std::string getSessionIdFromSequenceId(const std::string &sequence)
{return mSequenceToSession[sequence];}
/**
* Register the session.
*/
void registerSession(const std::string &id, SessionIO *io);
private:
/**
......@@ -75,11 +86,6 @@ class RequesterImpl
*/
SessionIO *getSessionIO(const std::string &sessionId);
/**
* Register the session.
*/
void registerSession(const std::string &id, SessionIO *io);
/**
* Register the string to return a Actual type.
*/
......
......@@ -18,6 +18,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "sessionio.h"
InputStreamer::InputStreamer(SessionIO *sessionIO)
: mSessionIO(sessionIO)
{}
......@@ -30,7 +32,6 @@ InputStreamer::run()
}
}
void
OutputStreamer::OutputStreamer(SessionIO *sessionIO)
: mSessionIO(sessionIO)
{}
......@@ -56,13 +57,22 @@ SessionIO::~SessionIO()
stop();
}
bool
SessionIO::isUp()
{
{
QMutexLocker guard(&mMutex);
return mIsUp;
}
}
void
SessionIO::start()
{
stop();
//just protecting the mutex
{
QMutexLock guard(&mMutex);
QMutexLocker guard(&mMutex);
mInputStreamer.start();
mOutputStreamer.start();
mIsUp = true;
......@@ -95,15 +105,15 @@ SessionIO::receive(std::string &answer)
void
SessionIO::send()
{
(*mOutputStream) << mOutputPool.pop();
mOutputPool->sync();
(*mOutput) << mOutputPool.pop();
mOutput->flush();
}
void
SessionIO::receive()
{
std::string s;
std::getline(*mInputStream, s);
std::getline(*mInput, s);
mInputPool.push(s);
}
......
......@@ -27,6 +27,49 @@
#include "objectpool.h"
class SessionIO;
/**
* This class is the thread that will read
* from the SessionIO.
*/
class InputStreamer : public QThread
{
public:
InputStreamer(SessionIO *sessionIO);
~InputStreamer();
/**
* This is the main processing function.
*/
virtual void run();
private:
SessionIO *mSessionIO;
};
/**
* This class is the thread that will write
* to the SessionIO.
*/
class OutputStreamer : public QThread
{
public:
OutputStreamer(SessionIO *sessionIO);
/**
* This is the main processing function
*/
virtual void run();
private:
SessionIO *mSessionIO;
};
/**
* This is the main class that will handle
* the IO.
......@@ -41,7 +84,8 @@ class SessionIO
* Those streams will be the streams read or write to.
*/
SessionIO(std::istream *input, std::ostream *output);
~SessionIO();
/**
* This is the function that will start the threads
* that will handle the streams.
......@@ -69,6 +113,8 @@ class SessionIO
*/
void receive(std::string &answer);
bool isUp();
private:
/**
* This function will send to the stream
......@@ -89,49 +135,14 @@ class SessionIO
ObjectPool< std::string > mInputPool;
ObjectPool< std::string > mOutputPool;
};
/**
* This class is the thread that will read
* from the SessionIO.
*/
class InputStreamer : public QThread
{
public:
InputStreamer(SessionIO *sessionIO);
~InputStreamer();
/**
* This is the main processing function.
*/
virtual void run();
private:
SessionIO *mSessionIO;
std::istream *mInput;
std::ostream *mOutput;
InputStreamer mInputStreamer;
OutputStreamer mOutputStreamer;
};
/**
* This class is the thread that will write
* to the SessionIO.
*/
class OutputStreamer : public QThread
{
public:
OutputStreamer(SessionIO *sessionIO);
/**
* This is the main processing function
*/
virtual void run();
private:
SessionIO *sessionIO;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment