libamxb  4.8.2
Bus Agnostic C API
amxb_ba_op_set.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <amxc/amxc.h>
#include <amxp/amxp.h>
#include <amxd/amxd_common.h>
#include <amxd/amxd_dm.h>
#include <amxd/amxd_path.h>
#include <amxd/amxd_object.h>
#include <amxb/amxb_be_intf.h>
#include <amxb/amxb.h>
#include "amxb_priv.h"

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

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 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 amxb_set (amxb_bus_ctx_t *const bus_ctx, const char *object, amxc_var_t *values, amxc_var_t *ret, int timeout)
 Sets parameter values of one single object or of multiple instance objects. More...
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 56 of file amxb_ba_op_set.c.

Function Documentation

◆ amxb_invoke_set()

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 
)
static

Definition at line 78 of file amxb_ba_op_set.c.

85  {
86 
87  amxb_invoke_t* invoke_ctx = NULL;
88  amxc_var_t args;
89  amxc_var_t* params;
90  int retval = amxd_status_unknown_error;
91 
92  amxc_var_init(&args);
93  when_true(amxc_var_type_of(values) != AMXC_VAR_ID_HTABLE &&
94  !amxc_var_is_null(values), exit);
95  when_true(amxc_var_type_of(ovalues) != AMXC_VAR_ID_HTABLE &&
96  !amxc_var_is_null(ovalues), exit);
97 
98  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
99  if((rel_path != NULL) && (*rel_path != 0)) {
100  amxc_var_add_key(cstring_t, &args, "rel_path", rel_path);
101  }
102  amxc_var_add_key(uint32_t, &args, "access", bus_ctx->access);
103  if(values != NULL) {
104  params = amxc_var_add_key(amxc_htable_t, &args, "parameters", NULL);
105  amxc_var_move(params, values);
106  }
107  if(ovalues != NULL) {
108  params = amxc_var_add_key(amxc_htable_t, &args, "oparameters", NULL);
109  amxc_var_move(params, ovalues);
110  }
111 
112  if((flags & AMXB_FLAG_PARTIAL) == AMXB_FLAG_PARTIAL) {
113  amxc_var_add_key(bool, &args, "allow_partial", true);
114  }
115 
116  retval = amxb_new_invoke(&invoke_ctx, bus_ctx, object, NULL, "_set");
117  when_failed(retval, exit);
118  retval = amxb_invoke(invoke_ctx, &args, ret, NULL, NULL, timeout);
119  when_failed(retval, exit);
120 
121 exit:
122  amxb_free_invoke(&invoke_ctx);
123  amxc_var_clean(&args);
124  return retval;
125 }
#define AMXB_FLAG_PARTIAL
int amxb_new_invoke(amxb_invoke_t **invoke_ctx, amxb_bus_ctx_t *const ctx, const char *object, const char *interface, const char *method)
Prepares a remote function invocation.
void amxb_free_invoke(amxb_invoke_t **invoke_ctx)
Deletes a function invoke context, and frees allocated memory.
int amxb_invoke(amxb_invoke_t *invoke_ctx, amxc_var_t *args, amxc_var_t *ret, amxb_be_cb_fn_t fn, void *priv, int timeout)
Invokes a remote function, as defined by the function invoke context.
uint32_t access
Definition: amxb_types.h:125
static amxb_bus_ctx_t * bus_ctx
Definition: test_amxb_e2e.c:84

◆ amxb_set_impl()

int 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)
#define amxb_is_valid_be_func(ft, member, ptr)
Definition: amxb_priv.h:78
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
The back-end interface structure.
amxb_be_set_t set
const amxb_be_funcs_t * bus_fn
Definition: amxb_types.h:121
void * bus_ctx
Definition: amxb_types.h:122