LCOV - code coverage report
Current view: top level - vnsw/agent/resource_manager - index_resource.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 42 50 84.0 %
Date: 2026-11-09 02:10:49 Functions: 15 18 83.3 %
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             : #include <boost/uuid/uuid_io.hpp>
       7             : #include <cmn/agent_cmn.h>
       8             : #include <init/agent_param.h>
       9             : #include <resource_manager/resource_manager.h>
      10             : #include <resource_manager/resource_table.h>
      11             : #include <resource_manager/index_resource.h>
      12             : 
      13        1277 : IndexResourceKey::IndexResourceKey(ResourceManager *rm,
      14        1277 :                                    Resource::Type resource_key_type) :
      15        1277 :     ResourceKey(rm, resource_key_type) {
      16        1277 : }
      17             : 
      18        1277 : IndexResourceKey::~IndexResourceKey() {
      19        1277 : }
      20             : 
      21        1277 : IndexResourceData::IndexResourceData(ResourceManager *rm, uint32_t index) :
      22        1277 :     ResourceData(rm), index_(index) {
      23        1277 : }
      24             : 
      25        2554 : IndexResourceData::~IndexResourceData() {
      26             : 
      27        2554 : }
      28             : 
      29        2554 : uint32_t IndexResourceData::index() const {
      30        2554 :     return index_;
      31             : }
      32             : 
      33          12 : IndexResourceTable::IndexResourceTable(ResourceManager *rm) :
      34          12 :     ResourceTable(rm) {
      35          12 : }
      36             : 
      37          24 : IndexResourceTable::~IndexResourceTable() {
      38          24 : }
      39             : 
      40          32 : void IndexResourceTable::ReserveIndex(uint32_t index) {
      41          32 :     ResourceKeyPtr dummy_key_entry;
      42          32 :     index_vector_.InsertAtIndex(index, dummy_key_entry);
      43          32 : }
      44             : 
      45        1309 : void IndexResourceTable::ReleaseIndex(uint32_t index) {
      46        1309 :     index_vector_.FreeIndex(index);
      47        1309 : }
      48             : 
      49        1277 : void IndexResourceTable::Release(uint32_t index) {
      50        1277 :     ResourceKeyPtr key = index_vector_.FindIndex(index);
      51        1277 :     if (key.get()) {
      52        1277 :         resource_manager()->Release(key);
      53             :     }
      54        1277 : }
      55             : // Allocate the Index resource data.
      56        1277 : ResourceTable::DataPtr IndexResourceTable::AllocateData(ResourceKeyPtr key) {
      57        1277 :     uint32_t index = AllocateIndex(key);
      58             :     ResourceTable::DataPtr data(static_cast<ResourceData *>
      59        1277 :             (new IndexResourceData(key->rm(), index)));
      60        1277 :     return data;
      61             : }
      62             : 
      63             : // Restore resource Index.
      64           0 : void IndexResourceTable::RestoreIndex(uint32_t index, ResourceKeyPtr key) {
      65           0 :     index_vector_.InsertAtIndex(index, key);
      66           0 : }
      67             : 
      68        1277 : uint32_t IndexResourceTable::AllocateIndex(ResourceKeyPtr key) {
      69             :     //Get the index, populate resource data
      70        1277 :     uint32_t index = index_vector_.AllocIndex(key);
      71        1277 :     return index;
      72             : }
      73             : // Restore the Key and Index
      74           0 : void IndexResourceTable::RestoreKey(KeyPtr key, DataPtr data) {
      75           0 :    IndexResourceData *index_data = static_cast<IndexResourceData *>(data.get());
      76           0 :    RestoreIndex(index_data->index(), key);
      77           0 :    InsertKey(key, data);
      78           0 : }
      79             : // Release the Key.
      80        1277 : void  IndexResourceTable::ReleaseKey(KeyPtr key, DataPtr data) {
      81        1277 :    IndexResourceData *index_data = static_cast<IndexResourceData *>(data.get());
      82        1277 :    ReleaseIndex(index_data->index());
      83        1277 :    DeleteKey(key);
      84        1277 : }

Generated by: LCOV version 1.14