126f30603SPiotr Pelplinski# Notify library {#notify} 293be26a5SKarol Latecki 326f30603SPiotr PelplinskiThe notify library implements an event bus, allowing users to register, generate, 426f30603SPiotr Pelplinskiand listen for events. For example, the bdev library may register a new event type 526f30603SPiotr Pelplinskifor bdev creation. Any time a bdev is created, it "sends" the event. Consumers of 626f30603SPiotr Pelplinskithat event may periodically poll for new events to retrieve them. 726f30603SPiotr PelplinskiThe event bus is implemented as a circular ring of fixed size. If event consumers 826f30603SPiotr Pelplinskido not poll frequently enough, events may be lost. All events are identified by a 926f30603SPiotr Pelplinskimonotonically increasing integer, so missing events may be detected, although 1026f30603SPiotr Pelplinskinot recovered. 1126f30603SPiotr Pelplinski 12*1e1fd9acSwawryk## Register event types {#notify_register} 1326f30603SPiotr Pelplinski 1426f30603SPiotr PelplinskiDuring initialization the sender library should register its own event types using 1526f30603SPiotr Pelplinski`spdk_notify_type_register(const char *type)`. Parameter 'type' is the name of 1626f30603SPiotr Pelplinskinotification type. 1726f30603SPiotr Pelplinski 18*1e1fd9acSwawryk## Get info about events {#notify_get_info} 1926f30603SPiotr Pelplinski 2026f30603SPiotr PelplinskiA consumer can get information about the available event types during runtime using 2187201f17Swuzhouhui`spdk_notify_foreach_type`, which iterates over registered notification types and 2226f30603SPiotr Pelplinskicalls a callback on each of them, so that user can produce detailed information 2326f30603SPiotr Pelplinskiabout notification. 2426f30603SPiotr Pelplinski 25*1e1fd9acSwawryk## Get new events {#notify_listen} 2626f30603SPiotr Pelplinski 27ab3f35b2SwuzhouhuiA consumer can get events by calling function `spdk_notify_foreach_event`. 2826f30603SPiotr PelplinskiThe caller should specify last received event and the maximum number of invocations. 2926f30603SPiotr PelplinskiThere might be multiple consumers of each event. The event bus is implemented as a 3026f30603SPiotr Pelplinskicircular buffer, so older events may be overwritten by newer ones. 3126f30603SPiotr Pelplinski 32*1e1fd9acSwawryk## Send events {#notify_send} 3326f30603SPiotr Pelplinski 3426f30603SPiotr PelplinskiWhen an event occurs, a library can invoke `spdk_notify_send` with two strings. 3526f30603SPiotr PelplinskiOne containing the type of the event, like "spdk_bdev_register", second with context, 3626f30603SPiotr Pelplinskifor example "Nvme0n1" 3726f30603SPiotr Pelplinski 38*1e1fd9acSwawryk## RPC Calls {#rpc_calls} 3926f30603SPiotr Pelplinski 40c7174d9eSMaciej WawrykSee [JSON-RPC documentation](jsonrpc.md/#rpc_notify_get_types) 41