NewMadeleine

Documentation

nm_rpc_interface.h
Go to the documentation of this file.
1/*
2 * NewMadeleine
3 * Copyright (C) 2016-2023 (see AUTHORS file)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#ifndef NM_RPC_INTERFACE_H
17#define NM_RPC_INTERFACE_H
18
19#include <nm_public.h>
22
71
74
77
79typedef void (*nm_rpc_handler_t)(nm_rpc_token_t p_token);
80
82typedef void (*nm_rpc_finalizer_t)(nm_rpc_token_t p_token);
83
85typedef void (*nm_rpc_req_notifier_t)(nm_rpc_req_t p_req, void*ref);
86
87/* ** service registration ********************************* */
88
95 nm_rpc_handler_t p_handler, nm_rpc_finalizer_t p_finalizer,
96 void*ref);
97
100
103
104
105/* ** send requests **************************************** */
106
109
112
116void nm_rpc_req_pack_header(nm_rpc_req_t p_rpc_req, const void*ptr, nm_len_t len);
117
121void nm_rpc_req_pack_body(nm_rpc_req_t p_rpc_req, const void*ptr, nm_len_t len);
122
127void nm_rpc_req_pack_body_data(nm_rpc_req_t p_rpc_req, const struct nm_data_s*p_data);
128
129
133
137
139static inline void nm_rpc_req_wait(nm_rpc_req_t p_req);
140
142static inline void nm_rpc_req_wait_all(nm_rpc_req_t*p_reqs, int n);
143
146
149 void*hptr, nm_len_t hlen, struct nm_data_s*p_body);
150
153 void*hptr, nm_len_t hlen, struct nm_data_s*p_body);
154
155
156/* ** receive requests ************************************* */
157
160
163
166
168static inline void nm_rpc_token_set_ref(nm_rpc_token_t p_token, void*ref);
169
171static inline void*nm_rpc_token_get_ref(nm_rpc_token_t p_token);
172
174static inline void nm_rpc_recv_header(nm_rpc_token_t p_token, void*hptr, nm_len_t hlen);
175
177static inline void nm_rpc_recv_header_data(nm_rpc_token_t p_token, struct nm_data_s*p_header);
178
182static inline void nm_rpc_irecv_body(nm_rpc_token_t p_token, void*ptr, nm_len_t len);
183
187static inline void nm_rpc_irecv_body_data(nm_rpc_token_t p_token, struct nm_data_s*p_body);
188
192static inline void nm_rpc_token_delay(struct nm_rpc_token_s*p_token);
193
196
200/* ********************************************************* */
201
203#include <nm_rpc_private.h>
204
205#endif /* NM_RPC_INTERFACE_H */
void nm_rpc_req_set_notifier(nm_rpc_req_t p_req, nm_rpc_req_notifier_t p_notifier, void *ref)
set a handler called upon RPC send completion
static void nm_rpc_req_set_priority(nm_rpc_req_t p_req, nm_prio_t priority)
set priority of the rpc send request
static void nm_rpc_token_set_ref(nm_rpc_token_t p_token, void *ref)
attach a user reference to a token, to transmit information between rpc handler and finalizer
void(* nm_rpc_handler_t)(nm_rpc_token_t p_token)
a RPC handler called upon request invocation
static void nm_rpc_recv_header(nm_rpc_token_t p_token, void *hptr, nm_len_t hlen)
receive header; to be called from a handler; data is available immediately upon function return
void nm_rpc_req_pack_body(nm_rpc_req_t p_rpc_req, const void *ptr, nm_len_t len)
pack a body chunk into an rpc request; may be called multiple times for multiple body chunks.
struct nm_rpc_req_s * nm_rpc_req_t
a RPC send request
nm_rpc_req_t nm_rpc_req_init(nm_rpc_service_t p_service, nm_gate_t p_gate, nm_tag_t tag)
initializes a new rpc send request
struct nm_rpc_service_s * nm_rpc_service_t
a RPC registered service
nm_rpc_req_t nm_rpc_isend(nm_rpc_service_t p_service, nm_gate_t p_gate, nm_tag_t tag, void *hptr, nm_len_t hlen, struct nm_data_s *p_body)
Legacy function to send an rpc request with one header and one nm_data body; non-blocking.
static void nm_rpc_send(nm_rpc_service_t p_service, nm_gate_t p_gate, nm_tag_t tag, void *hptr, nm_len_t hlen, struct nm_data_s *p_body)
Legacy function to send an rpc request with one header and one nm_data body; blocking.
void(* nm_rpc_req_notifier_t)(nm_rpc_req_t p_req, void *ref)
a RPC req notifier, called when the request send operation is completed
static void nm_rpc_req_wait(nm_rpc_req_t p_req)
wait for a send request completion
void nm_rpc_token_complete(struct nm_rpc_token_s *p_token)
complete a delayed RPC request
static void nm_rpc_irecv_body(nm_rpc_token_t p_token, void *ptr, nm_len_t len)
asynchronously posts the recv for the body of a received request; to be called from a handler; there ...
void nm_rpc_req_pack_header(nm_rpc_req_t p_rpc_req, const void *ptr, nm_len_t len)
pack a header chunk into an rpc request; may be called multiple times for multiple header chunks.
static void nm_rpc_irecv_body_data(nm_rpc_token_t p_token, struct nm_data_s *p_body)
asynchronously posts the recv for the body of a received request; to be called from a handler; same a...
void(* nm_rpc_finalizer_t)(nm_rpc_token_t p_token)
a RPC finalizer, called when all data has been received
static void nm_rpc_recv_header_data(nm_rpc_token_t p_token, struct nm_data_s *p_header)
receive header; to be called from a handler
static void * nm_rpc_service_get_ref(nm_rpc_service_t p_service)
get a user reference given upon service registration
static nm_gate_t nm_rpc_get_source(nm_rpc_token_t p_token)
get the source for the received request; to be called from a handler
void nm_rpc_req_set_hlen(nm_rpc_req_t p_rpc_req, nm_len_t hlen)
add extra size to the default hlen, so as to consider beginning of body as header.
void nm_rpc_req_isend(nm_rpc_req_t p_req)
send an rpc request once it is built; non-blocking operation, user must set a notifier or explicitely...
static nm_rpc_service_t nm_rpc_get_service(nm_rpc_token_t p_token)
get the service on which the given request has arrived
void nm_rpc_req_pack_body_data(nm_rpc_req_t p_rpc_req, const struct nm_data_s *p_data)
pack a body chunk into an rpc request (using an nm_data type); may be called multiple times for multi...
void nm_rpc_unregister(nm_rpc_service_t p_service)
stop listenning from RPC requests on given service
static void * nm_rpc_token_get_ref(nm_rpc_token_t p_token)
get a user reference previously attached to the token
static void nm_rpc_req_wait_all(nm_rpc_req_t *p_reqs, int n)
wait for completion of a vector of send requests
struct nm_rpc_token_s * nm_rpc_token_t
a RPC invocation token given to handlers
static nm_tag_t nm_rpc_get_tag(nm_rpc_token_t p_token)
get the tag for the received request; to be called from a handler
static void nm_rpc_token_delay(struct nm_rpc_token_s *p_token)
delay the unpacking of received body data.
nm_rpc_service_t nm_rpc_register(nm_session_t p_session, nm_tag_t tag, nm_tag_t tag_mask, nm_rpc_handler_t p_handler, nm_rpc_finalizer_t p_finalizer, void *ref)
register a new RPC service, listenning on the given tag/tag_mask.
nm_tag_t tag
the user-supplied tag
static nm_session_t p_session
static nm_gate_t p_gate
nm_prio_t priority
Definition: nm_headers.h:6
uint16_t hlen
length in header (header + data in header)
Definition: nm_headers.h:5
uint16_t len
chunk len
Definition: nm_headers.h:0
This is the common public header for NewMad.
Private header for the RPC interface; this is not part of the public API and is not supposed to be us...
int32_t nm_prio_t
message priority
Definition: nm_types.h:80
uint64_t nm_tag_t
user tags, 64 bits, contained in indirect hashtable
Definition: nm_types.h:58
uint64_t nm_len_t
data length used by nmad
Definition: nm_types.h:70
a data descriptor, used to pack/unpack data from app layout to/from contiguous buffers
Definition: nm_data.h:189
Connection to another process.
Definition: nm_gate.h:100
an outgoing rpc request
descriptor for a registered RPC service
an incoming rpc request
void * ref
user ref for the token
struct nm_rpc_service_s * p_service
service this token belongs to