LCOV - code coverage report
Current view: top level - lib/notify - notify_rpc.c (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 0 35 0.0 %
Date: 2024-12-14 14:15:14 Functions: 0 7 0.0 %

          Line data    Source code
       1             : /*   SPDX-License-Identifier: BSD-3-Clause
       2             :  *   Copyright (C) 2018 Intel Corporation.
       3             :  *   All rights reserved.
       4             :  */
       5             : 
       6             : 
       7             : #include "spdk/rpc.h"
       8             : #include "spdk/string.h"
       9             : #include "spdk/notify.h"
      10             : #include "spdk/env.h"
      11             : #include "spdk/util.h"
      12             : 
      13             : #include "spdk/log.h"
      14             : 
      15             : static int
      16           0 : notify_get_types_cb(const struct spdk_notify_type *type, void *ctx)
      17             : {
      18           0 :         spdk_json_write_string((struct spdk_json_write_ctx *)ctx, spdk_notify_type_get_name(type));
      19           0 :         return 0;
      20             : }
      21             : 
      22             : static void
      23           0 : rpc_notify_get_types(struct spdk_jsonrpc_request *request,
      24             :                      const struct spdk_json_val *params)
      25             : {
      26             :         struct spdk_json_write_ctx *w;
      27             : 
      28           0 :         if (params != NULL) {
      29           0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
      30             :                                                  "No parameters required");
      31           0 :                 return;
      32             :         }
      33             : 
      34           0 :         w = spdk_jsonrpc_begin_result(request);
      35           0 :         spdk_json_write_array_begin(w);
      36           0 :         spdk_notify_foreach_type(notify_get_types_cb, w);
      37           0 :         spdk_json_write_array_end(w);
      38             : 
      39           0 :         spdk_jsonrpc_end_result(request, w);
      40             : }
      41           0 : SPDK_RPC_REGISTER("notify_get_types", rpc_notify_get_types, SPDK_RPC_RUNTIME)
      42             : 
      43             : struct rpc_notify_get_notifications {
      44             :         uint64_t id;
      45             :         uint64_t max;
      46             : 
      47             :         struct spdk_json_write_ctx *w;
      48             : };
      49             : 
      50             : static const struct spdk_json_object_decoder rpc_notify_get_notifications_decoders[] = {
      51             :         {"id", offsetof(struct rpc_notify_get_notifications, id), spdk_json_decode_uint64, true},
      52             :         {"max", offsetof(struct rpc_notify_get_notifications, max), spdk_json_decode_uint64, true},
      53             : };
      54             : 
      55             : 
      56             : static int
      57           0 : notify_get_notifications_cb(uint64_t id, const struct spdk_notify_event *ev, void *ctx)
      58             : {
      59           0 :         struct rpc_notify_get_notifications *req = ctx;
      60             : 
      61           0 :         spdk_json_write_object_begin(req->w);
      62           0 :         spdk_json_write_named_string(req->w, "type", ev->type);
      63           0 :         spdk_json_write_named_string(req->w, "ctx", ev->ctx);
      64           0 :         spdk_json_write_named_uint64(req->w, "id", id);
      65           0 :         spdk_json_write_object_end(req->w);
      66           0 :         return 0;
      67             : }
      68             : 
      69             : static void
      70           0 : rpc_notify_get_notifications(struct spdk_jsonrpc_request *request,
      71             :                              const struct spdk_json_val *params)
      72             : {
      73           0 :         struct rpc_notify_get_notifications req = {0, UINT64_MAX};
      74             : 
      75           0 :         if (params &&
      76           0 :             spdk_json_decode_object(params, rpc_notify_get_notifications_decoders,
      77             :                                     SPDK_COUNTOF(rpc_notify_get_notifications_decoders), &req)) {
      78           0 :                 SPDK_DEBUGLOG(notify_rpc, "spdk_json_decode_object failed\n");
      79             : 
      80           0 :                 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
      81             :                                                  spdk_strerror(EINVAL));
      82           0 :                 return;
      83             :         }
      84             : 
      85             : 
      86           0 :         req.w = spdk_jsonrpc_begin_result(request);
      87             : 
      88           0 :         spdk_json_write_array_begin(req.w);
      89           0 :         spdk_notify_foreach_event(req.id, req.max, notify_get_notifications_cb, &req);
      90           0 :         spdk_json_write_array_end(req.w);
      91             : 
      92           0 :         spdk_jsonrpc_end_result(request, req.w);
      93             : }
      94           0 : SPDK_RPC_REGISTER("notify_get_notifications", rpc_notify_get_notifications, SPDK_RPC_RUNTIME)
      95             : 
      96           0 : SPDK_LOG_REGISTER_COMPONENT(notify_rpc)

Generated by: LCOV version 1.15