The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/remote: Use xrt_system_devices directly in the driver

And also make shutdown properly work.

+126 -65
+2 -2
src/xrt/drivers/remote/r_device.c
··· 1 - // Copyright 2020, Collabora, Ltd. 1 + // Copyright 2020-2022, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 195 195 rd->base.get_view_poses = r_device_get_view_poses; 196 196 rd->base.set_output = r_device_set_output; 197 197 rd->base.destroy = r_device_destroy; 198 - rd->base.tracking_origin = &r->base; 198 + rd->base.tracking_origin = &r->origin; 199 199 rd->base.orientation_tracking_supported = true; 200 200 rd->base.position_tracking_supported = true; 201 201 rd->base.hand_tracking_supported = true;
+2 -2
src/xrt/drivers/remote/r_hmd.c
··· 1 - // Copyright 2020, Collabora, Ltd. 1 + // Copyright 2020-2022, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 123 123 rh->base.get_view_poses = r_hmd_get_view_poses; 124 124 rh->base.set_output = r_hmd_set_output; 125 125 rh->base.destroy = r_hmd_destroy; 126 - rh->base.tracking_origin = &r->base; 126 + rh->base.tracking_origin = &r->origin; 127 127 rh->base.orientation_tracking_supported = true; 128 128 rh->base.position_tracking_supported = true; 129 129 rh->base.hand_tracking_supported = false;
+109 -21
src/xrt/drivers/remote/r_hub.c
··· 1 - // Copyright 2020, Collabora, Ltd. 1 + // Copyright 2020-2022, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 85 85 do_accept(struct r_hub *r) 86 86 { 87 87 struct sockaddr_in addr = {0}; 88 + struct timeval timeout = {.tv_sec = 1}; 89 + fd_set set; 88 90 int ret; 89 91 int conn_fd; 90 92 93 + // Shutting down. 94 + if (r->accept_fd < 0) { 95 + return -1; 96 + } 97 + 98 + do { 99 + FD_ZERO(&set); 100 + FD_SET(r->accept_fd, &set); 101 + 102 + ret = select(r->accept_fd + 1, &set, NULL, NULL, &timeout); 103 + } while (ret == 0); 104 + 105 + if (ret < 0) { 106 + U_LOG_E("select failed: %i", ret); 107 + return ret; 108 + } 109 + 91 110 socklen_t addr_length = (socklen_t)sizeof(addr); 92 111 ret = accept(r->accept_fd, (struct sockaddr *)&addr, &addr_length); 93 112 if (ret < 0) { ··· 120 139 121 140 ret = setup_accept_fd(r); 122 141 if (ret < 0) { 142 + U_LOG_I("Leaving thread"); 123 143 return NULL; 124 144 } 125 145 126 - while (true) { 146 + while (r->accept_fd >= 0) { 127 147 U_LOG_I("Listening on port '%i'.", r->port); 128 148 129 149 ret = do_accept(r); 150 + if (ret < 0) { 151 + U_LOG_I("Leaving thread"); 152 + return NULL; 153 + } 130 154 131 155 r_remote_connection_write_one(&r->rc, &r->reset); 132 156 r_remote_connection_write_one(&r->rc, &r->latest); ··· 143 167 } 144 168 } 145 169 170 + U_LOG_I("Leaving thread"); 146 171 return NULL; 147 172 } 148 173 149 174 void 150 - r_hub_destroy(struct r_hub *r) 175 + r_hub_destroy(struct xrt_system_devices *xsysd) 151 176 { 177 + struct r_hub *r = (struct r_hub *)xsysd; 178 + 179 + /* 180 + * Destroy all of the devices first. 181 + */ 182 + 183 + for (uint32_t i = 0; i < ARRAY_SIZE(r->base.xdevs); i++) { 184 + xrt_device_destroy(&r->base.xdevs[i]); 185 + } 186 + 187 + 188 + /* 189 + * Harshly pull the plug on the sockets to wakeup the thread. 190 + */ 191 + 192 + if (r->accept_fd >= 0) { 193 + close(r->accept_fd); 194 + r->accept_fd = -1; 195 + } 196 + 197 + if (r->rc.fd >= 0) { 198 + close(r->rc.fd); 199 + r->rc.fd = -1; 200 + } 201 + 202 + 203 + /* 204 + * Should be safe to stop the thread now. 205 + */ 206 + 207 + os_thread_helper_stop_and_wait(&r->oth); 208 + 152 209 free(r); 153 210 } 154 211 155 212 156 - /*! 157 - * 213 + /* 158 214 * 215 + * 'Exported' create function. 159 216 * 160 217 */ 161 218 162 219 int 163 - r_create_devices(uint16_t port, 164 - struct xrt_device **out_hmd, 165 - struct xrt_device **out_controller_left, 166 - struct xrt_device **out_controller_right) 220 + r_create_devices(uint16_t port, struct xrt_system_devices **out_xsysd) 167 221 { 168 222 struct r_hub *r = U_TYPED_CALLOC(struct r_hub); 169 223 int ret; 170 224 171 - r->base.type = XRT_TRACKING_TYPE_RGB; 172 - r->base.offset.orientation.w = 1.0f; // All other members are zero. 225 + r->base.destroy = r_hub_destroy; 226 + r->origin.type = XRT_TRACKING_TYPE_RGB; 227 + r->origin.offset.orientation.w = 1.0f; // All other members are zero. 173 228 r->reset.hmd.pose.position.y = 1.6f; 174 229 r->reset.hmd.pose.orientation.w = 1.0f; 175 230 r->reset.left.active = true; ··· 193 248 r->accept_fd = -1; 194 249 r->rc.fd = -1; 195 250 196 - snprintf(r->base.name, sizeof(r->base.name), "Remote Simulator"); 251 + snprintf(r->origin.name, sizeof(r->origin.name), "Remote Simulator"); 197 252 198 253 ret = os_thread_helper_init(&r->oth); 199 254 if (ret != 0) { 200 255 U_LOG_E("Failed to init threading!"); 201 - r_hub_destroy(r); 202 - return ret; 256 + r_hub_destroy(&r->base); 257 + return XRT_ERROR_ALLOCATION; 203 258 } 204 259 205 260 ret = os_thread_helper_start(&r->oth, run_thread, r); 206 261 if (ret != 0) { 207 262 U_LOG_E("Failed to start thread!"); 208 - r_hub_destroy(r); 209 - return ret; 263 + r_hub_destroy(&r->base); 264 + return XRT_ERROR_ALLOCATION; 210 265 } 211 266 212 - *out_hmd = r_hmd_create(r); 213 - *out_controller_left = r_device_create(r, true); 214 - *out_controller_right = r_device_create(r, false); 267 + 268 + /* 269 + * Setup system devices. 270 + */ 271 + 272 + struct xrt_device *head = r_hmd_create(r); 273 + struct xrt_device *left = r_device_create(r, true); 274 + struct xrt_device *right = r_device_create(r, false); 275 + 276 + r->base.xdevs[r->base.xdev_count++] = head; 277 + r->base.xdevs[r->base.xdev_count++] = left; 278 + r->base.xdevs[r->base.xdev_count++] = right; 215 279 216 - // Setup variable tracker. 280 + r->base.roles.head = head; 281 + r->base.roles.left = left; 282 + r->base.roles.right = right; 283 + r->base.roles.hand_tracking.left = left; 284 + r->base.roles.hand_tracking.right = right; 285 + 286 + 287 + /* 288 + * Setup variable tracker. 289 + */ 290 + 217 291 u_var_add_root(r, "Remote Hub", true); 218 292 // u_var_add_gui_header(r, &r->gui.hmd, "MHD"); 219 293 u_var_add_pose(r, &r->latest.hmd.pose, "hmd.pose"); ··· 228 302 u_var_add_bool(r, &r->latest.right.menu, "right.menu"); 229 303 u_var_add_pose(r, &r->latest.right.pose, "right.pose"); 230 304 231 - return 0; 305 + 306 + /* 307 + * Done now. 308 + */ 309 + 310 + *out_xsysd = &r->base; 311 + 312 + return XRT_SUCCESS; 232 313 } 314 + 315 + 316 + /* 317 + * 318 + * 'Exported' connection functions. 319 + * 320 + */ 233 321 234 322 int 235 323 r_remote_connection_init(struct r_remote_connection *rc, const char *ip_addr, uint16_t port)
+5 -8
src/xrt/drivers/remote/r_interface.h
··· 1 - // Copyright 2020, Collabora, Ltd. 1 + // Copyright 2020-2022, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 16 16 #endif 17 17 18 18 19 - struct xrt_device; 19 + struct xrt_system_devices; 20 20 21 21 /*! 22 22 * @defgroup drv_remote Remote debugging driver ··· 85 85 }; 86 86 87 87 /*! 88 - * Creates the remote devices. 88 + * Creates the remote system devices. 89 89 * 90 90 * @ingroup drv_remote 91 91 */ 92 - int 93 - r_create_devices(uint16_t port, 94 - struct xrt_device **out_hmd, 95 - struct xrt_device **out_controller_left, 96 - struct xrt_device **out_controller_right); 92 + xrt_result_t 93 + r_create_devices(uint16_t port, struct xrt_system_devices **out_xsysd); 97 94 98 95 /*! 99 96 * Initializes and connects the connection.
+7 -2
src/xrt/drivers/remote/r_internal.h
··· 1 - // Copyright 2020, Collabora, Ltd. 1 + // Copyright 2020-2022, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 10 10 #pragma once 11 11 12 12 #include "xrt/xrt_device.h" 13 + #include "xrt/xrt_system.h" 13 14 #include "xrt/xrt_tracking.h" 14 15 15 16 #include "os/os_threading.h" ··· 30 31 */ 31 32 struct r_hub 32 33 { 33 - struct xrt_tracking_origin base; 34 + // System devices wrapper. 35 + struct xrt_system_devices base; 36 + 37 + //! Origin for all locations. 38 + struct xrt_tracking_origin origin; 34 39 35 40 //! Connection to the controller. 36 41 struct r_remote_connection rc;
+1 -30
src/xrt/targets/common/target_builder_remote.c
··· 73 73 static xrt_result_t 74 74 remote_open_system(struct xrt_builder *xb, cJSON *config, struct xrt_prober *xp, struct xrt_system_devices **out_xsysd) 75 75 { 76 - struct u_system_devices *usysd = u_system_devices_allocate(); 77 - 78 76 assert(out_xsysd != NULL); 79 77 assert(*out_xsysd == NULL); 80 78 ··· 84 82 port = 4242; 85 83 } 86 84 87 - struct xrt_device *head = NULL, *left = NULL, *right = NULL; 88 - 89 - r_create_devices(port, &head, &left, &right); 90 - 91 - if (head == NULL) { 92 - u_system_devices_destroy(&usysd); 93 - xrt_device_destroy(&left); 94 - xrt_device_destroy(&right); 95 - return XRT_ERROR_ALLOCATION; 96 - } 97 - 98 - usysd->base.xdevs[usysd->base.xdev_count++] = head; 99 - if (left != NULL) { 100 - usysd->base.xdevs[usysd->base.xdev_count++] = left; 101 - } 102 - if (right != NULL) { 103 - usysd->base.xdevs[usysd->base.xdev_count++] = right; 104 - } 105 - 106 - usysd->base.roles.head = head; 107 - usysd->base.roles.left = left; 108 - usysd->base.roles.right = right; 109 - usysd->base.roles.hand_tracking.left = left; 110 - usysd->base.roles.hand_tracking.right = right; 111 - 112 - *out_xsysd = &usysd->base; 113 - 114 - return XRT_SUCCESS; 85 + return r_create_devices(port, out_xsysd); 115 86 } 116 87 117 88 static void