LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/config-client-mgr - config_json_parser_base.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 12 13 92.3 %
Date: 2026-11-09 02:10:49 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14