monado/src/xrt/state_trackers/gui/gui_prober.c

99 lines
1.5 KiB
C
Raw Normal View History

2019-08-31 13:53:14 +00:00
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Enable the use of the prober in the gui application.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#include "xrt/xrt_prober.h"
#include "xrt/xrt_instance.h"
2019-08-31 13:53:14 +00:00
#include "util/u_time.h"
#include "gui_common.h"
/*
*
* Helper functions.
*
*/
static int
2019-10-09 15:22:34 +00:00
do_exit(struct gui_program *p, int ret)
2019-08-31 13:53:14 +00:00
{
gui_prober_teardown(p);
return ret;
}
/*
*
* 'Exported' functions.
*
*/
int
2019-10-09 15:22:34 +00:00
gui_prober_init(struct gui_program *p)
2019-08-31 13:53:14 +00:00
{
int ret = 0;
// Initialize the prober.
ret = xrt_instance_create(&p->instance, NULL);
2019-08-31 13:53:14 +00:00
if (ret != 0) {
return do_exit(p, ret);
}
ret = xrt_instance_get_prober(p->instance, &p->xp);
2019-08-31 13:53:14 +00:00
if (ret != 0) {
return do_exit(p, ret);
}
if (p->xp != NULL) {
// Need to prime the prober with devices before dumping and
// listing.
ret = xrt_prober_probe(p->xp);
if (ret != 0) {
return do_exit(p, ret);
}
}
return 0;
}
2019-08-31 13:53:14 +00:00
int
2019-10-09 15:22:34 +00:00
gui_prober_select(struct gui_program *p)
{
int ret;
// Multiple devices can be found.
ret = xrt_instance_select(p->instance, p->xdevs, NUM_XDEVS);
2019-08-31 13:53:14 +00:00
if (ret != 0) {
return ret;
2019-08-31 13:53:14 +00:00
}
return 0;
}
void
2019-10-09 15:22:34 +00:00
gui_prober_update(struct gui_program *p)
2019-08-31 13:53:14 +00:00
{
for (size_t i = 0; i < NUM_XDEVS; i++) {
if (p->xdevs[i] == NULL) {
continue;
}
xrt_device_update_inputs(p->xdevs[i]);
2019-08-31 13:53:14 +00:00
}
}
void
2019-10-09 15:22:34 +00:00
gui_prober_teardown(struct gui_program *p)
2019-08-31 13:53:14 +00:00
{
for (size_t i = 0; i < NUM_XDEVS; i++) {
if (p->xdevs[i] == NULL) {
continue;
}
xrt_device_destroy(&(p->xdevs[i]));
2019-08-31 13:53:14 +00:00
}
xrt_instance_destroy(&p->instance);
2019-08-31 13:53:14 +00:00
}