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