LCOV - code coverage report
Current view: top level - ifmap - ifmap_object.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 21 26 80.8 %
Date: 2026-11-09 02:10:49 Functions: 9 11 81.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef ctrlplane_ifmap_entry_h
       7             : #define ctrlplane_ifmap_entry_h
       8             : 
       9             : #include <boost/crc.hpp>
      10             : #include <boost/intrusive_ptr.hpp>
      11             : #include <boost/intrusive/list.hpp>
      12             : #include <boost/dynamic_bitset.hpp>
      13             : 
      14             : #include "base/util.h"
      15             : #include "ifmap/ifmap_origin.h"
      16             : 
      17             : namespace pugi {
      18             : class xml_node;
      19             : }
      20             : 
      21             : struct AutogenProperty;
      22             : class IFMapTable;
      23             : 
      24             : class IFMapObject {
      25             : public:
      26             :     IFMapObject();
      27             :     virtual ~IFMapObject();
      28             :     virtual std::string ToString() const = 0;
      29             : 
      30             :     virtual void EncodeUpdate(pugi::xml_node *parent) const = 0;
      31             : 
      32       99124 :     void set_origin(IFMapOrigin origin) { origin_ = origin; }
      33             : 
      34       55307 :     uint64_t sequence_number() { return sequence_number_; }
      35           0 :     const uint64_t sequence_number() const { return sequence_number_; }
      36       67485 :     void set_sequence_number(uint64_t sequence_number) {
      37       67485 :         sequence_number_ = sequence_number;
      38       67485 :     }
      39      175047 :     IFMapOrigin origin() const { return origin_; }
      40             :     virtual bool ResolveStaleness() = 0; // return true if something was stale
      41             :     virtual boost::crc_32_type::value_type CalculateCrc() const = 0;
      42             : 
      43             : private:
      44             :     friend class IFMapNode;
      45             :     friend void intrusive_ptr_add_ref(IFMapObject *object);
      46             :     friend void intrusive_ptr_release(IFMapObject *object);
      47             :     friend void intrusive_ptr_add_ref(const IFMapObject *object);
      48             :     friend void intrusive_ptr_release(const IFMapObject *object);
      49             : 
      50             :     static void Release(IFMapObject *object);
      51             : 
      52             :     boost::intrusive::list_member_hook<> node_;
      53             :     mutable int refcount_;
      54             :     uint64_t sequence_number_;
      55             :     IFMapOrigin origin_;
      56             :     DISALLOW_COPY_AND_ASSIGN(IFMapObject);
      57             : };
      58             : 
      59             : typedef boost::intrusive_ptr<IFMapObject> IFMapObjectRef;
      60      358831 : inline void intrusive_ptr_add_ref(IFMapObject *object) {
      61      358831 :     if (object == NULL) {
      62           0 :         return;
      63             :     }
      64      358831 :     object->refcount_++;
      65             : }
      66      358831 : inline void intrusive_ptr_release(IFMapObject *object) {
      67      358831 :     if (object == NULL) {
      68           0 :         return;
      69             :     }
      70      358831 :     if (--object->refcount_ == 0) {
      71      131440 :         IFMapObject::Release(object);
      72             :     }
      73             : }
      74       32021 : inline void intrusive_ptr_add_ref(const IFMapObject *object) {
      75       32021 :     object->refcount_++;
      76       32021 : }
      77       32021 : inline void intrusive_ptr_release(const IFMapObject *object) {
      78       32021 :     if (--object->refcount_ == 0) {
      79       11620 :         IFMapObject::Release(const_cast<IFMapObject *>(object));
      80             :     }
      81       32021 : }
      82             : 
      83             : // Base class for entries that correspond to IF-MAP identifiers
      84             : class IFMapIdentifier : public IFMapObject {
      85             : public:
      86             :     IFMapIdentifier();
      87             :     explicit IFMapIdentifier(int property_count);
      88             : 
      89             :     virtual bool SetProperty(const std::string &attr_key,
      90             :                              AutogenProperty *data) = 0;
      91             :     virtual void ClearProperty(const std::string &attr_key) = 0;
      92             : 
      93             :     // Return true if any properties are set.
      94           0 :     virtual bool empty() const {
      95           0 :         return true;
      96             :     }
      97             : 
      98             :     void TransferPropertyToOldProperty();
      99             :     bool ResolveStalePropertiesAndResetOld();
     100         674 :     bool IsPropertySet(int id) const {return property_set_.test(id);};
     101             :     virtual bool ResolveStaleness();
     102             : 
     103             : protected:
     104             :     boost::dynamic_bitset<> property_set_;
     105             :     boost::dynamic_bitset<> old_property_set_;
     106             : 
     107             : private:
     108             :     DISALLOW_COPY_AND_ASSIGN(IFMapIdentifier);
     109             : };
     110             : 
     111             : // Base class for entries that correspond to meta-data with attributes
     112             : class IFMapLinkAttr : public IFMapObject {
     113             : public:
     114             :     IFMapLinkAttr();
     115             :     virtual bool SetData(const AutogenProperty *data) = 0;
     116             :     virtual bool ResolveStaleness();
     117             : 
     118             : private:
     119             :     DISALLOW_COPY_AND_ASSIGN(IFMapLinkAttr);
     120             : };
     121             : 
     122             : #endif

Generated by: LCOV version 1.14