FD.io VPP  v18.07-34-g55fbdb9
Vector Packet Processing
client_db.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __VOM_KEY_DB_H__
17 #define __VOM_KEY_DB_H__
18 
19 #include <map>
20 #include <set>
21 
22 #include "vom/object_base.hpp"
23 
24 namespace VOM {
25 /**
26  * A convenitent typedef for set of objects owned.
27  * A set of shared pointers. This is how the reference counting
28  * of an object in the model it managed. Once all these shared ptr
29  * and hence references are gone, the object is deleted and any state
30  * in VPP is removed.
31  */
32 typedef std::set<object_ref> object_ref_list;
33 
34 /**
35  * A DB storing the objects that each owner/key owns.
36  * Each object is reference counter by each key that owns it. When
37  * no more references exist the object is destroyed.
38  */
39 class client_db
40 {
41 public:
42  /**
43  * In the opflex world each entity is known by a URI which can be
44  * converted
45  * into a string. We use the string type, since it allows us to keep
46  * this VPP
47  * specific code independent of opflex types. I might consider making
48  * this
49  * a template parameter one day...
50  */
51  typedef const std::string key_t;
52 
53  /**
54  * Find the objects owned by the key
55  */
56  object_ref_list& find(const key_t& k);
57 
58  /**
59  * flush, i.e. un-reference, all objects owned by the key
60  */
61  void flush(const key_t& k);
62 
63  /**
64  * Print each of the object in the DB into the stream provided
65  */
66  void dump(const key_t& key, std::ostream& os);
67 
68  /**
69  * Print each KEY
70  */
71  void dump(std::ostream& os);
72 
73 private:
74  /**
75  * A map of keys versus the object they reference
76  */
77  std::map<key_t, object_ref_list> m_objs;
78 };
79 };
80 
81 /*
82  * fd.io coding-style-patch-verification: ON
83  *
84  * Local Variables:
85  * eval: (c-set-style "mozilla")
86  * End:
87  */
88 
89 #endif
void dump(const key_t &key, std::ostream &os)
Print each of the object in the DB into the stream provided.
Definition: client_db.cpp:35
std::set< object_ref > object_ref_list
A convenitent typedef for set of objects owned.
Definition: client_db.hpp:32
object_ref_list & find(const key_t &k)
Find the objects owned by the key.
Definition: client_db.cpp:20
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
void flush(const key_t &k)
flush, i.e.
Definition: client_db.cpp:26
A DB storing the objects that each owner/key owns.
Definition: client_db.hpp:39
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19