]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/include/spdk/notify.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / include / spdk / notify.h
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
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
16 * distribution.
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.
20 *
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.
32 */
33
34 #ifndef SPDK_NOTIFY_H
35 #define SPDK_NOTIFY_H
36
37 #include "spdk/stdinc.h"
38 #include "spdk/json.h"
39 #include "spdk/queue.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /**
46 * Opaque event type.
47 */
48 struct spdk_notify_type;
49
50 typedef int (*spdk_notify_foreach_type_cb)(const struct spdk_notify_type *type, void *ctx);
51
52 #define SPDK_NOTIFY_MAX_NAME_SIZE 128
53 #define SPDK_NOTIFY_MAX_CTX_SIZE 128
54
55 struct spdk_notify_event {
56 char type[SPDK_NOTIFY_MAX_NAME_SIZE];
57 char ctx[SPDK_NOTIFY_MAX_CTX_SIZE];
58 };
59
60 /**
61 * Callback type for event enumeration.
62 *
63 * \param idx Event index
64 * \param event Event data
65 * \param ctx User context
66 * \return Non zero to break iteration.
67 */
68 typedef int (*spdk_notify_foreach_event_cb)(uint64_t idx, const struct spdk_notify_event *event,
69 void *ctx);
70
71 /**
72 * Register \c type as new notification type.
73 *
74 * \note This function is thread safe.
75 *
76 * \param type New notification type to register.
77 * \return registered notification type or NULL on failure.
78 */
79 struct spdk_notify_type *spdk_notify_type_register(const char *type);
80
81 /**
82 * Return name of the notification type.
83 *
84 * \param type Notification type we are talking about.
85 * \return Name of notification type.
86 */
87 const char *spdk_notify_type_get_name(const struct spdk_notify_type *type);
88
89 /**
90 * Call cb_fn for all event types.
91 *
92 * \note Whole function call is under lock so user callback should not sleep.
93 * \param cb_fn
94 * \param ctx
95 */
96 void spdk_notify_foreach_type(spdk_notify_foreach_type_cb cb_fn, void *ctx);
97
98 /**
99 * Send given notification.
100 *
101 * \param type Notification type
102 * \param ctx Notification context
103 *
104 * \return Event index.
105 */
106 uint64_t spdk_notify_send(const char *type, const char *ctx);
107
108 /**
109 * Call cb_fn with events from given range.
110 *
111 * \note Whole function call is under lock so user callback should not sleep.
112 *
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
118 */
119 uint64_t spdk_notify_foreach_event(uint64_t start_idx, uint64_t max,
120 spdk_notify_foreach_event_cb cb_fn, void *ctx);
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #endif /* SPDK_NOTIFY_H */