各ピンへのread/writeを提供するサーバサンプル

Dependencies:   NySNICInterface mbed-rtos mbed

Fork of RESTServerSample2 by KDDI Fx0 hackathon

Committer:
komoritan
Date:
Thu Mar 12 12:40:48 2015 +0000
Revision:
1:e5d3bd4af9da
Parent:
0:998e2e00df0c
Bug fix - handle_request

Who changed what in which revision?

UserRevisionLine numberNew 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"
komoritan 0:998e2e00df0c 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;
komoritan 0:998e2e00df0c 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