LCOV - code coverage report
Current view: top level - spdk/lib/notify - notify_rpc.c (source / functions) Hit Total Coverage
Test: Combined Lines: 30 35 85.7 %
Date: 2024-08-09 23:39:43 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 10 40.0 %

           Branch data     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                 :         24 : notify_get_types_cb(const struct spdk_notify_type *type, void *ctx)
      17                 :            : {
      18                 :         24 :         spdk_json_write_string((struct spdk_json_write_ctx *)ctx, spdk_notify_type_get_name(type));
      19                 :         24 :         return 0;
      20                 :            : }
      21                 :            : 
      22                 :            : static void
      23                 :         12 : 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         [ -  + ]:         12 :         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                 :         12 :         w = spdk_jsonrpc_begin_result(request);
      35                 :         12 :         spdk_json_write_array_begin(w);
      36                 :         12 :         spdk_notify_foreach_type(notify_get_types_cb, w);
      37                 :         12 :         spdk_json_write_array_end(w);
      38                 :            : 
      39                 :         12 :         spdk_jsonrpc_end_result(request, w);
      40                 :            : }
      41                 :       2028 : 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                 :         90 : notify_get_notifications_cb(uint64_t id, const struct spdk_notify_event *ev, void *ctx)
      58                 :            : {
      59                 :         90 :         struct rpc_notify_get_notifications *req = ctx;
      60                 :            : 
      61                 :         90 :         spdk_json_write_object_begin(req->w);
      62                 :         90 :         spdk_json_write_named_string(req->w, "type", ev->type);
      63                 :         90 :         spdk_json_write_named_string(req->w, "ctx", ev->ctx);
      64                 :         90 :         spdk_json_write_named_uint64(req->w, "id", id);
      65                 :         90 :         spdk_json_write_object_end(req->w);
      66                 :         90 :         return 0;
      67                 :            : }
      68                 :            : 
      69                 :            : static void
      70                 :         32 : rpc_notify_get_notifications(struct spdk_jsonrpc_request *request,
      71                 :            :                              const struct spdk_json_val *params)
      72                 :            : {
      73                 :         32 :         struct rpc_notify_get_notifications req = {0, UINT64_MAX};
      74                 :            : 
      75   [ +  +  -  + ]:         49 :         if (params &&
      76                 :         17 :             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                 :         32 :         req.w = spdk_jsonrpc_begin_result(request);
      87                 :            : 
      88                 :         32 :         spdk_json_write_array_begin(req.w);
      89                 :         32 :         spdk_notify_foreach_event(req.id, req.max, notify_get_notifications_cb, &req);
      90                 :         32 :         spdk_json_write_array_end(req.w);
      91                 :            : 
      92                 :         32 :         spdk_jsonrpc_end_result(request, req.w);
      93                 :            : }
      94                 :       2028 : SPDK_RPC_REGISTER("notify_get_notifications", rpc_notify_get_notifications, SPDK_RPC_RUNTIME)
      95                 :            : 
      96                 :       2028 : SPDK_LOG_REGISTER_COMPONENT(notify_rpc)

Generated by: LCOV version 1.14