OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sandesh_http.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 //
6 // sandesh_http.h
7 //
8 // This class supports feeding Sandesh Requests into a process
9 // using a HTTP Client (Webbrowser) and getting the response back.
10 //
11 // It is the backdoor for getting operational state.
12 //
13 
14 #ifndef __SANDESH_HTTP_H__
15 #define __SANDESH_HTTP_H__
16 
17 #include "http/http_server.h"
18 #include "sandesh.h"
19 
20 class HttpServer;
21 class EventManager;
22 class SandeshRequest;
23 class Sandesh;
24 
25 class SandeshHttp {
26 public:
27  typedef boost::function<int32_t(SandeshRequest *)> RequestCallbackFn;
28 
29  static void Response(Sandesh *snh, std::string context);
30  static bool Init(EventManager *evm, const std::string module,
31  short port, RequestCallbackFn reqcb, int *hport,
32  const SandeshConfig &config = SandeshConfig());
33  static void Uninit(void);
34  static void UpdateDscp(uint8_t dscp);
35 
36  class HtmlInfo {
37  public:
38  HtmlInfo(const unsigned char * html_str, unsigned int html_len) :
39  str_(html_str), len_(html_len) {}
40  const unsigned char * html_str() const { return str_; }
41  unsigned int html_len() const { return len_; }
42  private:
43  const unsigned char * str_;
44  unsigned int len_;
45  };
46 
47  static HtmlInfo GetHtmlInfo(std::string const& s) {
48  map_type::iterator it = GetMap()->find(s);
49  if (it == GetMap()->end()) {
50  HtmlInfo hin(0,0);
51  return hin;
52  }
53  return it->second;
54  }
55 
56  SandeshHttp(std::string const& s, HtmlInfo h_info) {
57  GetMap()->insert(std::make_pair(s, h_info));
58  }
59 
60 private:
61  typedef std::map<std::string, HtmlInfo> map_type;
62 
63  static map_type* GetMap() {
64  if (!map_) {
65  map_ = new map_type();
66  }
67  return map_;
68  }
69 
70  static map_type *map_;
71  static HttpServer *hServ_;
72  static std::string index_str_;
74 
75 };
76 
77 #endif // __SANDESH_HTTP_H__
unsigned int html_len() const
Definition: sandesh_http.h:41
SandeshHttp(std::string const &s, HtmlInfo h_info)
Definition: sandesh_http.h:56
const unsigned char * html_str() const
Definition: sandesh_http.h:40
const unsigned char * str_
Definition: sandesh_http.h:43
static map_type * GetMap()
Definition: sandesh_http.h:63
std::map< std::string, HtmlInfo > map_type
Definition: sandesh_http.h:61
static std::string index_str_
Definition: sandesh_http.h:72
static HtmlInfo GetHtmlInfo(std::string const &s)
Definition: sandesh_http.h:47
static HtmlInfo * index_hti_
Definition: sandesh_http.h:73
static map_type * map_
Definition: sandesh_http.h:70
static HttpServer * hServ_
Definition: sandesh_http.h:71
boost::function< int32_t(SandeshRequest *)> RequestCallbackFn
Definition: sandesh_http.h:27
HtmlInfo(const unsigned char *html_str, unsigned int html_len)
Definition: sandesh_http.h:38
static bool Init(EventManager *evm, const std::string module, short port, RequestCallbackFn reqcb, int *hport, const SandeshConfig &config=SandeshConfig())
static void Response(Sandesh *snh, std::string context)
static void UpdateDscp(uint8_t dscp)
static void Uninit(void)
static EventManager evm