58 #include <uriparser/Uri.h>
60 #include <amxc/amxc.h>
61 #include <amxp/amxp.h>
63 #include <amxd/amxd_dm.h>
75 return amxc_string_append(buffer, tr->first, tr->afterLast - tr->first);
79 UriPathSegmentA* ps) {
81 const char* sep =
"/";
83 amxc_string_append(buffer, sep, strlen(sep));
99 amxc_string_t uri_part;
100 amxc_string_init(&uri_part, 0);
102 when_failed(uriParseSingleUriA(&parsed_uri, uri, NULL), exit);
104 *scheme = amxc_string_take_buffer(&uri_part);
105 when_null(*scheme, exit_clean);
107 *host = amxc_string_take_buffer(&uri_part);
109 *port = amxc_string_take_buffer(&uri_part);
111 *path = amxc_string_take_buffer(&uri_part);
116 uriFreeUriMembersA(&parsed_uri);
119 amxc_string_clean(&uri_part);
127 when_null(*ctx, exit);
129 (*ctx)->bus_fn = fns;
130 amxp_sigmngr_init(&(*ctx)->sigmngr);
131 amxc_htable_init(&(*ctx)->subscriptions, 5);
132 amxc_llist_init(&(*ctx)->client_subs);
150 when_null(ctx, exit);
151 when_not_null(*ctx, exit);
206 when_failed(retval, exit);
207 if((host != NULL) && (*host != 0) && (intf != NULL) && (*intf != 0)) {
209 amxc_string_t host_intf;
210 amxc_string_init(&host_intf, 64);
211 amxc_string_setf(&host_intf,
"%s%%%s", host, intf);
213 host = amxc_string_take_buffer(&host_intf);
214 amxc_string_clean(&host_intf);
248 when_failed(retval, exit);
271 const char* uri = NULL;
277 when_null(listen_ctx, exit);
278 uri = amxc_htable_it_get_key(&listen_ctx->
hit);
279 when_null(listen_ctx, exit);
281 when_failed(retval, exit);
284 if((*accepted_ctx)->bus_ctx == NULL) {
287 (*accepted_ctx)->dm = listen_ctx->
dm;
288 amxc_llist_append(&fns->
connections, &(*accepted_ctx)->it);
307 when_null(ctx, exit);
308 when_null(ctx->
bus_ctx, exit_clean);
324 if(fns->
free != NULL) {
331 amxc_llist_it_take(&ctx->
it);
332 amxc_htable_it_clean(&ctx->
hit, NULL);
340 when_null(ctx, exit);
341 when_null(*ctx, exit);
344 amxp_sigmngr_clean(&(*ctx)->sigmngr);
346 amxc_htable_for_each(it, &(*ctx)->subscriptions) {
348 amxc_htable_it_clean(it, NULL);
351 amxc_htable_clean(&(*ctx)->subscriptions, NULL);
361 amxc_htable_it_t* hit = amxc_htable_get(&
uri_bus_ctxs, uri);
371 amxc_array_t* keys = amxc_htable_get_sorted_keys(&
uri_bus_ctxs);
379 when_null(ctx, exit);
385 when_true(retval < 0, exit);
396 when_null(ctx, exit);
412 when_null(ctx, exit);
414 when_null(buf, exit);
415 when_true(count == 0, exit);
Ambiorix bus agnostic API header file.
static int amxb_bus_ctx_be_init(amxb_bus_ctx_t *ctx, amxb_be_funcs_t *fns, amxb_be_connect_fn_t fn, const char *uri, const char *host, const char *port, const char *path)
static int amxb_uri_part_to_string(amxc_string_t *buffer, UriTextRangeA *tr)
static int amxb_bus_ctx_init(amxb_bus_ctx_t **ctx, amxb_be_funcs_t *fns)
static amxc_htable_t uri_bus_ctxs
static int amxb_uri_path_to_string(amxc_string_t *buffer, UriPathSegmentA *ps)
static DESTRUCTOR void amxb_cleanup_connections(void)
static int amxb_bus_ctx_create(amxb_bus_ctx_t **ctx, amxb_be_funcs_t **fns, const char *uri, char **scheme, char **host, char **port, char **path)
static int amxb_uri_parse(const char *uri, char **scheme, char **host, char **port, char **path)
static CONSTRUCTOR void amxb_initialize_connections(void)
static void amxb_free_request(amxc_llist_it_t *it)
Ambiorix Bus Backend Interface.
int PRIVATE amxb_subscription_remove(amxb_subscription_t *subscription)
#define amxb_is_valid_be_func(ft, member, ptr)
void PRIVATE amxb_dm_event_to_object_event(const char *const sig_name, const amxc_var_t *const data, void *const priv)
void *(* amxb_be_connect_fn_t)(const char *host, const char *port, const char *path, amxp_signal_mngr_t *sigmngr)
Opens a bus connection or creates a socket connection.
void amxb_be_cache_remove_ctx(amxb_bus_ctx_t *ctx)
Removes a bus context from the lookup cache.
amxb_be_funcs_t * amxb_be_find(const char *name)
Gets a backend function table using its name.
int amxb_connect_intf(amxb_bus_ctx_t **ctx, const char *uri, const char *intf)
Create a bus connection.
int amxb_accept(amxb_bus_ctx_t *listen_ctx, amxb_bus_ctx_t **accepted_ctx)
Accepts an incomming connection request.
int amxb_listen(amxb_bus_ctx_t **ctx, const char *uri)
Create a listen socket.
amxc_array_t * amxb_list_uris(void)
List all open connections by their uri.
int amxb_connect(amxb_bus_ctx_t **ctx, const char *uri)
Create a bus connection.
amxb_bus_ctx_t * amxb_find_uri(const char *uri)
Find the bus context for a given uri.
int amxb_read_raw(const amxb_bus_ctx_t *const ctx, void *buf, size_t count)
Attempts to read up to count bytes from the file descriptor into the buffer starting at buf.
void amxb_free(amxb_bus_ctx_t **ctx)
Frees allocated memory.
int amxb_get_fd(const amxb_bus_ctx_t *const ctx)
Get the connection file descriptor.
int amxb_disconnect(amxb_bus_ctx_t *ctx)
Disconnects a bus connection.
int amxb_read(const amxb_bus_ctx_t *const ctx)
Reads data from the file descriptor.
#define AMXB_ERROR_BACKEND_FAILED
Back-end failed.
#define AMXB_ERROR_NOT_SUPPORTED_OP
Function/operation not supported.
#define AMXB_ERROR_NOT_SUPPORTED_SCHEME
URI scheme not supported.
#define AMXB_ERROR_INVALID_URI
Invalid URI.
The back-end interface structure.
amxb_be_connect_fn_t connect
amxb_be_disconnect_fn_t disconnect
amxb_be_accept_fn_t accept
amxb_be_listen_fn_t listen
amxb_be_read_raw_fn_t read_raw
amxb_be_get_fd_fn_t get_fd
const amxb_be_funcs_t * bus_fn
amxp_signal_mngr_t sigmngr