-
Notifications
You must be signed in to change notification settings - Fork 390
/
rest_server.h
64 lines (51 loc) · 1.64 KB
/
rest_server.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/
#ifndef _ROOT_REST_SERVER_H_
#define _ROOT_REST_SERVER_H_
#include <boost/regex.hpp>
class HttpServer;
class HttpSession;
class HttpRequest;
class Agent;
class RESTServer {
public:
explicit RESTServer(Agent *agent);
virtual ~RESTServer();
void InitDone();
void HandleRequest(HttpSession* session, const HttpRequest* request);
void Shutdown();
protected:
// REST handlers
struct RESTData {
const boost::smatch* match;
enum http_method method;
HttpSession* session;
const HttpRequest* request;
};
class HandlerSpecifier {
public:
typedef void (RESTServer::*HandlerFunc)(const struct RESTData&);
HandlerSpecifier(const boost::regex& request_regex,
enum http_method method,
HandlerFunc handler_func)
: request_regex(request_regex),
method(method),
handler_func(handler_func) {}
boost::regex request_regex;
enum http_method method;
HandlerFunc handler_func;
};
static const std::vector<HandlerSpecifier> RESTHandlers_;
void VmPortDeleteHandler(const struct RESTData&);
void VmPortGetHandler(const struct RESTData&);
void VmPortPostHandler(const struct RESTData&);
void VmPortSyncHandler(const struct RESTData& data);
void GatewayPostHandler(const struct RESTData& data);
void GatewayDeleteHandler(const struct RESTData& data);
private:
Agent *agent_;
HttpServer *http_server_;
DISALLOW_COPY_AND_ASSIGN(RESTServer);
};
#endif // _ROOT_REST_SERVER_H_