Skip to content
Snippets Groups Projects
Commit 7055c0d1 authored by yanmorin's avatar yanmorin
Browse files

New GuiServer.cpp than handle request
Don't compile yet...
parent ff6ef65f
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,7 @@ noinst_LTLIBRARIES = libsflphoneguiserver.la
libsflphoneguiserver_la_SOURCES = \
$(BUILT_SOURCES) \
guiserver.cpp \
lex.yy.cc \
protocol.tab.cc
guiserver.cpp
libsflphoneguiserver_la_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\"
libsflphoneguiserver_la_LIBADD =
......
......@@ -20,9 +20,6 @@
#include "guiserver.h"
#include <string>
#include <iostream>
#include "protocol.tab.h" // need by TCPStreamLexer.h but can't put in it
#include "TCPStreamLexer.h"
// default constructor
GUIServer::GUIServer()
......@@ -41,12 +38,12 @@ GUIServer::exec() {
//Creating a listening socket.
ost::TCPSocket aServer(addr, 3999);
RequestFactory factory;
Request *request;
std::cout << "listening on " << aServer.getLocal() << ":" << 3999 << std::endl;
int callid;
std::string status;
std::string output;
while (std::cin.good()) {
// waiting for a new connection
......@@ -54,22 +51,26 @@ GUIServer::exec() {
//I'm accepting an incomming connection
aServerStream = new TCPStreamLexer(aServer, this);
aServerStream = new ost::TCPStream(aServer);
// wait for the first message
std::cout << "accepting connection..." << std::endl;
std::string output;
*aServerStream << "Welcome to this serveur2" << std::endl;
output = "";
while(aServerStream->good() && output!="quit") {
// lire
//std::getline(*aServerStream, output);
std::getline(*aServerStream, output);
//_eventList.push_back(Event(output));
// analyser
//std::cout << output << ":" << output.length() << std::endl;
std::cout << output << ":" << output.length() << std::endl;
request = factory.createNewRequest(output);
request->execute();
delete request;
aServerStream->parse();
//aServerStream->parse();
/*
if ( output.find("call ") == 0 ) {
......@@ -91,7 +92,7 @@ GUIServer::exec() {
}
*/
// repondre
//*aServerStream << output.length() << std::endl;
*aServerStream << output.length() << std::endl;
}
delete aServerStream;
......
......@@ -23,22 +23,61 @@
#include <string>
#include <list>
#include <cc++/socket.h>
#include <map>
class Event {
class Request
{
public:
Event();
Event(const std::string &event) {
_message = event;
Request(const std::string &cseq) {
_cseq = cseq;
}
virtual ~Request(){}
virtual std::string execute();
std::string error(const std::string &code, const std::string &error) {
std::string returnError = code + " " + _cseq + " " + error;
return returnError;
}
~Event() {}
private:
std::string _cseq;
std::string _callid;
std::string _message;
};
typedef std::list<Event> EventList;
class TCPStreamLexer;
class RequestCall : public Request
{
public:
RequestCall(const std::string &cseq) : Request(cseq) {}
~RequestCall() {}
std::string execute() { return ""; }
};
class RequestSyntaxError : public Request
{
public:
RequestSyntaxError(const std::string &cseq = "seq0") : Request(cseq) {}
~RequestSyntaxError() {}
std::string execute() {
return error("501", "Syntax Error");
}
};
class RequestFactory
{
public:
RequestFactory(){
}
~RequestFactory(){
}
Request* createNewRequest(const std::string &requestLine)
{
int spacePos = requestLine.find(' ');
// we find a spacePos
if ( spacePos != -1 ) {
return new RequestSyntaxError();
}
}
};
class GUIServer : public GuiFramework {
public:
// GUIServer constructor
......@@ -49,7 +88,6 @@ public:
// exec loop
int exec(void);
// Reimplementation of virtual functions
virtual int incomingCall (short id);
virtual void peerAnsweredCall (short id);
......@@ -68,8 +106,8 @@ public:
virtual void stopVoiceMessageNotification (void);
private:
EventList _eventList;
TCPStreamLexer *aServerStream;
ost::TCPStream* aServerStream;
std::map<std::string, Request*> _requestMap;
};
#endif // __GUI_SERVER_H__
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