2022-05-09 17:19:02 +00:00
|
|
|
// Copyright 2019-2022, Collabora, Ltd.
|
2019-08-31 13:53:14 +00:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Enable the use of the prober in the gui application.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
*/
|
|
|
|
|
2019-10-09 20:53:21 +00:00
|
|
|
#include "xrt/xrt_prober.h"
|
2020-05-26 21:56:33 +00:00
|
|
|
#include "xrt/xrt_instance.h"
|
2022-05-09 17:19:02 +00:00
|
|
|
#include "xrt/xrt_system.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
|
|
|
{
|
2022-05-17 17:45:53 +00:00
|
|
|
xrt_result_t xret;
|
2019-08-31 13:53:14 +00:00
|
|
|
|
|
|
|
// Initialize the prober.
|
2022-05-17 17:45:53 +00:00
|
|
|
xret = xrt_instance_create(NULL, &p->instance);
|
|
|
|
if (xret != 0) {
|
|
|
|
return do_exit(p, -1);
|
2019-08-31 13:53:14 +00:00
|
|
|
}
|
2022-05-09 17:19:02 +00:00
|
|
|
|
|
|
|
// Still need the prober to get video devices.
|
2022-05-17 17:45:53 +00:00
|
|
|
xret = xrt_instance_get_prober(p->instance, &p->xp);
|
|
|
|
if (xret != XRT_SUCCESS) {
|
|
|
|
return do_exit(p, -1);
|
2019-08-31 13:53:14 +00:00
|
|
|
}
|
|
|
|
|
2020-05-26 21:56:33 +00:00
|
|
|
if (p->xp != NULL) {
|
2022-05-09 17:19:02 +00:00
|
|
|
// Need to prime the prober with devices before dumping and listing.
|
2022-05-17 17:45:53 +00:00
|
|
|
xret = xrt_prober_probe(p->xp);
|
|
|
|
if (xret != XRT_SUCCESS) {
|
|
|
|
return do_exit(p, -1);
|
2020-05-26 21:56:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-09 17:19:02 +00:00
|
|
|
|
2019-09-21 17:20:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-08-31 13:53:14 +00:00
|
|
|
|
2019-09-21 17:20:11 +00:00
|
|
|
int
|
2019-10-09 15:22:34 +00:00
|
|
|
gui_prober_select(struct gui_program *p)
|
2019-09-21 17:20:11 +00:00
|
|
|
{
|
2022-05-09 17:19:02 +00:00
|
|
|
xrt_result_t xret = xrt_instance_create_system(p->instance, &p->xsysd, NULL);
|
|
|
|
if (xret != XRT_SUCCESS) {
|
|
|
|
return -1;
|
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
|
|
|
{
|
2022-05-09 17:19:02 +00:00
|
|
|
if (!p->xsysd) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < p->xsysd->xdev_count; i++) {
|
|
|
|
if (p->xsysd->xdevs[i] == NULL) {
|
2019-08-31 13:53:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-05-09 17:19:02 +00:00
|
|
|
xrt_device_update_inputs(p->xsysd->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
|
|
|
{
|
2022-05-09 17:19:02 +00:00
|
|
|
xrt_system_devices_destroy(&p->xsysd);
|
2019-08-31 13:53:14 +00:00
|
|
|
|
2020-05-26 21:56:33 +00:00
|
|
|
xrt_instance_destroy(&p->instance);
|
2019-08-31 13:53:14 +00:00
|
|
|
}
|