Line data Source code
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 : 13 : #include "config_cass2json_adapter.h" 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 : 22 : class ConfigJsonParserBase { 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 : 31 : ConfigJsonParserBase(); 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(); 46 17582 : const ObjectTypeList &ObjectTypeListToRead() const { 47 17582 : 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 : 60 3673 : void Init(ConfigClientManager *mgr) { 61 3673 : SetupGraphFilter(); 62 3673 : mgr_ = mgr; 63 3673 : } 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 2106 : void AddObjectType(std::string object) { 82 2106 : obj_type_to_read_.insert(object); 83 2106 : } 84 : 85 44492 : const bool IsReadObjectType(std::string objectType) { 86 44492 : if (obj_type_to_read_.find(objectType) == obj_type_to_read_.end()) { 87 0 : return false; 88 : } 89 44492 : return true; 90 : } 91 : 92 : bool IsListOrMapPropEmpty(const std::string &uuid_key, 93 : const std::string &lookup_key) const; 94 : private: 95 : ConfigClientManager *mgr_; 96 : LinkNameMap link_name_map_; 97 : ParentNameMap parent_name_map_; 98 : 99 : WrapperFieldMap wrapper_field_map_; 100 : ObjectTypeList obj_type_to_read_; 101 : }; 102 : 103 : #endif // ctrlplane_config_json_parser_h