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:
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/pipe.hpp"
17 #include "vom/interface_factory.hpp"
18 #include "vom/pipe_cmds.hpp"
19 #include "vom/singular_db_funcs.hpp"
27 #define N_ENDS (WEST + 1)
29 pipe::event_handler pipe::m_evh;
31 static const std::string
32 pipe_mk_name(uint32_t instance)
34 return ("pipe" + std::to_string(instance));
38 * Construct a new object matching the desried state
40 pipe::pipe(uint32_t instance, admin_state_t state)
41 : interface(pipe_mk_name(instance), type_t::PIPE, state)
42 , m_instance(instance)
52 pipe::pipe(const pipe& o)
54 , m_instance(o.m_instance)
59 pipe::to_string(void) const
63 s << "[pipe: " << interface::to_string() << " instance:" << m_instance
64 << " ends:[" << m_hdl_pair.rc().to_string() << " "
65 << m_hdl_pair.data().first << ", " << m_hdl_pair.data().second << "]]";
71 pipe::mk_create_cmd(std::queue<cmd*>& q)
73 q.push(new pipe_cmds::create_cmd(m_hdl, m_name, m_instance, m_hdl_pair));
79 pipe::mk_delete_cmd(std::queue<cmd*>& q)
81 q.push(new pipe_cmds::delete_cmd(m_hdl, m_hdl_pair));
87 pipe::singular() const
89 return std::dynamic_pointer_cast<pipe>(singular_i());
92 std::shared_ptr<interface>
93 pipe::singular_i() const
95 return m_db.find_or_add(key(), *this);
99 pipe::find(const key_t& k)
101 return std::dynamic_pointer_cast<pipe>(m_db.find(k));
104 std::shared_ptr<interface>
108 if (rc_t::OK == m_hdl_pair.rc()) {
109 m_ends[WEST] = pipe_end(*this, WEST).singular();
110 m_ends[WEST]->set(m_hdl_pair.data().first);
114 return (m_ends[WEST]);
117 std::shared_ptr<interface>
121 if (rc_t::OK == m_hdl_pair.rc()) {
122 m_ends[EAST] = pipe_end(*this, EAST).singular();
123 m_ends[EAST]->set(m_hdl_pair.data().first);
127 return (m_ends[EAST]);
130 pipe::pipe_end::pipe_end(const pipe& p, uint8_t id)
131 : interface(p.name() + "." + std::to_string(id),
132 interface::type_t::PIPE_END,
133 interface::admin_state_t::UP)
134 , m_pipe(p.singular())
139 pipe::pipe_end::mk_create_cmd(std::queue<cmd*>& q)
145 pipe::pipe_end::mk_delete_cmd(std::queue<cmd*>& q)
151 pipe::set_ends(const handle_pair_t& p)
153 if (handle_t::INVALID != p.first && handle_t::INVALID != p.second) {
154 m_hdl_pair = { p, rc_t::OK };
156 m_hdl_pair = { p, rc_t::INVALID };
160 pipe::event_handler::event_handler()
162 OM::register_listener(this);
163 inspect::register_handler({ "pipe" }, "pipes", this);
167 pipe::event_handler::handle_replay()
173 pipe::event_handler::handle_populate(const client_db::key_t& key)
175 std::shared_ptr<pipe_cmds::dump_cmd> cmd =
176 std::make_shared<pipe_cmds::dump_cmd>();
181 for (auto& record : *cmd) {
182 std::shared_ptr<pipe> sp;
184 sp = interface_factory::new_pipe_interface(record.get_payload());
186 VOM_LOG(log_level_t::DEBUG) << " pipe-dump: " << sp->to_string();
187 OM::commit(key, *sp);
192 pipe::event_handler::order() const
194 return (dependency_t::VIRTUAL_INTERFACE);
198 pipe::event_handler::show(std::ostream& os)
206 * fd.io coding-style-patch-verification: ON
209 * eval: (c-set-style "mozilla")