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