OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
resource_table.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_resource_table_hpp
6 #define vnsw_agent_resource_table_hpp
7 #include "resource_cmn.h"
8 class ResourceManager;
9 class ResourceTable;
10 class ResourceData;
11 class ResourceKey {
12 public:
14  virtual ~ResourceKey();
15 
16  virtual const std::string ToString() {return "";}
17  virtual bool IsLess(const ResourceKey &rhs) const = 0;
18  virtual void Backup(ResourceData *data, uint16_t op) = 0;
19  bool operator<(const ResourceKey &rhs) const;
20  void set_dirty() {dirty_ = true;}
21  void reset_dirty() {dirty_ = false;}
22  bool dirty() const {return dirty_;}
24  ResourceManager* rm() {return rm_;}
25 private:
27  bool dirty_;
30 };
31 
32 class ResourceData {
33 public:
34  typedef boost::shared_ptr<ResourceData> Ptr;
36  virtual ~ResourceData();
37  virtual const std::string ToString() = 0;
38 private:
40 };
41 
43  bool operator()( const boost::shared_ptr<ResourceKey> lhs,
44  const boost::shared_ptr<ResourceKey> rhs) const {
45  ResourceKey *left = lhs.get();
46  ResourceKey *right = rhs.get();
47  return (*left).IsLess(*right);
48  }
49 };
50 
52 public:
54  virtual ~ResourceBackupEndKey();
55 
56  virtual const std::string ToString() {return "ResourceBackupEndKey";}
57  virtual bool IsLess(const ResourceKey &rhs) const {
58  assert(0);
59  return false;
60  }
61  virtual void Backup(ResourceData *data, uint16_t op) {
62  assert(0);
63  }
64 };
65 // This class is resposible for allocating & restoring the the resources.
66 // maintains the Resource Key and resource data value pairs.
68 public:
69  typedef boost::shared_ptr<ResourceKey> KeyPtr;
70  typedef boost::shared_ptr<ResourceData> DataPtr;
72  typedef std::map<KeyPtr, DataPtr, KeyDataMapComparator> KeyDataMap;
73  typedef KeyDataMap::iterator KeyDataMapIter;
75  virtual ~ResourceTable();
76  virtual const std::string ToString() = 0;
77  virtual DataPtr AllocateData(KeyPtr key) = 0;
78  virtual void RestoreKey(KeyPtr key, DataPtr data) = 0;
79  virtual void ReleaseKey(KeyPtr key, DataPtr data) = 0;
80  void InsertKey(KeyPtr key, DataPtr data);
81  void DeleteKey(KeyPtr key);
84  void FlushStale();
86  ResourceManager *resource_manager() const { return rm_; }
87 private:
91 };
92 
93 #endif //resource_table
virtual const std::string ToString()=0
boost::shared_ptr< ResourceData > Ptr
virtual const std::string ToString()
std::map< KeyPtr, DataPtr, KeyDataMapComparator > KeyDataMap
DISALLOW_COPY_AND_ASSIGN(ResourceKey)
virtual ~ResourceKey()
virtual void ReleaseKey(KeyPtr key, DataPtr data)=0
virtual DataPtr AllocateData(KeyPtr key)=0
virtual bool IsLess(const ResourceKey &rhs) const =0
boost::shared_ptr< ResourceKey > KeyPtr
virtual const std::string ToString()=0
void reset_dirty()
virtual void Backup(ResourceData *data, uint16_t op)
ResourceTable(ResourceManager *rm)
ResourceManager * rm_
ResourceManager * resource_manager() const
ResourceTable::KeyPtr ResourceKeyPtr
ResourceManager * rm_
ResourceData * FindKey(KeyPtr key)
virtual const std::string ToString()
ResourceTable * resource_table_
virtual ~ResourceData()
ResourceManager * rm()
uint8_t type
Definition: load_balance.h:109
void InsertKey(KeyPtr key, DataPtr data)
bool operator<(const ResourceKey &rhs) const
bool operator()(const boost::shared_ptr< ResourceKey > lhs, const boost::shared_ptr< ResourceKey > rhs) const
virtual ~ResourceBackupEndKey()
virtual ~ResourceTable()
DataPtr FindKeyPtr(KeyPtr key)
boost::shared_ptr< ResourceData > DataPtr
virtual void RestoreKey(KeyPtr key, DataPtr data)=0
ResourceData(ResourceManager *rm)
ResourceTable * resource_table()
DISALLOW_COPY_AND_ASSIGN(ResourceTable)
void set_dirty()
virtual bool IsLess(const ResourceKey &rhs) const
ResourceBackupEndKey(ResourceManager *rm)
ResourceTable::DataPtr Allocate(KeyPtr key)
KeyDataMap key_data_map_
void DeleteKey(KeyPtr key)
KeyDataMap::iterator KeyDataMapIter
ResourceManager * rm_
virtual void Backup(ResourceData *data, uint16_t op)=0
bool dirty() const
ResourceKey(ResourceManager *rm, Resource::Type type)