Program the control the fischertechnik robo interface or intelligent interface via tcp socket or via a java gui.
Diff: ftserver.h
- Revision:
- 0:7f26f0680202
- Child:
- 1:2c9d412ad471
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ftserver.h Fri Dec 31 14:01:14 2010 +0000 @@ -0,0 +1,66 @@ +#ifndef FTSERVER_H +#define FTSERVER_H +#include <list> +using namespace std; +/* +class queue{ +TCPSocket *sock; +static queue *head, *tail; +queue *next; +public: +queue(TCPSocket *s): sock(s) {} +}; +*/ +void handleMessage(char[7]); +class connection; + +class ftServer { + list<connection*> queue; + TCPSocket listeningSock; + TCPSocketErr err; + char msg[7]; + char *text; + char textlen, index; + bool isMsg; +protected: + void onTCPEvent(TCPSocketEvent ev); + char* render(); +public: + ftServer(IpAddr host, unsigned short port); + bool startServer(); +// void pollServer(); + void errorMsg(); + bool readStream(TCPSocket *pConnectedSock); + bool writeStream(char *); + bool writeStream(SMESSAGE*); + void remove(connection* c); + void handleMessage() { + ::handleMessage(msg); //change this to a function pointer + } + int clients() { return queue.size();} +}; + +class connection { + TCPSocket * pConnectedSock; + Host client; + ftServer *server; + void onConnectedTCPSocketEvent(TCPSocketEvent ev); +public: + connection(ftServer *svr, Host h, TCPSocket *s): server(svr), client(h), pConnectedSock(s) { + pConnectedSock->setOnEvent(this, &connection::onConnectedTCPSocketEvent); //Setup the new socket events + char str[80]; + sprintf(str, "Message from Server: Connection OK. Client nr %d", server->clients()); + writeStream(str); + //should also send the present state of the inputs, ne clean way to access the ft-interface + } + ~connection() { + pConnectedSock->close();//close and destroy the socket created by 'accept' + } + bool writeStream(char *); + bool writeStream(SMESSAGE*); + const TCPSocket* socket() const { + return pConnectedSock; + } +}; + +#endif \ No newline at end of file