From 0ee84ea4a8b6d809d62862fa9c484ecfc80bb849 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 28 Nov 2023 18:59:01 +0000 Subject: [PATCH] t/common: Use new u_builder helper --- .../targets/common/target_builder_legacy.c | 70 ++++++---------- .../common/target_builder_lighthouse.c | 82 ++++++++----------- .../common/target_builder_north_star.c | 77 +++++++---------- .../targets/common/target_builder_nreal_air.c | 64 +++++---------- .../targets/common/target_builder_qwerty.c | 67 ++++++--------- .../common/target_builder_rgb_tracking.c | 70 ++++++---------- .../targets/common/target_builder_rift_s.c | 74 +++++++---------- .../targets/common/target_builder_simulated.c | 67 ++++++--------- .../targets/common/target_builder_simulavr.c | 69 ++++++---------- src/xrt/targets/common/target_builder_wmr.c | 70 ++++++---------- 10 files changed, 268 insertions(+), 442 deletions(-) diff --git a/src/xrt/targets/common/target_builder_legacy.c b/src/xrt/targets/common/target_builder_legacy.c index 308a8c303..01b018dc9 100644 --- a/src/xrt/targets/common/target_builder_legacy.c +++ b/src/xrt/targets/common/target_builder_legacy.c @@ -111,18 +111,17 @@ legacy_estimate_system(struct xrt_builder *xb, } static xrt_result_t -legacy_open_system(struct xrt_builder *xb, - cJSON *config, - struct xrt_prober *xp, - struct xrt_system_devices **out_xsysd, - struct xrt_space_overseer **out_xso) +legacy_open_system_impl(struct xrt_builder *xb, + cJSON *config, + struct xrt_prober *xp, + struct xrt_tracking_origin *origin, + struct xrt_system_devices *xsysd, + struct xrt_frame_context *xfctx, + struct u_builder_roles_helper *ubrh) { xrt_result_t xret; int ret; - assert(out_xsysd != NULL); - assert(*out_xsysd == NULL); - /* * Create the devices. @@ -133,13 +132,8 @@ legacy_open_system(struct xrt_builder *xb, return xret; } - // Use the static system devices helper, no dynamic roles. - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); - struct xrt_system_devices *xsysd = &usysds->base.base; - ret = xrt_prober_select(xp, xsysd->xdevs, ARRAY_SIZE(xsysd->xdevs)); if (ret < 0) { - xrt_system_devices_destroy(&xsysd); return XRT_ERROR_DEVICE_CREATION_FAILED; } @@ -179,28 +173,11 @@ legacy_open_system(struct xrt_builder *xb, right_ht = u_system_devices_get_ht_device_right(xsysd); // Assign to role(s). - xsysd->static_roles.head = head; - xsysd->static_roles.hand_tracking.left = left_ht; - xsysd->static_roles.hand_tracking.right = right_ht; - - u_system_devices_static_finalize( // - usysds, // usysds - left, // left - right); // right - - - /* - * Done. - */ - - *out_xsysd = xsysd; - u_builder_create_space_overseer_legacy( // - head, // head - left, // left - right, // right - xsysd->xdevs, // xdevs - xsysd->xdev_count, // xdev_count - out_xso); // out_xso + ubrh->head = head; + ubrh->left = left; + ubrh->right = right; + ubrh->hand_tracking.left = left_ht; + ubrh->hand_tracking.right = right_ht; return XRT_SUCCESS; } @@ -221,14 +198,19 @@ legacy_destroy(struct xrt_builder *xb) struct xrt_builder * t_builder_legacy_create(void) { - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); - xb->estimate_system = legacy_estimate_system; - xb->open_system = legacy_open_system; - xb->destroy = legacy_destroy; - xb->identifier = "legacy"; - xb->name = "Legacy probing system"; - xb->driver_identifiers = driver_list; - xb->driver_identifier_count = ARRAY_SIZE(driver_list) - 1; + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); - return xb; + // xrt_builder fields. + ub->base.estimate_system = legacy_estimate_system; + ub->base.open_system = u_builder_open_system_static_roles; + ub->base.destroy = legacy_destroy; + ub->base.identifier = "legacy"; + ub->base.name = "Legacy probing system"; + ub->base.driver_identifiers = driver_list; + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list) - 1; + + // u_builder fields. + ub->open_system_static_roles = legacy_open_system_impl; + + return &ub->base; } diff --git a/src/xrt/targets/common/target_builder_lighthouse.c b/src/xrt/targets/common/target_builder_lighthouse.c index 2f7444ea8..3af063c49 100644 --- a/src/xrt/targets/common/target_builder_lighthouse.c +++ b/src/xrt/targets/common/target_builder_lighthouse.c @@ -118,8 +118,9 @@ enum lighthouse_driver struct lighthouse_system { - struct xrt_builder base; - struct u_system_devices_static *devices; + struct u_builder base; + + struct xrt_frame_context *xfctx; enum lighthouse_driver driver; //!< Which lighthouse implementation we are using bool is_valve_index; //!< Is our HMD a Valve Index? If so, try to set up hand-tracking and SLAM as needed struct vive_tracking_status vive_tstatus; //!< Visual tracking status for Index under Vive driver @@ -165,12 +166,11 @@ on_video_device(struct xrt_prober *xp, void *ptr) { struct lighthouse_system *lhs = (struct lighthouse_system *)ptr; - struct u_system_devices *usysd = &lhs->devices->base; // Hardcoded for the Index. if (product != NULL && manufacturer != NULL) { if ((strcmp(product, "3D Camera") == 0) && (strcmp(manufacturer, "Etron Technology, Inc.") == 0)) { - xrt_prober_open_video_device(xp, pdev, &usysd->xfctx, &lhs->xfs); + xrt_prober_open_video_device(xp, pdev, lhs->xfctx, &lhs->xfs); return; } } @@ -518,27 +518,19 @@ try_add_opengloves(struct xrt_device *left, } static xrt_result_t -lighthouse_open_system(struct xrt_builder *xb, - cJSON *config, - struct xrt_prober *xp, - struct xrt_system_devices **out_xsysd, - struct xrt_space_overseer **out_xso) +lighthouse_open_system_impl(struct xrt_builder *xb, + cJSON *config, + struct xrt_prober *xp, + struct xrt_tracking_origin *origin, + struct xrt_system_devices *xsysd, + struct xrt_frame_context *xfctx, + struct u_builder_roles_helper *ubrh) { struct lighthouse_system *lhs = (struct lighthouse_system *)xb; - - // Use the static system devices helper, no dynamic roles. - lhs->devices = u_system_devices_static_allocate(); - struct xrt_system_devices *xsysd = &lhs->devices->base.base; - struct xrt_frame_context *xfctx = &lhs->devices->base.xfctx; - - xrt_result_t result = XRT_SUCCESS; - if (out_xsysd == NULL || *out_xsysd != NULL) { - LH_ERROR("Invalid output system pointer"); - result = XRT_ERROR_DEVICE_CREATION_FAILED; - goto end_err; - } + // Needed when we probe for video devices. + lhs->xfctx = xfctx; // Decide whether to initialize the SLAM tracker bool slam_wanted = debug_get_bool_option_vive_slam(); @@ -755,28 +747,21 @@ end_valve_index: } // Assign to role(s). - xsysd->static_roles.head = head; - xsysd->static_roles.hand_tracking.left = left_ht; - xsysd->static_roles.hand_tracking.right = right_ht; + ubrh->head = head; + ubrh->left = left; + ubrh->right = right; + ubrh->hand_tracking.left = left_ht; + ubrh->hand_tracking.right = right_ht; - u_system_devices_static_finalize( // - lhs->devices, // usysds - left, // left - right); // right - - *out_xsysd = xsysd; - u_builder_create_space_overseer_legacy( // - head, // head - left, // left - right, // right - xsysd->xdevs, // xdevs - xsysd->xdev_count, // xdev_count - out_xso); // out_xso + // Clean up after us. + lhs->xfctx = NULL; return XRT_SUCCESS; + end_err: - xrt_system_devices_destroy(&xsysd); + // Clean up after us. + lhs->xfctx = NULL; return result; } @@ -799,13 +784,18 @@ struct xrt_builder * t_builder_lighthouse_create(void) { struct lighthouse_system *lhs = U_TYPED_CALLOC(struct lighthouse_system); - lhs->base.estimate_system = lighthouse_estimate_system; - lhs->base.open_system = lighthouse_open_system; - lhs->base.destroy = lighthouse_destroy; - lhs->base.identifier = "lighthouse"; - lhs->base.name = "Lighthouse-tracked (Vive, Index, Tundra trackers, etc.) devices builder"; - lhs->base.driver_identifiers = driver_list; - lhs->base.driver_identifier_count = ARRAY_SIZE(driver_list); - return &lhs->base; + // xrt_builder fields. + lhs->base.base.estimate_system = lighthouse_estimate_system; + lhs->base.base.open_system = u_builder_open_system_static_roles; + lhs->base.base.destroy = lighthouse_destroy; + lhs->base.base.identifier = "lighthouse"; + lhs->base.base.name = "Lighthouse-tracked (Vive, Index, Tundra trackers, etc.) devices builder"; + lhs->base.base.driver_identifiers = driver_list; + lhs->base.base.driver_identifier_count = ARRAY_SIZE(driver_list); + + // u_builder fields. + lhs->base.open_system_static_roles = lighthouse_open_system_impl; + + return &lhs->base.base; } diff --git a/src/xrt/targets/common/target_builder_north_star.c b/src/xrt/targets/common/target_builder_north_star.c index 404b634bd..b453aa237 100644 --- a/src/xrt/targets/common/target_builder_north_star.c +++ b/src/xrt/targets/common/target_builder_north_star.c @@ -102,7 +102,7 @@ struct ns_t265 struct ns_builder { - struct xrt_builder base; + struct u_builder base; const char *config_path; cJSON *config_json; @@ -442,30 +442,18 @@ ns_estimate_system(struct xrt_builder *xb, cJSON *config, struct xrt_prober *xp, return XRT_SUCCESS; } - - static xrt_result_t -ns_open_system(struct xrt_builder *xb, - cJSON *config, - struct xrt_prober *xp, - struct xrt_system_devices **out_xsysd, - struct xrt_space_overseer **out_xso) +ns_open_system_impl(struct xrt_builder *xb, + cJSON *config, + struct xrt_prober *xp, + struct xrt_tracking_origin *origin, + struct xrt_system_devices *xsysd, + struct xrt_frame_context *xfctx, + struct u_builder_roles_helper *ubrh) { struct ns_builder *nsb = (struct ns_builder *)xb; xrt_result_t result = XRT_SUCCESS; - // Use the static system devices helper, no dynamic roles. - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); - struct xrt_system_devices *xsysd = &usysds->base.base; - struct xrt_frame_context *xfctx = &usysds->base.xfctx; - - if (out_xsysd == NULL || *out_xsysd != NULL) { - NS_ERROR("Invalid output system pointer"); - result = XRT_ERROR_DEVICE_CREATION_FAILED; - goto end; - } - - bool load_success = ns_config_load(nsb); if (!load_success) { result = XRT_ERROR_DEVICE_CREATION_FAILED; @@ -591,31 +579,16 @@ ns_open_system(struct xrt_builder *xb, } // Assign to role(s). - xsysd->static_roles.head = head_wrap; - xsysd->static_roles.hand_tracking.left = left_ht; - xsysd->static_roles.hand_tracking.right = right_ht; - - u_system_devices_static_finalize( // - usysds, // usysds - left, // left - right); // right - + ubrh->head = head_wrap; + ubrh->left = left; + ubrh->right = right; + ubrh->hand_tracking.left = left_ht; + ubrh->hand_tracking.right = right_ht; end: - if (result == XRT_SUCCESS) { - *out_xsysd = xsysd; - u_builder_create_space_overseer_legacy( // - head_wrap, // head - left, // left - right, // right - xsysd->xdevs, // xdevs - xsysd->xdev_count, // xdev_count - out_xso); // out_xso - } else { - xrt_system_devices_destroy(&xsysd); - } if (nsb->config_json != NULL) { cJSON_Delete(nsb->config_json); + nsb->config_path = NULL; } return result; @@ -627,6 +600,7 @@ ns_destroy(struct xrt_builder *xb) free(xb); } + /* * * 'Exported' functions. @@ -637,13 +611,18 @@ struct xrt_builder * t_builder_north_star_create(void) { struct ns_builder *sb = U_TYPED_CALLOC(struct ns_builder); - sb->base.estimate_system = ns_estimate_system; - sb->base.open_system = ns_open_system; - sb->base.destroy = ns_destroy; - sb->base.identifier = "north_star"; - sb->base.name = "North Star headset"; - sb->base.driver_identifiers = driver_list; - sb->base.driver_identifier_count = ARRAY_SIZE(driver_list); - return &sb->base; + // xrt_builder fields. + sb->base.base.estimate_system = ns_estimate_system; + sb->base.base.open_system = u_builder_open_system_static_roles; + sb->base.base.destroy = ns_destroy; + sb->base.base.identifier = "north_star"; + sb->base.base.name = "North Star headset"; + sb->base.base.driver_identifiers = driver_list; + sb->base.base.driver_identifier_count = ARRAY_SIZE(driver_list); + + // u_builder fields. + sb->base.open_system_static_roles = ns_open_system_impl; + + return &sb->base.base; } diff --git a/src/xrt/targets/common/target_builder_nreal_air.c b/src/xrt/targets/common/target_builder_nreal_air.c index 189ea643d..9f1112f73 100644 --- a/src/xrt/targets/common/target_builder_nreal_air.c +++ b/src/xrt/targets/common/target_builder_nreal_air.c @@ -82,27 +82,22 @@ nreal_air_estimate_system(struct xrt_builder *xb, } static xrt_result_t -nreal_air_open_system(struct xrt_builder *xb, - cJSON *config, - struct xrt_prober *xp, - struct xrt_system_devices **out_xsysd, - struct xrt_space_overseer **out_xso) +nreal_air_open_system_impl(struct xrt_builder *xb, + cJSON *config, + struct xrt_prober *xp, + struct xrt_tracking_origin *origin, + struct xrt_system_devices *xsysd, + struct xrt_frame_context *xfctx, + struct u_builder_roles_helper *ubrh) { struct xrt_prober_device **xpdevs = NULL; size_t xpdev_count = 0; xrt_result_t xret = XRT_SUCCESS; - assert(out_xsysd != NULL); - assert(*out_xsysd == NULL); - DRV_TRACE_MARKER(); nreal_air_log_level = debug_get_log_option_nreal_air_log(); - // Use the static system devices helper, no dynamic roles. - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); - struct xrt_system_devices *xsysd = &usysds->base.base; - xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count); if (xret != XRT_SUCCESS) { goto unlock_and_fail; @@ -152,26 +147,7 @@ nreal_air_open_system(struct xrt_builder *xb, xsysd->xdevs[xsysd->xdev_count++] = na_device; // Assign to role(s). - xsysd->static_roles.head = na_device; - - u_system_devices_static_finalize( // - usysds, // usysds - NULL, // left - NULL); // right - - - /* - * Done. - */ - - *out_xsysd = xsysd; - u_builder_create_space_overseer_legacy( // - na_device, // head - NULL, // left - NULL, // right - xsysd->xdevs, // xdevs - xsysd->xdev_count, // xdev_count - out_xso); // out_xso + ubrh->head = na_device; return XRT_SUCCESS; @@ -188,8 +164,6 @@ unlock_and_fail: /* Fallthrough */ fail: - xrt_system_devices_destroy(&xsysd); - return XRT_ERROR_DEVICE_CREATION_FAILED; } @@ -209,15 +183,19 @@ nreal_air_destroy(struct xrt_builder *xb) struct xrt_builder * nreal_air_builder_create(void) { + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); - xb->estimate_system = nreal_air_estimate_system; - xb->open_system = nreal_air_open_system; - xb->destroy = nreal_air_destroy; - xb->identifier = "nreal_air"; - xb->name = "Nreal Air"; - xb->driver_identifiers = driver_list; - xb->driver_identifier_count = ARRAY_SIZE(driver_list); + // xrt_builder fields. + ub->base.estimate_system = nreal_air_estimate_system; + ub->base.open_system = u_builder_open_system_static_roles; + ub->base.destroy = nreal_air_destroy; + ub->base.identifier = "nreal_air"; + ub->base.name = "Nreal Air"; + ub->base.driver_identifiers = driver_list; + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); - return xb; + // u_builder fields. + ub->open_system_static_roles = nreal_air_open_system_impl; + + return &ub->base; } diff --git a/src/xrt/targets/common/target_builder_qwerty.c b/src/xrt/targets/common/target_builder_qwerty.c index b6757d727..2c66ad303 100644 --- a/src/xrt/targets/common/target_builder_qwerty.c +++ b/src/xrt/targets/common/target_builder_qwerty.c @@ -68,15 +68,14 @@ qwerty_estimate_system(struct xrt_builder *xb, } static xrt_result_t -qwerty_open_system(struct xrt_builder *xb, - cJSON *config, - struct xrt_prober *xp, - struct xrt_system_devices **out_xsysd, - struct xrt_space_overseer **out_xso) +qwerty_open_system_impl(struct xrt_builder *xb, + cJSON *config, + struct xrt_prober *xp, + struct xrt_tracking_origin *origin, + struct xrt_system_devices *xsysd, + struct xrt_frame_context *xfctx, + struct u_builder_roles_helper *ubrh) { - assert(out_xsysd != NULL); - assert(*out_xsysd == NULL); - struct xrt_device *head = NULL; struct xrt_device *left = NULL; struct xrt_device *right = NULL; @@ -87,10 +86,6 @@ qwerty_open_system(struct xrt_builder *xb, return xret; } - // Use the static system devices helper, no dynamic roles. - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); - struct xrt_system_devices *xsysd = &usysds->base.base; - // Add to device list. xsysd->xdevs[xsysd->xdev_count++] = head; if (left != NULL) { @@ -101,26 +96,9 @@ qwerty_open_system(struct xrt_builder *xb, } // Assign to role(s). - xsysd->static_roles.head = head; - - u_system_devices_static_finalize( // - usysds, // usysds - left, // left - right); // right - - - /* - * Done. - */ - - *out_xsysd = xsysd; - u_builder_create_space_overseer_legacy( // - head, // head - left, // left - right, // right - xsysd->xdevs, // xdevs - xsysd->xdev_count, // xdev_count - out_xso); // out_xso + ubrh->head = head; + ubrh->left = left; + ubrh->right = right; return XRT_SUCCESS; } @@ -141,15 +119,20 @@ qwerty_destroy(struct xrt_builder *xb) struct xrt_builder * t_builder_qwerty_create(void) { - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); - xb->estimate_system = qwerty_estimate_system; - xb->open_system = qwerty_open_system; - xb->destroy = qwerty_destroy; - xb->identifier = "qwerty"; - xb->name = "Qwerty devices builder"; - xb->driver_identifiers = driver_list; - xb->driver_identifier_count = ARRAY_SIZE(driver_list); - xb->exclude_from_automatic_discovery = !debug_get_bool_option_enable_qwerty(); + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); - return xb; + // xrt_builder fields. + ub->base.estimate_system = qwerty_estimate_system; + ub->base.open_system = u_builder_open_system_static_roles; + ub->base.destroy = qwerty_destroy; + ub->base.identifier = "qwerty"; + ub->base.name = "Qwerty devices builder"; + ub->base.driver_identifiers = driver_list; + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); + ub->base.exclude_from_automatic_discovery = !debug_get_bool_option_enable_qwerty(); + + // u_builder fields. + ub->open_system_static_roles = qwerty_open_system_impl; + + return &ub->base; } diff --git a/src/xrt/targets/common/target_builder_rgb_tracking.c b/src/xrt/targets/common/target_builder_rgb_tracking.c index e5ba912c5..33e227397 100644 --- a/src/xrt/targets/common/target_builder_rgb_tracking.c +++ b/src/xrt/targets/common/target_builder_rgb_tracking.c @@ -276,26 +276,19 @@ rgb_estimate_system(struct xrt_builder *xb, cJSON *config, struct xrt_prober *xp } static xrt_result_t -rgb_open_system(struct xrt_builder *xb, - cJSON *config, - struct xrt_prober *xp, - struct xrt_system_devices **out_xsysd, - struct xrt_space_overseer **out_xso) +rgb_open_system_impl(struct xrt_builder *xb, + cJSON *config, + struct xrt_prober *xp, + struct xrt_tracking_origin *origin, + struct xrt_system_devices *xsysd, + struct xrt_frame_context *xfctx, + struct u_builder_roles_helper *ubrh) { struct u_builder_search_results results = {0}; struct xrt_prober_device **xpdevs = NULL; size_t xpdev_count = 0; xrt_result_t xret = XRT_SUCCESS; - assert(out_xsysd != NULL); - assert(*out_xsysd == NULL); - - // Use the static system devices helper, no dynamic roles. - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); - struct xrt_tracking_origin *origin = &usysds->base.origin; - struct xrt_system_devices *xsysd = &usysds->base.base; - struct xrt_frame_context *xfctx = &usysds->base.xfctx; - /* * Tracking. @@ -327,7 +320,6 @@ rgb_open_system(struct xrt_builder *xb, // Lock the device list xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count); if (xret != XRT_SUCCESS) { - xrt_system_devices_destroy(&xsysd); return xret; } @@ -387,7 +379,6 @@ rgb_open_system(struct xrt_builder *xb, // Unlock the device list xret = xrt_prober_unlock_list(xp, &xpdevs); if (xret != XRT_SUCCESS) { - xrt_system_devices_destroy(&xsysd); return xret; } @@ -406,27 +397,9 @@ rgb_open_system(struct xrt_builder *xb, } // Assign to role(s). - xsysd->static_roles.head = head; - - u_system_devices_static_finalize( // - usysds, // usysds - left, // left - right); // right - - - /* - * Done. - */ - - *out_xsysd = xsysd; - u_builder_create_space_overseer_legacy( // - head, // head - left, // left - right, // right - xsysd->xdevs, // xdevs - xsysd->xdev_count, // xdev_count - out_xso); // out_xso - + ubrh->head = head; + ubrh->left = left; + ubrh->right = right; return XRT_SUCCESS; } @@ -447,14 +420,19 @@ rgb_destroy(struct xrt_builder *xb) struct xrt_builder * t_builder_rgb_tracking_create(void) { - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); - xb->estimate_system = rgb_estimate_system; - xb->open_system = rgb_open_system; - xb->destroy = rgb_destroy; - xb->identifier = "rgb_tracking"; - xb->name = "RGB tracking based devices (PSVR, PSMV, ...)"; - xb->driver_identifiers = driver_list; - xb->driver_identifier_count = ARRAY_SIZE(driver_list); + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); - return xb; + // xrt_builder fields. + ub->base.estimate_system = rgb_estimate_system; + ub->base.open_system = u_builder_open_system_static_roles; + ub->base.destroy = rgb_destroy; + ub->base.identifier = "rgb_tracking"; + ub->base.name = "RGB tracking based devices (PSVR, PSMV, ...)"; + ub->base.driver_identifiers = driver_list; + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); + + // u_builder fields. + ub->open_system_static_roles = rgb_open_system_impl; + + return &ub->base; } diff --git a/src/xrt/targets/common/target_builder_rift_s.c b/src/xrt/targets/common/target_builder_rift_s.c index 0da8fef4f..675b30322 100644 --- a/src/xrt/targets/common/target_builder_rift_s.c +++ b/src/xrt/targets/common/target_builder_rift_s.c @@ -93,27 +93,22 @@ rift_s_estimate_system(struct xrt_builder *xb, } static xrt_result_t -rift_s_open_system(struct xrt_builder *xb, - cJSON *config, - struct xrt_prober *xp, - struct xrt_system_devices **out_xsysd, - struct xrt_space_overseer **out_xso) +rift_s_open_system_impl(struct xrt_builder *xb, + cJSON *config, + struct xrt_prober *xp, + struct xrt_tracking_origin *origin, + struct xrt_system_devices *xsysd, + struct xrt_frame_context *xfctx, + struct u_builder_roles_helper *ubrh) { struct xrt_prober_device **xpdevs = NULL; size_t xpdev_count = 0; xrt_result_t xret = XRT_SUCCESS; - assert(out_xsysd != NULL); - assert(*out_xsysd == NULL); - DRV_TRACE_MARKER(); rift_s_log_level = debug_get_log_option_rift_s_log(); - // Use the static system devices helper, no dynamic roles. - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); - struct xrt_system_devices *xsysd = &usysds->base.base; - xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count); if (xret != XRT_SUCCESS) { goto unlock_and_fail; @@ -180,6 +175,9 @@ rift_s_open_system(struct xrt_builder *xb, xsysd->xdevs[xsysd->xdev_count++] = right_xdev; + struct xrt_device *left_ht = NULL; + struct xrt_device *right_ht = NULL; + #ifdef XRT_BUILD_DRIVER_HANDTRACKING struct xrt_device *ht_xdev = rift_s_system_get_hand_tracking_device(sys); if (ht_xdev != NULL) { @@ -189,8 +187,8 @@ rift_s_open_system(struct xrt_builder *xb, struct xrt_device *two_hands[2]; cemu_devices_create(hmd_xdev, ht_xdev, two_hands); - xsysd->static_roles.hand_tracking.left = two_hands[0]; - xsysd->static_roles.hand_tracking.right = two_hands[1]; + left_ht = two_hands[0]; + right_ht = two_hands[1]; xsysd->xdevs[xsysd->xdev_count++] = two_hands[0]; xsysd->xdevs[xsysd->xdev_count++] = two_hands[1]; @@ -203,26 +201,11 @@ rift_s_open_system(struct xrt_builder *xb, #endif // Assign to role(s). - xsysd->static_roles.head = hmd_xdev; - - u_system_devices_static_finalize( // - usysds, // usysds - left_xdev, // left - right_xdev); // right - - - /* - * Done. - */ - - *out_xsysd = xsysd; - u_builder_create_space_overseer_legacy( // - hmd_xdev, // head - left_xdev, // left - right_xdev, // right - xsysd->xdevs, // xdevs - xsysd->xdev_count, // xdev_count - out_xso); // out_xso + ubrh->head = hmd_xdev; + ubrh->left = left_xdev; + ubrh->right = right_xdev; + ubrh->hand_tracking.left = left_ht; + ubrh->hand_tracking.right = right_ht; return XRT_SUCCESS; @@ -235,7 +218,6 @@ unlock_and_fail: /* Fallthrough */ fail: - xrt_system_devices_destroy(&xsysd); return XRT_ERROR_DEVICE_CREATION_FAILED; } @@ -255,15 +237,19 @@ rift_s_destroy(struct xrt_builder *xb) struct xrt_builder * rift_s_builder_create(void) { + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); - xb->estimate_system = rift_s_estimate_system; - xb->open_system = rift_s_open_system; - xb->destroy = rift_s_destroy; - xb->identifier = "rift_s"; - xb->name = "Oculus Rift S"; - xb->driver_identifiers = driver_list; - xb->driver_identifier_count = ARRAY_SIZE(driver_list); + // xrt_builder fields. + ub->base.estimate_system = rift_s_estimate_system; + ub->base.open_system = u_builder_open_system_static_roles; + ub->base.destroy = rift_s_destroy; + ub->base.identifier = "rift_s"; + ub->base.name = "Oculus Rift S"; + ub->base.driver_identifiers = driver_list; + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); - return xb; + // u_builder fields. + ub->open_system_static_roles = rift_s_open_system_impl; + + return &ub->base; } diff --git a/src/xrt/targets/common/target_builder_simulated.c b/src/xrt/targets/common/target_builder_simulated.c index 6ef131f93..8c2709e67 100644 --- a/src/xrt/targets/common/target_builder_simulated.c +++ b/src/xrt/targets/common/target_builder_simulated.c @@ -90,15 +90,14 @@ simulated_estimate_system(struct xrt_builder *xb, } static xrt_result_t -simulated_open_system(struct xrt_builder *xb, - cJSON *config, - struct xrt_prober *xp, - struct xrt_system_devices **out_xsysd, - struct xrt_space_overseer **out_xso) +simulated_open_system_impl(struct xrt_builder *xb, + cJSON *config, + struct xrt_prober *xp, + struct xrt_tracking_origin *origin, + struct xrt_system_devices *xsysd, + struct xrt_frame_context *xfctx, + struct u_builder_roles_helper *ubrh) { - assert(out_xsysd != NULL); - assert(*out_xsysd == NULL); - const struct xrt_pose head_center = {XRT_QUAT_IDENTITY, {0.0f, 1.6f, 0.0f}}; // "nominal height" 1.6m const struct xrt_pose left_center = {XRT_QUAT_IDENTITY, {-0.2f, 1.3f, -0.5f}}; const struct xrt_pose right_center = {XRT_QUAT_IDENTITY, {0.2f, 1.3f, -0.5f}}; @@ -119,10 +118,6 @@ simulated_open_system(struct xrt_builder *xb, //! @todo Create a shared tracking origin on the system devices struct instead. head->tracking_origin->type = XRT_TRACKING_TYPE_OTHER; // Just anything other then none. - // Use the static system devices helper, no dynamic roles. - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); - struct xrt_system_devices *xsysd = &usysds->base.base; - // Add to device list. xsysd->xdevs[xsysd->xdev_count++] = head; if (left != NULL) { @@ -133,26 +128,9 @@ simulated_open_system(struct xrt_builder *xb, } // Assign to role(s). - xsysd->static_roles.head = head; - - u_system_devices_static_finalize( // - usysds, // usysds - left, // left - right); // right - - - /* - * Done. - */ - - *out_xsysd = xsysd; - u_builder_create_space_overseer_legacy( // - head, // head - left, // left - right, // right - xsysd->xdevs, // xdevs - xsysd->xdev_count, // xdev_count - out_xso); // out_xso + ubrh->head = head; + ubrh->left = left; + ubrh->right = right; return XRT_SUCCESS; } @@ -173,15 +151,20 @@ simulated_destroy(struct xrt_builder *xb) struct xrt_builder * t_builder_simulated_create(void) { - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); - xb->estimate_system = simulated_estimate_system; - xb->open_system = simulated_open_system; - xb->destroy = simulated_destroy; - xb->identifier = "simulated"; - xb->name = "Simulated devices builder"; - xb->driver_identifiers = driver_list; - xb->driver_identifier_count = ARRAY_SIZE(driver_list); - xb->exclude_from_automatic_discovery = !debug_get_bool_option_simulated_enabled(); + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); - return xb; + // xrt_builder fields. + ub->base.estimate_system = simulated_estimate_system; + ub->base.open_system = u_builder_open_system_static_roles; + ub->base.destroy = simulated_destroy; + ub->base.identifier = "simulated"; + ub->base.name = "Simulated devices builder"; + ub->base.driver_identifiers = driver_list; + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); + ub->base.exclude_from_automatic_discovery = !debug_get_bool_option_simulated_enabled(); + + // u_builder fields. + ub->open_system_static_roles = simulated_open_system_impl; + + return &ub->base; } diff --git a/src/xrt/targets/common/target_builder_simulavr.c b/src/xrt/targets/common/target_builder_simulavr.c index bd2ce07bd..4f5f4f86e 100644 --- a/src/xrt/targets/common/target_builder_simulavr.c +++ b/src/xrt/targets/common/target_builder_simulavr.c @@ -51,7 +51,8 @@ static const char *driver_list[] = { struct simula_builder { - struct xrt_builder base; + struct u_builder base; + struct svr_two_displays_distortion display_distortion; }; @@ -192,23 +193,24 @@ svr_estimate_system(struct xrt_builder *xb, cJSON *config, struct xrt_prober *xp } static xrt_result_t -svr_open_system(struct xrt_builder *xb, - cJSON *config, - struct xrt_prober *xp, - struct xrt_system_devices **out_xsysd, - struct xrt_space_overseer **out_xso) +svr_open_system_impl(struct xrt_builder *xb, + cJSON *config, + struct xrt_prober *xp, + struct xrt_tracking_origin *origin, + struct xrt_system_devices *xsysd, + struct xrt_frame_context *xfctx, + struct u_builder_roles_helper *ubrh) { struct simula_builder *sb = (struct simula_builder *)xb; xrt_result_t result = XRT_SUCCESS; - if (out_xsysd == NULL || *out_xsysd != NULL) { - SVR_ERROR("Invalid output system pointer"); + struct xrt_device *t265_dev = rs_create_tracked_device_internal_slam(); + if (t265_dev == NULL) { + SVR_ERROR("Failed to open T265 device!"); result = XRT_ERROR_DEVICE_CREATION_FAILED; goto end; } - struct xrt_device *t265_dev = rs_create_tracked_device_internal_slam(); - struct xrt_device *svr_dev = svr_hmd_create(&sb->display_distortion); struct xrt_pose ident = XRT_POSE_IDENTITY; @@ -217,36 +219,13 @@ svr_open_system(struct xrt_builder *xb, struct xrt_device *head_device = multi_create_tracking_override( XRT_TRACKING_OVERRIDE_ATTACHED, svr_dev, t265_dev, XRT_INPUT_GENERIC_TRACKER_POSE, &ident); - // Use the static system devices helper, no dynamic roles. - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); - struct xrt_system_devices *xsysd = &usysds->base.base; - // Add to device list. xsysd->xdevs[xsysd->xdev_count++] = head_device; // Assign to role(s). - xsysd->static_roles.head = head_device; - + ubrh->head = head_device; end: - if (result == XRT_SUCCESS) { - u_system_devices_static_finalize( // - usysds, // usysds - NULL, // left - NULL); // right - - *out_xsysd = xsysd; - u_builder_create_space_overseer_legacy( // - head_device, // head - NULL, // left - NULL, // right - xsysd->xdevs, // xdevs - xsysd->xdev_count, // xdev_count - out_xso); // out_xso - } else { - xrt_system_devices_destroy(&xsysd); - } - return result; } @@ -256,6 +235,7 @@ svr_destroy(struct xrt_builder *xb) free(xb); } + /* * * 'Exported' functions. @@ -266,13 +246,18 @@ struct xrt_builder * t_builder_simula_create(void) { struct simula_builder *sb = U_TYPED_CALLOC(struct simula_builder); - sb->base.estimate_system = svr_estimate_system; - sb->base.open_system = svr_open_system; - sb->base.destroy = svr_destroy; - sb->base.identifier = "simula"; - sb->base.name = "SimulaVR headset"; - sb->base.driver_identifiers = driver_list; - sb->base.driver_identifier_count = ARRAY_SIZE(driver_list); - return &sb->base; + // xrt_builder fields. + sb->base.base.estimate_system = svr_estimate_system; + sb->base.base.open_system = u_builder_open_system_static_roles; + sb->base.base.destroy = svr_destroy; + sb->base.base.identifier = "simula"; + sb->base.base.name = "SimulaVR headset"; + sb->base.base.driver_identifiers = driver_list; + sb->base.base.driver_identifier_count = ARRAY_SIZE(driver_list); + + // u_builder fields. + sb->base.open_system_static_roles = svr_open_system_impl; + + return &sb->base.base; } diff --git a/src/xrt/targets/common/target_builder_wmr.c b/src/xrt/targets/common/target_builder_wmr.c index 636563964..40df6b653 100644 --- a/src/xrt/targets/common/target_builder_wmr.c +++ b/src/xrt/targets/common/target_builder_wmr.c @@ -176,11 +176,13 @@ wmr_estimate_system(struct xrt_builder *xb, } static xrt_result_t -wmr_open_system(struct xrt_builder *xb, - cJSON *config, - struct xrt_prober *xp, - struct xrt_system_devices **out_xsysd, - struct xrt_space_overseer **out_xso) +wmr_open_system_impl(struct xrt_builder *xb, + cJSON *config, + struct xrt_prober *xp, + struct xrt_tracking_origin *origin, + struct xrt_system_devices *xsysd, + struct xrt_frame_context *xfctx, + struct u_builder_roles_helper *ubrh) { enum u_logging_level log_level = debug_get_log_option_wmr_log(); struct wmr_bt_controllers_search_results ctrls = {0}; @@ -271,9 +273,6 @@ wmr_open_system(struct xrt_builder *xb, assert(xret_unlock == XRT_SUCCESS); (void)xret_unlock; - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); - struct xrt_system_devices *xsysd = &usysds->base.base; - xsysd->xdevs[xsysd->xdev_count++] = head; if (left != NULL) { xsysd->xdevs[xsysd->xdev_count++] = left; @@ -298,33 +297,11 @@ wmr_open_system(struct xrt_builder *xb, // Assign to role(s). - xsysd->static_roles.head = head; - xsysd->static_roles.hand_tracking.left = ht_left; - xsysd->static_roles.hand_tracking.right = ht_right; - - u_system_devices_static_finalize( // - usysds, // usysds - left, // left - right); // right - - // Create space overseer last once all devices set. - struct xrt_space_overseer *xso = NULL; - u_builder_create_space_overseer_legacy( // - head, // head - left, // left - right, // right - xsysd->xdevs, // xdevs - xsysd->xdev_count, // xdev_count - &xso); // out_xso - assert(xso != NULL); - - - /* - * Output. - */ - - *out_xsysd = xsysd; - *out_xso = xso; + ubrh->head = head; + ubrh->left = left; + ubrh->right = right; + ubrh->hand_tracking.left = ht_left; + ubrh->hand_tracking.right = ht_right; return XRT_SUCCESS; @@ -355,14 +332,19 @@ wmr_destroy(struct xrt_builder *xb) struct xrt_builder * t_builder_wmr_create(void) { - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); - xb->estimate_system = wmr_estimate_system; - xb->open_system = wmr_open_system; - xb->destroy = wmr_destroy; - xb->identifier = "wmr"; - xb->name = "Windows Mixed Reality"; - xb->driver_identifiers = driver_list; - xb->driver_identifier_count = ARRAY_SIZE(driver_list); + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); - return xb; + // xrt_builder fields. + ub->base.estimate_system = wmr_estimate_system; + ub->base.open_system = u_builder_open_system_static_roles; + ub->base.destroy = wmr_destroy; + ub->base.identifier = "wmr"; + ub->base.name = "Windows Mixed Reality"; + ub->base.driver_identifiers = driver_list; + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); + + // u_builder fields. + ub->open_system_static_roles = wmr_open_system_impl; + + return &ub->base; }