00001 #pragma once
00002 #include "ippdme/ippdme.h"
00003 #include "ippdme/Server/ippEngine.h"
00004
00005
00006 class IPPDME_EXT_CLASS ippSpyServer;
00007 class IPPDME_EXT_CLASS ippSpyClient;
00008 class IPPDME_EXT_CLASS ippClientServerSpy;
00009
00010 class IPPDME_EXT_CLASS ippSpyServer : public ippEngine
00011 {
00012 public:
00013 enum STATE
00014 {
00015 uninitialized,
00016 listening,
00017 connected,
00018 };
00019 ippSpyServer();
00020 virtual ~ippSpyServer();
00021 bool PowerOn(int portNumber);
00022 bool PowerOff();
00023 virtual void HeartBeat();
00024 void WriteToSocket(const char* line);
00025 void setParent(ippClientServerSpy*);
00026
00027 STATE getStatus() const { return _state; }
00028 protected:
00029 virtual void ProcessLine(const char* inputline);
00030 virtual void ProcessMisformedLine(const char* inputline);
00031 void PerformListening();
00032 void OnClientConnected();
00033 void OnClientDisconnected();
00034 virtual void OnConnectionLost();
00035 private:
00036 STATE _state;
00037 ippSocket _listenSocket;
00038 int _portNumber;
00039 ippClientServerSpy* _parent;
00040 ippSpyServer(const ippSpyServer&);
00041 void operator=(const ippSpyServer&);
00042 };
00043
00044 class IPPDME_EXT_CLASS ippSpyClient : public ippEngine
00045 {
00046 public:
00047 enum STATE{
00048 disconnected,
00049 trying_to_connect,
00050 connected,
00051 };
00052 ippSpyClient();
00053 virtual ~ippSpyClient();
00054
00055 void setParent(ippClientServerSpy* parent);
00056
00057 void Connect(
00058 const char* hostname,
00059 int port
00060 );
00061
00062 void Disconnect();
00063 void SendCommand(const char* command);
00064 STATE getStatus() const { return _state; }
00065
00066 virtual void HeartBeat();
00067 protected:
00068 virtual void ProcessLine(const char* inputline);
00069 virtual void ProcessMisformedLine(const char* inputline);
00070
00071 private:
00072 STATE _state;
00073 ippClientServerSpy* _parent;
00074
00075 ippSpyClient(const ippSpyClient&);
00076 void operator=(const ippSpyClient&);
00077
00078 };
00079
00080
00081
00082 class IPPDME_EXT_CLASS ippClientServerSpy
00083 {
00084 public:
00085 enum STATE {
00086 disconnected,
00087 trying_to_connect_to_remote_server,
00088 listening,
00089 connected,
00090 };
00091 ippClientServerSpy();
00092 virtual ~ippClientServerSpy();
00093
00094 bool Start(int listening_port,const char* server_ip, int server_port);
00095
00096 void HeartBeat();
00097 void Stop();
00098
00099 virtual void SendCommandLine(const char* inputline,bool bwellFormed);
00100 virtual void SendResponseLine(const char* inputline,bool bwellFormed);
00101 virtual void OnStatusChanged(STATE) {}
00102 ippLogger* GetLogger() const;
00103 void setLogger(ippLogger* logger);
00104
00105 STATE getStatus() const;
00106
00107 private:
00108 ippSpyServer _server;
00109 ippSpyClient _client;
00110 ippSpyClient::STATE _oldClientState;
00111 ippSpyServer::STATE _oldServerState;
00112 STATE _state;
00113 int _listening_port;
00114 ippLogger* _logger;
00115
00116 ippClientServerSpy(const ippClientServerSpy&);
00117 void operator=(const ippClientServerSpy&);
00118 ippSpyClient::STATE getClientStatus() const;
00119 ippSpyServer::STATE getServerStatus() const;
00120
00121 };