MurataTypeYD_RPC_Sample fixed version for 050314
Dependencies: PowerControl SNICInterface_mod2 mbed-rtos mbed
Fork of HTTPClient_WiFi_HelloWorld by
HTTPServer.h@6:6c49fdc29825, 2015-03-12 (annotated)
- Committer:
- komoritan
- Date:
- Thu Mar 12 12:27:31 2015 +0000
- Revision:
- 6:6c49fdc29825
Fixed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
komoritan | 6:6c49fdc29825 | 1 | #ifndef HTTP_SERVER |
komoritan | 6:6c49fdc29825 | 2 | #define HTTP_SERVER |
komoritan | 6:6c49fdc29825 | 3 | |
komoritan | 6:6c49fdc29825 | 4 | #include <map> |
komoritan | 6:6c49fdc29825 | 5 | #include "mbed.h" |
komoritan | 6:6c49fdc29825 | 6 | #include "SNIC_WifiInterface.h" |
komoritan | 6:6c49fdc29825 | 7 | #include "TCPSocketServer.h" |
komoritan | 6:6c49fdc29825 | 8 | #include "TCPSocketConnection.h" |
komoritan | 6:6c49fdc29825 | 9 | #include "RequestHandler.h" |
komoritan | 6:6c49fdc29825 | 10 | #include "RPCObject.h" |
komoritan | 6:6c49fdc29825 | 11 | |
komoritan | 6:6c49fdc29825 | 12 | #define HTTP_REPLY_MAX_STRING 1024 |
komoritan | 6:6c49fdc29825 | 13 | |
komoritan | 6:6c49fdc29825 | 14 | enum |
komoritan | 6:6c49fdc29825 | 15 | { |
komoritan | 6:6c49fdc29825 | 16 | HTTP_200_OK = 200, |
komoritan | 6:6c49fdc29825 | 17 | HTTP_400_BADREQUEST = 400, |
komoritan | 6:6c49fdc29825 | 18 | HTTP_404_NOTFOUND = 404 |
komoritan | 6:6c49fdc29825 | 19 | }; |
komoritan | 6:6c49fdc29825 | 20 | |
komoritan | 6:6c49fdc29825 | 21 | |
komoritan | 6:6c49fdc29825 | 22 | class HTTPServer |
komoritan | 6:6c49fdc29825 | 23 | { |
komoritan | 6:6c49fdc29825 | 24 | public : |
komoritan | 6:6c49fdc29825 | 25 | HTTPServer(); |
komoritan | 6:6c49fdc29825 | 26 | virtual ~HTTPServer(); |
komoritan | 6:6c49fdc29825 | 27 | bool init(int port); |
komoritan | 6:6c49fdc29825 | 28 | void run(); |
komoritan | 6:6c49fdc29825 | 29 | void add_request_handler(char *name, RequestHandler* handler); |
komoritan | 6:6c49fdc29825 | 30 | |
komoritan | 6:6c49fdc29825 | 31 | private : |
komoritan | 6:6c49fdc29825 | 32 | void handle_request(char* buffer); |
komoritan | 6:6c49fdc29825 | 33 | void create_response(char* buffer); |
komoritan | 6:6c49fdc29825 | 34 | TCPSocketServer socketserver; |
komoritan | 6:6c49fdc29825 | 35 | std::map<char*, RequestHandler*, bool(*)(char*, char*)> handlers; |
komoritan | 6:6c49fdc29825 | 36 | RPCObject object; |
komoritan | 6:6c49fdc29825 | 37 | char reply[HTTP_REPLY_MAX_STRING]; |
komoritan | 6:6c49fdc29825 | 38 | int response_code; |
komoritan | 6:6c49fdc29825 | 39 | }; |
komoritan | 6:6c49fdc29825 | 40 | |
komoritan | 6:6c49fdc29825 | 41 | #endif |
komoritan | 6:6c49fdc29825 | 42 |