mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-28 17:38:27 +00:00
st/prober: Add the concept of active config to config file
This commit is contained in:
parent
a122b4b0b2
commit
27abc58d51
|
@ -10,6 +10,7 @@
|
|||
#include "util/u_file.h"
|
||||
#include "util/u_json.h"
|
||||
#include "util/u_debug.h"
|
||||
|
||||
#include "p_prober.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -17,6 +18,8 @@
|
|||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
DEBUG_GET_ONCE_OPTION(active_config, "P_OVERRIDE_ACTIVE_CONFIG", NULL)
|
||||
|
||||
|
||||
char *
|
||||
read_content(FILE *file)
|
||||
|
@ -150,6 +153,58 @@ get_obj_str(cJSON *json, const char *name, char *array, size_t array_size)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
is_json_ok(struct prober *p)
|
||||
{
|
||||
if (p->json.root == NULL) {
|
||||
if (p->json.file_loaded) {
|
||||
fprintf(stderr, "JSON not parsed!\n");
|
||||
} else {
|
||||
fprintf(stderr, "No config file!\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_active(const char *str,
|
||||
const char *from,
|
||||
enum p_active_config *out_active)
|
||||
{
|
||||
if (strcmp(str, "none") == 0) {
|
||||
*out_active = P_ACTIVE_CONFIG_NONE;
|
||||
} else if (strcmp(str, "tracking") == 0) {
|
||||
*out_active = P_ACTIVE_CONFIG_TRACKING;
|
||||
} else {
|
||||
fprintf(stderr, "Unknown active config '%s' from %s.\n", str,
|
||||
from);
|
||||
*out_active = P_ACTIVE_CONFIG_NONE;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
p_json_get_active(struct prober *p, enum p_active_config *out_active)
|
||||
{
|
||||
const char *str = debug_get_option_active_config();
|
||||
if (str != NULL && parse_active(str, "environment", out_active)) {
|
||||
return;
|
||||
}
|
||||
|
||||
char tmp[256];
|
||||
if (!is_json_ok(p) ||
|
||||
!get_obj_str(p->json.root, "active", tmp, sizeof(tmp))) {
|
||||
*out_active = P_ACTIVE_CONFIG_NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
parse_active(tmp, "json", out_active);
|
||||
}
|
||||
|
||||
bool
|
||||
p_json_get_tracking_settings(struct prober *p, struct xrt_settings_tracking *s)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
/*
|
||||
|
@ -656,10 +657,19 @@ select_device(struct xrt_prober *xp,
|
|||
size_t num_xdevs)
|
||||
{
|
||||
struct prober *p = (struct prober *)xp;
|
||||
enum p_active_config active;
|
||||
bool have_hmd = false;
|
||||
|
||||
add_from_devices(p, xdevs, num_xdevs, &have_hmd);
|
||||
add_from_auto_probers(p, xdevs, num_xdevs, &have_hmd);
|
||||
p_json_get_active(p, &active);
|
||||
|
||||
switch (active) {
|
||||
case P_ACTIVE_CONFIG_NONE:
|
||||
case P_ACTIVE_CONFIG_TRACKING:
|
||||
add_from_devices(p, xdevs, num_xdevs, &have_hmd);
|
||||
add_from_auto_probers(p, xdevs, num_xdevs, &have_hmd);
|
||||
break;
|
||||
default: assert(false);
|
||||
}
|
||||
|
||||
// It's easier if we just put the first hmd first,
|
||||
// but keep other internal ordering of devices.
|
||||
|
|
|
@ -60,6 +60,14 @@
|
|||
|
||||
#define MAX_AUTO_PROBERS 8
|
||||
|
||||
/*!
|
||||
* What config is currently active in the config file.
|
||||
*/
|
||||
enum p_active_config
|
||||
{
|
||||
P_ACTIVE_CONFIG_NONE = 0,
|
||||
P_ACTIVE_CONFIG_TRACKING = 1,
|
||||
};
|
||||
|
||||
#ifdef XRT_OS_LINUX
|
||||
/*!
|
||||
|
@ -194,6 +202,15 @@ struct prober
|
|||
void
|
||||
p_json_open_or_create_main_file(struct prober *p);
|
||||
|
||||
/*!
|
||||
* Read from the JSON loaded json config file and returns the active config,
|
||||
* can be overridden by `P_OVERRIDE_ACTIVE_CONFIG` envirmental variable.
|
||||
*
|
||||
* @public @memberof prober
|
||||
*/
|
||||
void
|
||||
p_json_get_active(struct prober *p, enum p_active_config *out_active);
|
||||
|
||||
/*!
|
||||
* Extract tracking settings from the JSON.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue