Line data Source code
1 : /* 2 : * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef vnsw_agent_index_resource_hpp 6 : #define vnsw_agent_index_resource_hpp 7 : 8 : #include "resource_manager/index_vector_resource.h" 9 : #include "resource_cmn.h" 10 : class ResourceTable; 11 : class ResourceManager; 12 : class ResourceKey; 13 : class ResourceData; 14 : 15 : class IndexResourceKey : public ResourceKey { 16 : public: 17 : IndexResourceKey(ResourceManager *rm, Resource::Type resource_key_type); 18 : virtual ~IndexResourceKey(); 19 : 20 0 : virtual const std::string ToString() {return "";} 21 : virtual bool IsLess(const ResourceKey &rhs) const = 0; 22 : virtual void Backup(ResourceData *data, uint16_t op) = 0; 23 : 24 : }; 25 : 26 : class IndexResourceData : public ResourceData { 27 : public: 28 : //Used by allocation & restore of resource 29 : IndexResourceData(ResourceManager *rm, 30 : uint32_t index); 31 : virtual ~IndexResourceData(); 32 : 33 : uint32_t index() const; 34 0 : virtual const std::string ToString() {return "";} 35 : private: 36 : uint32_t index_; 37 : DISALLOW_COPY_AND_ASSIGN(IndexResourceData); 38 : }; 39 : // This Class is responsible for allocating the unique resource index 40 : // for each key we are adding to the table. 41 : class IndexResourceTable : public ResourceTable { 42 : public: 43 : IndexResourceTable(ResourceManager *rm); 44 : virtual ~IndexResourceTable(); 45 : void ReserveIndex(uint32_t index); 46 : void ReleaseIndex(uint32_t index); 47 : void Release(uint32_t index); 48 : virtual ResourceTable::DataPtr AllocateData(ResourceKeyPtr key); 49 0 : virtual const std::string ToString() {return "";} 50 : 51 : uint32_t AllocateIndex(ResourceKeyPtr key); 52 : void RestoreIndex(uint32_t index, ResourceKeyPtr key); 53 : void RestoreKey(KeyPtr key, DataPtr data); 54 : void ReleaseKey(KeyPtr key, DataPtr data); 55 : 56 : private: 57 : IndexVectorResource<ResourceKeyPtr> index_vector_; 58 : DISALLOW_COPY_AND_ASSIGN(IndexResourceTable); 59 : }; 60 : 61 : #endif