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 #ifndef __VOM_EVENT_CMD_H__
17 #define __VOM_EVENT_CMD_H__
21 #include "vom/rpc_cmd.hpp"
23 #include <vapi/vapi.hpp>
27 * An Event command base class.
28 * Events are one of the sub-set of command type to VPP.
29 * A client performs a one time 'registration/subsription' to VPP for the
30 * event in question and then is notified asynchronously when those events
32 * The model here then is that the lifetime of the event command represensts
33 * the during of the clients subscription. When the command is 'issued' the
34 * subscription begins, when it is 'retired' the subscription ends. For the
35 * subscription duration the client will be notified as events are recieved.
36 * The client can then 'pop' these events from this command object.
38 template <typename WANT, typename EVENT>
39 class event_cmd : public rpc_cmd<HW::item<bool>, WANT>
45 event_cmd(HW::item<bool>& b)
46 : rpc_cmd<HW::item<bool>, WANT>(b)
53 virtual ~event_cmd() {}
56 * Typedef for the event type
58 typedef typename vapi::Event_registration<EVENT>::resp_type event_t;
59 typedef typename vapi::Event_registration<EVENT> reg_t;
61 typedef typename vapi::Result_set<typename reg_t::resp_type>::const_iterator
64 const_iterator begin() { return (m_reg->get_result_set().begin()); }
66 const_iterator end() { return (m_reg->get_result_set().end()); }
68 void lock() { m_mutex.lock(); }
69 void unlock() { m_mutex.unlock(); }
72 * flush/free all the events thus far reeived.
73 * Call with the lock held!
75 void flush() { m_reg->get_result_set().free_all_responses(); }
78 * Retire the command. This is only appropriate for Event Commands
79 * As they persist until retired.
81 virtual void retire(connection& con) = 0;
83 vapi_error_e operator()(reg_t& dl)
92 * Notify the command that data from VPP has arrived and been stored.
93 * The command should now inform its clients/listeners.
95 virtual void notify() = 0;
98 * The VAPI event registration
100 std::unique_ptr<vapi::Event_registration<EVENT>> m_reg;
103 * Mutex protection for the events
110 * fd.io coding-style-patch-verification: ON
113 * eval: (c-set-style "mozilla")