t/cli: Turn prober command into a cli interface for Monado

This commit is contained in:
Jakob Bornecrantz 2019-06-26 12:21:13 +01:00
parent 699bb8d5ad
commit 249b9a03ca
7 changed files with 208 additions and 129 deletions

View file

@ -38,4 +38,4 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(common)
add_subdirectory(openxr)
add_subdirectory(prober)
add_subdirectory(cli)

View file

@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSL-1.0
######
# Create a test executable for prober functionality.
# Create a cli interface for Monado.
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../../targets/common
@ -12,10 +12,12 @@ include_directories(
)
set(SOURCE_FILES
main.c
cli_cmd_test.c
cli_common.h
cli_main.c
cli_prober.c
)
# depends on above generated files
add_executable(prober
${SOURCE_FILES}
$<TARGET_OBJECTS:aux_os>
@ -26,7 +28,7 @@ add_executable(prober
)
set_target_properties(prober PROPERTIES
OUTPUT_NAME prober
OUTPUT_NAME monado-cli
PREFIX ""
)

View file

@ -0,0 +1,98 @@
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Prints a list of found devices and tests opening some of them.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#include <string.h>
#include <stdio.h>
#include "xrt/xrt_prober.h"
#include "cli_common.h"
static int
do_exit(struct xrt_prober **xp_ptr, int ret)
{
if (*xp_ptr != NULL) {
(*xp_ptr)->destroy(xp_ptr);
*xp_ptr = NULL;
}
printf(" :: Exiting '%i'\n", ret);
return ret;
}
#define NUM_XDEVS 32
int
cli_cmd_test(int argc, const char **argv)
{
struct xrt_device *xdevs[NUM_XDEVS] = {0};
struct xrt_prober *xp = NULL;
int ret = 0;
// Initialize the prober.
printf(" :: Creating prober!\n");
ret = xrt_prober_create(&xp);
if (ret != 0) {
return do_exit(&xp, 0);
}
// Need to prime the prober with devices before dumping and listing.
printf(" :: Probing!\n");
ret = xp->probe(xp);
if (ret != 0) {
return do_exit(&xp, ret);
}
// So the user can see what we found.
printf(" :: Dumping!\n");
ret = xp->dump(xp);
if (ret != 0) {
do_exit(&xp, ret);
}
// Multiple devices can be found.
printf(" :: Selecting devices!\n");
ret = xp->select(xp, xdevs, NUM_XDEVS);
if (ret != 0) {
do_exit(&xp, ret);
}
if (xdevs[0] == NULL) {
printf("\tNo HMD found! :(\n");
return do_exit(&xp, -1);
}
for (size_t i = 0; i < NUM_XDEVS; i++) {
if (xdevs[i] == NULL) {
continue;
}
printf("\tFound '%s'\n", xdevs[i]->name);
}
// End of program
printf(" :: All ok, shutting down.\n");
for (size_t i = 0; i < NUM_XDEVS; i++) {
if (xdevs[i] == NULL) {
continue;
}
printf("\tDestroying '%s'\n", xdevs[i]->name);
xdevs[i]->destroy(xdevs[i]);
xdevs[i] = NULL;
}
// Finally done
return do_exit(&xp, 0);
}

View file

@ -0,0 +1,13 @@
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Common file for the CLI program.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#pragma once
int
cli_cmd_test(int argc, const char **argv);

View file

@ -0,0 +1,45 @@
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief A cli program to configure and test Monado.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#include <string.h>
#include <stdio.h>
#include "cli_common.h"
#define P(...) fprintf(stderr, __VA_ARGS__)
static int
cli_print_help(int argc, const char **argv)
{
if (argc >= 2) {
fprintf(stderr, "Unknown command '%s'\n\n", argv[1]);
}
P("Monado-CLI 0.0.1\n");
P("Usage: %s command [options]\n", argv[0]);
P("\n");
P("Commands:\n");
P(" test - List found devices, for prober testing.\n");
return 1;
}
int
main(int argc, const char **argv)
{
if (argc <= 1) {
return cli_print_help(argc, argv);
}
if (strcmp(argv[1], "test") == 0) {
return cli_cmd_test(argc, argv);
} else {
return cli_print_help(argc, argv);
}
}

View file

@ -0,0 +1,45 @@
// 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 index,
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);
}

View file

@ -1,124 +0,0 @@
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief A program to help test the probing code in Monado.
* @author Jakob Bornecrantz <jakob@collabora.com>
*/
#include <string.h>
#include <stdio.h>
#include "target_lists.h"
static int
ps3_eye_found(struct xrt_prober *xp,
struct xrt_prober_device **devices,
size_t index,
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);
}
int
do_exit(struct xrt_prober **xp, int ret)
{
if (*xp != NULL) {
(*xp)->destroy(xp);
}
printf(" :: Exiting '%i'\n", ret);
return ret;
}
#define NUM_XDEVS 32
int
main(int argc, const char **argv)
{
struct xrt_device *xdevs[NUM_XDEVS] = {0};
struct xrt_prober *p = NULL;
int ret = 0;
printf(" :: Creating prober!\n");
ret = xrt_prober_create(&p);
if (ret != 0) {
return ret;
}
printf(" :: Probing!\n");
ret = p->probe(p);
if (ret != 0) {
return do_exit(&p, ret);
}
printf(" :: Dumping!\n");
ret = p->dump(p);
if (ret != 0) {
do_exit(&p, ret);
}
printf(" :: Selecting device!\n");
ret = p->select(p, xdevs, NUM_XDEVS);
if (ret != 0) {
do_exit(&p, ret);
}
if (xdevs[0] == NULL) {
printf("\tNo HMD found! :(\n");
return do_exit(&p, -1);
}
for (size_t i = 0; i < NUM_XDEVS; i++) {
if (xdevs[i] == NULL) {
continue;
}
printf("\tFound '%s'\n", xdevs[i]->name);
}
// End of program
printf(" :: All ok, shutting down.\n");
for (size_t i = 0; i < NUM_XDEVS; i++) {
if (xdevs[i] == NULL) {
continue;
}
printf("\tDestroying '%s'\n", xdevs[i]->name);
xdevs[i]->destroy(xdevs[i]);
xdevs[i] = NULL;
}
// Finally done
return do_exit(&p, 0);
}