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

Ambiorix Object Synchronization API header file. More...

#include <amxs/amxs_types.h>

Go to the source code of this file.

Functions

amxs_status_t amxs_sync_ctx_new (amxs_sync_ctx_t **ctx, const char *object_a, const char *object_b, int attributes)
 Synchronization context constructor function. More...
 
void amxs_sync_ctx_delete (amxs_sync_ctx_t **ctx)
 Synchronization context destructor function. More...
 
amxs_status_t amxs_sync_ctx_init (amxs_sync_ctx_t *ctx, const char *object_a, const char *object_b, int attributes)
 Synchronization context initialization function. More...
 
void amxs_sync_ctx_clean (amxs_sync_ctx_t *ctx)
 Synchronization context cleanup function. More...
 
amxs_status_t amxs_sync_ctx_copy (amxs_sync_ctx_t **dest, amxs_sync_ctx_t *src, void *priv)
 Copies an existing synchronization context to a new synchronization context. More...
 
amxs_status_t amxs_sync_ctx_start_sync (amxs_sync_ctx_t *ctx)
 Starts the object synchronization. More...
 
void amxs_sync_ctx_stop_sync (amxs_sync_ctx_t *ctx)
 Stops the object synchronization. More...
 
static bool amxs_sync_ctx_is_started (const amxs_sync_ctx_t *const ctx)
 Checks is the synchronization context is running. More...
 
amxs_status_t amxs_sync_ctx_set_paths (amxs_sync_ctx_t *const ctx, const char *object_a, const char *object_b)
 Updates the object paths of the synchronization context. More...
 
amxs_status_t amxs_sync_ctx_add_param (amxs_sync_ctx_t *ctx, amxs_sync_param_t *param)
 Adds a synchronization parameter to a synchronization context. More...
 
amxs_status_t amxs_sync_ctx_add_new_param (amxs_sync_ctx_t *ctx, const char *param_a, const char *param_b, int attributes, amxs_translation_cb_t translation_cb, amxs_action_cb_t action_cb, void *priv)
 Creates and adds a synchronization parameter to a synchronization context. More...
 
amxs_status_t amxs_sync_ctx_add_new_copy_param (amxs_sync_ctx_t *ctx, const char *param_a, const char *param_b, int attributes)
 Creates and adds a synchronization parameter to a synchronization context. More...
 
amxs_status_t amxs_sync_ctx_add_object (amxs_sync_ctx_t *ctx, amxs_sync_object_t *object)
 Adds a synchronization object to a synchronization context. More...
 
amxs_status_t amxs_sync_ctx_add_new_object (amxs_sync_ctx_t *ctx, const char *object_a, const char *object_b, int attributes, amxs_translation_cb_t translation_cb, amxs_action_cb_t action_cb, void *priv)
 Creates and adds a synchronization object to a synchronization context. More...
 
amxs_status_t amxs_sync_ctx_add_new_copy_object (amxs_sync_ctx_t *ctx, const char *object_a, const char *object_b, int attributes)
 Creates and adds a synchronization object to a synchronization context. More...
 
amxs_status_t amxs_sync_ctx_set_local_dm (amxs_sync_ctx_t *ctx, amxd_dm_t *dm_a, amxd_dm_t *dm_b)
 Set the local datamodel pointer for the sync root objects. More...
 

Detailed Description

Ambiorix Object Synchronization API header file.

Definition in file amxs_sync_ctx.h.

Function Documentation

◆ amxs_sync_ctx_add_new_copy_object()

amxs_status_t amxs_sync_ctx_add_new_copy_object ( amxs_sync_ctx_t ctx,
const char *  object_a,
const char *  object_b,
int  attributes 
)

Creates and adds a synchronization object to a synchronization context.

Allocates memory for a new synchronization object and initializes this object. Then adds it to the synchronization context.

Adding the synchronization object fails when:

  • The object was already added to the context
  • The object attributes are conflicting with those of the context. E.g. The context has the AMXS_SYNC_ONLY_B_TO_A attribute set, and the object has AMXS_SYNC_ONLY_A_TO_B set.

If the context attributes are more strict than those of the object, the object attributes will be updated to match those of the context.

Uses default translation amxs_sync_object_copy_trans_cb and action amxs_sync_object_copy_action_cb callbacks.

Parameters
ctxPointer to a synchronization context.
object_aName of the object in object A
object_bName of the object in object B
attributesBitwise OR of zero or more of the following attributes:
Returns
  • amxs_status_ok: the new synchronization object is added to the synchronization context
  • amxs_status_duplicate: another synchronization object with the same direction and object names already exists for this synchronization context
  • amxs_status_invalid_attr: the attributes of the synchronization object are conflicting with those of the synchronization context
  • amxs_status_unknown_error: any other error

Definition at line 951 of file amxs_sync_ctx.c.

954  {
955  return amxs_sync_ctx_add_new_object(ctx,
956  object_a,
957  object_b,
958  attributes,
961  NULL);
962 }
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...
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.
amxs_status_t amxs_sync_ctx_add_new_object(amxs_sync_ctx_t *ctx, const char *object_a, const char *object_b, int attributes, amxs_translation_cb_t translation_cb, amxs_action_cb_t action_cb, void *priv)
Creates and adds a synchronization object to a synchronization context.

◆ amxs_sync_ctx_set_local_dm()

amxs_status_t amxs_sync_ctx_set_local_dm ( amxs_sync_ctx_t ctx,
amxd_dm_t *  dm_a,
amxd_dm_t *  dm_b 
)

Set the local datamodel pointer for the sync root objects.

If one or both root objects for the synchronization are located in the same process as the synchronization code, it is possible to add read-only parameters to the sync.

Having access to the datamodel enables the writing of read-only parameters.

The datamodel pointer should only be set if the synchronization needs to write the object.

Parameters
ctxPointer to a synchronization context.
dm_aPointer to the local datamodel which contains object A, may be NULL
dm_bPointer to the local datamodel which contains object B, may be NULL
Returns
  • amxs_status_ok: the datamodel pointers have been set successfully
  • amxs_status_unknown_error: any other error

Definition at line 964 of file amxs_sync_ctx.c.

966  {
968  when_null(ctx, exit);
969  when_false_status(ctx->type == amxs_sync_type_ctx, exit, status = amxs_status_invalid_type);
970 
971  if(((ctx->attributes & AMXS_SYNC_ONLY_B_TO_A) != 0) && (dm_b != NULL)) {
972  status = amxs_status_invalid_arg;
973  goto exit;
974  }
975 
976  if(((ctx->attributes & AMXS_SYNC_ONLY_A_TO_B) != 0) && (dm_a != NULL)) {
977  status = amxs_status_invalid_arg;
978  goto exit;
979  }
980 
981  ctx->local_dm_a = dm_a;
982  ctx->local_dm_b = dm_b;
983 
984  status = amxs_status_ok;
985 
986 exit:
987  return status;
988 }
@ amxs_status_ok
Definition: amxs_types.h:86
@ amxs_status_unknown_error
Definition: amxs_types.h:90
@ 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_ctx
Definition: amxs_types.h:100
#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
amxd_dm_t * local_dm_b
Definition: amxs_types.h:178
amxs_sync_entry_type_t type
Definition: amxs_types.h:170
amxd_dm_t * local_dm_a
Definition: amxs_types.h:177
int attributes
Definition: amxs_types.h:165