bio
 
Loading...
Searching...
No Matches
service.h
1#ifndef BIO_SERVICE_H
2#define BIO_SERVICE_H
3
4#include <bio/bio.h>
5#include <bio/mailbox.h>
6
47
54typedef struct {
55 bio_signal_t bio__ack_signal;
56 bio_signal_t bio__cancel_signal;
58
78
84#define BIO_SERVICE(T) \
85 struct { \
86 bio_coro_t coro; \
87 BIO_MAILBOX(T) mailbox; \
88 }
89
91#define BIO_SERVICE_MSG bio_service_msg_base_t bio__service_msg_base;
92
102#define bio_start_service(ptr, entry, args) \
103 bio_start_service_ex(ptr, entry, args, NULL)
104
120#define bio_start_service_ex(ptr, entry, args, options) \
121 bio__service_start(\
122 &(ptr)->coro, \
123 &(ptr)->mailbox.bio__handle, \
124 sizeof(*((ptr)->mailbox.bio__message)), \
125 options, \
126 entry, \
127 &args, \
128 sizeof(args) \
129 )
130
141#define bio_stop_service(service) \
142 bio__service_stop((service).coro, (service).mailbox.bio__handle)
143
152#define bio_get_service_info(userdata, mailbox_ptr, args_ptr) \
153 bio__service_get_info(userdata, &(mailbox_ptr)->bio__handle, args_ptr)
154
180#define bio_call_service(service, message, cancel_signal) \
181 ( \
182 BIO__TYPECHECK_EXP((message), *((service).mailbox.bio__message)), \
183 bio__service_call( \
184 (service).coro, \
185 (service).mailbox.bio__handle, \
186 &((message).bio__service_msg_base), \
187 &(message), \
188 sizeof(message), \
189 cancel_signal \
190 ) \
191 )
192
199#define bio_service_state(service) \
200 bio_coro_state((service).coro)
201
215#define bio_notify_service(service, message, retry_condition) \
216 bio_wait_and_send_message( \
217 ((bio_service_state(service) != BIO_CORO_DEAD) && (retry_condition)), \
218 (service).mailbox, \
219 (message) \
220 )
221
235#define bio_is_call_cancelled(msg) \
236 bio__service_is_call_cancelled(&(msg).bio__service_msg_base)
237
249#define bio_service_loop(msg, mailbox) \
250 bio_foreach_message(msg, mailbox) \
251 for ( \
252 int bio__svc_loop = 0; \
253 (bio__svc_loop < 1) && !bio_is_call_cancelled(msg); \
254 ++bio__svc_loop \
255 )
256
316#define bio_respond(msg) \
317 for ( \
318 bool bio__should_respond = bio_begin_response(msg); \
319 bio__should_respond; \
320 bio__should_respond = false, bio_end_response(msg) \
321 )
322
323#ifndef DOXYGEN
324
325#define bio_begin_response(msg) \
326 (bio__service_begin_response(&(msg).bio__service_msg_base))
327
328#define bio_end_response(msg) \
329 bio_raise_signal((msg).bio__service_msg_base.bio__ack_signal)
330
331void
332bio__service_start(
333 bio_coro_t* coro_ptr,
334 bio_handle_t* mailbox_ptr,
335 size_t mailbox_msg_size,
336 const bio_service_options_t* service_options,
337 bio_entrypoint_t entry,
338 const void* args,
339 size_t args_size
340);
341
342void
343bio__service_get_info(void* userdata, bio_handle_t* mailbox_ptr, void* args);
344
345void
346bio__service_stop(bio_coro_t coro, bio_handle_t mailbox);
347
349bio__service_call(
350 bio_coro_t coro,
351 bio_handle_t mailbox,
352 bio_service_msg_base_t* service_msg_base,
353 const void* msg,
354 size_t msg_size,
355 bio_signal_t cancel_signal
356);
357
358bool
359bio__service_is_call_cancelled(const bio_service_msg_base_t* msg_base);
360
361bool
362bio__service_begin_response(const bio_service_msg_base_t* msg_base);
363
364#endif
365
368#endif
void(* bio_entrypoint_t)(void *userdata)
Entrypoint for a coroutine.
Definition bio.h:120
bio_call_status_t
The status of a call using bio_call_service.
Definition service.h:39
@ BIO_CALL_TARGET_DEAD
The service has terminated during or before the call.
Definition service.h:45
@ BIO_CALL_CANCELLED
The call was cancelled by the caller.
Definition service.h:43
@ BIO_CALL_OK
The call was handled by the service.
Definition service.h:41
Coroutine spawn options.
Definition bio.h:535
Handle to a coroutine.
Definition bio.h:137
Definition bio.h:126
The base for a message type of a service.
Definition service.h:54
Options for service.
Definition service.h:64
uint32_t mailbox_capacity
Capacity of the service's mailbox.
Definition service.h:76
bio_coro_options_t coro_options
Coroutine options.
Definition service.h:70
Handle to a signal.
Definition bio.h:147