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