NewMadeleine

Documentation

nm_rpc_private.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_PRIVATE_H
17#define NM_RPC_PRIVATE_H
18
24#include <assert.h>
25#include <nm_log.h>
26#include <nm_core_interface.h>
27
30{
39};
40
44{
45 PUK_LIST_LINK(nm_rpc_token);
50 void*ref;
51 int delayed;
53};
55
58{
59 struct nm_rpc_token_list_s token_list;
66 void*ref;
67 int running;
68};
69
70
71/* ** inline function ************************************** */
72
75
77 void*hptr, nm_len_t hlen, struct nm_data_s*p_body)
78{
79 nm_rpc_req_t p_req = nm_rpc_isend(p_service, p_gate, tag, hptr, hlen, p_body);
80 nm_rpc_req_wait(p_req);
81}
82
84{
85 p_req->priority = priority;
86}
87
88static inline void nm_rpc_req_wait(nm_rpc_req_t p_req)
89{
90 nm_sr_swait(p_req->request.p_session, &p_req->request);
91 nm_rpc_req_delete(p_req);
92}
93
94static inline void nm_rpc_req_wait_all(nm_rpc_req_t*p_reqs, int n)
95{
96 assert((void*)&p_reqs[0]->request == (void*)p_reqs[0]); /* nm_sr_request_t must be the first field in nm_rpc_req_s */
98 int i;
99 for(i = 0; i < n; i++)
100 {
101 if(p_reqs[i] != NULL)
102 nm_rpc_req_delete(p_reqs[i]);
103 }
104}
105
106static inline void*nm_rpc_service_get_ref(struct nm_rpc_service_s*p_service)
107{
108 return p_service->ref;
109}
110
111static inline nm_gate_t nm_rpc_get_source(struct nm_rpc_token_s*p_token)
112{
114 return p_gate;
115}
116
117static inline nm_tag_t nm_rpc_get_tag(struct nm_rpc_token_s*p_token)
118{
120 return tag;
121}
122
124{
125 return p_token->p_service;
126}
127
128static inline void*nm_rpc_token_get_ref(struct nm_rpc_token_s*p_token)
129{
130 return p_token->ref;
131}
132
133static inline void nm_rpc_token_set_ref(struct nm_rpc_token_s*p_token, void*ref)
134{
135 p_token->ref = ref;
136}
137
138static inline void nm_rpc_token_delay(struct nm_rpc_token_s*p_token)
139{
140 p_token->delayed = 1;
141}
142
143static inline void nm_rpc_recv_header_data(nm_rpc_token_t p_token, struct nm_data_s*p_header)
144{
145 assert(nm_datav_size(&p_token->bodyv) == 0); /* all headers must be unpacked before body chunks */
146 const nm_len_t peek_offset = nm_datav_size(&p_token->headerv); /* compute size of headers so far */
147 const nm_len_t peek_size = nm_data_size(p_header);
148 struct nm_data_s datav;
149 nm_datav_add_chunk_data(&p_token->headerv, p_header);
150 nm_data_datav_build(&datav, &p_token->headerv); /* build data type for full header */
151 int rc = nm_sr_recv_peek_offset(p_token->p_service->p_session, &p_token->request, &datav, peek_offset, peek_size);
152 if(rc != NM_ESUCCESS)
153 {
154 NM_FATAL("# nm_rpc: rc = %d in nm_sr_recv_peek()\n", rc);
155 }
156 nm_datav_uncommit(&p_token->headerv);
157 nm_sr_recv_offset(p_token->p_service->p_session, &p_token->request, peek_offset + peek_size);
158}
159
160static inline void nm_rpc_recv_header(nm_rpc_token_t p_token, void*hptr, nm_len_t hlen)
161{
162 struct nm_data_s data;
163 nm_data_contiguous_build(&data, (void*)hptr, hlen);
164 nm_rpc_recv_header_data(p_token, &data);
165}
166
167static inline void nm_rpc_irecv_body_data(struct nm_rpc_token_s*p_token, struct nm_data_s*p_body)
168{
169 nm_datav_add_chunk_data(&p_token->bodyv, p_body);
170}
171
172static inline void nm_rpc_irecv_body(nm_rpc_token_t p_token, void*ptr, nm_len_t len)
173{
174 struct nm_data_s data;
175 nm_data_contiguous_build(&data, (void*)ptr, len);
176 nm_rpc_irecv_body_data(p_token, &data);
177}
178
179#endif /* NM_RPC_PRIVATE_H */
nm_status_t nm_cond_status_t
status with synchronization (wait/signal)
@ NM_ESUCCESS
successful operation
Definition: nm_errno.h:34
static void nm_datav_uncommit(struct nm_datav_s *p_datav)
'uncommit' a datav: explicitely declare that nm_data pointing to this datav has been destroyed.
Definition: nm_data.h:611
static nm_len_t nm_datav_size(struct nm_datav_s *p_datav)
get the size (number of bytes) of data contained in the datav
Definition: nm_data.h:600
static void nm_datav_add_chunk_data(struct nm_datav_s *p_datav, const struct nm_data_s *p_data)
add a chunk of data to datav; given p_data content is copied.
Definition: nm_data.h:572
static nm_len_t nm_data_size(const struct nm_data_s *p_data)
returns the amount of data contained in the descriptor
Definition: nm_data.h:440
void(* nm_rpc_handler_t)(nm_rpc_token_t p_token)
a RPC handler called upon request invocation
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.
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
void(* nm_rpc_finalizer_t)(nm_rpc_token_t p_token)
a RPC finalizer, called when all data has been received
static nm_gate_t nm_sr_request_get_gate(nm_sr_request_t *p_request)
static nm_tag_t nm_sr_request_get_tag(nm_sr_request_t *p_request)
Retrieve the tag from a sendrecv request.
static void nm_sr_request_wait_all(nm_sr_request_t **p_requests, int n)
wait for completion of an array of requests
nm_tag_t tag
the user-supplied tag
static void nm_data_contiguous_build(struct nm_data_s *p_data, void *ptr, nm_len_t len)
Definition: nm_data.h:315
static void nm_data_datav_build(struct nm_data_s *p_datav_data, struct nm_datav_s *p_datav)
frontend to build a nm_data from a datav
Definition: nm_data.h:351
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
Basic primitives to display info & warnings.
#define NM_FATAL(format,...)
Definition: nm_log.h:36
static void nm_rpc_req_set_priority(nm_rpc_req_t p_req, nm_prio_t priority)
static nm_rpc_service_t nm_rpc_get_service(struct nm_rpc_token_s *p_token)
static void nm_rpc_recv_header(nm_rpc_token_t p_token, void *hptr, nm_len_t hlen)
void nm_rpc_req_delete(nm_rpc_req_t p_rpc_req)
static void * nm_rpc_service_get_ref(struct nm_rpc_service_s *p_service)
PUK_LIST_DECLARE_TYPE(nm_rpc_token)
static void nm_rpc_token_set_ref(struct nm_rpc_token_s *p_token, void *ref)
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)
static void nm_rpc_req_wait(nm_rpc_req_t p_req)
static void nm_rpc_irecv_body(nm_rpc_token_t p_token, void *ptr, nm_len_t len)
PUK_LIST_CREATE_FUNCS(nm_rpc_token)
static nm_tag_t nm_rpc_get_tag(struct nm_rpc_token_s *p_token)
static void * nm_rpc_token_get_ref(struct nm_rpc_token_s *p_token)
static void nm_rpc_recv_header_data(nm_rpc_token_t p_token, struct nm_data_s *p_header)
static void nm_rpc_irecv_body_data(struct nm_rpc_token_s *p_token, struct nm_data_s *p_body)
static void nm_rpc_req_wait_all(nm_rpc_req_t *p_reqs, int n)
static nm_gate_t nm_rpc_get_source(struct nm_rpc_token_s *p_token)
static void nm_rpc_token_delay(struct nm_rpc_token_s *p_token)
static int nm_sr_swait(nm_session_t p_session, nm_sr_request_t *p_request)
Wait for the completion of a non blocking send request.
static void nm_sr_recv_offset(nm_session_t p_session, nm_sr_request_t *p_request, nm_len_t offset)
set offset of data to receive; data before offset will be discarded
static int nm_sr_recv_peek_offset(nm_session_t p_session, nm_sr_request_t *p_request, const struct nm_data_s *p_data, nm_len_t peek_offset, nm_len_t peek_len)
peek for already received (unexpected) data, with offset and explicit len
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
encapsulate a dynamic vector of nm_data
Definition: nm_data.h:245
Connection to another process.
Definition: nm_gate.h:100
an outgoing rpc request
struct nm_datav_s headerv
vector of user-supplied chunks of headers
nm_prio_t priority
nm_sr_request_t request
the sendrecv request, actually allocated here
nm_rpc_req_notifier_t p_notifier
notification function to call uppon req completion
struct nm_datav_s bodyv
vector of user-supplied chunks of body
nm_len_t extra_hlen
size added to default header size
void * p_notifier_ref
user-supplied parameter for the notifier
struct nm_rpc_service_s * p_service
descriptor for a registered RPC service
nm_tag_t tag
tag(s) to listen to for this service
nm_session_t p_session
session used to send/recv requests
nm_tag_t tag_mask
tag mask to apply to above tag
int running
whether the service is currently running
nm_rpc_finalizer_t p_finalizer
user-supplied function, called upon data body arrival
nm_rpc_handler_t p_handler
user-supplied function, called upon header arrival
struct nm_rpc_token_list_s token_list
tokens given to rpc handlers
nm_spinlock_t token_list_lock
lock for the above list
void * ref
user-supplied ref for the service
an incoming rpc request
void * ref
user ref for the token
nm_sr_request_t request
the sr request used for the full rpc_body_data
struct nm_datav_s bodyv
struct nm_rpc_service_s * p_service
service this token belongs to
int delayed
if set to 1, unpack data later
nm_cond_status_t done
PUK_LIST_LINK(nm_rpc_token)
struct nm_datav_s headerv
internal defintion of the sendrecv request
nm_session_t p_session
session this request belongs to