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