/
sandesh_http.h
74 lines (60 loc) · 1.8 KB
/
sandesh_http.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
65
66
67
68
69
70
71
72
73
74
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
//
// sandesh_http.h
//
// This class supports feeding Sandesh Requests into a process
// using a HTTP Client (Webbrowser) and getting the response back.
//
// It is the backdoor for getting operational state.
//
#ifndef __SANDESH_HTTP_H__
#define __SANDESH_HTTP_H__
#include "http/http_server.h"
class HttpServer;
class EventManager;
class SandeshRequest;
class Sandesh;
class SandeshHttp {
public:
typedef boost::function<int32_t(SandeshRequest *)> RequestCallbackFn;
static void Response(Sandesh *snh, std::string context);
static bool Init(EventManager *evm, const std::string module,
short port, RequestCallbackFn reqcb, int *hport);
static void Uninit(void);
class HtmlInfo {
public:
HtmlInfo(const unsigned char * html_str, unsigned int html_len) :
str_(html_str), len_(html_len) {}
const unsigned char * html_str() const { return str_; }
unsigned int html_len() const { return len_; }
private:
const unsigned char * str_;
unsigned int len_;
};
static HtmlInfo GetHtmlInfo(std::string const& s) {
map_type::iterator it = GetMap()->find(s);
if (it == GetMap()->end()) {
HtmlInfo hin(0,0);
return hin;
}
return it->second;
}
SandeshHttp(std::string const& s, HtmlInfo h_info) {
GetMap()->insert(std::make_pair(s, h_info));
}
private:
typedef std::map<std::string, HtmlInfo> map_type;
static map_type* GetMap() {
if (!map_) {
map_ = new map_type();
}
return map_;
}
static map_type *map_;
static HttpServer *hServ_;
static std::string index_str_;
static HtmlInfo *index_hti_;
};
#endif // __SANDESH_HTTP_H__