| 413 | } |
| 414 | |
| 415 | cbm_daemon_client_id_t cbm_daemon_client_connected(cbm_daemon_coordinator_t *coordinator, |
| 416 | uint64_t now_ms) { |
| 417 | if (!coordinator) { |
| 418 | return CBM_DAEMON_CLIENT_ID_INVALID; |
| 419 | } |
| 420 | |
| 421 | cbm_daemon_client_t *client = malloc(sizeof(*client)); |
| 422 | if (!client) { |
| 423 | return CBM_DAEMON_CLIENT_ID_INVALID; |
| 424 | } |
| 425 | |
| 426 | cbm_mutex_lock(&coordinator->mutex); |
| 427 | if (coordinator->state != CBM_DAEMON_COORDINATOR_RUNNING) { |
| 428 | cbm_mutex_unlock(&coordinator->mutex); |
| 429 | free(client); |
| 430 | return CBM_DAEMON_CLIENT_ID_INVALID; |
| 431 | } |
| 432 | cbm_daemon_client_id_t client_id = issue_client_id_locked(coordinator); |
| 433 | if (client_id == CBM_DAEMON_CLIENT_ID_INVALID) { |
| 434 | cbm_mutex_unlock(&coordinator->mutex); |
| 435 | free(client); |
| 436 | return CBM_DAEMON_CLIENT_ID_INVALID; |
| 437 | } |
| 438 | client->id = client_id; |
| 439 | client->last_heartbeat_ms = now_ms; |
| 440 | client->next = coordinator->clients; |
| 441 | coordinator->clients = client; |
| 442 | coordinator->client_count++; |
| 443 | cbm_mutex_unlock(&coordinator->mutex); |
| 444 | return client_id; |
| 445 | } |
| 446 | |
| 447 | bool cbm_daemon_client_disconnected(cbm_daemon_coordinator_t *coordinator, |
| 448 | cbm_daemon_client_id_t client_id, uint64_t now_ms) { |
no test coverage detected