libamxb  4.8.2
Bus Agnostic C API
amxb_priv.h File Reference
#include <amxc/amxc_macros.h>

Go to the source code of this file.

Data Structures

struct  _sub
 
struct  _req
 

Macros

#define amxb_is_valid_be_func(ft, member, ptr)    (ft != NULL && offsetof(amxb_be_funcs_t, member) < ft->size && ptr != NULL)
 

Typedefs

typedef struct _sub amxb_sub_t
 
typedef struct _req amxb_req_t
 

Functions

void PRIVATE amxb_dm_event_to_object_event (const char *const sig_name, const amxc_var_t *const data, void *const priv)
 
amxd_object_t * amxb_fetch_local_object (amxb_bus_ctx_t *ctx, const char *object)
 
bool PRIVATE amxb_is_local_object (amxb_bus_ctx_t *ctx, const char *obj_path)
 
int PRIVATE amxb_subscription_remove (amxb_subscription_t *subscription)
 
int PRIVATE amxb_set_impl (amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxc_var_t *values, amxc_var_t *ovalues, amxc_var_t *ret, int timeout)
 
int PRIVATE amxb_follow_reference (amxb_bus_ctx_t *const bus_ctx, amxd_path_t *reference, int timeout)
 
uint32_t PRIVATE amxb_be_get_capabilities (amxb_bus_ctx_t *bus_ctx)
 
amxb_bus_ctx_tamxb_be_who_has_impl (const char *object_path, bool full_match)
 

Macro Definition Documentation

◆ amxb_is_valid_be_func

#define amxb_is_valid_be_func (   ft,
  member,
  ptr 
)     (ft != NULL && offsetof(amxb_be_funcs_t, member) < ft->size && ptr != NULL)

Definition at line 78 of file amxb_priv.h.

Typedef Documentation

◆ amxb_req_t

typedef struct _req amxb_req_t

◆ amxb_sub_t

typedef struct _sub amxb_sub_t

Function Documentation

◆ amxb_be_get_capabilities()

uint32_t PRIVATE amxb_be_get_capabilities ( amxb_bus_ctx_t bus_ctx)

Definition at line 157 of file amxb_ba_priv.c.

157  {
159  const amxb_be_funcs_t* fns = NULL;
160 
161  when_null(bus_ctx, exit);
162  fns = bus_ctx->bus_fn;
163 
164  if(amxb_is_valid_be_func(fns, capabilities, fns->capabilities)) {
165  caps = fns->capabilities(bus_ctx->bus_ctx);
166  }
167 
168 exit:
169  return caps;
170 }
#define AMXB_BE_DISCOVER_RESOLVE
Definition: amxb_be_intf.h:344
#define AMXB_BE_DISCOVER_DESCRIBE
Definition: amxb_be_intf.h:341
#define AMXB_BE_DISCOVER_LIST
Definition: amxb_be_intf.h:342
#define amxb_is_valid_be_func(ft, member, ptr)
Definition: amxb_priv.h:78
static uint32_t caps
Definition: dummy_be.c:70
The back-end interface structure.
amxb_be_capabilities_fn_t capabilities
const amxb_be_funcs_t * bus_fn
Definition: amxb_types.h:121
void * bus_ctx
Definition: amxb_types.h:122
static amxb_bus_ctx_t * bus_ctx
Definition: test_amxb_e2e.c:84

◆ amxb_be_who_has_impl()

amxb_bus_ctx_t* amxb_be_who_has_impl ( const char *  object_path,
bool  full_match 
)

Definition at line 257 of file amxb_backend_mngr.c.

257  {
258  amxb_bus_ctx_t* ctx = NULL;
259  amxc_htable_it_t* cache_hit = NULL;
260  amxb_who_has_cache_t* cache = NULL;
261 
262  when_str_empty(object_path, exit);
263  when_true(strcmp(object_path, ".") == 0, exit);
264 
265  cache_hit = amxc_htable_get(&amxb_cache_table, object_path);
266  if(cache_hit != NULL) {
267  cache = amxc_container_of(cache_hit, amxb_who_has_cache_t, hit);
268  ctx = cache->ctx;
269  amxc_llist_prepend(&amxb_cache_list, &cache->lit);
270  goto exit;
271  }
272 
273  amxc_htable_for_each(hit, &amxb_backends) {
274  amxb_be_funcs_t* funcs = amxc_htable_it_get_data(hit, amxb_be_funcs_t, it);
275  ctx = amxb_be_find_connection(&funcs->connections, object_path, full_match);
276  if(ctx == NULL) {
277  continue;
278  }
279  if(amxb_cache_size == 0) {
280  break;
281  }
282  if(amxc_htable_size(&amxb_cache_table) >= amxb_cache_size) {
283  amxc_llist_it_t* it = amxc_llist_take_last(&amxb_cache_list);
284  if(it != NULL) {
285  cache = amxc_container_of(it, amxb_who_has_cache_t, lit);
286  amxc_htable_it_clean(&cache->hit, NULL);
287  free(cache);
288  }
289  }
290 
291  cache = (amxb_who_has_cache_t*) calloc(1, sizeof(amxb_who_has_cache_t));
292  when_null(cache, exit);
293  cache->ctx = ctx;
294  amxc_htable_insert(&amxb_cache_table, object_path, &cache->hit);
295  amxc_llist_prepend(&amxb_cache_list, &cache->lit);
296  break;
297  }
298 
299 exit:
300  return ctx;
301 }
static amxc_htable_t amxb_backends
static uint32_t amxb_cache_size
static amxb_bus_ctx_t * amxb_be_find_connection(amxc_llist_t *connections, const char *object_path, bool full_match)
static amxc_llist_t amxb_cache_list
static amxc_htable_t amxb_cache_table
amxc_llist_t connections
amxb_bus_ctx_t * ctx
amxc_htable_it_t hit
amxc_llist_it_t lit

◆ amxb_dm_event_to_object_event()

void PRIVATE amxb_dm_event_to_object_event ( const char *const  sig_name,
const amxc_var_t *const  data,
void *const  priv 
)

Definition at line 76 of file amxb_ba_priv.c.

78  {
79  amxc_htable_it_t* sub_hit = (amxc_htable_it_t*) priv;
80  const char* subscriber_object = amxc_htable_it_get_key(sub_hit);
81  amxb_bus_ctx_t* ctx = amxc_container_of(sub_hit->ait->array, amxb_bus_ctx_t, subscriptions);
82 
83  amxc_var_add_key(cstring_t, (amxc_var_t*) data, "notification", sig_name);
84  amxp_sigmngr_emit_signal(&ctx->sigmngr, subscriber_object, data);
85 }
amxp_signal_mngr_t sigmngr
Definition: amxb_types.h:120

◆ amxb_fetch_local_object()

amxd_object_t* amxb_fetch_local_object ( amxb_bus_ctx_t ctx,
const char *  object 
)

Definition at line 87 of file amxb_ba_priv.c.

88  {
89  amxd_dm_t* dm = ctx->dm;
90  amxd_object_t* object = amxd_dm_findf(dm, "%s", obj_path);
91  return object;
92 }
amxd_dm_t * dm
Definition: amxb_types.h:123
static amxd_dm_t dm
Definition: test_amxb_e2e.c:85

◆ amxb_follow_reference()

int PRIVATE amxb_follow_reference ( amxb_bus_ctx_t *const  bus_ctx,
amxd_path_t *  reference,
int  timeout 
)

Definition at line 116 of file amxb_ba_priv.c.

118  {
119  int retval = amxd_status_unknown_error;
120  amxc_var_t resolved;
121  char* ref = amxd_path_get_reference_part(reference, true);
122  uint32_t index = amxd_path_get_reference_index(reference);
123  amxd_path_t ref_path;
124  amxc_var_t* real_path = NULL;
125 
126  amxd_path_init(&ref_path, ref);
127  amxc_var_init(&resolved);
128 
129  when_true(index == 0, exit);
130  when_str_empty(amxd_path_get_param(&ref_path), exit);
131  retval = amxb_get(bus_ctx, ref, 0, &resolved, timeout);
132  when_failed(retval, exit);
133 
134  when_true(amxc_htable_size(amxc_var_constcast(amxc_htable_t, GETP_ARG(&resolved, "0"))) > 1, exit);
135 
136  real_path = amxc_var_get_pathf(&resolved, AMXC_VAR_FLAG_DEFAULT,
137  "0.0.%s",
138  amxd_path_get_param(&ref_path));
139 
140  amxc_var_cast(real_path, AMXC_VAR_ID_CSV_STRING);
141  amxc_var_cast(real_path, AMXC_VAR_ID_LIST);
142 
143  if(index - 1 >= amxc_llist_size(amxc_var_constcast(amxc_llist_t, real_path))) {
144  goto exit;
145  }
146 
147  amxd_path_setf(&ref_path, true, "%s", GETI_CHAR(real_path, index - 1));
148  amxd_path_prepend(reference, amxd_path_get(&ref_path, 0));
149 
150 exit:
151  amxd_path_clean(&ref_path);
152  free(ref);
153  amxc_var_clean(&resolved);
154  return retval;
155 }
int amxb_get(amxb_bus_ctx_t *const bus_ctx, const char *object, int32_t depth, amxc_var_t *ret, int timeout)
Fetches one or more objects or a single parameter.

◆ amxb_is_local_object()

bool PRIVATE amxb_is_local_object ( amxb_bus_ctx_t ctx,
const char *  obj_path 
)

Definition at line 94 of file amxb_ba_priv.c.

95  {
96  amxd_dm_t* dm = ctx->dm;
97  amxd_path_t path;
98  amxd_object_t* object = NULL;
99 
100  amxd_path_init(&path, NULL);
101  amxd_path_setf(&path, true, "%s", obj_path);
102  when_null(dm, exit);
103 
104  while(object == NULL && !amxc_string_is_empty(&path.path)) {
105  char* part = NULL;
106  object = amxd_dm_findf(dm, "%s", amxd_path_get(&path, AMXD_OBJECT_TERMINATE));
107  part = amxd_path_get_last(&path, true);
108  free(part);
109  }
110 
111 exit:
112  amxd_path_clean(&path);
113  return object != NULL;
114 }

◆ amxb_set_impl()

int PRIVATE amxb_set_impl ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
uint32_t  flags,
amxc_var_t *  values,
amxc_var_t *  ovalues,
amxc_var_t *  ret,
int  timeout 
)

Definition at line 127 of file amxb_ba_op_set.c.

133  {
134  int retval = amxd_status_unknown_error;
135  const amxb_be_funcs_t* fns = NULL;
136  bool lobject = false;
137  amxd_path_t path;
138  char* fixed = NULL;
139  const char* rel_path = NULL;
140 
141  amxd_path_init(&path, NULL);
142  when_null(bus_ctx, exit);
143  when_null(bus_ctx->bus_ctx, exit);
144 
145  amxd_path_setf(&path, true, "%s", object);
146 
147  while(amxd_path_get_type(&path) == amxd_path_reference) {
148  retval = amxb_follow_reference(bus_ctx, &path, timeout);
149  when_failed(retval, exit);
150  }
151 
152  fixed = amxd_path_get_fixed_part(&path, true);
153  rel_path = amxd_path_get(&path, AMXD_OBJECT_TERMINATE);
154 
155  lobject = amxb_is_local_object(bus_ctx, fixed);
156  fns = bus_ctx->bus_fn;
157 
158  if(lobject || !amxb_is_valid_be_func(fns, set, fns->set)) {
159  retval = amxb_invoke_set(bus_ctx, fixed, rel_path, flags,
160  values, ovalues, ret, timeout);
161  } else {
162  retval = fns->set(bus_ctx->bus_ctx, fixed, rel_path, flags,
163  values, ovalues, bus_ctx->access, ret, timeout);
164  }
165 
166 exit:
167  free(fixed);
168  amxd_path_clean(&path);
169  return retval;
170 }
static int amxb_invoke_set(amxb_bus_ctx_t *const bus_ctx, const char *object, const char *rel_path, uint32_t flags, amxc_var_t *values, amxc_var_t *ovalues, amxc_var_t *ret, int timeout)
int PRIVATE amxb_follow_reference(amxb_bus_ctx_t *const bus_ctx, amxd_path_t *reference, int timeout)
Definition: amxb_ba_priv.c:116
bool PRIVATE amxb_is_local_object(amxb_bus_ctx_t *ctx, const char *obj_path)
Definition: amxb_ba_priv.c:94
amxb_be_set_t set
uint32_t access
Definition: amxb_types.h:125

◆ amxb_subscription_remove()

int PRIVATE amxb_subscription_remove ( amxb_subscription_t subscription)

Definition at line 172 of file amxb_subscription.c.

172  {
173  int rv = AMXB_STATUS_OK;
174  amxb_sub_t* sub = amxc_container_of(subscription, amxb_sub_t, data);
175 
176  if(sub->it.llist != NULL) {
177  amxb_bus_ctx_t* bus_ctx = NULL;
178  bus_ctx = amxc_container_of(sub->it.llist, amxb_bus_ctx_t, client_subs);
179  amxc_llist_it_take(&sub->it);
180  rv = amxb_unsubscribe(bus_ctx, subscription->object, subscription->slot_cb,
181  subscription->priv);
182  }
183 
184  return rv;
185 }
#define AMXB_STATUS_OK
All ok.
Definition: amxb_error.h:86
int amxb_unsubscribe(amxb_bus_ctx_t *const ctx, const char *object, amxp_slot_fn_t slot_cb, void *priv)
Removes an event subscription.
amxp_slot_fn_t slot_cb
Definition: amxb_types.h:159
Definition: amxb_priv.h:64
amxc_llist_it_t it
Definition: amxb_priv.h:65