2 * Copyright (c) 2018 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 #ifndef __VOM_PIPE_H__
17 #define __VOM_PIPE_H__
19 #include "vom/interface.hpp"
24 * A pipe is composed for 3 'interfaces'.
25 * 1) the 'parent' interface - this is used as the 'key' for the pipe
26 * 2) the two 'ends' of the pipe - these are used to RX/TX packets
27 * form/to. The ends are retreivable using the east()/west() functions.
28 * The east and west end are exactly equivalent, they are merely
29 * named differently for logical purposes.
31 class pipe : public interface
34 typedef std::pair<handle_t, handle_t> handle_pair_t;
37 * Construct a new object matching the desried state
39 pipe(uint32_t instance, admin_state_t state);
52 * comparison operator - for UT
54 bool operator==(const pipe& s) const;
57 * Return the matching 'singular instance' of the sub-interface
59 std::shared_ptr<pipe> singular() const;
62 * Find a subinterface from its key
64 static std::shared_ptr<pipe> find(const key_t& k);
67 * The interface that is the east end of the pipe
69 std::shared_ptr<interface> east();
72 * The interface that is the west end of the pipe.
73 * The east and west end are exactly equivalent, they are merely
74 * named differently for logical purposes.
76 std::shared_ptr<interface> west();
78 virtual std::string to_string(void) const;
80 void set_ends(const handle_pair_t& p);
84 * The interface type that forms the ends of the pipe
86 class pipe_end : public interface
89 pipe_end(const pipe& p, uint8_t id);
92 virtual std::queue<cmd*>& mk_create_cmd(std::queue<cmd*>& cmds);
93 virtual std::queue<cmd*>& mk_delete_cmd(std::queue<cmd*>& cmds);
95 std::shared_ptr<pipe> m_pipe;
99 *Class definition for listeners to OM events
101 class event_handler : public OM::listener, public inspect::command_handler
105 virtual ~event_handler() = default;
108 * Handle a populate event
110 void handle_populate(const client_db::key_t& key);
113 * Handle a replay event
115 void handle_replay();
118 * Show the object in the Singular DB
120 void show(std::ostream& os);
123 * Get the sortable Id of the listener
125 dependency_t order() const;
127 static event_handler m_evh;
130 * Return the matching 'instance' of the pipe
131 * over-ride from the base class
133 std::shared_ptr<interface> singular_i() const;
136 * Virtual functions to construct an interface create commands.
138 virtual std::queue<cmd*>& mk_create_cmd(std::queue<cmd*>& cmds);
141 * Virtual functions to construct an interface delete commands.
143 virtual std::queue<cmd*>& mk_delete_cmd(std::queue<cmd*>& cmds);
146 * the handles that are set during the create command
148 HW::item<handle_pair_t> m_hdl_pair;
151 * The ends of the pipe
153 std::shared_ptr<interface> m_ends[2];
164 * fd.io coding-style-patch-verification: ON
167 * eval: (c-set-style "mozilla")