libamxs  0.6.0
Data Model Synchronization C API
amxs_sync_object.c
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 
55 #ifndef _GNU_SOURCE
56 #define _GNU_SOURCE
57 #endif
58 
59 #include <stdlib.h>
60 #include <string.h>
61 
62 #include <amxc/amxc.h>
63 
64 #include <amxs/amxs_sync_object.h>
65 #include <amxs/amxs_sync_param.h>
66 #include <amxs/amxs_util.h>
67 
68 #include "amxs_priv.h"
69 #include "amxs_sync_entry.h"
70 
72  const char* object_a,
73  const char* object_b,
74  int attributes,
75  amxs_translation_cb_t translation_cb,
76  amxs_action_cb_t action_cb,
77  void* priv) {
78  return amxs_sync_entry_new(object,
79  object_a,
80  object_b,
81  attributes,
82  translation_cb,
83  action_cb,
85  priv);
86 }
87 
89  const char* object_a,
90  const char* object_b,
91  int attributes) {
92  return amxs_sync_object_new(object,
93  object_a,
94  object_b,
95  attributes,
98  NULL);
99 }
100 
102  when_null(object, exit);
103  when_null(*object, exit);
104  when_false((*object)->type == amxs_sync_type_object, exit);
105 
106  amxs_sync_entry_delete(object);
107 
108 exit:
109  return;
110 }
111 
114  when_null(object, exit);
115  when_null(param, exit);
116  when_false_status(object->type == amxs_sync_type_object, exit, status = amxs_status_invalid_type);
117  when_false_status(param->type == amxs_sync_type_param, exit, status = amxs_status_invalid_type);
118 
119  status = amxs_sync_entry_add_entry(object, param);
120 
121 exit:
122  return status;
123 }
124 
126  const char* param_a,
127  const char* param_b,
128  int attributes,
129  amxs_translation_cb_t translation_cb,
130  amxs_action_cb_t action_cb,
131  void* priv) {
133  amxs_sync_param_t* param = NULL;
134 
135  status = amxs_sync_param_new(&param, param_a, param_b, attributes, translation_cb, action_cb, priv);
136  when_failed(status, exit);
137 
138  status = amxs_sync_object_add_param(object, param);
139  if(status != amxs_status_ok) {
140  amxs_sync_param_delete(&param);
141  }
142 
143 exit:
144  return status;
145 }
146 
148  const char* param_a,
149  const char* param_b,
150  int attributes) {
151  return amxs_sync_object_add_new_param(object,
152  param_a,
153  param_b,
154  attributes | AMXS_SYNC_PARAM_BATCH,
155  NULL,
156  NULL,
157  NULL);
158 }
159 
162  when_null(parent, exit);
163  when_null(child, exit);
164  when_false_status(parent->type == amxs_sync_type_object, exit, status = amxs_status_invalid_type);
165  when_false_status(child->type == amxs_sync_type_object, exit, status = amxs_status_invalid_type);
166 
167  status = amxs_sync_entry_add_entry(parent, child);
168 
169 exit:
170  return status;
171 }
172 
174  const char* object_a,
175  const char* object_b,
176  int attributes,
177  amxs_translation_cb_t translation_cb,
178  amxs_action_cb_t action_cb,
179  void* priv) {
181  amxs_sync_object_t* child = NULL;
182 
183  status = amxs_sync_object_new(&child, object_a, object_b, attributes, translation_cb, action_cb, priv);
184  when_failed(status, exit);
185 
186  status = amxs_sync_object_add_object(parent, child);
187  if(status != amxs_status_ok) {
188  amxs_sync_object_delete(&child);
189  }
190 
191 exit:
192  return status;
193 }
194 
196  const char* object_a,
197  const char* object_b,
198  int attributes) {
199  return amxs_sync_object_add_new_object(parent,
200  object_a,
201  object_b,
202  attributes,
205  NULL);
206 }
amxs_status_t amxs_sync_entry_add_entry(amxs_sync_entry_t *parent, amxs_sync_entry_t *child)
amxs_status_t amxs_sync_entry_new(amxs_sync_entry_t **entry, const char *a, const char *b, int attributes, amxs_translation_cb_t translation_cb, amxs_action_cb_t action_cb, amxs_sync_entry_type_t type, void *priv)
void amxs_sync_entry_delete(amxs_sync_entry_t **entry)
Ambiorix Object Synchronization API header file.
Ambiorix Object Synchronization API header file.
@ 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
enum _amxs_status amxs_status_t
@ amxs_sync_type_param
Definition: amxs_types.h:102
@ amxs_sync_type_object
Definition: amxs_types.h:101
amxs_status_t amxs_sync_object_add_new_copy_object(amxs_sync_object_t *parent, const char *object_a, const char *object_b, int attributes)
Creates and adds a synchronization object to a synchronization object.
amxs_status_t amxs_sync_object_add_new_copy_param(amxs_sync_object_t *object, const char *param_a, const char *param_b, int attributes)
Creates and adds a synchronization parameter to a synchronization object.
amxs_status_t amxs_sync_object_new(amxs_sync_object_t **object, const char *object_a, const char *object_b, int attributes, amxs_translation_cb_t translation_cb, amxs_action_cb_t action_cb, void *priv)
Synchronization object constructor function.
amxs_status_t amxs_sync_object_add_new_object(amxs_sync_object_t *parent, 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 object.
amxs_status_t amxs_sync_object_new_copy(amxs_sync_object_t **object, const char *object_a, const char *object_b, int attributes)
Synchronization object constructor function.
amxs_status_t amxs_sync_object_add_param(amxs_sync_object_t *object, amxs_sync_param_t *param)
Adds a synchronization parameter to a synchronization object.
void amxs_sync_object_delete(amxs_sync_object_t **object)
Synchronization object destructor function.
amxs_status_t amxs_sync_object_add_new_param(amxs_sync_object_t *object, 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 object.
amxs_status_t amxs_sync_object_add_object(amxs_sync_object_t *parent, amxs_sync_object_t *child)
Adds a synchronization object to a synchronization object.
void amxs_sync_param_delete(amxs_sync_param_t **param)
Synchronization parameter destructor function.
amxs_status_t amxs_sync_param_new(amxs_sync_param_t **param, const char *param_a, const char *param_b, int attributes, amxs_translation_cb_t translation_cb, amxs_action_cb_t action_cb, void *priv)
Synchronization parameter constructor function.
#define AMXS_SYNC_PARAM_BATCH
Indicate that this parameter may be part of a batch copy operation.
Definition: amxs_types.h:210
amxs_status_t(* amxs_action_cb_t)(const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, amxc_var_t *data, void *priv)
Definition of the action callback function.
Definition: amxs_types.h:156
amxs_status_t(* amxs_translation_cb_t)(const amxs_sync_entry_t *entry, amxs_sync_direction_t direction, const amxc_var_t *input, amxc_var_t *output, void *priv)
Definition of the translation callback function.
Definition: amxs_types.h:131
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.
Definition: amxs_types.h:161
amxs_sync_entry_type_t type
Definition: amxs_types.h:170