diff --git a/CMakeLists.txt b/CMakeLists.txt
index ea5acde..2dfc305 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -156,13 +156,15 @@ if (requirements)
if (SAI_SERVER)
add_subdirectory(src/server)
add_subdirectory(src/web)
+ if (NOT MSVC AND NOT WIN32 AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "SunOS"))
+ add_subdirectory(src/power)
+ endif()
endif()
if (SAI_BUILDER)
add_subdirectory(src/builder)
add_subdirectory(src/resource)
if (NOT MSVC AND NOT WIN32 AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "SunOS"))
- add_subdirectory(src/power)
add_subdirectory(src/device)
add_subdirectory(src/expect)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
diff --git a/assets/sai.js b/assets/sai.js
index 2410dd3..cfe9592 100644
--- a/assets/sai.js
+++ b/assets/sai.js
@@ -2568,6 +2568,10 @@ function ws_open_sai()
location.reload();
break;
+ case "com.warmcat.sai.event_deleted":
+ window.location.href = window.location.origin + window.location.pathname;
+ break;
+
case "com-warmcat-sai-logs":
var s1;
try {
diff --git a/src/builder/b-deletion.c b/src/builder/b-deletion.c
index 7e08dbe..a4564d5 100644
--- a/src/builder/b-deletion.c
+++ b/src/builder/b-deletion.c
@@ -134,7 +134,7 @@ sai_deletion_worker(const char *home_dir)
lwsl_info("%s: performing rm -rf %s\n", __func__, full_path);
if (lws_dir_via_info(&di))
- lwsl_err("%s: failed to delete %s: %s\n",
+ lwsl_info("%s: failed to delete %s: %s\n",
__func__, full_path, strerror(errno));
}
} while (1);
diff --git a/src/builder/b-power.c b/src/builder/b-power.c
index 1422fec..beaae9b 100644
--- a/src/builder/b-power.c
+++ b/src/builder/b-power.c
@@ -49,7 +49,7 @@ saib_power_client_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf,
{
saib_power_client_t *g = (saib_power_client_t *)userobj;
- return sai_ss_tx_from_buflist_helper(ss_power_client, &g->bl_tx,
+ return sai_ss_tx_from_buflist_helper(g->ss, &g->bl_tx,
buf, len, flags);
}
@@ -77,7 +77,7 @@ saib_power_client_state(void *userobj, void *sh, lws_ss_constate_t state,
switch (state) {
case LWSSSCS_CREATING:
lwsl_notice("%s: CREATING sai-power client connection to %s\n", __func__, builder.url_sai_power);
- if (lws_ss_set_metadata((struct lws_ss_handle *)sh, "url",
+ if (lws_ss_set_metadata(g->ss, "url",
builder.url_sai_power,
strlen(builder.url_sai_power)))
lwsl_err("%s: failed to set metadata\n", __func__);
@@ -120,7 +120,7 @@ saib_power_client_state(void *userobj, void *sh, lws_ss_constate_t state,
} lws_end_foreach_dll(d);
/* Send it */
- sai_ss_serialize_queue_helper(ss_power_client, &g->bl_tx,
+ sai_ss_serialize_queue_helper(g->ss, &g->bl_tx,
lsm_schema_builder_registration,
LWS_ARRAY_SIZE(lsm_schema_builder_registration),
&r);
@@ -360,8 +360,9 @@ sul_do_suspend_cb(lws_sorted_usec_list_t *sul)
lwsl_notice("%s: actioning suspend...\n", __func__);
- n = write(fd, &te, 1);
- if (n == 1) {
+ if (fd >= 0) {
+ n = write(fd, &te, 1);
+ if (n == 1) {
#if defined(WIN32)
Sleep(2000);
#else
@@ -374,8 +375,10 @@ sul_do_suspend_cb(lws_sorted_usec_list_t *sul)
lws_sul_schedule(builder.context, 0, &builder.sul_idle,
sul_idle_cb, SAI_IDLE_GRACE_US);
lwsl_notice("%s: resuming after suspend\n", __func__);
+ } else
+ lwsl_err("%s: failed to request suspend\n", __func__);
} else
- lwsl_err("%s: failed to request suspend\n", __func__);
+ lwsl_err("%s: no suspender pipe\n", __func__);
#endif
}
@@ -388,7 +391,10 @@ sul_shutdown_cb(lws_sorted_usec_list_t *sul)
lwsl_warn("%s: device shutting down\n", __func__);
- n = write(fd, &te, 1);
+ if (fd >= 0)
+ n = write(fd, &te, 1);
+ else
+ n = -1;
if (n != 1)
lwsl_err("%s: shutdown request failed\n", __func__);
@@ -501,11 +507,15 @@ saib_power_init(void)
* Do we have a url for sai-power? If not, nothing we can do.
*/
+ lwsl_notice("====== ENTERED SAIB_POWER_INIT ======\n");
+
if (!builder.url_sai_power) {
- lwsl_err("%s: *** missing URL for url_sai_power\n", __func__);
+ lwsl_err("====== *** missing URL for url_sai_power ======\n");
return 1;
}
+ lwsl_notice("====== URL_SAI_POWER IS: %s ======\n", builder.url_sai_power);
+
/* Existing SS creation for power-off logic */
lwsl_notice("%s: *** creating sai-power ss...\n", __func__);
diff --git a/src/builder/b-sai.c b/src/builder/b-sai.c
index 954a275..e7206c6 100644
--- a/src/builder/b-sai.c
+++ b/src/builder/b-sai.c
@@ -351,8 +351,6 @@ app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
return 1;
}
- saib_power_init();
-
#if defined(__linux__) || defined(__NetBSD__) || defined(__APPLE__)
if (saib_suspender_fork(argv0))
return 1;
@@ -384,6 +382,10 @@ app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
return 1;
}
+ lwsl_notice("====== EXECUTING SAIB_POWER_INIT ======\n");
+ saib_power_init();
+ lwsl_notice("====== EXECUTED SAIB_POWER_INIT ======\n");
+
if (builder.power_controller_name) {
lws_start_foreach_dll(struct lws_dll2 *, d, builder.sai_plat_owner.head) {
struct sai_plat *sp = lws_container_of(d, struct sai_plat, sai_plat_list);
diff --git a/src/builder/b-suspender.c b/src/builder/b-suspender.c
index 980c036..3461553 100644
--- a/src/builder/b-suspender.c
+++ b/src/builder/b-suspender.c
@@ -63,7 +63,7 @@ int
saib_suspender_get_pipe(void)
{
#if defined(__linux__)
- int fd = lws_spawn_get_fd_stdxxx(lsp_suspender, 0);
+ int fd = lsp_suspender ? lws_spawn_get_fd_stdxxx(lsp_suspender, 0) : -1;
#else
#if defined(__APPLE__) || defined(__NetBSD__)
int fd = builder.pipe_suspender_wr;
@@ -252,13 +252,20 @@ saib_suspender_start(void)
uint8_t d;
n = read(0, &d, 1);
- lwsl_notice("%s: suspend process read returned %d\n", __func__, (int)n);
+ if (n < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ continue;
+ lwsl_err("%s: suspend process read failed %d\n", __func__, errno);
+ break;
+ }
#if defined(__APPLE__)
sleep(1);
#endif
- if (n <= 0)
- continue;
+ if (n == 0) {
+ lwsl_notice("%s: suspend process pipe closed\n", __func__);
+ break;
+ }
if (d == 2) {
lwsl_warn("%s: suspend process ending\n", __func__);
@@ -348,6 +355,7 @@ suspender_destroy()
* Clean up after the suspend process
*/
- write(fd, &te, 1);
+ if (fd >= 0)
+ write(fd, &te, 1);
}
}
diff --git a/src/power/p-ws-server.c b/src/power/p-ws-server.c
index c1282b0..20b004f 100644
--- a/src/power/p-ws-server.c
+++ b/src/power/p-ws-server.c
@@ -53,7 +53,7 @@ saip_queue_energy_report(saip_server_t *sps)
int r = 0;
int count = 0;
- if (!sps->ss)
+ if (!sps || !sps->ss)
return 0;
m = (saip_server_link_t *)lws_ss_to_user_object(sps->ss);
@@ -137,6 +137,9 @@ saip_queue_stay_info(saip_server_t *sps)
/* lwsl_ss_notice(sps->ss, "@@@@@@@@@@@@@@ sai-power CONNECTED to server"); */
+ if (!sps)
+ return 0;
+
m = (saip_server_link_t *)lws_ss_to_user_object(sps->ss);
memset(&pmb, 0, sizeof(pmb));
@@ -151,7 +154,7 @@ saip_queue_stay_info(saip_server_t *sps)
lws_strncpy(pc1->name, pc->name, sizeof(pc1->name));
pc1->on = (unsigned int)pc->on;
pc1->manual_on = !!(pc->flags & SAIP_PCON_F_MANUAL_STAY);
- if (pc->depends_on[0])
+ if (pc->depends_on && pc->depends_on[0])
lws_strncpy(pc1->depends_on, pc->depends_on, sizeof(pc1->depends_on));
if (pc->type[0])
lws_strncpy(pc1->type, pc->type, sizeof(pc1->type));
diff --git a/src/web/w-ws-browser.c b/src/web/w-ws-browser.c
index 33f4bc5..053a365 100644
--- a/src/web/w-ws-browser.c
+++ b/src/web/w-ws-browser.c
@@ -292,8 +292,14 @@ saiw_pss_schedule_taskinfo(struct pss *pss, const char *task_uuid, int logsub)
/* open the event-specific database object */
if (sai_event_db_ensure_open(pss->vhd->context, &pss->vhd->sqlite3_cache,
- pss->vhd->sqlite3_path_lhs, event_uuid, 0, &pdb))
+ pss->vhd->sqlite3_path_lhs, event_uuid, 0, &pdb)) {
+ uint8_t buf[LWS_PRE + 128];
+ int n1 = lws_snprintf((char *)buf + LWS_PRE, sizeof(buf) - LWS_PRE,
+ "{\"schema\":\"com.warmcat.sai.event_deleted\"}");
+ saiw_ws_browser_queue_REQUIRES_LWS_PRE(pss, buf + LWS_PRE, (size_t)n1,
+ LWS_WRITE_TEXT);
return 0;
+ }
/*
* get the related task object into its own ac... there might
@@ -789,9 +795,16 @@ saiw_broadcast_logs_batch(struct vhd *vhd, struct pss *pss)
if (sai_event_db_ensure_open(vhd->context, &vhd->sqlite3_cache,
vhd->sqlite3_path_lhs, event_uuid,
0, &pdb)) {
+ uint8_t buf[LWS_PRE + 128];
+ int n1;
lwsl_notice("%s: unable to open event-specific database\n",
__func__);
+ n1 = lws_snprintf((char *)buf + LWS_PRE, sizeof(buf) - LWS_PRE,
+ "{\"schema\":\"com.warmcat.sai.event_deleted\"}");
+ saiw_ws_browser_queue_REQUIRES_LWS_PRE(pss, buf + LWS_PRE, (size_t)n1,
+ LWS_WRITE_TEXT);
+
return 0;
}
@@ -1344,7 +1357,6 @@ saiw_browser_broadcast_queue_builders(struct vhd *vhd, struct pss *pss)
LWS_ARRAY_SIZE(lsm_schema_map_plat_simple),
0, b);
if (!js) {
- lwsac_unreference(&vhd->builders);
free(d.buf);
return 1;
}
@@ -1353,7 +1365,6 @@ saiw_browser_broadcast_queue_builders(struct vhd *vhd, struct pss *pss)
if (subsequent && start_of_this_builder) {
if (sai_dyn_buf_append(&d, ",", 1)) {
lws_struct_json_serialize_destroy(&js);
- lwsac_unreference(&vhd->builders);
free(d.buf);
return 1;
}
@@ -1364,7 +1375,6 @@ saiw_browser_broadcast_queue_builders(struct vhd *vhd, struct pss *pss)
if (w && sai_dyn_buf_append(&d, buf, w)) {
lws_struct_json_serialize_destroy(&js);
- lwsac_unreference(&vhd->builders);
free(d.buf);
return 1;
}
@@ -1372,7 +1382,6 @@ saiw_browser_broadcast_queue_builders(struct vhd *vhd, struct pss *pss)
switch (r) {
case LSJS_RESULT_ERROR:
lws_struct_json_serialize_destroy(&js);
- lwsac_unreference(&vhd->builders);
free(d.buf);
return 1;
case LSJS_RESULT_CONTINUE:
@@ -1389,12 +1398,10 @@ saiw_browser_broadcast_queue_builders(struct vhd *vhd, struct pss *pss)
n = lws_snprintf(buf, sizeof(buf), " \n]}");
if (sai_dyn_buf_append(&d, buf, (size_t)n)) {
- lwsac_unreference(&vhd->builders);
free(d.buf);
return 1;
}
- lwsac_unreference(&vhd->builders);
saiw_browser_broadcast_queue_power_history(vhd, pss);