libamxs  0.6.0
Data Model Synchronization C API
amxs_util.h File Reference

Go to the source code of this file.

Functions

bool amxs_sync_entry_remove_bidrection_object (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, const char *path)
 
bool amxs_sync_entry_check_bidrection_object (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, const char *path, const char *opposite_path)
 
bool amxs_sync_entry_check_bidirectional_loop (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, amxc_var_t *value, const char *path, const char *opposite_path)
 
bool amxs_sync_entry_is_bidirectional (const amxs_sync_entry_t *entry)
 
bool amxs_sync_entry_direction_allowed (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction)
 
bool amxs_sync_entry_is_batch_param (const amxs_sync_entry_t *const entry)
 
const char * amxs_sync_entry_get_name (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction)
 
const char * amxs_sync_entry_get_opposite_name (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction)
 
amxs_sync_entry_tamxs_sync_entry_get_parent (const amxs_sync_entry_t *entry)
 
amxs_sync_ctx_tamxs_sync_entry_get_ctx (const amxs_sync_entry_t *entry)
 
amxp_signal_mngr_t * amxs_sync_entry_get_signal_manager (const amxs_sync_entry_t *const entry)
 
amxb_bus_ctx_t * amxs_sync_ctx_get_opposite_bus_ctx (const amxs_sync_ctx_t *ctx, amxs_sync_direction_t direction)
 
amxb_bus_ctx_t * amxs_sync_ctx_get_bus_ctx (const amxs_sync_ctx_t *ctx, amxs_sync_direction_t direction)
 
amxd_dm_t * amxs_sync_ctx_get_opposite_dm (const amxs_sync_ctx_t *ctx, amxs_sync_direction_t direction)
 
amxd_dm_t * amxs_sync_ctx_get_dm (const amxs_sync_ctx_t *ctx, amxs_sync_direction_t direction)
 
unsigned int amxs_sync_entry_get_opposite_index (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, unsigned int index)
 
char * amxs_sync_entry_get_opposite_path (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, const char *old_path)
 
char * amxs_sync_entry_get_opposite_parent_path (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, const char *old_path)
 
char * amxs_sync_entry_get_regex_path (const amxs_sync_entry_t *const entry, amxs_sync_direction_t direction)
 
char * amxs_sync_entry_get_regex_parent_path (const amxs_sync_entry_t *const entry, amxs_sync_direction_t direction)
 
amxs_status_t amxs_sync_entry_get_batch_params (const amxs_sync_entry_t *const entry, amxc_var_t *params, amxs_sync_direction_t direction)
 
amxs_status_t amxs_sync_param_copy_trans_cb (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, const amxc_var_t *input, amxc_var_t *output, void *priv)
 Translates data from a dm:object-changed event to data suited for an amxb_set call for a single parameter. More...
 
amxs_status_t amxs_sync_batch_param_copy_trans_cb (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, const amxc_var_t *input, amxc_var_t *output, void *priv)
 Translates data from a dm:object-changed event to data suited for an amxb_set call for all parameters in the event that are marked as batch copy parameters. More...
 
amxs_status_t amxs_sync_param_copy_action_cb (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, amxc_var_t *data, void *priv)
 Sets the new parameter value. More...
 
amxs_status_t amxs_sync_object_copy_trans_cb (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, const amxc_var_t *input, amxc_var_t *output, void *priv)
 Translates data from a dm:instance-added or dm:instance-removed event to data suited for an amxb call for this instance and all it's parameters. More...
 
amxs_status_t amxs_sync_object_copy_action_cb (const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, amxc_var_t *data, void *priv)
 Adds, removes or updates an object with the given data using an amxb call. More...
 

Function Documentation

◆ amxs_sync_ctx_get_bus_ctx()

amxb_bus_ctx_t* amxs_sync_ctx_get_bus_ctx ( const amxs_sync_ctx_t ctx,
amxs_sync_direction_t  direction 
)

Definition at line 343 of file amxs_util.c.

344  {
345  amxb_bus_ctx_t* bus_ctx = NULL;
346  when_null(ctx, exit);
347  when_false(ctx->type == amxs_sync_type_ctx, exit);
348 
349  bus_ctx = direction == amxs_sync_a_to_b ? ctx->bus_ctx_a : ctx->bus_ctx_b;
350 
351 exit:
352  return bus_ctx;
353 }
@ amxs_sync_a_to_b
Definition: amxs_types.h:80
@ amxs_sync_type_ctx
Definition: amxs_types.h:100
amxs_sync_entry_type_t type
Definition: amxs_types.h:170
amxb_bus_ctx_t * bus_ctx_a
Definition: amxs_types.h:171
amxb_bus_ctx_t * bus_ctx_b
Definition: amxs_types.h:172
static amxb_bus_ctx_t * bus_ctx

◆ amxs_sync_ctx_get_dm()

amxd_dm_t* amxs_sync_ctx_get_dm ( const amxs_sync_ctx_t ctx,
amxs_sync_direction_t  direction 
)

Definition at line 367 of file amxs_util.c.

368  {
369  amxd_dm_t* dm = NULL;
370  when_null(ctx, exit);
371  when_false(ctx->type == amxs_sync_type_ctx, exit);
372 
373  dm = direction == amxs_sync_a_to_b ? ctx->local_dm_a : ctx->local_dm_b;
374 
375 exit:
376  return dm;
377 }
amxd_dm_t * local_dm_b
Definition: amxs_types.h:178
amxd_dm_t * local_dm_a
Definition: amxs_types.h:177

◆ amxs_sync_ctx_get_opposite_bus_ctx()

amxb_bus_ctx_t* amxs_sync_ctx_get_opposite_bus_ctx ( const amxs_sync_ctx_t ctx,
amxs_sync_direction_t  direction 
)

Definition at line 331 of file amxs_util.c.

332  {
333  amxb_bus_ctx_t* bus_ctx = NULL;
334  when_null(ctx, exit);
335  when_false(ctx->type == amxs_sync_type_ctx, exit);
336 
337  bus_ctx = direction == amxs_sync_a_to_b ? ctx->bus_ctx_b : ctx->bus_ctx_a;
338 
339 exit:
340  return bus_ctx;
341 }

◆ amxs_sync_ctx_get_opposite_dm()

amxd_dm_t* amxs_sync_ctx_get_opposite_dm ( const amxs_sync_ctx_t ctx,
amxs_sync_direction_t  direction 
)

Definition at line 355 of file amxs_util.c.

356  {
357  amxd_dm_t* dm = NULL;
358  when_null(ctx, exit);
359  when_false(ctx->type == amxs_sync_type_ctx, exit);
360 
361  dm = direction == amxs_sync_a_to_b ? ctx->local_dm_b : ctx->local_dm_a;
362 
363 exit:
364  return dm;
365 }

◆ amxs_sync_entry_check_bidirectional_loop()

bool amxs_sync_entry_check_bidirectional_loop ( const amxs_sync_entry_t entry,
amxs_sync_direction_t  direction,
amxc_var_t *  value,
const char *  path,
const char *  opposite_path 
)

Definition at line 168 of file amxs_util.c.

172  {
173  bool ret = false;
174  amxc_string_t str;
175  amxc_var_t* current_list = NULL;
176  amxc_var_t* opposite_list = NULL;
177  amxc_var_t* current_table = NULL;
178  amxc_var_t* opposite_table = NULL;
179  amxc_var_t* value_storage = NULL;
181 
182  amxc_string_init(&str, 0);
183 
184  when_null(entry, exit);
185  when_null(ctx, exit);
186  when_null(value, exit);
187  when_str_empty(path, exit);
188  when_str_empty(opposite_path, exit);
189  when_false(amxs_sync_entry_is_bidirectional(entry), exit);
190 
191  opposite_table = direction == amxs_sync_a_to_b ? &ctx->b_to_a : &ctx->a_to_b;
192  current_table = direction == amxs_sync_a_to_b ? &ctx->a_to_b : &ctx->b_to_a;
193 
194  // Find current path in opposite table
195  amxc_string_setf(&str, "%s%s", path, amxs_sync_entry_get_name(entry, direction));
196  opposite_list = GET_ARG(opposite_table, amxc_string_get(&str, 0));
197  if(opposite_list != NULL) {
198  // Entry found, do the regular loop detection for parameters
199  ret = amxs_sync_entry_check_bidirectional_param(opposite_list, value);
200  when_true(ret, exit);
201  }
202 
203  amxc_string_setf(&str, "%s%s", opposite_path, amxs_sync_entry_get_opposite_name(entry, direction));
204  current_list = GET_ARG(current_table, amxc_string_get(&str, 0));
205  if(current_list == NULL) {
206  // Add the opposite path to the current ctx htable
207  current_list = amxc_var_add_key(amxc_llist_t, current_table, amxc_string_get(&str, 0), NULL);
208  }
209 
210  // Add the current value to the current list
211  value_storage = amxc_var_add_new(current_list);
212  amxc_var_copy(value_storage, value);
213 
214 exit:
215  amxc_string_clean(&str);
216  return ret;
217 }
const char * amxs_sync_entry_get_opposite_name(const amxs_sync_entry_t *const entry, amxs_sync_direction_t direction)
Definition: amxs_util.c:275
static bool amxs_sync_entry_check_bidirectional_param(amxc_var_t *list, amxc_var_t *value)
Definition: amxs_util.c:138
amxs_sync_ctx_t * amxs_sync_entry_get_ctx(const amxs_sync_entry_t *const entry)
Definition: amxs_util.c:297
const char * amxs_sync_entry_get_name(const amxs_sync_entry_t *const entry, amxs_sync_direction_t direction)
Definition: amxs_util.c:264
bool amxs_sync_entry_is_bidirectional(const amxs_sync_entry_t *entry)
Definition: amxs_util.c:219
Definition: amxs_types.h:161
amxc_var_t b_to_a
Definition: amxs_types.h:176
amxc_var_t a_to_b
Definition: amxs_types.h:175

◆ amxs_sync_entry_check_bidrection_object()

bool amxs_sync_entry_check_bidrection_object ( const amxs_sync_entry_t entry,
amxs_sync_direction_t  direction,
const char *  path,
const char *  opposite_path 
)

Definition at line 101 of file amxs_util.c.

104  {
105  bool ret = false;
106  amxd_path_t check_path;
107  amxc_var_t* opposite_list = NULL;
108  amxc_var_t* current_list = NULL;
109  amxc_var_t* opposite = NULL;
111 
112  amxd_path_init(&check_path, opposite_path);
113 
114  when_null(entry, exit);
115  when_null(ctx, exit);
116  when_str_empty(path, exit);
117  when_str_empty(opposite_path, exit);
118  when_false(amxs_sync_entry_is_bidirectional(entry), exit);
119 
120  opposite_list = direction == amxs_sync_a_to_b ? &ctx->b_to_a : &ctx->a_to_b;
121  current_list = direction == amxs_sync_a_to_b ? &ctx->a_to_b : &ctx->b_to_a;
122  opposite = GET_ARG(opposite_list, path);
123 
124  when_true(amxd_path_is_instance_path(&check_path), exit);
125 
126  if(opposite != NULL) {
127  amxc_var_delete(&opposite);
128  ret = true;
129  } else {
130  amxc_var_add_key(bool, current_list, opposite_path, true);
131  }
132 
133 exit:
134  amxd_path_clean(&check_path);
135  return ret;
136 }

◆ amxs_sync_entry_direction_allowed()

bool amxs_sync_entry_direction_allowed ( const amxs_sync_entry_t entry,
amxs_sync_direction_t  direction 
)

Definition at line 231 of file amxs_util.c.

232  {
233  bool ret = true;
234 
235  if((direction == amxs_sync_a_to_b) &&
236  ((entry->attributes & AMXS_SYNC_ONLY_B_TO_A) != 0)) {
237  ret = false;
238  goto exit;
239  }
240 
241  if((direction == amxs_sync_b_to_a) &&
242  ((entry->attributes & AMXS_SYNC_ONLY_A_TO_B) != 0)) {
243  ret = false;
244  goto exit;
245  }
246 
247 exit:
248  return ret;
249 }
@ amxs_sync_b_to_a
Definition: amxs_types.h:81
#define AMXS_SYNC_ONLY_B_TO_A
Only synchronize from object B to object A.
Definition: amxs_types.h:195
#define AMXS_SYNC_ONLY_A_TO_B
Only synchronize from object A to object B.
Definition: amxs_types.h:200
int attributes
Definition: amxs_types.h:165

◆ amxs_sync_entry_get_batch_params()

amxs_status_t amxs_sync_entry_get_batch_params ( const amxs_sync_entry_t *const  entry,
amxc_var_t *  params,
amxs_sync_direction_t  direction 
)

Definition at line 514 of file amxs_util.c.

516  {
518 
519  when_null(entry, exit);
520  when_null(params, exit);
521  when_true_status(entry->type == amxs_sync_type_param, exit, status = amxs_status_invalid_type);
522 
523  amxc_llist_iterate(it, &entry->entries) {
524  amxs_sync_entry_t* child = amxc_llist_it_get_data(it, amxs_sync_entry_t, it);
525  if(!amxs_sync_entry_is_batch_param(child)) {
526  continue;
527  }
528 
529  if(!amxs_sync_entry_direction_allowed(child, direction)) {
530  continue;
531  }
532 
533  amxc_var_add(cstring_t, params, direction == amxs_sync_a_to_b ? child->a : child->b);
534  }
535 
536  status = amxs_status_ok;
537 
538 exit:
539  return status;
540 }
@ amxs_status_ok
Definition: amxs_types.h:86
@ amxs_status_invalid_type
Definition: amxs_types.h:92
@ amxs_status_invalid_arg
Definition: amxs_types.h:89
enum _amxs_status amxs_status_t
@ amxs_sync_type_param
Definition: amxs_types.h:102
bool amxs_sync_entry_is_batch_param(const amxs_sync_entry_t *const entry)
Definition: amxs_util.c:251
bool amxs_sync_entry_direction_allowed(const amxs_sync_entry_t *const entry, amxs_sync_direction_t direction)
Definition: amxs_util.c:231
char * a
Definition: amxs_types.h:163
char * b
Definition: amxs_types.h:164
amxc_llist_t entries
Definition: amxs_types.h:169

◆ amxs_sync_entry_get_ctx()

amxs_sync_ctx_t* amxs_sync_entry_get_ctx ( const amxs_sync_entry_t entry)

Definition at line 297 of file amxs_util.c.

297  {
298  amxs_sync_ctx_t* ctx = NULL;
299  amxs_sync_entry_t* tmp = NULL;
300  when_null(entry, exit);
301 
302  when_true_status(entry->type == amxs_sync_type_ctx, exit, ctx = (amxs_sync_ctx_t*) entry);
303 
304  tmp = amxs_sync_entry_get_parent(entry);
305  while(tmp != NULL && tmp->type != amxs_sync_type_ctx) {
306  tmp = amxs_sync_entry_get_parent(tmp);
307  }
308 
309  if((tmp != NULL) && (tmp->type == amxs_sync_type_ctx)) {
310  ctx = tmp;
311  }
312 
313 exit:
314  return ctx;
315 }
amxs_sync_entry_t * amxs_sync_entry_get_parent(const amxs_sync_entry_t *const entry)
Definition: amxs_util.c:286

◆ amxs_sync_entry_get_name()

const char* amxs_sync_entry_get_name ( const amxs_sync_entry_t entry,
amxs_sync_direction_t  direction 
)

Definition at line 264 of file amxs_util.c.

265  {
266  const char* name = NULL;
267  when_null(entry, exit);
268 
269  name = direction == amxs_sync_a_to_b ? entry->a : entry->b;
270 
271 exit:
272  return name;
273 }

◆ amxs_sync_entry_get_opposite_index()

unsigned int amxs_sync_entry_get_opposite_index ( const amxs_sync_entry_t entry,
amxs_sync_direction_t  direction,
unsigned int  index 
)

◆ amxs_sync_entry_get_opposite_name()

const char* amxs_sync_entry_get_opposite_name ( const amxs_sync_entry_t entry,
amxs_sync_direction_t  direction 
)

Definition at line 275 of file amxs_util.c.

276  {
277  const char* opposite = NULL;
278  when_null(entry, exit);
279 
280  opposite = direction == amxs_sync_a_to_b ? entry->b : entry->a;
281 
282 exit:
283  return opposite;
284 }

◆ amxs_sync_entry_get_opposite_parent_path()

char* amxs_sync_entry_get_opposite_parent_path ( const amxs_sync_entry_t entry,
amxs_sync_direction_t  direction,
const char *  old_path 
)

Definition at line 456 of file amxs_util.c.

458  {
459  char* new_path = NULL;
461  when_null(parent, exit);
462 
463  new_path = amxs_sync_entry_get_opposite_path(parent, direction, old_path);
464 
465 exit:
466  return new_path;
467 }
char * amxs_sync_entry_get_opposite_path(const amxs_sync_entry_t *const entry, amxs_sync_direction_t direction, const char *const old_path)
Definition: amxs_util.c:429

◆ amxs_sync_entry_get_opposite_path()

char* amxs_sync_entry_get_opposite_path ( const amxs_sync_entry_t entry,
amxs_sync_direction_t  direction,
const char *  old_path 
)

Definition at line 429 of file amxs_util.c.

431  {
432  char* new_path = NULL;
433  amxc_string_t path_str;
434  amxd_path_t path;
435  const amxs_sync_entry_t* tmp = entry;
436 
437  when_null(entry, exit);
438  when_str_empty(old_path, exit);
439 
440  amxd_path_init(&path, old_path);
441  amxc_string_init(&path_str, 0);
442 
443  while(amxd_path_get_depth(&path) != 0 && tmp != NULL) {
444  when_false(amxs_sync_entry_build_opposite_path_entry(tmp, direction, &path, &path_str) == 0, exit);
445  tmp = amxs_sync_entry_get_parent(tmp);
446  }
447 
448  new_path = amxc_string_take_buffer(&path_str);
449 
450 exit:
451  amxd_path_clean(&path);
452  amxc_string_clean(&path_str);
453  return new_path;
454 }
static int amxs_sync_entry_build_opposite_path_entry(const amxs_sync_entry_t *const entry, amxs_sync_direction_t direction, amxd_path_t *path, amxc_string_t *path_str)
Definition: amxs_util.c:391

◆ amxs_sync_entry_get_parent()

amxs_sync_entry_t* amxs_sync_entry_get_parent ( const amxs_sync_entry_t entry)

Definition at line 286 of file amxs_util.c.

286  {
287  amxs_sync_entry_t* parent = NULL;
288  when_null(entry, exit);
289  when_false(amxc_llist_it_is_in_list(&entry->it), exit);
290 
291  parent = amxc_container_of(entry->it.llist, amxs_sync_entry_t, entries);
292 
293 exit:
294  return parent;
295 }
amxc_llist_it_t it
Definition: amxs_types.h:162

◆ amxs_sync_entry_get_regex_parent_path()

char* amxs_sync_entry_get_regex_parent_path ( const amxs_sync_entry_t *const  entry,
amxs_sync_direction_t  direction 
)

Definition at line 502 of file amxs_util.c.

503  {
504  char* path = NULL;
506  when_null(parent, exit);
507 
508  path = amxs_sync_entry_get_regex_path(parent, direction);
509 
510 exit:
511  return path;
512 }
char * amxs_sync_entry_get_regex_path(const amxs_sync_entry_t *const entry, amxs_sync_direction_t direction)
Definition: amxs_util.c:469

◆ amxs_sync_entry_get_regex_path()

char* amxs_sync_entry_get_regex_path ( const amxs_sync_entry_t *const  entry,
amxs_sync_direction_t  direction 
)

Definition at line 469 of file amxs_util.c.

470  {
471  char* path_str = NULL;
472  const amxs_sync_entry_t* tmp = entry;
473  amxc_string_t str;
474 
475  when_null(entry, exit);
476  amxc_string_init(&str, 0);
477  amxc_string_set(&str, "$");
478 
479  while(tmp != NULL) {
480  amxd_path_t path;
481  const char* name = amxs_sync_entry_get_name(tmp, direction);
482  when_str_empty(name, exit);
483  amxd_path_init(&path, name);
484 
485  if((entry->type == amxs_sync_type_object) && (amxd_path_is_instance_path(&path) == false)) {
486  amxc_string_prependf(&str, "%s([0-9]+\\.)?", name);
487  } else {
488  amxc_string_prependf(&str, "%s", name);
489  }
490  amxd_path_clean(&path);
491  tmp = amxs_sync_entry_get_parent(tmp);
492  }
493  amxc_string_prependf(&str, "%s", "^");
494 
495  path_str = amxc_string_take_buffer(&str);
496 
497 exit:
498  amxc_string_clean(&str);
499  return path_str;
500 }
@ amxs_sync_type_object
Definition: amxs_types.h:101

◆ amxs_sync_entry_get_signal_manager()

amxp_signal_mngr_t* amxs_sync_entry_get_signal_manager ( const amxs_sync_entry_t *const  entry)

Definition at line 317 of file amxs_util.c.

317  {
318  amxp_signal_mngr_t* sig_mngr = NULL;
319  amxs_sync_ctx_t* ctx = NULL;
320 
321  ctx = amxs_sync_entry_get_ctx(entry);
322  when_null(ctx, exit);
323 
324  sig_mngr = ctx->sig_mngr;
325 
326 exit:
327  return sig_mngr;
328 }
amxp_signal_mngr_t * sig_mngr
Definition: amxs_types.h:174

◆ amxs_sync_entry_is_batch_param()

bool amxs_sync_entry_is_batch_param ( const amxs_sync_entry_t *const  entry)

Definition at line 251 of file amxs_util.c.

251  {
252  bool ret = false;
253 
254  when_null(entry, exit);
255  when_false(entry->type == amxs_sync_type_param, exit);
256  when_true((entry->attributes & AMXS_SYNC_PARAM_BATCH) == 0, exit);
257 
258  ret = true;
259 
260 exit:
261  return ret;
262 }
#define AMXS_SYNC_PARAM_BATCH
Indicate that this parameter may be part of a batch copy operation.
Definition: amxs_types.h:210

◆ amxs_sync_entry_is_bidirectional()

bool amxs_sync_entry_is_bidirectional ( const amxs_sync_entry_t entry)

Definition at line 219 of file amxs_util.c.

219  {
220  bool ret = true;
221 
222  when_null(entry, exit);
223  if((entry->attributes & (AMXS_SYNC_ONLY_B_TO_A | AMXS_SYNC_ONLY_A_TO_B)) != 0) {
224  ret = false;
225  }
226 
227 exit:
228  return ret;
229 }

◆ amxs_sync_entry_remove_bidrection_object()

bool amxs_sync_entry_remove_bidrection_object ( const amxs_sync_entry_t entry,
amxs_sync_direction_t  direction,
const char *  path 
)

Definition at line 76 of file amxs_util.c.

78  {
79  bool ret = false;
80  amxc_var_t* opposite_list = NULL;
81  amxc_var_t* opposite = NULL;
83 
84  when_null(entry, exit);
85  when_null(ctx, exit);
86  when_str_empty(path, exit);
87  when_false(amxs_sync_entry_is_bidirectional(entry), exit);
88 
89  opposite_list = direction == amxs_sync_a_to_b ? &ctx->b_to_a : &ctx->a_to_b;
90  opposite = GET_ARG(opposite_list, path);
91 
92  if(opposite != NULL) {
93  amxc_var_delete(&opposite);
94  ret = true;
95  }
96 
97 exit:
98  return ret;
99 }