Skip to content

Commit fa7251b

Browse files
committed
Event service extension specfication
Refs #61
1 parent 76cf223 commit fa7251b

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

wsrep_event_service.h

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Copyright (C) 2021 Codership Oy <[email protected]>
3+
*
4+
* This file is part of wsrep-API.
5+
*
6+
* Wsrep-API is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Wsrep-API is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with wsrep-API. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
/** @file wsrep_event_service.h
21+
*
22+
* This file defines interface for various unordered events generated by the
23+
* cluster or the provider.
24+
*
25+
* An event has a type and a payload. The type can be predefined or generic.
26+
* In the first case the payload is a POD C struct. Generic event is a JSON-
27+
* encoded buffer.
28+
*
29+
* The provider which is capable of using the service interface v1 must
30+
* export the following functions.
31+
*
32+
* int wsrep_init_event_service_v1(wsrep_event_service_v1_t*)
33+
* void wsrep_deinit_event_service_v1()
34+
*
35+
* which can be probed by the application.
36+
*
37+
* The application must initialize the service via above init function
38+
* before the provider is initialized via wsrep->init(). The deinit
39+
* function must be called after the provider side resources have been
40+
* released via wsrep->free().
41+
*/
42+
43+
#ifndef WSREP_EVENT_SERVICE_H
44+
#define WSREP_EVENT_SERVICE_H
45+
46+
#include "wsrep_api.h"
47+
48+
#include <sys/types.h> /* posix size_t */
49+
50+
#ifdef __cplusplus
51+
extern "C"
52+
{
53+
#endif /* __cplusplus */
54+
55+
/**
56+
* Type tag for application defined event processing context.
57+
*
58+
* Application may pass pointer to the context when initializing
59+
* the event service. This pointer is passed a first parameter for
60+
* each service call.
61+
*/
62+
typedef struct wsrep_event_context wsrep_event_context_t;
63+
64+
65+
/**
66+
* Event types: generic and concrete
67+
*/
68+
typedef enum wsrep_event_type
69+
{
70+
/**
71+
* Generic JSON-encoded event type.
72+
*/
73+
wsrep_event_generic,
74+
/**
75+
* Progress event.
76+
*/
77+
wsrep_event_progress
78+
}
79+
wsrep_event_type_t;
80+
81+
82+
/**
83+
* Progress event structure
84+
*/
85+
typedef struct wsrep_event_st
86+
{
87+
wsrep_buf_t payload;
88+
wsrep_event_type_t type;
89+
}
90+
wsrep_event_t;
91+
92+
93+
/**
94+
* Progress event structure
95+
*/
96+
typedef struct wsrep_event_progress_st
97+
{
98+
/**
99+
* Total amount of work to do.
100+
*/
101+
uint64_t total;
102+
/**
103+
* Amount of work already done.
104+
*/
105+
uint64_t done;
106+
/**
107+
* Current node state
108+
*/
109+
wsrep_member_status_t status;
110+
}
111+
wsrep_event_progress_t;
112+
113+
/**
114+
* Indefinite progress value when the progress cannot be assessed
115+
*/
116+
static float const wsrep_event_progress_indefinite = -1.0f;
117+
118+
119+
/**
120+
* Process an event
121+
*
122+
* @param event.
123+
*
124+
* @return void, it is up to the receiver to decide what to do about
125+
* possible error.
126+
*/
127+
typedef void (*wsrep_event_cb_t)(wsrep_event_context_t*,
128+
const wsrep_event_t*);
129+
130+
131+
/**
132+
* Event service struct.
133+
*
134+
* A pointer to this struct must be passed to the call to
135+
* wsrep_init_event_service_v1.
136+
*
137+
* The application must provide implementation to all functions defined
138+
* in this struct.
139+
*/
140+
typedef struct wsrep_event_service_v1_st
141+
{
142+
/* Event receiver callback */
143+
wsrep_event_cb_t event_cb;
144+
/* Pointer to application defined event context. */
145+
wsrep_event_context_t* context;
146+
} wsrep_event_service_v1_t;
147+
148+
#ifdef __cplusplus
149+
}
150+
#endif /* __cplusplus */
151+
152+
153+
#define WSREP_EVENT_SERVICE_INIT_FUNC_V1 "wsrep_init_event_service_v1"
154+
#define WSREP_EVENT_SERVICE_DEINIT_FUNC_V1 "wsrep_deinit_event_service_v1"
155+
156+
#endif /* WSREP_EVENT_SERVICE_H */
157+

0 commit comments

Comments
 (0)