OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
index_resource.cc
Go to the documentation of this file.
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>
11 
13  Resource::Type resource_key_type) :
14  ResourceKey(rm, resource_key_type) {
15 }
16 
18 }
19 
21  ResourceData(rm), index_(index) {
22 }
23 
25 
26 }
27 
28 uint32_t IndexResourceData::index() const {
29  return index_;
30 }
31 
33  ResourceTable(rm) {
34 }
35 
37 }
38 
39 void IndexResourceTable::ReserveIndex(uint32_t index) {
40  ResourceKeyPtr dummy_key_entry;
41  index_vector_.InsertAtIndex(index, dummy_key_entry);
42 }
43 
44 void IndexResourceTable::ReleaseIndex(uint32_t index) {
45  index_vector_.FreeIndex(index);
46 }
47 
48 void IndexResourceTable::Release(uint32_t index) {
50  if (key.get()) {
51  resource_manager()->Release(key);
52  }
53 }
54 // Allocate the Index resource data.
56  uint32_t index = AllocateIndex(key);
57  ResourceTable::DataPtr data(static_cast<ResourceData *>
58  (new IndexResourceData(key->rm(), index)));
59  return data;
60 }
61 
62 // Restore resource Index.
64  index_vector_.InsertAtIndex(index, key);
65 }
66 
68  //Get the index, populate resource data
69  uint32_t index = index_vector_.AllocIndex(key);
70  return index;
71 }
72 // Restore the Key and Index
74  IndexResourceData *index_data = static_cast<IndexResourceData *>(data.get());
75  RestoreIndex(index_data->index(), key);
76  InsertKey(key, data);
77 }
78 // Release the Key.
80  IndexResourceData *index_data = static_cast<IndexResourceData *>(data.get());
81  ReleaseIndex(index_data->index());
82  DeleteKey(key);
83 }
virtual ResourceTable::DataPtr AllocateData(ResourceKeyPtr key)
void Release(KeyPtr key)
IndexResourceTable(ResourceManager *rm)
boost::shared_ptr< ResourceKey > KeyPtr
void RestoreKey(KeyPtr key, DataPtr data)
void ReleaseIndex(uint32_t index)
ResourceManager * resource_manager() const
IndexResourceData(ResourceManager *rm, uint32_t index)
IndexVectorResource< ResourceKeyPtr > index_vector_
ResourceTable::KeyPtr ResourceKeyPtr
void InsertKey(KeyPtr key, DataPtr data)
IndexResourceKey(ResourceManager *rm, Resource::Type resource_key_type)
uint32_t AllocateIndex(ResourceKeyPtr key)
uint32_t InsertAtIndex(uint32_t index, Object entry)
virtual ~IndexResourceTable()
void RestoreIndex(uint32_t index, ResourceKeyPtr key)
boost::shared_ptr< ResourceData > DataPtr
uint32_t AllocIndex(Object entry)
virtual ~IndexResourceKey()
Object FindIndex(size_t index)
virtual ~IndexResourceData()
uint32_t index() const
void DeleteKey(KeyPtr key)
void FreeIndex(uint32_t index)
void ReleaseKey(KeyPtr key, DataPtr data)
void ReserveIndex(uint32_t index)
void Release(uint32_t index)