Line data Source code
1 : /* 2 : * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef _ROOT_REST_SERVER_H_ 7 : #define _ROOT_REST_SERVER_H_ 8 : 9 : #include "base/regex.h" 10 : #include "http/http_request.h" 11 : #include "http/http_session.h" 12 : #include "http/client/http_client.h" 13 : 14 : class Agent; 15 : 16 : class RestServer { 17 : public: 18 : explicit RestServer(Agent *agent); 19 : virtual ~RestServer(); 20 : 21 : void InitDone(); 22 : void HandleRequest(HttpSession* session, const HttpRequest* request); 23 : void Shutdown(); 24 : 25 : protected: 26 : // REST handlers 27 : struct RESTData { 28 : const boost::smatch* match; 29 : enum http_method method; 30 : HttpSession* session; 31 : const HttpRequest* request; 32 : }; 33 : 34 : class HandlerSpecifier { 35 : public: 36 : typedef void (RestServer::*HandlerFunc)(const struct RESTData&); 37 : 38 26 : HandlerSpecifier(const contrail::regex &request_regex, 39 : enum http_method method, 40 : HandlerFunc handler_func) 41 26 : : request_regex(request_regex), 42 26 : method(method), 43 26 : handler_func(handler_func) {} 44 : 45 : contrail::regex request_regex; 46 : enum http_method method; 47 : HandlerFunc handler_func; 48 : }; 49 : 50 : static const std::vector<HandlerSpecifier> RESTHandlers_; 51 : 52 : void VmPortDeleteHandler(const struct RESTData&); 53 : void VmPortGetHandler(const struct RESTData&); 54 : void VmPortPostHandler(const struct RESTData&); 55 : void VmPortSyncHandler(const struct RESTData& data); 56 : void GatewayPostHandler(const struct RESTData& data); 57 : void GatewayDeleteHandler(const struct RESTData& data); 58 : void VmPortEnableHandler(const struct RESTData& data); 59 : void VmPortDisableHandler(const struct RESTData& data); 60 : 61 : // Handler for VM+VN based messages 62 : void VmVnPortPostHandler(const struct RESTData&); 63 : void VmVnPortGetHandler(const struct RESTData&); 64 : void VmVnPortDeleteHandler(const struct RESTData&); 65 : void VmVnPortCfgGetHandler(const struct RESTData& data); 66 : 67 : private: 68 : friend class RestServerGetVmCfgTask; 69 : 70 : Agent *agent_; 71 : HttpServer *http_server_; 72 : DISALLOW_COPY_AND_ASSIGN(RestServer); 73 : }; 74 : 75 : #endif // _ROOT_REST_SERVER_H_