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