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 40 : IndexResourceKey::IndexResourceKey(ResourceManager *rm, 13 40 : Resource::Type resource_key_type) : 14 40 : ResourceKey(rm, resource_key_type) { 15 40 : } 16 : 17 40 : IndexResourceKey::~IndexResourceKey() { 18 40 : } 19 : 20 40 : IndexResourceData::IndexResourceData(ResourceManager *rm, uint32_t index) : 21 40 : ResourceData(rm), index_(index) { 22 40 : } 23 : 24 80 : IndexResourceData::~IndexResourceData() { 25 : 26 80 : } 27 : 28 80 : uint32_t IndexResourceData::index() const { 29 80 : 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 56 : void IndexResourceTable::ReleaseIndex(uint32_t index) { 45 56 : index_vector_.FreeIndex(index); 46 56 : } 47 : 48 40 : void IndexResourceTable::Release(uint32_t index) { 49 40 : ResourceKeyPtr key = index_vector_.FindIndex(index); 50 40 : if (key.get()) { 51 40 : resource_manager()->Release(key); 52 : } 53 40 : } 54 : // Allocate the Index resource data. 55 40 : ResourceTable::DataPtr IndexResourceTable::AllocateData(ResourceKeyPtr key) { 56 40 : uint32_t index = AllocateIndex(key); 57 : ResourceTable::DataPtr data(static_cast<ResourceData *> 58 40 : (new IndexResourceData(key->rm(), index))); 59 40 : 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 40 : uint32_t IndexResourceTable::AllocateIndex(ResourceKeyPtr key) { 68 : //Get the index, populate resource data 69 40 : uint32_t index = index_vector_.AllocIndex(key); 70 40 : 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 40 : void IndexResourceTable::ReleaseKey(KeyPtr key, DataPtr data) { 80 40 : IndexResourceData *index_data = static_cast<IndexResourceData *>(data.get()); 81 40 : ReleaseIndex(index_data->index()); 82 40 : DeleteKey(key); 83 40 : }