monado/src/xrt/state_trackers/prober/p_prober.h

351 lines
6.1 KiB
C
Raw Normal View History

2019-04-30 13:33:34 +00:00
// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Main prober code.
* @author Jakob Bornecrantz <jakob@collabora.com>
* @ingroup st_prober
*/
#pragma once
#include "xrt/xrt_config_have.h"
2020-03-03 22:39:03 +00:00
#include "xrt/xrt_config_os.h"
2019-04-30 13:33:34 +00:00
#include "xrt/xrt_compiler.h"
#include "xrt/xrt_prober.h"
#include "xrt/xrt_settings.h"
2019-04-30 13:33:34 +00:00
#ifdef XRT_HAVE_LIBUSB
2020-07-16 02:39:36 +00:00
#include <libusb.h>
2019-04-30 13:33:34 +00:00
#endif
#ifdef XRT_HAVE_LIBUVC
#include <libuvc/libuvc.h>
#endif
#ifndef __KERNEL__
#include <sys/types.h>
#endif
2019-04-30 13:33:34 +00:00
/*
*
* Struct and defines
*
*/
#define P_SPEW(p, ...) \
do { \
if (p->print_spew) { \
fprintf(stderr, "%s - ", __func__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} \
} while (false)
#define P_DEBUG(p, ...) \
do { \
if (p->print_debug) { \
fprintf(stderr, "%s - ", __func__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} \
} while (false)
#define P_ERROR(p, ...) \
do { \
fprintf(stderr, "%s - ", __func__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} while (false)
#define MAX_AUTO_PROBERS 8
#ifdef XRT_OS_LINUX
2019-04-30 13:33:34 +00:00
/*!
* A hidraw interface that a @ref prober_device exposes.
*/
struct prober_hidraw
{
ssize_t interface;
const char *path;
2019-04-30 13:33:34 +00:00
};
2019-06-20 17:27:21 +00:00
/*!
* A v4l interface that a @ref prober_device exposes.
*/
struct prober_v4l
{
const char *path;
2019-06-20 17:27:21 +00:00
int32_t usb_iface;
uint32_t v4l_index;
};
#endif
2019-04-30 13:33:34 +00:00
/*!
2020-06-03 16:43:30 +00:00
* A single device found by a @ref prober.
*
* @implements xrt_prober_device
2019-04-30 13:33:34 +00:00
*/
struct prober_device
{
struct xrt_prober_device base;
struct
{
uint16_t bus;
uint16_t addr;
const char *product;
const char *manufacturer;
const char *serial;
const char *path;
uint8_t ports[8];
uint32_t num_ports;
2019-04-30 13:33:34 +00:00
#ifdef XRT_HAVE_LIBUSB
libusb_device *dev;
2019-04-30 13:33:34 +00:00
#endif
} usb;
struct
{
uint64_t id;
} bluetooth;
#ifdef XRT_HAVE_LIBUVC
struct
{
uvc_device_t *dev;
2019-04-30 13:33:34 +00:00
} uvc;
#endif
#ifdef XRT_HAVE_V4L2
2019-06-20 17:27:21 +00:00
size_t num_v4ls;
struct prober_v4l *v4ls;
#endif
2019-04-30 13:33:34 +00:00
#ifdef XRT_OS_LINUX
2019-04-30 13:33:34 +00:00
size_t num_hidraws;
struct prober_hidraw *hidraws;
#endif
2019-04-30 13:33:34 +00:00
};
2020-06-03 16:43:30 +00:00
/*!
* @implements xrt_prober
*/
2019-04-30 13:33:34 +00:00
struct prober
{
struct xrt_prober base;
struct xrt_prober_entry_lists *lists;
2019-04-30 13:33:34 +00:00
struct
{
//! For error reporting, was it loaded but not parsed?
bool file_loaded;
cJSON *root;
} json;
#ifdef XRT_HAVE_LIBUSB
2019-04-30 13:33:34 +00:00
struct
{
libusb_context *ctx;
libusb_device **list;
2019-04-30 13:33:34 +00:00
ssize_t count;
} usb;
#endif
2019-04-30 13:33:34 +00:00
#ifdef XRT_HAVE_LIBUVC
struct
{
uvc_context_t *ctx;
uvc_device_t **list;
2019-04-30 13:33:34 +00:00
ssize_t count;
} uvc;
#endif
struct xrt_auto_prober *auto_probers[MAX_AUTO_PROBERS];
2019-04-30 13:33:34 +00:00
size_t num_devices;
struct prober_device *devices;
2019-04-30 13:33:34 +00:00
size_t num_entries;
struct xrt_prober_entry **entries;
2019-04-30 13:33:34 +00:00
bool print_debug;
bool print_spew;
};
/*
*
* Functions.
*
*/
/*!
* Load the JSON config file.
2020-06-03 16:43:30 +00:00
*
* @public @memberof prober
*/
void
p_json_open_or_create_main_file(struct prober *p);
/*!
* Extract tracking settings from the JSON.
2020-06-03 16:43:30 +00:00
*
* @public @memberof prober
* @relatesalso xrt_settings_tracking
*/
bool
p_json_get_tracking_settings(struct prober *p, struct xrt_settings_tracking *s);
2019-04-30 13:33:34 +00:00
/*!
* Dump the given device to stdout.
2020-06-03 16:43:30 +00:00
*
* @public @memberof prober
2019-04-30 13:33:34 +00:00
*/
void
p_dump_device(struct prober *p, struct prober_device *pdev, int id);
2019-04-30 13:33:34 +00:00
/*!
* Get or create a @ref prober_device from the device.
2020-06-03 16:43:30 +00:00
*
* @public @memberof prober
2019-04-30 13:33:34 +00:00
*/
int
p_dev_get_usb_dev(struct prober *p,
2019-04-30 13:33:34 +00:00
uint16_t bus,
uint16_t addr,
uint16_t vendor_id,
uint16_t product_id,
struct prober_device **out_pdev);
2019-04-30 13:33:34 +00:00
/*!
* Get or create a @ref prober_device from the device.
2020-06-03 16:43:30 +00:00
*
* @public @memberof prober
2019-04-30 13:33:34 +00:00
*/
int
p_dev_get_bluetooth_dev(struct prober *p,
2019-04-30 13:33:34 +00:00
uint64_t id,
uint16_t vendor_id,
uint16_t product_id,
struct prober_device **out_pdev);
2019-04-30 13:33:34 +00:00
2020-06-03 16:43:30 +00:00
/*!
* @name Tracking systems
* @{
*/
/*!
* Init the tracking factory.
2020-06-03 16:43:30 +00:00
*
* @private @memberof prober
* @relatesalso xrt_tracking_factory
*/
int
p_tracking_init(struct prober *p);
/*!
* Teardown the tracking factory.
2020-06-03 16:43:30 +00:00
*
* @private @memberof prober
* @relatesalso xrt_tracking_factory
*/
void
p_tracking_teardown(struct prober *p);
2020-06-03 16:43:30 +00:00
/*!
* @}
*/
#ifdef XRT_HAVE_LIBUSB
2020-06-03 16:43:30 +00:00
/*!
* @name libusb
* @{
*/
/*!
* @private @memberof prober
*/
int
p_libusb_init(struct prober *p);
2020-06-03 16:43:30 +00:00
/*!
* @private @memberof prober
*/
void
p_libusb_teardown(struct prober *p);
2020-06-03 16:43:30 +00:00
/*!
* @private @memberof prober
*/
int
p_libusb_probe(struct prober *p);
2020-06-03 16:43:30 +00:00
/*!
* @private @memberof prober
*/
int
p_libusb_get_string_descriptor(struct prober *p,
struct prober_device *pdev,
enum xrt_prober_string which_string,
unsigned char *buffer,
int length);
2020-06-03 16:43:30 +00:00
/*!
* @private @memberof prober
*/
bool
p_libusb_can_open(struct prober *p, struct prober_device *pdev);
2020-06-03 16:43:30 +00:00
/*!
* @}
*/
#endif
2019-04-30 13:33:34 +00:00
#ifdef XRT_HAVE_LIBUVC
2020-06-03 16:43:30 +00:00
/*!
* @name libuvc
* @{
*/
/*!
* @private @memberof prober
*/
int
p_libuvc_init(struct prober *p);
2020-06-03 16:43:30 +00:00
/*!
* @private @memberof prober
*/
void
p_libuvc_teardown(struct prober *p);
2020-06-03 16:43:30 +00:00
/*!
* @private @memberof prober
*/
int
p_libuvc_probe(struct prober *p);
2020-06-03 16:43:30 +00:00
/*!
* @}
*/
#endif
2019-04-30 13:33:34 +00:00
#ifdef XRT_HAVE_LIBUDEV
2020-06-03 16:43:30 +00:00
/*!
* @name udev
* @{
*/
/*!
* @private @memberof prober
*/
2019-04-30 13:33:34 +00:00
int
p_udev_probe(struct prober *p);
2020-06-03 16:43:30 +00:00
/*!
* @}
*/
2019-04-30 13:33:34 +00:00
#endif