mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Remove bbfdm.linker request and response events
This commit is contained in:
parent
bd9f7db4fb
commit
e3757b5f37
5 changed files with 11 additions and 91 deletions
|
|
@ -71,10 +71,6 @@ static int bbfdm_handler_async(struct ubus_context *ctx, struct ubus_object *obj
|
|||
|
||||
// Send linker cleanup event for all services
|
||||
send_linker_cleanup_event(ctx);
|
||||
|
||||
// Event handler to wait for linker response
|
||||
context->linker_handler.cb = linker_response_callback;
|
||||
ubus_register_event_handler(ctx, &context->linker_handler, "bbfdm.linker.response");
|
||||
}
|
||||
|
||||
fill_optional_input(tb[BBFDM_INPUT], &requested_proto, &context->raw_format);
|
||||
|
|
|
|||
|
|
@ -122,15 +122,23 @@ static void resolve_reference_path(struct async_request_context *ctx, struct blo
|
|||
// Search for token in the linker list
|
||||
struct linker_args *linker = NULL;
|
||||
bool linker_found = false;
|
||||
bool linker_empty = false;
|
||||
list_for_each_entry(linker, &ctx->linker_list, list) {
|
||||
if (strcmp(linker->path, token) == 0 && linker->value[0] != '\0') {
|
||||
pos += snprintf(&output[pos], output_len - pos, "%s,", linker->value);
|
||||
if (strcmp(linker->path, token) == 0) {
|
||||
linker_found = true;
|
||||
|
||||
if (linker->value[0] != '\0') {
|
||||
pos += snprintf(&output[pos], output_len - pos, "%s,", linker->value);
|
||||
} else {
|
||||
linker_empty = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (linker_found) {
|
||||
if (linker_empty) continue;
|
||||
if (!is_ref_list) break;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -230,7 +238,6 @@ void send_response(struct async_request_context *ctx)
|
|||
prepare_and_send_response(ctx);
|
||||
|
||||
if (strcmp(ctx->ubus_method, "get") == 0) {
|
||||
ubus_unregister_event_handler(ctx->ubus_ctx, &ctx->linker_handler);
|
||||
send_linker_cleanup_event(ctx->ubus_ctx);
|
||||
free_linker_entries(ctx);
|
||||
}
|
||||
|
|
@ -367,23 +374,3 @@ void send_linker_cleanup_event(struct ubus_context *ctx)
|
|||
blob_buf_free(&bb);
|
||||
}
|
||||
|
||||
void linker_response_callback(struct ubus_context *ctx __attribute__((unused)), struct ubus_event_handler *ev, const char *type __attribute__((unused)), struct blob_attr *msg)
|
||||
{
|
||||
struct async_request_context *context = NULL;
|
||||
struct blob_attr *attr = NULL;
|
||||
size_t rem = 0;
|
||||
|
||||
if (!msg)
|
||||
return;
|
||||
|
||||
context = container_of(ev, struct async_request_context, linker_handler);
|
||||
if (context == NULL) {
|
||||
BBFDM_ERR("Failed to get the request context");
|
||||
return;
|
||||
}
|
||||
|
||||
blobmsg_for_each_attr(attr, msg, rem) {
|
||||
BBFDM_DEBUG("LINKER RESPONSE: '%s' <=> '%s'", blobmsg_name(attr), blobmsg_get_string(attr));
|
||||
add_linker_entry(context, blobmsg_name(attr), blobmsg_get_string(attr));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ struct linker_args {
|
|||
struct async_request_context {
|
||||
struct ubus_context *ubus_ctx;
|
||||
struct ubus_request_data request_data;
|
||||
struct ubus_event_handler linker_handler;
|
||||
struct list_head linker_list;
|
||||
struct blob_buf tmp_bb;
|
||||
bool service_list_processed;
|
||||
|
|
@ -47,7 +46,6 @@ struct ubus_request_tracker {
|
|||
};
|
||||
|
||||
void send_linker_cleanup_event(struct ubus_context *ctx);
|
||||
void linker_response_callback(struct ubus_context *ctx, struct ubus_event_handler *ev, const char *type, struct blob_attr *msg);
|
||||
|
||||
void run_async_call(struct async_request_context *ctx, const char *ubus_obj, struct blob_attr *msg);
|
||||
void send_response(struct async_request_context *ctx);
|
||||
|
|
|
|||
|
|
@ -222,22 +222,6 @@ int bbf_set_alias(struct dmctx *ctx, struct uci_section *s, const char *option_n
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void send_linker_request_event(struct ubus_context *ctx, const char *path)
|
||||
{
|
||||
struct blob_buf bb;
|
||||
|
||||
if (DM_STRLEN(path) == 0)
|
||||
return;
|
||||
|
||||
memset(&bb, 0, sizeof(struct blob_buf));
|
||||
blob_buf_init(&bb, 0);
|
||||
|
||||
blobmsg_add_string(&bb, "path", path);
|
||||
|
||||
ubus_send_event(ctx, "bbfdm.linker.request", bb.head);
|
||||
blob_buf_free(&bb);
|
||||
}
|
||||
|
||||
int bbfdm_get_references(struct dmctx *ctx, int match_action, const char *base_path, const char *key_name, char *key_value, char *out, size_t out_len)
|
||||
{
|
||||
char param_path[1024] = {0};
|
||||
|
|
@ -287,8 +271,6 @@ int bbfdm_get_references(struct dmctx *ctx, int match_action, const char *base_p
|
|||
|
||||
snprintf(param_path, sizeof(param_path), "%s[%s==\"%s\"].", base_path, key_name, key_value);
|
||||
|
||||
send_linker_request_event(ctx->ubus_ctx, param_path);
|
||||
|
||||
snprintf(&out[len], out_len - len, "%s%s", len ? (match_action == MATCH_FIRST ? "," : ";") : "", param_path);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -766,19 +766,6 @@ static int regiter_ubus_object(struct ubus_context *ctx)
|
|||
return ubus_add_object(ctx, &bbf_object);
|
||||
}
|
||||
|
||||
static void send_linker_response_event(struct ubus_context *ctx, const char *reference_path, const char *reference_value)
|
||||
{
|
||||
struct blob_buf bb;
|
||||
|
||||
memset(&bb, 0, sizeof(struct blob_buf));
|
||||
blob_buf_init(&bb, 0);
|
||||
|
||||
bb_add_string(&bb, reference_path, reference_value ? reference_value : "");
|
||||
|
||||
ubus_send_event(ctx, "bbfdm.linker.response", bb.head);
|
||||
blob_buf_free(&bb);
|
||||
}
|
||||
|
||||
static void bbfdm_linker_cb(struct ubus_context *ctx, struct ubus_event_handler *ev,
|
||||
const char *type, struct blob_attr *msg)
|
||||
{
|
||||
|
|
@ -796,36 +783,6 @@ static void bbfdm_linker_cb(struct ubus_context *ctx, struct ubus_event_handler
|
|||
if (strcmp(type, "bbfdm.linker.cleanup") == 0) {
|
||||
//BBF_ERR("bbfdm.linker.cleanup");
|
||||
free_pv_list(&u->linker_list);
|
||||
} else if (strcmp(type, "bbfdm.linker.request") == 0) {
|
||||
//BBF_ERR("bbfdm.linker.request");
|
||||
|
||||
struct dmctx bbf_ctx = {0};
|
||||
struct blob_attr *tb[1] = {0};
|
||||
const struct blobmsg_policy p[1] = {
|
||||
{ "path", BLOBMSG_TYPE_STRING }
|
||||
};
|
||||
|
||||
blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg));
|
||||
|
||||
char *reference_path = tb[0] ? blobmsg_get_string(tb[0]) : "";
|
||||
|
||||
if (DM_STRLEN(reference_path) == 0)
|
||||
return;
|
||||
|
||||
if (!match_with_path_list(&u->obj_list, reference_path))
|
||||
return;
|
||||
|
||||
if (present_in_pv_list(&u->linker_list, reference_path))
|
||||
return;
|
||||
|
||||
bbf_init(&bbf_ctx);
|
||||
|
||||
char *reference_value = get_value_by_reference_path(&bbf_ctx, reference_path);
|
||||
|
||||
add_pv_list(reference_path, reference_value, NULL, &u->linker_list);
|
||||
send_linker_response_event(ctx, reference_path, reference_value);
|
||||
|
||||
bbf_cleanup(&bbf_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -932,7 +889,7 @@ int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx)
|
|||
if (err != 0)
|
||||
return err;
|
||||
|
||||
return ubus_register_event_handler(&bbfdm_ctx->ubus_ctx, &bbfdm_linker_handler, "bbfdm.linker.*");
|
||||
return ubus_register_event_handler(&bbfdm_ctx->ubus_ctx, &bbfdm_linker_handler, "bbfdm.linker.cleanup");
|
||||
}
|
||||
|
||||
int bbfdm_ubus_regiter_free(struct bbfdm_context *bbfdm_ctx)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue