fib: fib api updates
[vpp.git] / extras / vom / vom / srpc_cmd.hpp
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    */
35   srpc_cmd(HW::item<handle_t>& item)
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: ON
68  *
69  * Local Variables:
70  * eval: (c-set-style "mozilla")
71  * End:
72  */
73
74 #endif