Cleanup magic strings in event sending code

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
pull/195/head
Jim Ramsay 2022-11-24 20:51:05 -05:00 committed by Andri Yngvason
parent 5c8014d19b
commit 19862aace8
1 changed files with 9 additions and 10 deletions

View File

@ -971,11 +971,12 @@ json_t* pack_connection_event_params(
"connection_count", new_connection_count); "connection_count", new_connection_count);
} }
int ctl_server_enqueue_event(struct ctl* self, const char* event_name, int ctl_server_enqueue_event(struct ctl* self, enum event_type evt_type,
json_t* params) json_t* params)
{ {
const char* event_name = evt_list[evt_type].name;
char* param_str = json_dumps(params, JSON_COMPACT); char* param_str = json_dumps(params, JSON_COMPACT);
nvnc_log(NVNC_LOG_DEBUG, "Enqueueing %s event: {%s", event_name, param_str); nvnc_log(NVNC_LOG_DEBUG, "Enqueueing %s event: %s", event_name, param_str);
free(param_str); free(param_str);
struct jsonipc_request* event = jsonipc_event_new(event_name, params); struct jsonipc_request* event = jsonipc_event_new(event_name, params);
json_decref(params); json_decref(params);
@ -1007,7 +1008,7 @@ int ctl_server_enqueue_event(struct ctl* self, const char* event_name,
} }
static void ctl_server_event_connect(struct ctl* self, static void ctl_server_event_connect(struct ctl* self,
bool connected, enum event_type evt_type,
const char* client_id, const char* client_id,
const char* client_hostname, const char* client_hostname,
const char* client_username, const char* client_username,
@ -1015,9 +1016,7 @@ static void ctl_server_event_connect(struct ctl* self,
{ {
json_t* params = pack_connection_event_params(client_id, client_hostname, json_t* params = pack_connection_event_params(client_id, client_hostname,
client_username, new_connection_count); client_username, new_connection_count);
ctl_server_enqueue_event(self, ctl_server_enqueue_event(self, evt_type, params);
connected ? "client-connected" : "client-disconnected",
params);
} }
void ctl_server_event_connected(struct ctl* self, void ctl_server_event_connected(struct ctl* self,
@ -1026,8 +1025,8 @@ void ctl_server_event_connected(struct ctl* self,
const char* client_username, const char* client_username,
int new_connection_count) int new_connection_count)
{ {
ctl_server_event_connect(self, true, client_id, client_hostname, ctl_server_event_connect(self, EVT_CLIENT_CONNECTED, client_id,
client_username, new_connection_count); client_hostname, client_username, new_connection_count);
} }
void ctl_server_event_disconnected(struct ctl* self, void ctl_server_event_disconnected(struct ctl* self,
@ -1036,6 +1035,6 @@ void ctl_server_event_disconnected(struct ctl* self,
const char* client_username, const char* client_username,
int new_connection_count) int new_connection_count)
{ {
ctl_server_event_connect(self, false, client_id, client_hostname, ctl_server_event_connect(self, EVT_CLIENT_DISCONNECTED, client_id,
client_username, new_connection_count); client_hostname, client_username, new_connection_count);
} }