Fix coverity warnings in VOM and VAPI
[vpp.git] / src / vpp-api / vom / lldp_global.hpp
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_LLDP_GLOBAL_H__
17 #define __VOM_LLDP_GLOBAL_H__
18
19 #include "vom/dump_cmd.hpp"
20 #include "vom/hw.hpp"
21 #include "vom/inspect.hpp"
22 #include "vom/interface.hpp"
23 #include "vom/object_base.hpp"
24 #include "vom/om.hpp"
25 #include "vom/rpc_cmd.hpp"
26 #include "vom/singular_db.hpp"
27 #include "vom/sub_interface.hpp"
28
29 #include <vapi/lldp.api.vapi.hpp>
30
31 namespace VOM {
32 /**
33  * A representation of LLDP global configuration
34  */
35 class lldp_global : public object_base
36 {
37 public:
38   /**
39    * Construct a new object matching the desried state
40    */
41   lldp_global(const std::string& system_name,
42               uint32_t tx_hold,
43               uint32_t tx_interval);
44
45   /**
46    * Copy Constructor
47    */
48   lldp_global(const lldp_global& o);
49
50   /**
51    * Destructor
52    */
53   ~lldp_global();
54
55   /**
56    * Return the 'singular' of the LLDP global that matches this object
57    */
58   std::shared_ptr<lldp_global> singular() const;
59
60   /**
61    * convert to string format for debug purposes
62    */
63   std::string to_string() const;
64
65   /**
66    * Dump all LLDP globals into the stream provided
67    */
68   static void dump(std::ostream& os);
69
70   /**
71    * A command class that binds the LLDP global to the interface
72    */
73   class config_cmd : public rpc_cmd<HW::item<bool>, rc_t, vapi::Lldp_config>
74   {
75   public:
76     /**
77      * Constructor
78      */
79     config_cmd(HW::item<bool>& item,
80                const std::string& system_name,
81                uint32_t tx_hold,
82                uint32_t tx_interval);
83
84     /**
85      * Issue the command to VPP/HW
86      */
87     rc_t issue(connection& con);
88     /**
89      * convert to string format for debug purposes
90      */
91     std::string to_string() const;
92
93     /**
94      * Comparison operator - only used for UT
95      */
96     bool operator==(const config_cmd& i) const;
97
98   private:
99     /**
100      * The system name
101      */
102     const std::string m_system_name;
103
104     /**
105      * TX timer configs
106      */
107     uint32_t m_tx_hold;
108     uint32_t m_tx_interval;
109   };
110
111 private:
112   /**
113    * Class definition for listeners to OM events
114    */
115   class event_handler : public OM::listener, public inspect::command_handler
116   {
117   public:
118     event_handler();
119     virtual ~event_handler() = default;
120
121     /**
122      * Handle a populate event
123      */
124     void handle_populate(const client_db::key_t& key);
125
126     /**
127      * Handle a replay event
128      */
129     void handle_replay();
130
131     /**
132      * Show the object in the Singular DB
133      */
134     void show(std::ostream& os);
135
136     /**
137      * Get the sortable Id of the listener
138      */
139     dependency_t order() const;
140   };
141
142   /**
143    * event_handler to register with OM
144    */
145   static event_handler m_evh;
146
147   /**
148    * Enquue commonds to the VPP command Q for the update
149    */
150   void update(const lldp_global& obj);
151
152   /**
153    * Find or add LLDP global to the OM
154    */
155   static std::shared_ptr<lldp_global> find_or_add(const lldp_global& temp);
156
157   /*
158    * It's the OM class that calls singular()
159    */
160   friend class OM;
161
162   /**
163    * It's the singular_db class that calls replay()
164    */
165   friend class singular_db<interface::key_type, lldp_global>;
166
167   /**
168    * Sweep/reap the object if still stale
169    */
170   void sweep(void);
171
172   /**
173    * replay the object to create it in hardware
174    */
175   void replay(void);
176
177   /**
178    * The system name
179    */
180   const std::string m_system_name;
181
182   /**
183    * TX timer configs
184    */
185   uint32_t m_tx_hold;
186   uint32_t m_tx_interval;
187
188   /**
189    * HW globaluration for the binding. The bool representing the
190    * do/don't bind.
191    */
192   HW::item<bool> m_binding;
193
194   /**
195    * A map of all Lldp globals keyed against the system name.
196    *  there needs to be some sort of key, that will do.
197    */
198   static singular_db<std::string, lldp_global> m_db;
199 };
200 };
201
202 /*
203  * fd.io coding-style-patch-verification: ON
204  *
205  * Local Variables:
206  * eval: (c-set-style "mozilla")
207  * End:
208  */
209
210 #endif