FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
srpc_cmd.hpp
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #ifndef __VOM_SRPC_CMD_H__
17 #define __VOM_SRPC_CMD_H__
18 
19 #include "vom/hw.hpp"
20 #include "vom/rpc_cmd.hpp"
21 
22 namespace VOM {
23 template <typename MSG>
24 class srpc_cmd : public rpc_cmd<HW::item<handle_t>, MSG>
25 {
26 public:
27  /**
28  * convenient typedef
29  */
30  typedef MSG msg_t;
31 
32  /**
33  * Constructor taking the HW item that will be updated by the command
34  */
36  : rpc_cmd<HW::item<handle_t>, MSG>(item)
37  {
38  }
39 
40  /**
41  * Desructor
42  */
43  virtual ~srpc_cmd() {}
44 
45  virtual vapi_error_e operator()(MSG& reply)
46  {
47  int stats_index = reply.get_response().get_payload().stats_index;
48  int retval = reply.get_response().get_payload().retval;
49 
50  VOM_LOG(log_level_t::DEBUG) << this->to_string() << " " << retval;
51 
52  rc_t rc = rc_t::from_vpp_retval(retval);
53  handle_t handle = handle_t::INVALID;
54 
55  if (rc_t::OK == rc) {
56  handle = stats_index;
57  }
58 
59  this->fulfill(HW::item<handle_t>(handle, rc));
60 
61  return (VAPI_OK);
62  }
63 };
64 };
65 
66 /*
67  * fd.io coding-style-patch-verification: OFF
68  *
69  * Local Variables:
70  * eval: (c-set-style "mozilla")
71  * End:
72  */
73 
74 #endif
stats_index
u32 stats_index
Definition: ip.api:174
vapi_error_e
vapi_error_e
Definition: vapi_common.h:25
VOM::HW::item< handle_t >
VOM_LOG
#define VOM_LOG(lvl)
Definition: logger.hpp:181
VOM
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
VOM::rc_t::OK
const static rc_t OK
The HW write was successfull.
Definition: types.hpp:109
VOM::srpc_cmd::srpc_cmd
srpc_cmd(HW::item< handle_t > &item)
Constructor taking the HW item that will be updated by the command.
Definition: srpc_cmd.hpp:35
VOM::rc_t::from_vpp_retval
static const rc_t & from_vpp_retval(int32_t rv)
Get the rc_t from the VPP API value.
Definition: types.cpp:33
VOM::rpc_cmd
A base class for all RPC commands to VPP.
Definition: rpc_cmd.hpp:40
VAPI_OK
@ VAPI_OK
success
Definition: vapi_common.h:27
VOM::cmd::to_string
virtual std::string to_string() const =0
convert to string format for debug purposes
hw.hpp
VOM::handle_t
A type declaration of an interface handle in VPP.
Definition: types.hpp:233
VOM::log_level_t::DEBUG
const static log_level_t DEBUG
Definition: logger.hpp:32
VOM::rpc_cmd< HW::item< handle_t >, MSG >::item
HW::item< handle_t > & item()
return the HW item the command updates
Definition: rpc_cmd.hpp:66
VOM::srpc_cmd
Definition: srpc_cmd.hpp:24
VOM::HW
Definition: hw.hpp:34
VOM::srpc_cmd::operator()
virtual vapi_error_e operator()(MSG &reply)
call operator used as a callback by VAPI when the reply is available
Definition: srpc_cmd.hpp:45
VOM::handle_t::INVALID
const static handle_t INVALID
A value of an interface handle_t that means the itf does not exist.
Definition: types.hpp:268
VOM::rc_t
Error codes that VPP will return during a HW write.
Definition: types.hpp:89
VOM::srpc_cmd::~srpc_cmd
virtual ~srpc_cmd()
Desructor.
Definition: srpc_cmd.hpp:43
VOM::rpc_cmd< HW::item< handle_t >, MSG >::fulfill
void fulfill(const HW::item< handle_t > &d)
Fulfill the commands promise.
Definition: rpc_cmd.hpp:76
VOM::srpc_cmd::msg_t
MSG msg_t
convenient typedef
Definition: srpc_cmd.hpp:30
rpc_cmd.hpp