static void *broadcast_message_thread(void *data) { for (;;) { ipc_message msg; int ret = ipc_get_status(&msg); if (!ret && strlen(msg.data.status.desc) != 0) { struct mg_mgr *mgr = (struct mg_mgr *) data; char text[4096]; char str[4160]; snescape(text, sizeof(text), msg.data.status.desc); snprintf(str, sizeof(str), "{\r\n" "\t\"type\": \"message\",\r\n" "\t\"level\": \"%d\",\r\n" "\t\"text\": \"%s\"\r\n" "}\r\n", (msg.data.status.error) ? 3 : 6, /* RFC 5424 */ text); broadcast(mgr, str); continue; } usleep(50 * 1000); } return NULL; }
/** * \brief Process an interrupt request on the given IPC. * * \param p_ipc Pointer to an IPC instance. */ static void ipc_handler_process(Ipc *p_ipc) { uint32_t status, i, ipc; (p_ipc == IPC0) ? (ipc = 0) : (ipc = 1); /* Read IPC interrupt status */ status = ipc_get_status(p_ipc); status &= ipc_get_interrupt_mask(p_ipc); /* Check pending events */ if (status != 0) { /* Find triggering source */ i = 0; while ((status != 0) && (i < IPC_MAX_INTERRUPT_SOURCES)) { if ((status & ipc_handler[ipc][i].mask) != 0) { ipc_handler[ipc][i].handler(p_ipc, ipc_handler[ipc][i].mask); status &= ~(ipc_handler[ipc][i].mask); } i++; } } }
static void recovery_status(struct mg_connection *nc, int ev, void *ev_data) { ipc_message ipc; int ret; char buf[4096]; (void)ev; (void)ev_data; ret = ipc_get_status(&ipc); if (ret) { mg_http_send_error(nc, 500, NULL); return; } snprintf(buf, sizeof(buf), "{\r\n" "\t\"Status\" : \"%d\",\r\n" "\t\"Msg\" : \"%s\",\r\n" "\t\"Error\" : \"%d\",\r\n" "\t\"LastResult\" : \"%d\"\r\n" "}\r\n", ipc.data.status.current, strlen(ipc.data.status.desc) ? ipc.data.status.desc : "", ipc.data.status.error, ipc.data.status.last_result); mg_send_head(nc, 200, strlen(buf), "Cache: no-cache\r\n" "Content-Type: text/plain"); mg_send(nc, buf, strlen(buf)); nc->flags |= MG_F_SEND_AND_CLOSE; }