mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-09 23:34:41 +01:00
Publish session start and end event
This commit is contained in:
parent
148e30344d
commit
63251b6c97
3 changed files with 40 additions and 0 deletions
|
|
@ -34,6 +34,7 @@
|
||||||
#include "cwmp_du_state.h"
|
#include "cwmp_du_state.h"
|
||||||
#include "cwmp_http.h"
|
#include "cwmp_http.h"
|
||||||
#include "uci_utils.h"
|
#include "uci_utils.h"
|
||||||
|
#include "ubus_utils.h"
|
||||||
|
|
||||||
static struct rpc *cwmp_add_session_rpc_acs_head(int type);
|
static struct rpc *cwmp_add_session_rpc_acs_head(int type);
|
||||||
static int cwmp_session_rpc_destructor(struct rpc *rpc);
|
static int cwmp_session_rpc_destructor(struct rpc *rpc);
|
||||||
|
|
@ -407,6 +408,9 @@ void start_cwmp_session(void)
|
||||||
|
|
||||||
CWMP_LOG(INFO, "Start session");
|
CWMP_LOG(INFO, "Start session");
|
||||||
|
|
||||||
|
// Send session start event
|
||||||
|
icwmp_ubus_send_event("icwmp.session", "{\"status\":\"start\"}");
|
||||||
|
|
||||||
get_uci_path_value(NULL, "cwmp.cpe.exec_download", exec_download, BUF_SIZE_256);
|
get_uci_path_value(NULL, "cwmp.cpe.exec_download", exec_download, BUF_SIZE_256);
|
||||||
if (CWMP_STRCMP(exec_download, "1") == 0) {
|
if (CWMP_STRCMP(exec_download, "1") == 0) {
|
||||||
CWMP_LOG(INFO, "Firmware downloaded and applied successfully");
|
CWMP_LOG(INFO, "Firmware downloaded and applied successfully");
|
||||||
|
|
@ -689,6 +693,9 @@ int run_session_end_func(void)
|
||||||
{
|
{
|
||||||
CWMP_LOG(INFO, "Handling end session with: (%u)", end_session_flag);
|
CWMP_LOG(INFO, "Handling end session with: (%u)", end_session_flag);
|
||||||
|
|
||||||
|
// Send session end event
|
||||||
|
icwmp_ubus_send_event("icwmp.session", "{\"status\":\"end\"}");
|
||||||
|
|
||||||
if (end_session_flag & END_SESSION_RESTART_SERVICES) {
|
if (end_session_flag & END_SESSION_RESTART_SERVICES) {
|
||||||
CWMP_LOG(INFO, "Restart modified services");
|
CWMP_LOG(INFO, "Restart modified services");
|
||||||
icwmp_restart_services(RELOAD_END_SESSION, true, true);
|
icwmp_restart_services(RELOAD_END_SESSION, true, true);
|
||||||
|
|
|
||||||
|
|
@ -458,6 +458,37 @@ void icwmp_uloop_ubus_exit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void icwmp_ubus_send_event(const char *event, const char *data)
|
||||||
|
{
|
||||||
|
if (CWMP_STRLEN(event) == 0) {
|
||||||
|
CWMP_LOG(ERROR, "No event name found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ubus_ctx == NULL) {
|
||||||
|
CWMP_LOG(ERROR, "Failed to connect with ubus err: %d", errno);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct blob_buf b = {0};
|
||||||
|
blob_buf_init(&b, 0);
|
||||||
|
|
||||||
|
if (CWMP_STRLEN(data)) {
|
||||||
|
if (blobmsg_add_json_from_string(&b, data) != true) {
|
||||||
|
CWMP_LOG(ERROR, "Failed to parse event data: %s", data);
|
||||||
|
blob_buf_free(&b);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ubus_send_event(ubus_ctx, event, b.head) != UBUS_STATUS_OK) {
|
||||||
|
CWMP_LOG(ERROR, "Failed to send event: %s", event);
|
||||||
|
}
|
||||||
|
|
||||||
|
blob_buf_free(&b);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg, icwmp_ubus_cb icwmp_callback, void *callback_arg)
|
int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg, icwmp_ubus_cb icwmp_callback, void *callback_arg)
|
||||||
{
|
{
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,13 @@
|
||||||
#define __ICWMP_UBUS_UTILS_H__
|
#define __ICWMP_UBUS_UTILS_H__
|
||||||
|
|
||||||
#include <libubus.h>
|
#include <libubus.h>
|
||||||
|
#include <libubox/blobmsg_json.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
typedef void (*icwmp_ubus_cb)(struct ubus_request *req, int type, struct blob_attr *msg);
|
typedef void (*icwmp_ubus_cb)(struct ubus_request *req, int type, struct blob_attr *msg);
|
||||||
typedef void (*icwmp_ubus_async_cb)(struct ubus_request *req, int ret);
|
typedef void (*icwmp_ubus_async_cb)(struct ubus_request *req, int ret);
|
||||||
void bb_add_string(struct blob_buf *bb, const char *name, const char *value);
|
void bb_add_string(struct blob_buf *bb, const char *name, const char *value);
|
||||||
|
void icwmp_ubus_send_event(const char *event, const char *data);
|
||||||
int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg,
|
int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg,
|
||||||
icwmp_ubus_cb icwmp_callback, void *callback_arg);
|
icwmp_ubus_cb icwmp_callback, void *callback_arg);
|
||||||
int icwmp_ubus_invoke_timeout(const char *obj, const char *method, struct blob_attr *msg,
|
int icwmp_ubus_invoke_timeout(const char *obj, const char *method, struct blob_attr *msg,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue