MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / runtime_worker_handle_status

Function runtime_worker_handle_status

src/daemon/runtime.c:1509–1555  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1507}
1508
1509static void runtime_worker_handle_status(cbm_daemon_runtime_worker_t *worker,
1510 const uint8_t *payload, uint32_t length) {
1511 cbm_daemon_runtime_service_t *service = worker->service;
1512 char requested_build[CBM_DAEMON_BUILD_FINGERPRINT_SIZE] = {0};
1513 bool peer_verified =
1514 runtime_control_request_decode(payload, length, requested_build) &&
1515 runtime_activation_peer_matches_claim(service, worker->peer_process_id, requested_build);
1516 uint8_t response[CBM_DAEMON_STATUS_RESPONSE_SIZE];
1517 memset(response, 0, sizeof(response));
1518 if (peer_verified) {
1519 uint8_t count = 0U;
1520 uint32_t pids[CBM_DAEMON_CONTROL_CLIENT_CAP] = {0};
1521 cbm_mutex_lock(&service->mutex);
1522 response[0] = 1U;
1523 response[1] =
1524 (uint8_t)((service->permanent ? 0x01U : 0U) |
1525 (service->state != CBM_DAEMON_RUNTIME_SERVICE_RUNNING ? 0x02U : 0U));
1526 uint16_t committed = service->committed_clients > UINT16_MAX
1527 ? UINT16_MAX
1528 : (uint16_t)service->committed_clients;
1529 response[2] = (uint8_t)(committed >> 8);
1530 response[3] = (uint8_t)(committed & 0xFFU);
1531 uint32_t daemon_pid = (uint32_t)runtime_current_process_id();
1532 response[4] = (uint8_t)(daemon_pid >> 24);
1533 response[5] = (uint8_t)(daemon_pid >> 16);
1534 response[6] = (uint8_t)(daemon_pid >> 8);
1535 response[7] = (uint8_t)(daemon_pid & 0xFFU);
1536 runtime_control_collect_clients_locked(service, worker, &count, pids);
1537 response[8] = count;
1538 for (size_t index = 0; index < CBM_DAEMON_CONTROL_CLIENT_CAP; index++) {
1539 size_t offset = 12U + index * 4U;
1540 response[offset] = (uint8_t)(pids[index] >> 24);
1541 response[offset + 1U] = (uint8_t)(pids[index] >> 16);
1542 response[offset + 2U] = (uint8_t)(pids[index] >> 8);
1543 response[offset + 3U] = (uint8_t)(pids[index] & 0xFFU);
1544 }
1545 (void)snprintf((char *)response + 44U, CBM_DAEMON_BUILD_FINGERPRINT_SIZE, "%s",
1546 service->identity.build_fingerprint);
1547 (void)snprintf((char *)response + 109U, 12U, "%s",
1548 service->identity.semantic_version ? service->identity.semantic_version
1549 : "");
1550 cbm_mutex_unlock(&service->mutex);
1551 }
1552 (void)runtime_worker_send_frame(worker, CBM_DAEMON_FRAME_RESPONSE, CBM_DAEMON_RUNTIME_OP_STATUS,
1553 response, (uint32_t)sizeof(response));
1554 runtime_worker_finish(worker);
1555}
1556
1557static void runtime_worker_handle_stop(cbm_daemon_runtime_worker_t *worker, const uint8_t *payload,
1558 uint32_t length) {

Callers 1

Tested by

no test coverage detected