2 * Copyright (c) 2019 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "vom/qos_map.hpp"
17 #include "vom/api_types.hpp"
18 #include "vom/qos_map_cmds.hpp"
19 #include "vom/qos_types_api.hpp"
20 #include "vom/singular_db_funcs.hpp"
25 singular_db<map::key_t, map> map::m_db;
27 map::event_handler map::m_evh;
29 map::map(uint32_t id, const outputs_t& o)
36 map::map(const map& r)
37 : m_config(r.m_config)
39 , m_outputs(r.m_outputs)
46 m_db.release(key(), this);
62 map::operator==(const map& m) const
64 return (key() == m.key() && m_outputs == m.m_outputs);
71 HW::enqueue(new map_cmds::delete_cmd(m_config, m_id));
80 HW::enqueue(new map_cmds::create_cmd(m_config, m_id, m_outputs));
85 map::to_string() const
88 s << "qos-map:" << (int)m_id;
94 map::update(const map& m)
96 m_outputs = m.m_outputs;
98 if (rc_t::OK != m_config.rc()) {
99 HW::enqueue(new map_cmds::create_cmd(m_config, m_id, m_outputs));
104 map::find_or_add(const map& temp)
106 return (m_db.find_or_add(temp.key(), temp));
110 map::find(const key_t& k)
112 return (m_db.find(k));
116 map::singular() const
118 return find_or_add(*this);
122 map::dump(std::ostream& os)
127 map::event_handler::event_handler()
129 OM::register_listener(this);
130 inspect::register_handler({ "qos-map" }, "QoS Map", this);
134 map::event_handler::handle_replay()
139 static const map::outputs_t
140 from_api(vapi_type_qos_egress_map_row rows[4])
144 for (uint32_t ii = 0; ii < 4; ii++) {
145 std::copy(std::begin(rows[ii].outputs), std::end(rows[ii].outputs),
153 map::event_handler::handle_populate(const client_db::key_t& key)
155 std::shared_ptr<map_cmds::dump_cmd> cmd =
156 std::make_shared<map_cmds::dump_cmd>();
161 for (auto& rr : *cmd) {
162 auto& payload = rr.get_payload();
164 map qr(payload.map.id, from_api(payload.map.rows));
170 map::event_handler::order() const
172 return (dependency_t::TABLE);
176 map::event_handler::show(std::ostream& os)
185 * fd.io coding-style-patch-verification: ON
188 * eval: (c-set-style "mozilla")