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.
37 #include "spdk/stdinc.h"
38 #include "spdk/json.h"
39 #include "spdk/queue.h"
48 struct spdk_notify_type
;
50 typedef int (*spdk_notify_foreach_type_cb
)(const struct spdk_notify_type
*type
, void *ctx
);
52 #define SPDK_NOTIFY_MAX_NAME_SIZE 128
53 #define SPDK_NOTIFY_MAX_CTX_SIZE 128
55 struct spdk_notify_event
{
56 char type
[SPDK_NOTIFY_MAX_NAME_SIZE
];
57 char ctx
[SPDK_NOTIFY_MAX_CTX_SIZE
];
61 * Callback type for event enumeration.
63 * \param idx Event index
64 * \param event Event data
65 * \param ctx User context
66 * \return Non zero to break iteration.
68 typedef int (*spdk_notify_foreach_event_cb
)(uint64_t idx
, const struct spdk_notify_event
*event
,
72 * Register \c type as new notification type.
74 * \note This function is thread safe.
76 * \param type New notification type to register.
77 * \return registered notification type or NULL on failure.
79 struct spdk_notify_type
*spdk_notify_type_register(const char *type
);
82 * Return name of the notification type.
84 * \param type Notification type we are talking about.
85 * \return Name of notification type.
87 const char *spdk_notify_type_get_name(const struct spdk_notify_type
*type
);
90 * Call cb_fn for all event types.
92 * \note Whole function call is under lock so user callback should not sleep.
96 void spdk_notify_foreach_type(spdk_notify_foreach_type_cb cb_fn
, void *ctx
);
99 * Send given notification.
101 * \param type Notification type
102 * \param ctx Notification context
104 * \return Event index.
106 uint64_t spdk_notify_send(const char *type
, const char *ctx
);
109 * Call cb_fn with events from given range.
111 * \note Whole function call is under lock so user callback should not sleep.
113 * \param start_idx First event index
114 * \param cb_fn User callback function. Return non-zero to break iteration.
115 * \param max Maximum number of invocations of user calback function.
116 * \param ctx User context
117 * \return Number of user callback invocations
119 uint64_t spdk_notify_foreach_event(uint64_t start_idx
, uint64_t max
,
120 spdk_notify_foreach_event_cb cb_fn
, void *ctx
);
126 #endif /* SPDK_NOTIFY_H */