FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
object_base.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_OBJECT_H__
17 #define __VOM_OBJECT_H__
18 
19 #include <memory>
20 #include <string>
21 
22 #include "vom/types.hpp"
23 
24 namespace VOM {
25 /**
26  * A base class for all object_base in the VPP object_base-Model.
27  * provides the abstract interface.
28  */
30 {
31 public:
32  /**
33  * convert to string format for debug purposes
34  */
35  virtual std::string to_string() const = 0;
36 
37  /**
38  * Sweep/reap the object if still stale
39  */
40  virtual void sweep(void) = 0;
41 
42  /**
43  * replay the object to create it in hardware
44  */
45  virtual void replay(void) = 0;
46 
47 protected:
48  /**
49  * Constructable by derived classes only
50  */
51  object_base() = default;
52  /**
53  * Destructor
54  */
55  virtual ~object_base() = default;
56 
57 private:
58  /**
59  * note we are not maintaining dependencies back to the
60  * keys. i.e. this object does not know all the keys that
61  * refer to it.
62  */
63 };
64 
65 /**
66  * object state
67  */
69 {
71  /**
72  * indicates the object is stale. This flag is set
73  * when a new epoch is declared. the flag is cleared
74  * when the object is updated in the new epoch. If the
75  * flag is still set after convergence is declared then
76  * the object is deleted
77  */
79 };
80 
81 /**
82  * A represenation of a reference to a VPP object.
83  * the reference counting is held through the use of shared pointers.
84  * We also maintain the state of the object ready for mark n' sweep.
85  */
87 {
88 public:
89  /**
90  * Constructor
91  */
92  object_ref(std::shared_ptr<object_base> obj);
93 
94  /**
95  * less than operator
96  */
97  bool operator<(const object_ref& other) const;
98 
99  /**
100  * Return the shared pointer
101  */
102  std::shared_ptr<object_base> obj() const;
103 
104  /**
105  * Mark the reference object as stale
106  */
107  void mark() const;
108 
109  /**
110  * Clear the stale flag on the object
111  */
112  void clear() const;
113 
114  /**
115  * Query if the object is stale
116  */
117  bool stale() const;
118 
119 private:
120  /**
121  * The reference object
122  */
123  std::shared_ptr<object_base> m_obj;
124 
125  /**
126  * Not part of the key (in the set) so we can change it
127  * whilst iterating
128  */
129  mutable obj_state_t m_state;
130 };
131 
132 /**
133  * ostream print of a VPP Obect
134  */
135 std::ostream& operator<<(std::ostream& os, const object_base& o);
136 };
137 
138 /*
139  * fd.io coding-style-patch-verification: ON
140  *
141  * Local Variables:
142  * eval: (c-set-style "mozilla")
143  * End:
144  */
145 
146 #endif
virtual std::string to_string() const =0
convert to string format for debug purposes
virtual void sweep(void)=0
Sweep/reap the object if still stale.
A represenation of a reference to a VPP object.
Definition: object_base.hpp:86
obj_state_t
object state
Definition: object_base.hpp:68
indicates the object is stale.
Definition: object_base.hpp:78
virtual void replay(void)=0
replay the object to create it in hardware
object_base()=default
Constructable by derived classes only.
A base class for all object_base in the VPP object_base-Model.
Definition: object_base.hpp:29
std::ostream & operator<<(std::ostream &os, const std::pair< direction_t, interface::key_t > &key)
virtual ~object_base()=default
Destructor.
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19