diff --git a/src/gui/server/Makefile.am b/src/gui/server/Makefile.am index afaa0ee7ec862069a51851d92300e9842bf82ed4..f6cb36eb81e1dd5ee44ca624eb83ab593afb7ba2 100644 --- a/src/gui/server/Makefile.am +++ b/src/gui/server/Makefile.am @@ -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 = diff --git a/src/gui/server/guiserver.cpp b/src/gui/server/guiserver.cpp index 4f40407a8df3cb6f88efcdc4f73b03cdd5019f66..0625deac2af2c31efb9d05c7e37ea31d8a48e0c1 100644 --- a/src/gui/server/guiserver.cpp +++ b/src/gui/server/guiserver.cpp @@ -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; diff --git a/src/gui/server/guiserver.h b/src/gui/server/guiserver.h index a7fce55913480ece0e186be916ebfc7366e55082..0917fb8e0eb27668dfc18d7ccbb4112192e801be 100644 --- a/src/gui/server/guiserver.h +++ b/src/gui/server/guiserver.h @@ -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__