4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef SPDK_RPC_CONFIG_H_
35 #define SPDK_RPC_CONFIG_H_
37 #include "spdk/stdinc.h"
39 #include "spdk/jsonrpc.h"
46 * Start listening for RPC connections.
48 * \param listen_addr Listening address.
50 * \return 0 on success, -1 on failure.
52 int spdk_rpc_listen(const char *listen_addr
);
55 * Poll the RPC server.
57 void spdk_rpc_accept(void);
60 * Stop listening for RPC connections.
62 void spdk_rpc_close(void);
65 * Function signature for RPC request handlers.
67 * \param request RPC request to handle.
68 * \param params Parameters associated with the RPC request.
70 typedef void (*spdk_rpc_method_handler
)(struct spdk_jsonrpc_request
*request
,
71 const struct spdk_json_val
*params
);
74 * Register an RPC method.
76 * \param method Name for the registered method.
77 * \param func Function registered for this method to handle the RPC request.
78 * \param state_mask State mask of the registered method. If the bit of the state of
79 * the RPC server is set in the state_mask, the method is allowed. Otherwise, it is rejected.
81 void spdk_rpc_register_method(const char *method
, spdk_rpc_method_handler func
,
85 * Register a deprecated alias for an RPC method.
87 * \param method Name for the registered method.
88 * \param alias Alias for the registered method.
90 void spdk_rpc_register_alias_deprecated(const char *method
, const char *alias
);
93 * Check if \c method is allowed for \c state_mask
95 * \param method Method name
96 * \param state_mask state mask to check against
97 * \return 0 if method is allowed or negative error code:
98 * -EPERM method is not allowed
99 * -ENOENT method not found
101 int spdk_rpc_is_method_allowed(const char *method
, uint32_t state_mask
);
103 #define SPDK_RPC_STARTUP 0x1
104 #define SPDK_RPC_RUNTIME 0x2
106 #define SPDK_RPC_REGISTER(method, func, state_mask) \
107 static void __attribute__((constructor)) rpc_register_##func(void) \
109 spdk_rpc_register_method(method, func, state_mask); \
112 #define SPDK_RPC_REGISTER_ALIAS_DEPRECATED(method, alias) \
113 static void __attribute__((constructor)) rpc_register_##alias(void) \
115 spdk_rpc_register_alias_deprecated(#method, #alias); \
119 * Set the state mask of the RPC server. Any RPC method whose state mask is
120 * equal to the state of the RPC server is allowed.
122 * \param state_mask New state mask of the RPC server.
124 void spdk_rpc_set_state(uint32_t state_mask
);
127 * Get the current state of the RPC server.
129 * \return The current state of the RPC server.
131 uint32_t spdk_rpc_get_state(void);