ipc: Replace ipc_result_t with global xrt_result_t

Functions down the line should be able to fail and return a status.

They can be called either through IPC or directly depending on compile settings,
therefore we need an internal result type for various XR_ERROR_* errors, but also IPC failure.

For now functions in ipc_client_utils.c only return XRT_SUCCESS or XRT_ERROR_IPC_FAILURE.
If there is no IPC failure, the generated protocol will extract and return the called functions'
actual return value from the reply.

v2: make failure results negative
This commit is contained in:
Christoph Haag 2020-06-04 13:48:49 +02:00
parent dab96ef356
commit db5db10a19
10 changed files with 92 additions and 88 deletions

View file

@ -0,0 +1,16 @@
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Internal result type for XRT.
* @author Christoph Haag <christoph.haag@collabora.com>
* @ingroup xrt_iface
*/
#pragma once
typedef enum xrt_result
{
XRT_SUCCESS = 0,
XRT_ERROR_IPC_FAILURE = -1,
} xrt_result_t;

View file

@ -91,17 +91,17 @@ typedef struct ipc_connection
* These functions are called by generated IPC client code.
* @{
*/
ipc_result_t
xrt_result_t
ipc_client_send_message(ipc_connection_t *ipc_c, void *message, size_t size);
ipc_result_t
xrt_result_t
ipc_client_send_and_get_reply(struct ipc_connection *ipc_c,
void *msg_ptr,
size_t msg_size,
void *reply_ptr,
size_t reply_size);
ipc_result_t
xrt_result_t
ipc_client_send_and_get_reply_fds(ipc_connection_t *ipc_c,
void *msg_ptr,
size_t msg_size,

View file

@ -97,7 +97,7 @@ compositor_disconnect(ipc_connection_t *ipc_c)
}
#define CALL_CHK(call) \
if ((call) != IPC_SUCCESS) { \
if ((call) != XRT_SUCCESS) { \
IPC_ERROR(icc->ipc_c, "IPC: %s call error!", __func__); \
}
@ -180,7 +180,7 @@ ipc_compositor_swapchain_create(struct xrt_compositor *xc,
struct ipc_client_compositor *icc = ipc_client_compositor(xc);
int remote_fds[IPC_MAX_SWAPCHAIN_FDS] = {0};
ipc_result_t r = 0;
xrt_result_t r = XRT_SUCCESS;
uint32_t handle;
uint32_t num_images;
uint64_t size;
@ -200,7 +200,7 @@ ipc_compositor_swapchain_create(struct xrt_compositor *xc,
&size, // out
remote_fds, // fds
IPC_MAX_SWAPCHAIN_FDS); // fds
if (r != IPC_SUCCESS) {
if (r != XRT_SUCCESS) {
return NULL;
}

View file

@ -82,9 +82,9 @@ ipc_client_device_update_inputs(struct xrt_device *xdev)
{
struct ipc_client_device *icd = ipc_client_device(xdev);
ipc_result_t r =
xrt_result_t r =
ipc_call_device_update_input(icd->ipc_c, icd->device_id);
if (r != IPC_SUCCESS) {
if (r != XRT_SUCCESS) {
IPC_DEBUG(icd->ipc_c, "IPC: Error sending input update!");
}
}
@ -98,10 +98,10 @@ ipc_client_device_get_tracked_pose(struct xrt_device *xdev,
{
struct ipc_client_device *icd = ipc_client_device(xdev);
ipc_result_t r = ipc_call_device_get_tracked_pose(
xrt_result_t r = ipc_call_device_get_tracked_pose(
icd->ipc_c, icd->device_id, name, at_timestamp_ns,
out_relation_timestamp_ns, out_relation);
if (r != IPC_SUCCESS) {
if (r != XRT_SUCCESS) {
IPC_DEBUG(icd->ipc_c, "IPC: Error sending input update!");
}
}
@ -122,9 +122,9 @@ ipc_client_device_set_output(struct xrt_device *xdev,
{
struct ipc_client_device *icd = ipc_client_device(xdev);
ipc_result_t r =
xrt_result_t r =
ipc_call_device_set_output(icd->ipc_c, icd->device_id, name, value);
if (r != IPC_SUCCESS) {
if (r != XRT_SUCCESS) {
IPC_DEBUG(icd->ipc_c, "IPC: Error sending set output!");
}
}

View file

@ -82,9 +82,9 @@ ipc_client_hmd_update_inputs(struct xrt_device *xdev)
{
struct ipc_client_hmd *ich = ipc_client_hmd(xdev);
ipc_result_t r =
xrt_result_t r =
ipc_call_device_update_input(ich->ipc_c, ich->device_id);
if (r != IPC_SUCCESS) {
if (r != XRT_SUCCESS) {
IPC_DEBUG(ich->ipc_c, "IPC: Error calling input update!");
}
}
@ -98,10 +98,10 @@ ipc_client_hmd_get_tracked_pose(struct xrt_device *xdev,
{
struct ipc_client_hmd *ich = ipc_client_hmd(xdev);
ipc_result_t r = ipc_call_device_get_tracked_pose(
xrt_result_t r = ipc_call_device_get_tracked_pose(
ich->ipc_c, ich->device_id, name, at_timestamp_ns,
out_relation_timestamp_ns, out_relation);
if (r != IPC_SUCCESS) {
if (r != XRT_SUCCESS) {
IPC_DEBUG(ich->ipc_c, "IPC: Error calling tracked pose!");
}
}
@ -114,9 +114,9 @@ ipc_client_hmd_get_view_pose(struct xrt_device *xdev,
{
struct ipc_client_hmd *ich = ipc_client_hmd(xdev);
ipc_result_t r = ipc_call_device_get_view_pose(
xrt_result_t r = ipc_call_device_get_view_pose(
ich->ipc_c, ich->device_id, eye_relation, view_index, out_pose);
if (r != IPC_SUCCESS) {
if (r != XRT_SUCCESS) {
IPC_DEBUG(ich->ipc_c, "IPC: Error calling view pose!");
}
}

View file

@ -215,9 +215,9 @@ ipc_instance_create(struct xrt_instance **out_xinst)
}
// get our xdev shm from the server and mmap it
ipc_result_t r =
xrt_result_t r =
ipc_call_instance_get_shm_fd(&ii->ipc_c, &ii->ipc_c.ism_fd, 1);
if (r != IPC_SUCCESS) {
if (r != XRT_SUCCESS) {
IPC_ERROR(&ii->ipc_c, "Failed to retrieve shm fd");
free(ii);
return -1;

View file

@ -17,7 +17,7 @@
#include <string.h>
#include <sys/socket.h>
ipc_result_t
xrt_result_t
ipc_client_send_and_get_reply(struct ipc_connection *ipc_c,
void *msg_ptr,
size_t msg_size,
@ -30,14 +30,14 @@ ipc_client_send_and_get_reply(struct ipc_connection *ipc_c,
if (ipc_c->socket_fd < 0) {
IPC_ERROR(ipc_c, "Error sending - not connected!");
os_mutex_unlock(&ipc_c->mutex);
return IPC_FAILURE;
return XRT_ERROR_IPC_FAILURE;
}
ssize_t len = send(ipc_c->socket_fd, msg_ptr, msg_size, 0);
if ((size_t)len != msg_size) {
IPC_ERROR(ipc_c, "Error sending - cannot continue!");
os_mutex_unlock(&ipc_c->mutex);
return IPC_FAILURE;
return XRT_ERROR_IPC_FAILURE;
}
@ -60,21 +60,21 @@ ipc_client_send_and_get_reply(struct ipc_connection *ipc_c,
IPC_ERROR(ipc_c, "recvmsg failed with error: %s",
strerror(errno));
os_mutex_unlock(&ipc_c->mutex);
return IPC_FAILURE;
return XRT_ERROR_IPC_FAILURE;
}
if ((size_t)len != reply_size) {
IPC_ERROR(ipc_c, "recvmsg failed with error: wrong size %i %i",
(int)len, (int)reply_size);
os_mutex_unlock(&ipc_c->mutex);
return IPC_FAILURE;
return XRT_ERROR_IPC_FAILURE;
}
os_mutex_unlock(&ipc_c->mutex);
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_client_send_and_get_reply_fds(ipc_connection_t *ipc_c,
void *msg_ptr,
size_t msg_size,
@ -88,7 +88,7 @@ ipc_client_send_and_get_reply_fds(ipc_connection_t *ipc_c,
if (send(ipc_c->socket_fd, msg_ptr, msg_size, 0) == -1) {
IPC_ERROR(ipc_c, "Error sending - cannot continue!");
os_mutex_unlock(&ipc_c->mutex);
return IPC_FAILURE;
return XRT_ERROR_IPC_FAILURE;
}
union {
@ -115,29 +115,29 @@ ipc_client_send_and_get_reply_fds(ipc_connection_t *ipc_c,
IPC_ERROR(ipc_c, "recvmsg failed with error: %s",
strerror(errno));
os_mutex_unlock(&ipc_c->mutex);
return -1;
return XRT_ERROR_IPC_FAILURE;
}
if (len == 0) {
IPC_ERROR(ipc_c, "recvmsg failed with error: no data");
os_mutex_unlock(&ipc_c->mutex);
return -1;
return XRT_ERROR_IPC_FAILURE;
}
// Did the server actually return file descriptors.
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg == NULL) {
os_mutex_unlock(&ipc_c->mutex);
return IPC_SUCCESS;
return XRT_SUCCESS;
}
memcpy(fds, (int *)CMSG_DATA(cmsg), fds_size);
os_mutex_unlock(&ipc_c->mutex);
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_client_send_message(ipc_connection_t *ipc_c, void *message, size_t size)
{
return ipc_client_send_and_get_reply(ipc_c, message, size, message,

View file

@ -14,6 +14,8 @@
#include "xrt/xrt_compiler.h"
#include "xrt/xrt_compositor.h"
#include "xrt/xrt_results.h"
#include <semaphore.h>
#define IPC_MSG_SOCK_FILE "/tmp/monado_comp_ipc"
@ -191,20 +193,6 @@ struct ipc_shared_memory
} wait_frame;
};
/*
*
* Enums
*
*/
typedef enum ipc_result
{
IPC_SUCCESS = 0,
IPC_FAILURE,
} ipc_result_t;
/*
*
* Reset of protocol is generated.

View file

@ -36,7 +36,7 @@
*
*/
ipc_result_t
xrt_result_t
ipc_handle_instance_get_shm_fd(volatile struct ipc_client_state *cs,
size_t max_num_fds,
int *out_fds,
@ -46,24 +46,24 @@ ipc_handle_instance_get_shm_fd(volatile struct ipc_client_state *cs,
out_fds[0] = cs->server->ism_fd;
*out_num_fds = 1;
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_session_begin(volatile struct ipc_client_state *cs)
{
cs->active = true;
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_session_end(volatile struct ipc_client_state *cs)
{
cs->active = false;
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_compositor_get_formats(volatile struct ipc_client_state *cs,
struct ipc_formats_info *out_info)
{
@ -72,29 +72,29 @@ ipc_handle_compositor_get_formats(volatile struct ipc_client_state *cs,
out_info->formats[i] = cs->xc->formats[i];
}
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_compositor_wait_frame(volatile struct ipc_client_state *cs)
{
ipc_server_wait_add_frame(cs->server->iw, cs);
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_compositor_begin_frame(volatile struct ipc_client_state *cs)
{
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_compositor_discard_frame(volatile struct ipc_client_state *cs)
{
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_compositor_layer_sync(volatile struct ipc_client_state *cs,
uint32_t slot_id,
uint32_t *out_free_slot_id)
@ -138,10 +138,10 @@ ipc_handle_compositor_layer_sync(volatile struct ipc_client_state *cs,
*out_free_slot_id = (slot_id + 1) % IPC_MAX_SLOTS;
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_swapchain_create(volatile struct ipc_client_state *cs,
enum xrt_swapchain_create_flags create,
enum xrt_swapchain_usage_bits bits,
@ -169,7 +169,7 @@ ipc_handle_swapchain_create(volatile struct ipc_client_state *cs,
if (index >= IPC_MAX_CLIENT_SWAPCHAINS) {
fprintf(stderr, "ERROR: Too many swapchains!\n");
return IPC_FAILURE;
return XRT_ERROR_IPC_FAILURE;
}
// It's now safe to increment the number of swapchains.
@ -214,10 +214,10 @@ ipc_handle_swapchain_create(volatile struct ipc_client_state *cs,
out_fds[i] = xcsfd->images[i].fd;
}
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_swapchain_wait_image(volatile struct ipc_client_state *cs,
uint32_t id,
uint64_t timeout,
@ -229,10 +229,10 @@ ipc_handle_swapchain_wait_image(volatile struct ipc_client_state *cs,
xrt_swapchain_wait_image(xsc, timeout, index);
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_swapchain_acquire_image(volatile struct ipc_client_state *cs,
uint32_t id,
uint32_t *out_index)
@ -244,10 +244,10 @@ ipc_handle_swapchain_acquire_image(volatile struct ipc_client_state *cs,
xrt_swapchain_acquire_image(xsc, out_index);
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_swapchain_release_image(volatile struct ipc_client_state *cs,
uint32_t id,
uint32_t index)
@ -258,10 +258,10 @@ ipc_handle_swapchain_release_image(volatile struct ipc_client_state *cs,
xrt_swapchain_release_image(xsc, index);
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_swapchain_destroy(volatile struct ipc_client_state *cs, uint32_t id)
{
//! @todo Implement destroy swapchain.
@ -270,10 +270,10 @@ ipc_handle_swapchain_destroy(volatile struct ipc_client_state *cs, uint32_t id)
xrt_swapchain_destroy((struct xrt_swapchain **)&cs->xscs[id]);
cs->swapchain_data[id].active = false;
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_device_update_input(volatile struct ipc_client_state *cs,
uint32_t id)
{
@ -292,10 +292,10 @@ ipc_handle_device_update_input(volatile struct ipc_client_state *cs,
memcpy(dst, src, sizeof(struct xrt_input) * idev->num_inputs);
// Reply.
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_device_get_tracked_pose(volatile struct ipc_client_state *cs,
uint32_t id,
enum xrt_input_name name,
@ -312,10 +312,10 @@ ipc_handle_device_get_tracked_pose(volatile struct ipc_client_state *cs,
xrt_device_get_tracked_pose(xdev, name, at_timestamp, out_timestamp,
out_relation);
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_device_get_view_pose(volatile struct ipc_client_state *cs,
uint32_t id,
struct xrt_vec3 *eye_relation,
@ -330,10 +330,10 @@ ipc_handle_device_get_view_pose(volatile struct ipc_client_state *cs,
// Get the pose.
xrt_device_get_view_pose(xdev, eye_relation, view_index, out_pose);
return IPC_SUCCESS;
return XRT_SUCCESS;
}
ipc_result_t
xrt_result_t
ipc_handle_device_set_output(volatile struct ipc_client_state *cs,
uint32_t id,
enum xrt_output_name name,
@ -346,7 +346,7 @@ ipc_handle_device_set_output(volatile struct ipc_client_state *cs,
// Set the output.
xrt_device_set_output(xdev, name, value);
return IPC_SUCCESS;
return XRT_SUCCESS;
}

View file

@ -94,7 +94,7 @@ class Call:
args.extend(arg.get_func_argument_out() for arg in self.out_args)
if self.out_fds:
args.extend(("int *fds", "size_t num_fds"))
write_decl(f, 'ipc_result_t', 'ipc_call_' + self.name, args)
write_decl(f, 'xrt_result_t', 'ipc_call_' + self.name, args)
def write_handle_decl(self, f):
"""Write declaration of ipc_handle_CALLNAME."""
@ -106,7 +106,7 @@ class Call:
"size_t max_num_fds",
"int *out_fds",
"size_t *out_num_fds"))
write_decl(f, 'ipc_result_t', 'ipc_handle_' + self.name, args)
write_decl(f, 'xrt_result_t', 'ipc_handle_' + self.name, args)
def __init__(self, name, data):
"""Construct a call from call name and call data dictionary."""
@ -197,7 +197,7 @@ struct ipc_command_msg
struct ipc_result_reply
{
\tipc_result_t result;
\txrt_result_t result;
};
struct ipc_formats_info
@ -231,7 +231,7 @@ ipc_cmd_to_str(ipc_command_t id)
if call.out_args:
f.write("\nstruct ipc_" + call.name + "_reply\n")
f.write("{\n")
f.write("\tipc_result_t result;\n")
f.write("\txrt_result_t result;\n")
for arg in call.out_args:
f.write("\t" + arg.get_struct_field() + ";\n")
f.write("};\n")
@ -280,10 +280,10 @@ def generate_client_c(file, p):
if call.out_fds:
func += '_fds'
args.extend(('fds', 'num_fds'))
write_invocation(f, 'ipc_result_t ret', func, args, indent="\t")
write_invocation(f, 'xrt_result_t ret', func, args, indent="\t")
f.write(';')
f.write('''
\tif (ret != IPC_SUCCESS) {
\tif (ret != XRT_SUCCESS) {
\t\treturn ret;
\t}
\n''')