64 #include <amxc/amxc.h>
65 #include <amxp/amxp.h>
67 #include <amxd/amxd_dm.h>
68 #include <amxd/amxd_object.h>
69 #include <amxd/amxd_path.h>
75 #include "amxb_version.h"
92 .
major = AMXB_VERSION_MAJOR,
93 .minor = AMXB_VERSION_MINOR,
94 .build = AMXB_VERSION_BUILD
98 void* handle = fns->handle;
99 char* no_dlclose = getenv(
"AMXB_NO_DLCLOSE");
103 if(no_dlclose == NULL) {
104 retval = dlclose(handle);
106 const char* errstr = dlerror();
107 printf(
"dlclose failed - %s", errstr != NULL? errstr:
"no error");
120 amxc_htable_it_t* it) {
132 const amxc_var_t* args,
137 amxc_llist_for_each(it, connections) {
142 retval = fn(ctx, args, priv);
143 when_failed(retval, exit);
162 amxd_path_init(&path, NULL);
163 amxd_path_setf(&path,
true,
"%s",
object);
167 object = amxd_path_get(&path, 0);
169 part = amxd_path_get_last(&path,
true);
170 }
while(part != NULL && !retval);
172 amxd_path_clean(&path);
180 const amxc_var_t*
const data,
182 bool* found = (
bool*) priv;
190 const char* object_path,
196 char* fixed_path = NULL;
199 amxd_path_init(&path, NULL);
200 amxc_var_init(&data);
201 amxd_path_setf(&path,
true,
"%s", object_path);
202 fixed_path = amxd_path_get_fixed_part(&path,
false);
205 if((fixed_path != NULL) && (*fixed_path != 0)) {
206 int len = strlen(fixed_path);
207 if(fixed_path[len - 1] ==
'.') {
208 fixed_path[len - 1] = 0;
212 amxc_llist_for_each(it, connections) {
228 if(amxc_var_is_null(&data)) {
245 amxd_path_clean(&path);
246 amxc_var_clean(&data);
251 amxc_var_t*
const config) {
259 amxc_htable_it_t* cache_hit = NULL;
262 when_str_empty(object_path, exit);
263 when_true(strcmp(object_path,
".") == 0, exit);
266 if(cache_hit != NULL) {
286 amxc_htable_it_clean(&cache->
hit, NULL);
292 when_null(cache, exit);
341 if((min->
major == -1) || (max->
major == -1)) {
374 amxc_htable_it_t* hit = NULL;
376 when_null(funcs, exit);
377 when_null(funcs->
name, exit);
378 when_true(*(funcs->
name) == 0, exit);
385 when_not_null(hit, exit);
391 amxc_htable_it_init(&funcs->
it);
396 amxc_var_t* cfg = amxc_var_get_key(
amxb_conf, funcs->
name, AMXC_VAR_FLAG_DEFAULT);
408 amxc_htable_it_t* hit = NULL;
410 when_null(funcs, exit);
411 when_null(funcs->
name, exit);
412 when_true(*(funcs->
name) == 0, exit);
416 when_null(hit, exit);
417 when_true(hit != &funcs->
it, exit);
434 amxc_htable_it_t* hit = NULL;
436 when_null(name, exit);
437 when_true(*(name) == 0, exit);
440 when_null(hit, exit);
452 amxc_htable_it_t* hit = NULL;
454 when_null(name, exit);
455 when_true(*(name) == 0, exit);
458 when_null(hit, exit);
463 when_null(be_get_info, exit);
464 info = be_get_info();
475 when_str_empty(path_name, exit);
482 handle = dlopen(path_name, RTLD_LAZY);
484 const char* errstr = dlerror();
485 printf(
"DLOPEN - %s\n", errstr != NULL? errstr:
"no error");
490 when_null(be_get_info, exit);
529 if((retval != 0) && (handle != NULL)) {
538 const amxc_llist_t* list = NULL;
539 amxc_llist_t list_bes;
541 amxc_llist_init(&list_bes);
543 when_null(bes, exit);
544 when_true(amxc_var_type_of(bes) != AMXC_VAR_ID_LIST &&
545 amxc_var_type_of(bes) != AMXC_VAR_ID_CSTRING, exit);
548 if(amxc_var_type_of(bes) == AMXC_VAR_ID_CSTRING) {
549 amxc_string_t* str_bes = amxc_var_take(amxc_string_t, bes);
550 when_null(str_bes, exit);
551 amxc_string_split_to_llist(str_bes, &list_bes,
':');
553 amxc_var_set_type(bes, AMXC_VAR_ID_LIST);
554 amxc_llist_for_each(it, (&list_bes)) {
555 amxc_string_t* str = amxc_string_from_llist_it(it);
556 amxc_var_add(cstring_t, bes, amxc_string_get(str, 0));
558 amxc_string_delete(&str_bes);
560 list = amxc_var_constcast(amxc_llist_t, bes);
562 when_true(amxc_llist_is_empty(list), exit);
564 amxc_llist_for_each(it, list) {
565 amxc_var_t* be = amxc_var_from_llist_it(it);
566 if(
amxb_be_load(amxc_var_constcast(cstring_t, be)) == 0) {
567 amxc_var_delete(&be);
574 amxc_llist_clean(&list_bes, amxc_string_list_it_free);
580 amxc_htable_it_t* hit = NULL;
583 when_str_empty(backend_name, exit);
586 when_null(hit, exit);
589 when_null(fns->
handle, exit);
591 amxc_htable_it_clean(hit, NULL);
611 const amxc_var_t* args,
632 const amxc_var_t* args,
655 when_null(ctx, exit);
659 if(cache->
ctx == ctx) {
660 amxc_llist_it_take(&cache->
lit);
661 amxc_htable_it_clean(&cache->
hit, NULL);
671 amxc_htable_it_t* cache_hit = NULL;
674 when_str_empty(object_path, exit);
675 when_true(strcmp(object_path,
".") == 0, exit);
678 when_null(cache_hit, exit);
681 amxc_llist_it_take(&cache->
lit);
682 amxc_htable_it_clean(&cache->
hit, NULL);
694 amxc_llist_it_take(&cache->
lit);
695 amxc_htable_it_clean(&cache->
hit, NULL);
717 amxc_var_t* be_config = GET_ARG(
config, amxc_htable_it_get_key(hit));
718 if(be_config == NULL) {
719 be_config = amxc_var_add_key(amxc_htable_t,
config, amxc_htable_it_get_key(hit), NULL);
Ambiorix bus agnostic API header file.
static const amxc_var_t * amxb_conf
static amxb_be_funcs_t * current_be
static int amxb_be_invoke_on_all_connections(amxc_llist_t *connections, amxb_be_task_fn_t fn, const amxc_var_t *args, uint32_t type, void *priv)
static amxb_version_t lib_version
amxb_bus_ctx_t * amxb_be_who_has_impl(const char *object_path, bool full_match)
static void amxb_be_remove_connections(amxc_llist_it_t *lit)
static void amxb_apply_be_config(amxb_be_funcs_t *funcs, amxc_var_t *const config)
struct _amxb_who_has_cache amxb_who_has_cache_t
static amxc_htable_t amxb_backends
static uint32_t amxb_cache_size
static int amxb_close_backend(UNUSED amxb_be_funcs_t *fns)
static amxb_bus_ctx_t * amxb_be_find_connection(amxc_llist_t *connections, const char *object_path, bool full_match)
static bool amxb_has_object(amxb_bus_ctx_t *bus_ctx, const char *object, bool full_match)
static void amxb_be_object_exists(UNUSED const amxb_bus_ctx_t *bus_ctx, const amxc_var_t *const data, void *priv)
static CONSTRUCTOR void amxb_cache_init(void)
static amxc_llist_t amxb_cache_list
static void amxb_be_remove_backend(UNUSED const char *key, amxc_htable_it_t *it)
static amxc_htable_t amxb_cache_table
static DESTRUCTOR void amxb_cache_clean(void)
Ambiorix Bus Backend Interface.
#define AMXB_BE_DISCOVER_DESCRIBE
#define AMXB_BE_DISCOVER_LIST
#define AMXB_FLAG_FIRST_LVL
#define amxb_is_valid_be_func(ft, member, ptr)
bool PRIVATE amxb_is_local_object(amxb_bus_ctx_t *ctx, const char *obj_path)
uint32_t PRIVATE amxb_be_get_capabilities(amxb_bus_ctx_t *bus_ctx)
int(* amxb_be_task_fn_t)(amxb_bus_ctx_t *bus_ctx, const amxc_var_t *args, void *priv)
amxb_be_info_t *(* amxb_be_info_fn_t)(void)
int amxb_be_for_all_listeners(amxb_be_task_fn_t fn, const amxc_var_t *args, void *priv)
Calls a function on all listen sockets.
int amxb_be_for_all_connections(amxb_be_task_fn_t fn, const amxc_var_t *args, void *priv)
Calls a function on all open connections.
amxb_bus_ctx_t * amxb_be_who_has(const char *object_path)
Searches a bus context that can provide a certain object.
int amxb_be_unregister(amxb_be_funcs_t *const funcs)
Unregisters a backend interface.
void amxb_be_cache_remove_ctx(amxb_bus_ctx_t *ctx)
Removes a bus context from the lookup cache.
const amxb_version_t * amxb_get_version(void)
Gets the version of the library.
int amxb_be_register(amxb_be_funcs_t *const funcs)
Registers backend interface.
void amxb_be_cache_set_size(uint32_t size)
Changes the size of the lookup cache.
const amxb_be_info_t * amxb_be_get_info(const char *name)
Gets a backend information.
int amxb_be_load(const char *path_name)
Loads a shared object that implements a bus specific backend interface.
int amxb_be_load_multiple(amxc_var_t *const bes)
Loads multiple shared objects that each implement a bus specific backend interface.
void amxb_be_cache_remove_path(const char *object_path)
Removes an object path and its corresponding bus context from the lookup cache.
int amxb_check_be_versions(const amxb_version_t *min, const amxb_version_t *max)
Checks if the library version is in the given range.
int amxb_be_remove(const char *backend_name)
Removes and unloads a backend with a given name.
int amxb_check_version(const amxb_version_t *be_version)
Compares the given version with the library version.
amxb_be_funcs_t * amxb_be_find(const char *name)
Gets a backend function table using its name.
int amxb_set_config(amxc_var_t *const config)
Passes configuration options to the backends.
void amxb_be_remove_all(void)
Removes and unloads all backends.
amxc_array_t * amxb_be_list(void)
Get the loaded back-end names.
void amxb_free(amxb_bus_ctx_t **ctx)
Frees allocated memory.
#define AMXB_ERROR_UNKNOWN
Unknown error.
#define AMXB_STATUS_OK
All ok.
int amxb_describe(amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxc_var_t *ret, int timeout)
Describes an object.
int amxb_list(amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxb_be_cb_fn_t fn, void *priv)
List the service elements/nodes of an object.
The back-end interface structure.
amxb_be_set_config_t set_config
const amxb_version_t * min_supported
const amxb_version_t * max_supported
const amxb_be_funcs_t * bus_fn
static amxb_be_info_t be_info
static amxb_version_t be_version
static amxb_bus_ctx_t * bus_ctx