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

Generated by: LCOV version 1.14