![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Revision 2016.05.03
Dependencies: MbedJSONValue1 WIZnetInterface mbed
Fork of WIZwiki-REST_mc by
HTTPServer.h@2:ca36ecca24c2, 2016-05-03 (annotated)
- Committer:
- joon874
- Date:
- Tue May 03 02:15:59 2016 +0000
- Revision:
- 2:ca36ecca24c2
- Parent:
- 1:728e5b5c8dae
Revision 2016.05.03
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joon874 | 0:5886f525a4ad | 1 | #ifndef HTTP_SERVER |
joon874 | 0:5886f525a4ad | 2 | #define HTTP_SERVER |
joon874 | 0:5886f525a4ad | 3 | |
joon874 | 0:5886f525a4ad | 4 | #include <map> |
joon874 | 0:5886f525a4ad | 5 | |
joon874 | 0:5886f525a4ad | 6 | #include "mbed.h" |
joon874 | 0:5886f525a4ad | 7 | #include <string> |
joon874 | 0:5886f525a4ad | 8 | #include "RequestHandler.h" |
joon874 | 0:5886f525a4ad | 9 | #include "EthernetInterface.h" |
joon874 | 0:5886f525a4ad | 10 | |
joon874 | 2:ca36ecca24c2 | 11 | //#define DEBUG_HTTP |
joon874 | 2:ca36ecca24c2 | 12 | |
joon874 | 0:5886f525a4ad | 13 | typedef enum _HTTP_RESULT |
joon874 | 0:5886f525a4ad | 14 | { |
joon874 | 0:5886f525a4ad | 15 | HTTP_INVALID_URI = -3, |
joon874 | 0:5886f525a4ad | 16 | HTTP_INVALID_DATA = -2, |
joon874 | 0:5886f525a4ad | 17 | HTTP_INVALID_HANDLE = -1, |
joon874 | 0:5886f525a4ad | 18 | HTTP_SUCCESS = 1 |
joon874 | 0:5886f525a4ad | 19 | }HTTP_RESULT; |
joon874 | 0:5886f525a4ad | 20 | |
joon874 | 0:5886f525a4ad | 21 | |
MidnightCow | 1:728e5b5c8dae | 22 | static char HTTPBUF[512] ={0,}; |
MidnightCow | 1:728e5b5c8dae | 23 | static char rest_result[512] = {0,}; |
joon874 | 0:5886f525a4ad | 24 | |
joon874 | 0:5886f525a4ad | 25 | class HTTPServer |
joon874 | 0:5886f525a4ad | 26 | { |
joon874 | 0:5886f525a4ad | 27 | public : |
joon874 | 0:5886f525a4ad | 28 | |
joon874 | 0:5886f525a4ad | 29 | HTTPServer(); |
joon874 | 0:5886f525a4ad | 30 | virtual ~HTTPServer(); |
joon874 | 0:5886f525a4ad | 31 | |
joon874 | 0:5886f525a4ad | 32 | bool init(int port); |
joon874 | 0:5886f525a4ad | 33 | |
joon874 | 0:5886f525a4ad | 34 | void run(); |
joon874 | 0:5886f525a4ad | 35 | |
joon874 | 0:5886f525a4ad | 36 | void add_request_handler(char *name, RequestHandler* handler); |
joon874 | 0:5886f525a4ad | 37 | |
joon874 | 0:5886f525a4ad | 38 | private : |
joon874 | 0:5886f525a4ad | 39 | |
joon874 | 0:5886f525a4ad | 40 | HTTP_RESULT handle_request(char *buffer); |
joon874 | 0:5886f525a4ad | 41 | |
joon874 | 0:5886f525a4ad | 42 | TCPSocketServer socket; |
joon874 | 0:5886f525a4ad | 43 | std::map<char*, RequestHandler*, bool(*)(char*, char*)> handlers; |
joon874 | 0:5886f525a4ad | 44 | //char rest_result[2048]; |
joon874 | 0:5886f525a4ad | 45 | |
joon874 | 0:5886f525a4ad | 46 | }; |
joon874 | 0:5886f525a4ad | 47 | |
joon874 | 0:5886f525a4ad | 48 | #endif |
joon874 | 0:5886f525a4ad | 49 |