libamxb  4.8.2
Bus Agnostic C API
amxb_ba_op_list.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 void amxb_fill_list (amxc_var_t *ret, const char *object, amxc_string_t *full_name, amxc_var_t *data)
 
static void amxb_build_list (amxc_var_t *ret, const char *object, uint32_t flags, amxc_var_t *full)
 
static int amxb_invoke_list (amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxb_be_cb_fn_t fn, void *priv)
 
int amxb_list (amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxb_be_cb_fn_t fn, void *priv)
 List the service elements/nodes of an object. More...
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 56 of file amxb_ba_op_list.c.

Function Documentation

◆ amxb_build_list()

static void amxb_build_list ( amxc_var_t *  ret,
const char *  object,
uint32_t  flags,
amxc_var_t *  full 
)
static

Definition at line 91 of file amxb_ba_op_list.c.

94  {
95  amxc_var_t* table = GETI_ARG(full, 0);
96  amxc_var_t* obj = GET_ARG(table, "objects");
97  amxc_var_t* inst = GET_ARG(table, "instances");
98  amxc_var_t* funcs = GET_ARG(table, "functions");
99  amxc_var_t* params = GET_ARG(table, "parameters");
100  amxc_string_t full_name;
101 
102  amxc_string_init(&full_name, strlen(object) + 32);
103 
104  if(inst && ((flags & AMXB_FLAG_INSTANCES) != 0)) {
105  amxc_var_for_each(name, inst) {
106  if((flags & AMXB_FLAG_NAMED) != 0) {
107  amxc_string_setf(&full_name, "%s%s.", object, GET_CHAR(name, "name"));
108  } else {
109  amxc_string_setf(&full_name, "%s%d.", object, GET_UINT32(name, "index"));
110  }
111  amxc_var_add(cstring_t, ret, amxc_string_get(&full_name, 0));
112  }
113  }
114  if((flags & AMXB_FLAG_PARAMETERS) != 0) {
115  amxb_fill_list(ret, object, &full_name, params);
116  }
117  if((flags & AMXB_FLAG_FUNCTIONS) != 0) {
118  amxb_fill_list(ret, object, &full_name, funcs);
119  }
120  if((flags & AMXB_FLAG_OBJECTS) != 0) {
121  amxb_fill_list(ret, object, &full_name, obj);
122  }
123 
124  amxc_string_clean(&full_name);
125  return;
126 }
static void amxb_fill_list(amxc_var_t *ret, const char *object, amxc_string_t *full_name, amxc_var_t *data)
#define AMXB_FLAG_NAMED
#define AMXB_FLAG_INSTANCES
#define AMXB_FLAG_FUNCTIONS
#define AMXB_FLAG_PARAMETERS
#define AMXB_FLAG_OBJECTS

◆ amxb_fill_list()

static void amxb_fill_list ( amxc_var_t *  ret,
const char *  object,
amxc_string_t *  full_name,
amxc_var_t *  data 
)
static

Definition at line 78 of file amxb_ba_op_list.c.

81  {
82  if(data != NULL) {
83  amxc_var_for_each(name, data) {
84  const char* str_name = amxc_var_constcast(cstring_t, name);
85  amxc_string_setf(full_name, "%s%s", object, str_name);
86  amxc_var_add(cstring_t, ret, amxc_string_get(full_name, 0));
87  }
88  }
89 }

◆ amxb_invoke_list()

static int amxb_invoke_list ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
uint32_t  flags,
amxb_be_cb_fn_t  fn,
void *  priv 
)
static

Definition at line 128 of file amxb_ba_op_list.c.

132  {
133  amxb_invoke_t* invoke_ctx = NULL;
134  amxc_var_t list_return;
135  amxc_var_t args;
136  amxd_path_t path;
137  amxc_var_t ret;
138  int retval = amxd_status_unknown_error;
139 
140  amxd_path_init(&path, NULL);
141  amxd_path_setf(&path, true, "%s", object);
142  amxc_var_init(&list_return);
143  amxc_var_init(&ret);
144  amxc_var_init(&args);
145 
146  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
147  amxc_var_add_key(bool, &args, "parameters", (flags & AMXB_FLAG_PARAMETERS) != 0);
148  amxc_var_add_key(bool, &args, "functions", (flags & AMXB_FLAG_FUNCTIONS) != 0);
149  amxc_var_add_key(bool, &args, "template_info", (flags & AMXB_FLAG_TEMPLATE_INFO) != 0);
150  amxc_var_add_key(bool, &args, "instances", (flags & AMXB_FLAG_INSTANCES) != 0);
151  amxc_var_add_key(bool, &args, "objects", (flags & AMXB_FLAG_OBJECTS) != 0);
152  amxc_var_add_key(uint32_t, &args, "access", bus_ctx->access);
153  retval = amxb_new_invoke(&invoke_ctx, bus_ctx, object, NULL, "_list");
154  when_failed(retval, exit);
155  retval = amxb_invoke(invoke_ctx, &args, &list_return, NULL, NULL, 5);
156  when_failed(retval, exit);
157 
158  amxc_var_set_type(&ret, AMXC_VAR_ID_LIST);
159  amxb_build_list(&ret, amxd_path_get(&path, AMXD_OBJECT_TERMINATE),
160  flags, &list_return);
161  if(fn != NULL) {
162  fn(bus_ctx, &ret, priv);
163  }
164 
165 exit:
166  if(fn != NULL) {
167  fn(bus_ctx, NULL, priv);
168  }
169  amxc_var_clean(&ret);
170  amxd_path_clean(&path);
171  amxc_var_clean(&args);
172  amxc_var_clean(&list_return);
173  amxb_free_invoke(&invoke_ctx);
174  return retval;
175 }
static void amxb_build_list(amxc_var_t *ret, const char *object, uint32_t flags, amxc_var_t *full)
#define AMXB_FLAG_TEMPLATE_INFO
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