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.
36 #include "spdk/string.h"
37 #include "spdk/notify.h"
39 #include "spdk/util.h"
41 #include "spdk_internal/log.h"
44 get_notification_types_cb(const struct spdk_notify_type
*type
, void *ctx
)
46 spdk_json_write_string((struct spdk_json_write_ctx
*)ctx
, spdk_notify_type_get_name(type
));
51 spdk_rpc_get_notification_types(struct spdk_jsonrpc_request
*request
,
52 const struct spdk_json_val
*params
)
54 struct spdk_json_write_ctx
*w
;
57 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
,
58 "No parameters required");
62 w
= spdk_jsonrpc_begin_result(request
);
67 spdk_json_write_array_begin(w
);
68 spdk_notify_foreach_type(get_notification_types_cb
, w
);
69 spdk_json_write_array_end(w
);
71 spdk_jsonrpc_end_result(request
, w
);
73 SPDK_RPC_REGISTER("get_notification_types", spdk_rpc_get_notification_types
, SPDK_RPC_RUNTIME
)
75 struct rpc_get_notifications
{
79 struct spdk_json_write_ctx
*w
;
82 static const struct spdk_json_object_decoder rpc_get_notifications_decoders
[] = {
83 {"id", offsetof(struct rpc_get_notifications
, id
), spdk_json_decode_uint64
, true},
84 {"max", offsetof(struct rpc_get_notifications
, max
), spdk_json_decode_uint64
, true},
89 get_notifications_cb(uint64_t id
, const struct spdk_notify_event
*ev
, void *ctx
)
91 struct rpc_get_notifications
*req
= ctx
;
93 spdk_json_write_object_begin(req
->w
);
94 spdk_json_write_named_string(req
->w
, "type", ev
->type
);
95 spdk_json_write_named_string(req
->w
, "ctx", ev
->ctx
);
96 spdk_json_write_named_uint64(req
->w
, "id", id
);
97 spdk_json_write_object_end(req
->w
);
102 spdk_rpc_get_notifications(struct spdk_jsonrpc_request
*request
,
103 const struct spdk_json_val
*params
)
105 struct rpc_get_notifications req
= {0, UINT64_MAX
};
108 spdk_json_decode_object(params
, rpc_get_notifications_decoders
,
109 SPDK_COUNTOF(rpc_get_notifications_decoders
), &req
)) {
110 SPDK_DEBUGLOG(SPDK_NOTIFY_RPC
, "spdk_json_decode_object failed\n");
112 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
,
113 spdk_strerror(EINVAL
));
118 req
.w
= spdk_jsonrpc_begin_result(request
);
123 spdk_json_write_array_begin(req
.w
);
124 spdk_notify_foreach_event(req
.id
, req
.max
, get_notifications_cb
, &req
);
125 spdk_json_write_array_end(req
.w
);
127 spdk_jsonrpc_end_result(request
, req
.w
);
129 SPDK_RPC_REGISTER("get_notifications", spdk_rpc_get_notifications
, SPDK_RPC_RUNTIME
)
131 SPDK_LOG_REGISTER_COMPONENT("notify_rpc", SPDK_NOTIFY_RPC
)