OpenSDN source code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
config_json_parser_base.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef ctrlplane_config_json_parser_base_h
6 #define ctrlplane_config_json_parser_base_h
7 
8 #include <list>
9 #include <map>
10 #include <set>
11 #include <string>
12 
14 #include "config_client_manager.h"
15 #include "base/queue_task.h"
16 
17 #include "rapidjson/document.h"
18 
19 #include <boost/function.hpp>
20 
21 
23 public:
24  typedef std::set<std::string> ObjectTypeList;
25  typedef std::pair<std::string, std::string> LinkMemberPair;
26  typedef std::pair<std::string, bool> LinkDataPair;
27  typedef std::map<LinkMemberPair, std::string> ParentNameMap;
28  typedef std::map<LinkMemberPair, LinkDataPair> LinkNameMap;
29  typedef std::map<std::string, std::string> WrapperFieldMap;
30 
32  virtual ~ConfigJsonParserBase();
33  // This fucntion is used to setup object graphy concerned
34  // by user, please follow the step:
35  // 1. add concerned object with AddObjectType API one by one
36  // 2. add relationship of object with AddParentName or
37  // AddLinkName, if do not set this, ref/parent info will be
38  // filtered out
39  // 3. AddWrapperField for property map/list, if do no set this
40  // this property map/list will be filtered out.
41  // please see ifmap/client/config_json_parser.cc as example.
42  virtual void SetupGraphFilter() = 0;
43  virtual bool Receive(const ConfigCass2JsonAdapter &adapter,
44  bool add_change) = 0;
45  virtual void EndOfConfig();
47  return obj_type_to_read_;
48  }
49 
50  std::string GetParentName(const std::string &left,
51  const std::string &right) const;
52  std::string GetLinkName(const std::string &left,
53  const std::string &right) const;
54  std::string GetWrapperFieldName(const std::string &type_name,
55  const std::string &property_name) const;
56 
57  bool IsLinkWithAttr(const std::string &left,
58  const std::string &right) const;
59 
62  mgr_ = mgr;
63  }
64 
65  uint64_t GetGenerationNumber() const {
66  return mgr_->GetGenerationNumber();
67  }
68 
69  void AddLinkName(LinkMemberPair member_pair, LinkDataPair data_pair) {
70  link_name_map_.insert(make_pair(member_pair, data_pair));
71  }
72 
73  void AddParentName(LinkMemberPair member_pair, std::string s) {
74  parent_name_map_.insert(make_pair(member_pair, s));
75  }
76 
77  void AddWrapperField(std::string key, std::string value) {
78  wrapper_field_map_.insert(make_pair(key, value));
79  }
80 
81  void AddObjectType(std::string object) {
82  obj_type_to_read_.insert(object);
83  }
84 
85  const bool IsReadObjectType(std::string objectType) {
86  if (obj_type_to_read_.find(objectType) == obj_type_to_read_.end()) {
87  return false;
88  }
89  return true;
90  }
91 
92  bool IsListOrMapPropEmpty(const std::string &uuid_key,
93  const std::string &lookup_key) const;
94 private:
98 
101 };
102 
103 #endif // ctrlplane_config_json_parser_h
void AddParentName(LinkMemberPair member_pair, std::string s)
void AddLinkName(LinkMemberPair member_pair, LinkDataPair data_pair)
bool IsLinkWithAttr(const std::string &left, const std::string &right) const
bool IsListOrMapPropEmpty(const std::string &uuid_key, const std::string &lookup_key) const
uint64_t GetGenerationNumber() const
std::pair< std::string, bool > LinkDataPair
void AddWrapperField(std::string key, std::string value)
std::set< std::string > ObjectTypeList
WrapperFieldMap wrapper_field_map_
std::string GetParentName(const std::string &left, const std::string &right) const
std::map< std::string, std::string > WrapperFieldMap
std::string GetLinkName(const std::string &left, const std::string &right) const
const bool IsReadObjectType(std::string objectType)
void Init(ConfigClientManager *mgr)
ConfigClientManager * mgr_
std::map< LinkMemberPair, std::string > ParentNameMap
uint64_t GetGenerationNumber() const
const ObjectTypeList & ObjectTypeListToRead() const
virtual bool Receive(const ConfigCass2JsonAdapter &adapter, bool add_change)=0
virtual void SetupGraphFilter()=0
std::map< LinkMemberPair, LinkDataPair > LinkNameMap
std::string GetWrapperFieldName(const std::string &type_name, const std::string &property_name) const
std::pair< std::string, std::string > LinkMemberPair
void AddObjectType(std::string object)