Program the control the fischertechnik robo interface or intelligent interface via tcp socket or via a java gui.

Dependencies:   mbed ConfigFile

Committer:
networker
Date:
Fri Dec 31 14:01:14 2010 +0000
Revision:
0:7f26f0680202
initial release: comprises ftlib (no usb), ft-over-ip socket server, and the http server (the html page and java jar I still have to publish somewhere)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
networker 0:7f26f0680202 1
networker 0:7f26f0680202 2 /*
networker 0:7f26f0680202 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
networker 0:7f26f0680202 4
networker 0:7f26f0680202 5 Permission is hereby granted, free of charge, to any person obtaining a copy
networker 0:7f26f0680202 6 of this software and associated documentation files (the "Software"), to deal
networker 0:7f26f0680202 7 in the Software without restriction, including without limitation the rights
networker 0:7f26f0680202 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
networker 0:7f26f0680202 9 copies of the Software, and to permit persons to whom the Software is
networker 0:7f26f0680202 10 furnished to do so, subject to the following conditions:
networker 0:7f26f0680202 11
networker 0:7f26f0680202 12 The above copyright notice and this permission notice shall be included in
networker 0:7f26f0680202 13 all copies or substantial portions of the Software.
networker 0:7f26f0680202 14
networker 0:7f26f0680202 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
networker 0:7f26f0680202 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
networker 0:7f26f0680202 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
networker 0:7f26f0680202 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
networker 0:7f26f0680202 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
networker 0:7f26f0680202 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
networker 0:7f26f0680202 21 THE SOFTWARE.
networker 0:7f26f0680202 22 */
networker 0:7f26f0680202 23
networker 0:7f26f0680202 24 /** \file
networker 0:7f26f0680202 25 HTTP Server header file
networker 0:7f26f0680202 26 */
networker 0:7f26f0680202 27
networker 0:7f26f0680202 28 #ifndef HTTP_SERVER_H
networker 0:7f26f0680202 29 #define HTTP_SERVER_H
networker 0:7f26f0680202 30
networker 0:7f26f0680202 31 class HTTPRequestHandler;
networker 0:7f26f0680202 32 class HTTPRequestDispatcher;
networker 0:7f26f0680202 33
networker 0:7f26f0680202 34 #include "core/net.h"
networker 0:7f26f0680202 35 #include "HTTPRequestHandler.h"
networker 0:7f26f0680202 36 #include "HTTPRequestDispatcher.h"
networker 0:7f26f0680202 37
networker 0:7f26f0680202 38 #include <string>
networker 0:7f26f0680202 39 using std::string;
networker 0:7f26f0680202 40
networker 0:7f26f0680202 41 #include <map>
networker 0:7f26f0680202 42 using std::map;
networker 0:7f26f0680202 43
networker 0:7f26f0680202 44 ///A simple HTTP server implementation
networker 0:7f26f0680202 45 /**
networker 0:7f26f0680202 46 The HTTPServer is composed of:
networker 0:7f26f0680202 47 - The actual server (HTTPServer)
networker 0:7f26f0680202 48 - A request dispatcher, instanciated on each request (HTTPRequestDispatcher)
networker 0:7f26f0680202 49 - Request handlers instanciated by the dispatcher(deriving from HTTPRequestHandler)
networker 0:7f26f0680202 50 */
networker 0:7f26f0680202 51 class HTTPServer
networker 0:7f26f0680202 52 {
networker 0:7f26f0680202 53 public:
networker 0:7f26f0680202 54 ///Instantiates the HTTP Server
networker 0:7f26f0680202 55 HTTPServer();
networker 0:7f26f0680202 56 ~HTTPServer();
networker 0:7f26f0680202 57
networker 0:7f26f0680202 58 struct handlersComp //Used to order handlers in the right way
networker 0:7f26f0680202 59 {
networker 0:7f26f0680202 60 bool operator() (const string& handler1, const string& handler2) const
networker 0:7f26f0680202 61 {
networker 0:7f26f0680202 62 //The first handler is longer than the second one
networker 0:7f26f0680202 63 if (handler1.length() > handler2.length())
networker 0:7f26f0680202 64 return true; //Returns true if handler1 is to appear before handler2
networker 0:7f26f0680202 65 else if (handler1.length() < handler2.length())
networker 0:7f26f0680202 66 return false;
networker 0:7f26f0680202 67 else //To avoid the == case, sort now by address
networker 0:7f26f0680202 68 return ((&handler1)>(&handler2));
networker 0:7f26f0680202 69 }
networker 0:7f26f0680202 70 };
networker 0:7f26f0680202 71
networker 0:7f26f0680202 72 ///Adds a handler
networker 0:7f26f0680202 73 /**
networker 0:7f26f0680202 74 Appends a handler to the handlers list
networker 0:7f26f0680202 75 @param T : class which will be instanciated to serve these requests
networker 0:7f26f0680202 76 @param path : requests starting with this path will be served using this handler
networker 0:7f26f0680202 77 */
networker 0:7f26f0680202 78 template<typename T>
networker 0:7f26f0680202 79 void addHandler(const char* path) //Template decl in header
networker 0:7f26f0680202 80 { m_lpHandlers[path] = &T::inst; }
networker 0:7f26f0680202 81
networker 0:7f26f0680202 82 ///Starts listening
networker 0:7f26f0680202 83 /**
networker 0:7f26f0680202 84 Binds server to a specific port and starts listening
networker 0:7f26f0680202 85 @param port : port on which to listen for incoming connections
networker 0:7f26f0680202 86 */
networker 0:7f26f0680202 87 void bind(int port = 80);
networker 0:7f26f0680202 88
networker 0:7f26f0680202 89 private:
networker 0:7f26f0680202 90 friend class HTTPRequestDispatcher;
networker 0:7f26f0680202 91
networker 0:7f26f0680202 92 void onTCPSocketEvent(TCPSocketEvent e);
networker 0:7f26f0680202 93
networker 0:7f26f0680202 94 TCPSocket* m_pTCPSocket;
networker 0:7f26f0680202 95 map< string, HTTPRequestHandler*(*)(const char*, const char*, TCPSocket*), handlersComp > m_lpHandlers;
networker 0:7f26f0680202 96
networker 0:7f26f0680202 97 };
networker 0:7f26f0680202 98
networker 0:7f26f0680202 99 //Including handlers here for more convenience
networker 0:7f26f0680202 100 #include "impl/RPCHandler.h"
networker 0:7f26f0680202 101 #include "impl/FSHandler.h"
networker 0:7f26f0680202 102 #include "impl/SimpleHandler.h"
networker 0:7f26f0680202 103
networker 0:7f26f0680202 104 #endif