#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <amxc/amxc_string_split.h>
#include <amxb_be_ubus/amxb_be_ubus.h>
#include "amxb_ubus.h"
#include <amxb_ubus_version.h>
Go to the source code of this file.
|
static void | amxb_ubus_remove_sub (AMXB_UNUSED const char *key, amxc_htable_it_t *it) |
|
static int | amxb_ubus_set_config (amxc_var_t *const configuration) |
|
static void | amxb_ubus_remove_connections (amxc_llist_it_t *lit) |
|
static void | amxb_ubus_reactivate_subscription (UNUSED amxp_timer_t *timer, void *priv) |
|
static void | amxb_ubus_watcher (UNUSED struct ubus_context *ctx, struct ubus_event_handler *ev, UNUSED const char *type, struct blob_attr *msg) |
|
static void | amxb_ubus_object_available (UNUSED amxp_timer_t *timer, UNUSED void *priv) |
|
static void | amxb_ubus_wait_watcher (UNUSED struct ubus_context *ctx, UNUSED struct ubus_event_handler *ev, UNUSED const char *type, struct blob_attr *msg) |
|
static void | amxb_ubus_config_changed (UNUSED const char *const sig_name, UNUSED const amxc_var_t *const data, void *const priv) |
|
const amxc_var_t * | amxb_ubus_get_config_option (const char *name) |
|
void *PRIVATE | amxb_ubus_connect (const char *host, const char *port, const char *path, amxp_signal_mngr_t *sigmngr) |
|
int PRIVATE | amxb_ubus_disconnect (void *ctx) |
|
int PRIVATE | amxb_ubus_get_fd (void *ctx) |
|
int PRIVATE | amxb_ubus_read (void *ctx) |
|
void PRIVATE | amxb_ubus_free (void *ctx) |
|
static void | amxb_ubus_wait_for_done (UNUSED const char *const sig_name, UNUSED const amxc_var_t *const d, void *const priv) |
|
static int | amxb_ubus_wait_for (void *const ctx, UNUSED const char *object) |
|
static uint32_t | amxb_ubus_capabilities (UNUSED void *ctx) |
|
static bool | amxb_ubus_has (void *ctx, const char *object) |
|
amxb_be_info_t * | amxb_be_info (void) |
|
int | amxb_be_ubus_init (void) |
|
int | amxb_be_ubus_clean (void) |
|
◆ amxb_be_info()
amxb_be_info_t* amxb_be_info |
( |
void |
| ) |
|
Definition at line 442 of file amxb_ubus.c.
amxb_be_info_t amxb_ubus_be_info
◆ amxb_be_ubus_clean()
int amxb_be_ubus_clean |
( |
void |
| ) |
|
Definition at line 450 of file amxb_ubus.c.
static void amxb_ubus_remove_connections(amxc_llist_it_t *lit)
static amxb_be_funcs_t amxb_ubus_impl
◆ amxb_be_ubus_init()
int amxb_be_ubus_init |
( |
void |
| ) |
|
◆ amxb_ubus_capabilities()
static uint32_t amxb_ubus_capabilities |
( |
UNUSED void * |
ctx | ) |
|
|
static |
Definition at line 356 of file amxb_ubus.c.
357 return AMXB_BE_DISCOVER | AMXB_BE_DISCOVER_RESOLVE;
◆ amxb_ubus_config_changed()
static void amxb_ubus_config_changed |
( |
UNUSED const char *const |
sig_name, |
|
|
UNUSED const amxc_var_t *const |
data, |
|
|
void *const |
priv |
|
) |
| |
|
static |
Definition at line 200 of file amxb_ubus.c.
205 if(amxb_ubus_ctx->
watcher.cb == NULL) {
207 ubus_register_event_handler(amxb_ubus_ctx->
ubus_ctx,
208 &amxb_ubus_ctx->
watcher,
"ubus.object.add");
211 if(amxb_ubus_ctx->
watcher.cb != NULL) {
212 ubus_unregister_event_handler(amxb_ubus_ctx->
ubus_ctx, &amxb_ubus_ctx->
watcher);
213 amxb_ubus_ctx->
watcher.cb = NULL;
static const amxc_var_t * config_opts
static void amxb_ubus_watcher(UNUSED struct ubus_context *ctx, struct ubus_event_handler *ev, UNUSED const char *type, struct blob_attr *msg)
struct ubus_event_handler watcher
struct ubus_context * ubus_ctx
◆ amxb_ubus_connect()
void* PRIVATE amxb_ubus_connect |
( |
const char * |
host, |
|
|
const char * |
port, |
|
|
const char * |
path, |
|
|
amxp_signal_mngr_t * |
sigmngr |
|
) |
| |
Definition at line 222 of file amxb_ubus.c.
228 when_not_null(host, exit);
229 when_not_null(port, exit);
232 when_null(amxb_ubus_ctx, exit);
234 amxb_ubus_ctx->
ubus_ctx = ubus_connect(path);
235 if(amxb_ubus_ctx->
ubus_ctx == NULL) {
237 amxb_ubus_ctx = NULL;
242 blob_buf_init(&amxb_ubus_ctx->
b, 0);
249 ubus_register_event_handler(amxb_ubus_ctx->
ubus_ctx,
250 &amxb_ubus_ctx->
watcher,
"ubus.object.add");
252 amxp_slot_connect(NULL,
259 return amxb_ubus_ctx;
static void amxb_ubus_config_changed(UNUSED const char *const sig_name, UNUSED const amxc_var_t *const data, void *const priv)
amxc_htable_t subscribers
amxc_llist_t pending_reqs
amxc_llist_t registered_objs
amxp_signal_mngr_t * sigmngr
static amxp_signal_mngr_t * sigmngr
◆ amxb_ubus_disconnect()
int PRIVATE amxb_ubus_disconnect |
( |
void * |
ctx | ) |
|
Definition at line 262 of file amxb_ubus.c.
265 when_null(amxb_ubus_ctx, exit);
266 when_null(amxb_ubus_ctx->
ubus_ctx, exit);
268 amxp_slot_disconnect_with_priv(NULL,
275 blob_buf_free(&amxb_ubus_ctx->
b);
static void amxb_ubus_remove_sub(AMXB_UNUSED const char *key, amxc_htable_it_t *it)
void PRIVATE amxb_ubus_cancel_requests(amxb_ubus_t *amxb_ubus_ctx)
◆ amxb_ubus_free()
void PRIVATE amxb_ubus_free |
( |
void * |
ctx | ) |
|
Definition at line 316 of file amxb_ubus.c.
319 when_null(amxb_ubus_ctx, exit);
void PRIVATE amxb_ubus_obj_it_free(amxc_llist_it_t *it)
◆ amxb_ubus_get_config_option()
const amxc_var_t* amxb_ubus_get_config_option |
( |
const char * |
name | ) |
|
◆ amxb_ubus_get_fd()
int PRIVATE amxb_ubus_get_fd |
( |
void * |
ctx | ) |
|
Definition at line 282 of file amxb_ubus.c.
286 when_null(amxb_ubus_ctx, exit);
287 when_null(amxb_ubus_ctx->
ubus_ctx, exit);
289 fd = amxb_ubus_ctx->
ubus_ctx->sock.fd;
◆ amxb_ubus_has()
static bool amxb_ubus_has |
( |
void * |
ctx, |
|
|
const char * |
object |
|
) |
| |
|
static |
Definition at line 360 of file amxb_ubus.c.
363 bool has_object =
false;
365 when_null(
object, exit);
367 retval = ubus_lookup_id(amxb_ubus_ctx->
ubus_ctx,
object, &
id);
369 when_failed(retval, exit);
371 has_object = (
id != 0);
◆ amxb_ubus_object_available()
static void amxb_ubus_object_available |
( |
UNUSED amxp_timer_t * |
timer, |
|
|
UNUSED void * |
priv |
|
) |
| |
|
static |
Definition at line 163 of file amxb_ubus.c.
165 amxc_string_t* path = amxc_string_from_llist_it(it);
166 amxp_sigmngr_emit_signal(NULL, amxc_string_get(path, 0), NULL);
167 amxc_string_delete(&path);
static amxp_timer_t * wait_timer
static amxc_llist_t avaiable_paths
◆ amxb_ubus_reactivate_subscription()
static void amxb_ubus_reactivate_subscription |
( |
UNUSED amxp_timer_t * |
timer, |
|
|
void * |
priv |
|
) |
| |
|
static |
Definition at line 103 of file amxb_ubus.c.
105 amxc_htable_t* subscribers = NULL;
107 const char* path = NULL;
110 subscribers = container_of(amxb_ubus_sub->
it.ait->array, amxc_htable_t, table);
111 amxb_ubus_ctx = container_of(subscribers,
amxb_ubus_t, subscribers);
112 path = amxc_htable_it_get_key(&amxb_ubus_sub->
it);
114 amxc_htable_it_take(&amxb_ubus_sub->
it);
115 ret = ubus_unregister_subscriber(amxb_ubus_ctx->
ubus_ctx, &amxb_ubus_sub->
sub);
116 when_failed(ret, exit);
120 amxp_timer_delete(&amxb_ubus_sub->
reactivate);
121 amxc_htable_it_clean(&amxb_ubus_sub->
it, NULL);
int PRIVATE amxb_ubus_subscribe(void *const ctx, const char *object)
amxp_timer_t * reactivate
struct ubus_subscriber sub
◆ amxb_ubus_read()
int PRIVATE amxb_ubus_read |
( |
void * |
ctx | ) |
|
Definition at line 295 of file amxb_ubus.c.
297 struct ubus_context* ubus_ctx = NULL;
300 when_null(amxb_ubus_ctx, exit);
301 when_null(amxb_ubus_ctx->
ubus_ctx, exit);
304 ubus_ctx->sock.cb(&ubus_ctx->sock, ULOOP_READ);
306 if(ubus_ctx->sock.eof) {
◆ amxb_ubus_remove_connections()
static void amxb_ubus_remove_connections |
( |
amxc_llist_it_t * |
lit | ) |
|
|
static |
Definition at line 98 of file amxb_ubus.c.
99 amxb_bus_ctx_t*
bus_ctx = amxc_llist_it_get_data(lit, amxb_bus_ctx_t, it);
static amxb_bus_ctx_t * bus_ctx
◆ amxb_ubus_remove_sub()
static void amxb_ubus_remove_sub |
( |
AMXB_UNUSED const char * |
key, |
|
|
amxc_htable_it_t * |
it |
|
) |
| |
|
static |
◆ amxb_ubus_set_config()
static int amxb_ubus_set_config |
( |
amxc_var_t *const |
configuration | ) |
|
|
static |
Definition at line 78 of file amxb_ubus.c.
80 amxc_var_t* uris = GET_ARG(configuration,
"uris");
84 if((configuration != NULL) && (uris == NULL)) {
85 uris = amxc_var_add_key(amxc_llist_t, configuration,
"uris", NULL);
88 if(stat(
"/var/run/ubus.sock", &sb) == 0) {
89 amxc_var_add(cstring_t, uris,
"ubus:/var/run/ubus.sock");
91 if(stat(
"/var/run/ubus/ubus.sock", &sb) == 0) {
92 amxc_var_add(cstring_t, uris,
"ubus:/var/run/ubus/ubus.sock");
◆ amxb_ubus_wait_for()
static int amxb_ubus_wait_for |
( |
void *const |
ctx, |
|
|
UNUSED const char * |
object |
|
) |
| |
|
static |
Definition at line 338 of file amxb_ubus.c.
342 when_null(amxb_ubus_ctx, exit);
345 ubus_register_event_handler(amxb_ubus_ctx->
ubus_ctx,
static void amxb_ubus_wait_watcher(UNUSED struct ubus_context *ctx, UNUSED struct ubus_event_handler *ev, UNUSED const char *type, struct blob_attr *msg)
static void amxb_ubus_wait_for_done(UNUSED const char *const sig_name, UNUSED const amxc_var_t *const d, void *const priv)
struct ubus_event_handler wait_watcher
◆ amxb_ubus_wait_for_done()
static void amxb_ubus_wait_for_done |
( |
UNUSED const char *const |
sig_name, |
|
|
UNUSED const amxc_var_t *const |
d, |
|
|
void *const |
priv |
|
) |
| |
|
static |
◆ amxb_ubus_wait_watcher()
static void amxb_ubus_wait_watcher |
( |
UNUSED struct ubus_context * |
ctx, |
|
|
UNUSED struct ubus_event_handler * |
ev, |
|
|
UNUSED const char * |
type, |
|
|
struct blob_attr * |
msg |
|
) |
| |
|
static |
Definition at line 173 of file amxb_ubus.c.
177 amxc_var_t watch_event;
178 amxc_string_t* sig_name = NULL;
180 amxc_var_init(&watch_event);
181 amxc_var_set_type(&watch_event, AMXC_VAR_ID_HTABLE);
183 (
struct blob_attr*) blob_data(msg),
186 amxc_string_new(&sig_name, 0);
187 amxc_string_setf(sig_name,
"wait:%s.", GET_CHAR(&watch_event,
"path"));
188 if(amxp_sigmngr_find_signal(NULL, amxc_string_get(sig_name, 0)) != NULL) {
195 amxc_string_delete(&sig_name);
197 amxc_var_clean(&watch_event);
static void amxb_ubus_object_available(UNUSED amxp_timer_t *timer, UNUSED void *priv)
int PRIVATE amxb_ubus_parse_blob_table(amxc_var_t *var, struct blob_attr *attr, int len)
◆ amxb_ubus_watcher()
static void amxb_ubus_watcher |
( |
UNUSED struct ubus_context * |
ctx, |
|
|
struct ubus_event_handler * |
ev, |
|
|
UNUSED const char * |
type, |
|
|
struct blob_attr * |
msg |
|
) |
| |
|
static |
Definition at line 125 of file amxb_ubus.c.
130 amxc_var_t watch_event;
131 amxc_htable_it_t* it = NULL;
132 const char* p = NULL;
134 amxc_string_t signal_name;
136 amxc_string_init(&signal_name, 0);
137 amxc_var_init(&watch_event);
138 amxc_var_set_type(&watch_event, AMXC_VAR_ID_HTABLE);
140 (
struct blob_attr*) blob_data(msg),
143 p = GET_CHAR(&watch_event,
"path");
144 amxc_string_setf(&signal_name,
"wait:%s.", p);
145 amxp_sigmngr_trigger_signal(NULL, amxc_string_get(&signal_name, 0), NULL);
147 it = amxc_htable_get(&amxb_ubus_ctx->
subscribers, p);
156 amxp_timer_start(amxb_ubus_sub->
reactivate, 100);
159 amxc_string_clean(&signal_name);
160 amxc_var_clean(&watch_event);
static void amxb_ubus_reactivate_subscription(UNUSED amxp_timer_t *timer, void *priv)
◆ amxb_ubus_be_info
amxb_be_info_t amxb_ubus_be_info |
Initial value:= {
.name = "ubus",
.description = "AMXB Backend for UBUS (Openwrt/Prplwrt)",
}
static amxb_version_t ubus_be_version
static amxb_version_t sup_max_lib_version
static amxb_version_t sup_min_lib_version
Definition at line 433 of file amxb_ubus.c.
◆ amxb_ubus_impl
amxb_be_funcs_t amxb_ubus_impl |
|
static |
◆ avaiable_paths
amxc_llist_t avaiable_paths |
|
static |
◆ config_opts
const amxc_var_t* config_opts = NULL |
|
static |
◆ sup_max_lib_version
amxb_version_t sup_max_lib_version |
|
static |
Initial value:= {
.major = 4,
.minor = -1,
.build = -1
}
Definition at line 421 of file amxb_ubus.c.
◆ sup_min_lib_version
amxb_version_t sup_min_lib_version |
|
static |
Initial value:= {
.major = 4,
.minor = 8,
.build = 0
}
Definition at line 415 of file amxb_ubus.c.
◆ ubus_be_version
amxb_version_t ubus_be_version |
|
static |
Initial value:= {
.major = AMXB_UBUS_VERSION_MAJOR,
.minor = AMXB_UBUS_VERSION_MINOR,
.build = AMXB_UBUS_VERSION_BUILD,
}
Definition at line 427 of file amxb_ubus.c.
◆ wait_timer
amxp_timer_t* wait_timer = NULL |
|
static |