Fix coverity warnings in VOM and VAPI
[vpp.git] / src / vpp-api / vom / sub_interface.cpp
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 #include "vom/sub_interface.hpp"
17
18 namespace VOM {
19 /**
20  * Construct a new object matching the desried state
21  */
22 sub_interface::sub_interface(const interface& parent,
23                              admin_state_t state,
24                              vlan_id_t vlan)
25   : interface(mk_name(parent, vlan), parent.type(), state)
26   , m_parent(parent.singular())
27   , m_vlan(vlan)
28 {
29 }
30
31 sub_interface::sub_interface(const handle_t& handle,
32                              const interface& parent,
33                              admin_state_t state,
34                              vlan_id_t vlan)
35   : interface(handle,
36               l2_address_t::ZERO,
37               mk_name(parent, vlan),
38               parent.type(),
39               state)
40   , m_parent(parent.singular())
41   , m_vlan(vlan)
42 {
43 }
44
45 sub_interface::~sub_interface()
46 {
47   sweep();
48   release();
49 }
50
51 sub_interface::sub_interface(const sub_interface& o)
52   : interface(o)
53   , m_parent(o.m_parent)
54   , m_vlan(o.m_vlan)
55 {
56 }
57
58 std::string
59 sub_interface::mk_name(const interface& parent, vlan_id_t vlan)
60 {
61   return (parent.name() + "." + std::to_string(vlan));
62 }
63
64 std::queue<cmd*>&
65 sub_interface::mk_create_cmd(std::queue<cmd*>& q)
66 {
67   q.push(new create_cmd(m_hdl, name(), m_parent->handle(), m_vlan));
68
69   return (q);
70 }
71
72 std::queue<cmd*>&
73 sub_interface::mk_delete_cmd(std::queue<cmd*>& q)
74 {
75   q.push(new delete_cmd(m_hdl));
76
77   return (q);
78 }
79
80 std::shared_ptr<sub_interface>
81 sub_interface::singular() const
82 {
83   return std::dynamic_pointer_cast<sub_interface>(singular_i());
84 }
85
86 std::shared_ptr<interface>
87 sub_interface::singular_i() const
88 {
89   return m_db.find_or_add(name(), *this);
90 }
91 }
92
93 /*
94  * fd.io coding-style-patch-verification: ON
95  *
96  * Local Variables:
97  * eval: (c-set-style "mozilla")
98  * End:
99  */