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_DUMP_CMD_H__
17 #define __VOM_DUMP_CMD_H__
21 #include "vom/cmd.hpp"
24 #include <vapi/vapi.hpp>
28 * A function type def for calculating a message's size
30 typedef unsigned int (*get_msg_size_t)(void*);
33 * A base class for VPP dump commands.
34 * Dump commands are one of the sub-set of command types to VPP. Here the
36 * makes a read request on the resource and VPP responds with all the
38 * This command is executed synchronously. Once complete the client can
40 * the records from the command object
42 template <typename MSG>
43 class dump_cmd : public cmd
47 typedef typename MSG::resp_type record_t;
49 typedef typename vapi::Result_set<typename MSG::resp_type>::const_iterator
63 virtual ~dump_cmd() {}
65 dump_cmd(const dump_cmd& d) = default;
68 * Constant iterator to the start of the records retunred during the dump
70 const_iterator begin()
73 * m_dump is NULL during client UT when the commands are not issued.
76 return const_iterator();
77 return (m_dump->get_result_set().begin());
81 * Constant iterator to the end of the records retunred during the dump
86 return const_iterator();
87 return (m_dump->get_result_set().end());
91 * Wait for the issue of the command to complete
95 std::future_status status;
96 std::future<rc_t> result;
98 result = m_promise.get_future();
99 status = result.wait_for(std::chrono::seconds(5));
101 if (status != std::future_status::ready) {
102 return (rc_t::TIMEOUT);
105 return (result.get());
109 * Call operator called when the dump is complete
111 vapi_error_e operator()(MSG& d)
113 m_promise.set_value(rc_t::OK);
119 * Retire/cancel a long running command
121 virtual void retire(connection& con) {}
125 * The underlying promise that implements the synchornous nature
126 * of the command issue
128 std::promise<rc_t> m_promise;
131 * Dump commands should not be issued whilst the HW is disabled
136 * The HW::cmd_q is a friend so it can call suceedded.
138 friend class HW::cmd_q;
141 * The VAPI event registration
143 std::unique_ptr<MSG> m_dump;
148 * fd.io coding-style-patch-verification: ON
151 * eval: (c-set-style "mozilla")