mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-02-01 11:28:28 +00:00
t/cli: Port to use xrt_instance, instead of xrt_prober directly.
This commit is contained in:
parent
51dba8ad94
commit
1a313b6f58
|
@ -11,7 +11,6 @@ set(SOURCE_FILES
|
||||||
cli_cmd_test.c
|
cli_cmd_test.c
|
||||||
cli_common.h
|
cli_common.h
|
||||||
cli_main.c
|
cli_main.c
|
||||||
cli_prober.c
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(cli
|
add_executable(cli
|
||||||
|
@ -27,8 +26,7 @@ target_link_libraries(cli PRIVATE
|
||||||
aux_os
|
aux_os
|
||||||
aux_util
|
aux_util
|
||||||
aux_math
|
aux_math
|
||||||
st_prober
|
target_instance_no_comp
|
||||||
target_lists
|
|
||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS cli
|
install(TARGETS cli
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "xrt/xrt_instance.h"
|
||||||
#include "xrt/xrt_prober.h"
|
#include "xrt/xrt_prober.h"
|
||||||
#include "util/u_misc.h"
|
#include "util/u_misc.h"
|
||||||
#include "cli_common.h"
|
#include "cli_common.h"
|
||||||
|
@ -18,6 +19,7 @@
|
||||||
|
|
||||||
struct program
|
struct program
|
||||||
{
|
{
|
||||||
|
struct xrt_instance *xi;
|
||||||
struct xrt_prober *xp;
|
struct xrt_prober *xp;
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
|
@ -29,13 +31,26 @@ init(struct program *p)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
// Fist initialize the prober.
|
// Fist initialize the instance.
|
||||||
ret = xrt_prober_create(&p->xp);
|
ret = xrt_instance_create(&p->xi);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "Failed to create prober\n");
|
fprintf(stderr, "Failed to create instance\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the prober pointer.
|
||||||
|
// In general, null probers are OK, but this module directly uses the
|
||||||
|
// prober.
|
||||||
|
ret = xrt_instance_get_prober(p->xi, &p->xp);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "Failed to get prober from instance.\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
if (p->xp == NULL) {
|
||||||
|
fprintf(stderr, "Null prober returned - cannot proceed.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Need to prime the prober before listing devices.
|
// Need to prime the prober before listing devices.
|
||||||
ret = xrt_prober_probe(p->xp);
|
ret = xrt_prober_probe(p->xp);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
@ -114,9 +129,8 @@ print_cameras(struct program *p)
|
||||||
static int
|
static int
|
||||||
do_exit(struct program *p, int ret)
|
do_exit(struct program *p, int ret)
|
||||||
{
|
{
|
||||||
if (p->xp != NULL) {
|
p->xp = NULL;
|
||||||
xrt_prober_destroy(&p->xp);
|
xrt_instance_destroy(&p->xi);
|
||||||
}
|
|
||||||
|
|
||||||
printf(" :: Exiting '%i'\n", ret);
|
printf(" :: Exiting '%i'\n", ret);
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,15 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "xrt/xrt_prober.h"
|
#include "xrt/xrt_instance.h"
|
||||||
|
#include "xrt/xrt_device.h"
|
||||||
#include "cli_common.h"
|
#include "cli_common.h"
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
do_exit(struct xrt_prober **xp_ptr, int ret)
|
do_exit(struct xrt_instance **xi_ptr, int ret)
|
||||||
{
|
{
|
||||||
xrt_prober_destroy(xp_ptr);
|
xrt_instance_destroy(xi_ptr);
|
||||||
|
|
||||||
printf(" :: Exiting '%i'\n", ret);
|
printf(" :: Exiting '%i'\n", ret);
|
||||||
|
|
||||||
|
@ -29,23 +30,23 @@ int
|
||||||
cli_cmd_probe(int argc, const char **argv)
|
cli_cmd_probe(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
struct xrt_device *xdevs[NUM_XDEVS] = {0};
|
struct xrt_device *xdevs[NUM_XDEVS] = {0};
|
||||||
struct xrt_prober *xp = NULL;
|
struct xrt_instance *xi = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
// Initialize the prober.
|
// Initialize the prober.
|
||||||
printf(" :: Creating prober!\n");
|
printf(" :: Creating instance!\n");
|
||||||
|
|
||||||
ret = xrt_prober_create(&xp);
|
ret = xrt_instance_create(&xi);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return do_exit(&xp, 0);
|
return do_exit(&xi, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to prime the prober with devices before dumping and listing.
|
// Need to prime the prober with devices before dumping and listing.
|
||||||
printf(" :: Probing!\n");
|
printf(" :: Probing and selecting!\n");
|
||||||
|
|
||||||
ret = xrt_prober_probe(xp);
|
ret = xrt_instance_select(xi, xdevs, NUM_XDEVS);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return do_exit(&xp, ret);
|
return do_exit(&xi, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of program
|
// End of program
|
||||||
|
@ -57,11 +58,9 @@ cli_cmd_probe(int argc, const char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\tDestroying '%s'\n", xdevs[i]->str);
|
printf("\tDestroying '%s'\n", xdevs[i]->str);
|
||||||
|
xrt_device_destroy(&xdevs[i]);
|
||||||
xdevs[i]->destroy(xdevs[i]);
|
|
||||||
xdevs[i] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally done
|
// Finally done
|
||||||
return do_exit(&xp, 0);
|
return do_exit(&xi, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,15 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "xrt/xrt_instance.h"
|
||||||
#include "xrt/xrt_prober.h"
|
#include "xrt/xrt_prober.h"
|
||||||
#include "cli_common.h"
|
#include "cli_common.h"
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
do_exit(struct xrt_prober **xp_ptr, int ret)
|
do_exit(struct xrt_instance **xi_ptr, int ret)
|
||||||
{
|
{
|
||||||
xrt_prober_destroy(xp_ptr);
|
xrt_instance_destroy(xi_ptr);
|
||||||
|
|
||||||
printf(" :: Exiting '%i'\n", ret);
|
printf(" :: Exiting '%i'\n", ret);
|
||||||
|
|
||||||
|
@ -29,45 +30,58 @@ int
|
||||||
cli_cmd_test(int argc, const char **argv)
|
cli_cmd_test(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
struct xrt_device *xdevs[NUM_XDEVS] = {0};
|
struct xrt_device *xdevs[NUM_XDEVS] = {0};
|
||||||
struct xrt_prober *xp = NULL;
|
struct xrt_instance *xi = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
// Initialize the prober.
|
// Initialize the prober.
|
||||||
printf(" :: Creating prober!\n");
|
printf(" :: Creating instance!\n");
|
||||||
|
|
||||||
ret = xrt_prober_create(&xp);
|
ret = xrt_instance_create(&xi);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return do_exit(&xp, 0);
|
return do_exit(&xi, 0);
|
||||||
|
}
|
||||||
|
struct xrt_prober *xp = NULL;
|
||||||
|
|
||||||
|
ret = xrt_instance_get_prober(xi, &xp);
|
||||||
|
if (ret != 0) {
|
||||||
|
do_exit(&xi, ret);
|
||||||
|
}
|
||||||
|
if (xp != NULL) {
|
||||||
|
// This instance provides an xrt_prober so we can dump some
|
||||||
|
// internal info.
|
||||||
|
|
||||||
|
// Need to prime the prober with devices before dumping and
|
||||||
|
// listing.
|
||||||
|
printf(" :: Probing!\n");
|
||||||
|
|
||||||
|
ret = xrt_prober_probe(xp);
|
||||||
|
if (ret != 0) {
|
||||||
|
return do_exit(&xi, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
// So the user can see what we found.
|
||||||
|
printf(" :: Dumping!\n");
|
||||||
|
|
||||||
|
ret = xrt_prober_dump(xp);
|
||||||
|
if (ret != 0) {
|
||||||
|
do_exit(&xi, ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to prime the prober with devices before dumping and listing.
|
// Regardless of whether xrt_prober is used, we can find and select
|
||||||
printf(" :: Probing!\n");
|
// (multiple) devices.
|
||||||
|
printf(" :: Probing and selecting devices!\n");
|
||||||
|
|
||||||
ret = xrt_prober_probe(xp);
|
ret = xrt_instance_select(xi, xdevs, NUM_XDEVS);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return do_exit(&xp, ret);
|
return do_exit(&xi, ret);
|
||||||
}
|
|
||||||
|
|
||||||
// So the user can see what we found.
|
|
||||||
printf(" :: Dumping!\n");
|
|
||||||
|
|
||||||
ret = xrt_prober_dump(xp);
|
|
||||||
if (ret != 0) {
|
|
||||||
do_exit(&xp, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Multiple devices can be found.
|
|
||||||
printf(" :: Selecting devices!\n");
|
|
||||||
|
|
||||||
ret = xrt_prober_select(xp, xdevs, NUM_XDEVS);
|
|
||||||
if (ret != 0) {
|
|
||||||
do_exit(&xp, ret);
|
|
||||||
}
|
}
|
||||||
if (xdevs[0] == NULL) {
|
if (xdevs[0] == NULL) {
|
||||||
printf("\tNo HMD found! :(\n");
|
printf("\tNo HMD found! :(\n");
|
||||||
return do_exit(&xp, -1);
|
return do_exit(&xi, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (size_t i = 0; i < NUM_XDEVS; i++) {
|
for (size_t i = 0; i < NUM_XDEVS; i++) {
|
||||||
if (xdevs[i] == NULL) {
|
if (xdevs[i] == NULL) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -85,11 +99,9 @@ cli_cmd_test(int argc, const char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\tDestroying '%s'\n", xdevs[i]->str);
|
printf("\tDestroying '%s'\n", xdevs[i]->str);
|
||||||
|
xrt_device_destroy(&xdevs[i]);
|
||||||
xdevs[i]->destroy(xdevs[i]);
|
|
||||||
xdevs[i] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally done
|
// Finally done
|
||||||
return do_exit(&xp, 0);
|
return do_exit(&xi, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
// Copyright 2019, Collabora, Ltd.
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
/*!
|
|
||||||
* @file
|
|
||||||
* @brief Small file to allow the prober to start.
|
|
||||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "target_lists.h"
|
|
||||||
#include "cli_common.h"
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
ps3_eye_found(struct xrt_prober *xp,
|
|
||||||
struct xrt_prober_device **devices,
|
|
||||||
size_t num_devices,
|
|
||||||
size_t index,
|
|
||||||
cJSON *attached_data,
|
|
||||||
struct xrt_device **out_xdev)
|
|
||||||
{
|
|
||||||
printf("Found PS3 Eye!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct xrt_prober_entry quirks_list[] = {
|
|
||||||
{0x1415, 0x2000, ps3_eye_found, "PS3 Eye"},
|
|
||||||
{0x0000, 0x0000, NULL, NULL}, // Terminate
|
|
||||||
};
|
|
||||||
|
|
||||||
struct xrt_prober_entry *entry_lists[] = {
|
|
||||||
quirks_list, target_entry_list,
|
|
||||||
NULL, // Terminate
|
|
||||||
};
|
|
||||||
|
|
||||||
struct xrt_prober_entry_lists list = {
|
|
||||||
entry_lists,
|
|
||||||
target_auto_list,
|
|
||||||
NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
|
||||||
xrt_prober_create(struct xrt_prober **out_xp)
|
|
||||||
{
|
|
||||||
return xrt_prober_create_with_lists(out_xp, &list);
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@ cli = executable(
|
||||||
'cli_cmd_probe.c',
|
'cli_cmd_probe.c',
|
||||||
'cli_cmd_test.c',
|
'cli_cmd_test.c',
|
||||||
'cli_common.h',
|
'cli_common.h',
|
||||||
'cli_instance.c',
|
|
||||||
'cli_main.c',
|
'cli_main.c',
|
||||||
),
|
),
|
||||||
link_whole: [
|
link_whole: [
|
||||||
|
@ -16,7 +15,7 @@ cli = executable(
|
||||||
lib_aux_util,
|
lib_aux_util,
|
||||||
lib_aux_math,
|
lib_aux_math,
|
||||||
lib_st_prober,
|
lib_st_prober,
|
||||||
lib_target_lists,
|
lib_target_instance_no_comp,
|
||||||
] + driver_libs,
|
] + driver_libs,
|
||||||
include_directories: [
|
include_directories: [
|
||||||
aux_include,
|
aux_include,
|
||||||
|
|
Loading…
Reference in a new issue