ipc/server: Remove (f)printf usage from code

This commit is contained in:
Jakob Bornecrantz 2020-12-09 19:11:17 +00:00
parent 1154e58d06
commit 4b74d6b7eb
2 changed files with 27 additions and 23 deletions

View file

@ -34,7 +34,7 @@ validate_swapchain_state(volatile struct ipc_client_state *ics,
}
if (index >= IPC_MAX_CLIENT_SWAPCHAINS) {
fprintf(stderr, "ERROR: Too many swapchains!\n");
IPC_ERROR(ics->server, "Too many swapchains!\n");
return XRT_ERROR_IPC_FAILURE;
}
@ -282,7 +282,8 @@ ipc_handle_system_set_primary_client(volatile struct ipc_client_state *ics,
{
ics->server->active_client_index = client_id;
printf("system setting active client to %d\n", client_id);
IPC_INFO(ics->server, "system setting active client to %d\n",
client_id);
update_server_state(ics->server);
return XRT_SUCCESS;
}
@ -291,8 +292,9 @@ xrt_result_t
ipc_handle_system_set_focused_client(volatile struct ipc_client_state *ics,
uint32_t client_id)
{
printf("UNIMPLEMENTED: system setting focused client to %d\n",
client_id);
IPC_INFO(ics->server,
"UNIMPLEMENTED: system setting focused client to %d\n",
client_id);
return XRT_SUCCESS;
}
@ -355,7 +357,8 @@ ipc_handle_swapchain_create(volatile struct ipc_client_state *ics,
struct xrt_swapchain *xsc = NULL;
xret = xrt_comp_create_swapchain(ics->xc, info, &xsc);
if (xret != XRT_SUCCESS) {
fprintf(stderr, "ERROR: xrt_comp_create_swapchain failed!\n");
IPC_ERROR(ics->server,
"ERROR: xrt_comp_create_swapchain failed!\n");
return xret;
}

View file

@ -32,8 +32,11 @@
*/
static int
setup_epoll(int listen_socket)
setup_epoll(volatile struct ipc_client_state *ics)
{
int listen_socket = ics->imc.socket_fd;
assert(listen_socket >= 0);
int ret = epoll_create1(EPOLL_CLOEXEC);
if (ret < 0) {
return ret;
@ -47,8 +50,8 @@ setup_epoll(int listen_socket)
ev.data.fd = listen_socket;
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, listen_socket, &ev);
if (ret < 0) {
fprintf(stderr, "ERROR: epoll_ctl(listen_socket) failed '%i'\n",
ret);
IPC_ERROR(ics->server, "epoll_ctl(listen_socket) failed '%i'\n",
ret);
return ret;
}
@ -65,13 +68,13 @@ setup_epoll(int listen_socket)
static void
client_loop(volatile struct ipc_client_state *ics)
{
fprintf(stderr, "SERVER: Client connected\n");
IPC_INFO(ics->server, "Client connected\n");
// Make sure it's ready for the client.
u_rt_helper_client_clear((struct u_rt_helper *)&ics->urth);
// Claim the client fd.
int epoll_fd = setup_epoll(ics->imc.socket_fd);
int epoll_fd = setup_epoll(ics);
if (epoll_fd < 0) {
return;
}
@ -85,10 +88,10 @@ client_loop(volatile struct ipc_client_state *ics)
// We use epoll here to be able to timeout.
int ret = epoll_wait(epoll_fd, &event, 1, half_a_second_ms);
if (ret < 0) {
fprintf(stderr,
"ERROR: Failed epoll_wait '%i', disconnecting "
"client.\n",
ret);
IPC_ERROR(
ics->server,
"Failed epoll_wait '%i', disconnecting client.\n",
ret);
break;
}
@ -99,7 +102,7 @@ client_loop(volatile struct ipc_client_state *ics)
// Detect clients disconnecting gracefully.
if (ret > 0 && (event.events & EPOLLHUP) != 0) {
fprintf(stderr, "SERVER: Client disconnected\n");
IPC_INFO(ics->server, "Client disconnected\n");
break;
}
@ -107,10 +110,9 @@ client_loop(volatile struct ipc_client_state *ics)
//! @todo replace this call
ssize_t len = recv(ics->imc.socket_fd, &buf, IPC_BUF_SIZE, 0);
if (len < 4) {
fprintf(stderr,
"ERROR: Invalid packet received, "
"disconnecting "
"client.\n");
IPC_ERROR(
ics->server,
"Invalid packet received, disconnecting client.\n");
break;
}
@ -118,10 +120,9 @@ client_loop(volatile struct ipc_client_state *ics)
ipc_command_t *ipc_command = (uint32_t *)buf;
xrt_result_t result = ipc_dispatch(ics, ipc_command);
if (result != XRT_SUCCESS) {
fprintf(stderr,
"ERROR: During packet handling, "
"disconnecting "
"client.\n");
IPC_ERROR(
ics->server,
"During packet handling, disconnecting client.\n");
break;
}
}