The open source OpenXR runtime
0
fork

Configure Feed

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

xrt: Use error messages in various instance and prober functions

+103 -78
+7 -7
src/xrt/auxiliary/util/u_system_helpers.c
··· 56 56 xrt_result_t 57 57 u_system_devices_create_from_prober(struct xrt_instance *xinst, struct xrt_system_devices **out_xsysd) 58 58 { 59 - int ret = 0; 59 + xrt_result_t xret; 60 60 61 61 assert(out_xsysd != NULL); 62 62 assert(*out_xsysd == NULL); ··· 67 67 */ 68 68 69 69 struct xrt_prober *xp = NULL; 70 - ret = xrt_instance_get_prober(xinst, &xp); 71 - if (ret < 0) { 72 - return XRT_ERROR_ALLOCATION; 70 + xret = xrt_instance_get_prober(xinst, &xp); 71 + if (xret != XRT_SUCCESS) { 72 + return xret; 73 73 } 74 74 75 - ret = xrt_prober_probe(xp); 76 - if (ret < 0) { 77 - return XRT_ERROR_ALLOCATION; 75 + xret = xrt_prober_probe(xp); 76 + if (xret < 0) { 77 + return xret; 78 78 } 79 79 80 80 return xrt_prober_create_system(xp, out_xsysd);
+4 -5
src/xrt/include/xrt/xrt_instance.h
··· 103 103 * @param[out] out_xp Pointer to xrt_prober pointer, will be populated 104 104 * or set to NULL. 105 105 * 106 - * @return 0 on success, <0 on error. (Note that success may mean 107 - * returning a null pointer!) 106 + * @return XRT_SUCCESS on success, other error code on error. 108 107 */ 109 - int (*get_prober)(struct xrt_instance *xinst, struct xrt_prober **out_xp); 108 + xrt_result_t (*get_prober)(struct xrt_instance *xinst, struct xrt_prober **out_xp); 110 109 111 110 /*! 112 111 * Destroy the instance and its owned objects, including the prober (if ··· 145 144 * 146 145 * @public @memberof xrt_instance 147 146 */ 148 - static inline int 147 + static inline xrt_result_t 149 148 xrt_instance_get_prober(struct xrt_instance *xinst, struct xrt_prober **out_xp) 150 149 { 151 150 return xinst->get_prober(xinst, out_xp); ··· 195 194 * 196 195 * @relates xrt_instance 197 196 */ 198 - int 197 + xrt_result_t 199 198 xrt_instance_create(struct xrt_instance_info *ii, struct xrt_instance **out_xinst); 200 199 201 200 /*!
+2 -2
src/xrt/include/xrt/xrt_prober.h
··· 136 136 * @note Code consuming this interface should use xrt_prober_probe() 137 137 * @see xrt_prober::lock_list, xrt_prober::unlock_list 138 138 */ 139 - int (*probe)(struct xrt_prober *xp); 139 + xrt_result_t (*probe)(struct xrt_prober *xp); 140 140 141 141 /*! 142 142 * Locks the prober list of probed devices and returns it, while locked ··· 265 265 * 266 266 * @public @memberof xrt_prober 267 267 */ 268 - static inline int 268 + static inline xrt_result_t 269 269 xrt_prober_probe(struct xrt_prober *xp) 270 270 { 271 271 return xp->probe(xp);
+11 -11
src/xrt/ipc/client/ipc_client_instance.c
··· 291 291 * 292 292 * @public @memberof ipc_instance 293 293 */ 294 - int 294 + xrt_result_t 295 295 ipc_instance_create(struct xrt_instance_info *i_info, struct xrt_instance **out_xinst) 296 296 { 297 297 struct ipc_client_instance *ii = U_TYPED_CALLOC(struct ipc_client_instance); ··· 316 316 "#\n" 317 317 "###"); 318 318 free(ii); 319 - return -1; 319 + return XRT_ERROR_IPC_FAILURE; 320 320 } 321 321 322 322 // get our xdev shm from the server and mmap it 323 - xrt_result_t r = ipc_call_instance_get_shm_fd(&ii->ipc_c, &ii->ipc_c.ism_handle, 1); 324 - if (r != XRT_SUCCESS) { 323 + xrt_result_t xret = ipc_call_instance_get_shm_fd(&ii->ipc_c, &ii->ipc_c.ism_handle, 1); 324 + if (xret != XRT_SUCCESS) { 325 325 IPC_ERROR((&ii->ipc_c), "Failed to retrieve shm fd!"); 326 326 free(ii); 327 - return -1; 327 + return xret; 328 328 } 329 329 330 330 struct ipc_app_state desc = {0}; 331 331 desc.info = *i_info; 332 332 desc.pid = getpid(); // Extra info. 333 333 334 - r = ipc_call_system_set_client_info(&ii->ipc_c, &desc); 335 - if (r != XRT_SUCCESS) { 334 + xret = ipc_call_system_set_client_info(&ii->ipc_c, &desc); 335 + if (xret != XRT_SUCCESS) { 336 336 IPC_ERROR((&ii->ipc_c), "Failed to set instance info!"); 337 337 free(ii); 338 - return -1; 338 + return xret; 339 339 } 340 340 341 341 const int flags = MAP_SHARED; ··· 346 346 if (ii->ipc_c.ism == NULL) { 347 347 IPC_ERROR((&ii->ipc_c), "Failed to mmap shm!"); 348 348 free(ii); 349 - return -1; 349 + return XRT_ERROR_IPC_FAILURE; 350 350 } 351 351 352 352 if (strncmp(u_git_tag, ii->ipc_c.ism->u_git_tag, IPC_VERSION_NAME_LEN) != 0) { ··· 355 355 if (!debug_get_bool_option_ipc_ignore_version()) { 356 356 IPC_ERROR((&ii->ipc_c), "Set IPC_IGNORE_VERSION=1 to ignore this version conflict"); 357 357 free(ii); 358 - return -1; 358 + return XRT_ERROR_IPC_FAILURE; 359 359 } 360 360 } 361 361 ··· 400 400 401 401 os_mutex_init(&ii->ipc_c.mutex); 402 402 403 - return 0; 403 + return XRT_SUCCESS; 404 404 }
+10 -7
src/xrt/ipc/server/ipc_server_process.c
··· 449 449 static int 450 450 init_all(struct ipc_server *s) 451 451 { 452 + xrt_result_t xret; 453 + int ret; 454 + 452 455 s->process = u_process_create_if_not_running(); 453 456 454 457 if (!s->process) { ··· 462 465 s->exit_on_disconnect = debug_get_bool_option_exit_on_disconnect(); 463 466 s->log_level = debug_get_log_option_ipc_log(); 464 467 465 - int ret = xrt_instance_create(NULL, &s->xinst); 466 - if (ret < 0) { 468 + xret = xrt_instance_create(NULL, &s->xinst); 469 + if (xret != XRT_SUCCESS) { 467 470 IPC_ERROR(s, "Failed to create instance!"); 468 471 teardown_all(s); 469 - return ret; 472 + return -1; 470 473 } 471 474 472 - ret = xrt_instance_create_system(s->xinst, &s->xsysd, &s->xsysc); 473 - if (ret < 0) { 475 + xret = xrt_instance_create_system(s->xinst, &s->xsysd, &s->xsysc); 476 + if (xret != XRT_SUCCESS) { 474 477 IPC_ERROR(s, "Could not create system!"); 475 478 teardown_all(s); 476 - return ret; 479 + return -1; 477 480 } 478 481 479 482 ret = init_idevs(s); ··· 487 490 if (ret < 0) { 488 491 IPC_ERROR(s, "Failed to init tracking origins!"); 489 492 teardown_all(s); 490 - return -1; 493 + return ret; 491 494 } 492 495 493 496 ret = init_shm(s);
+10 -10
src/xrt/state_trackers/gui/gui_prober.c
··· 36 36 int 37 37 gui_prober_init(struct gui_program *p) 38 38 { 39 - int ret = 0; 39 + xrt_result_t xret; 40 40 41 41 // Initialize the prober. 42 - ret = xrt_instance_create(NULL, &p->instance); 43 - if (ret != 0) { 44 - return do_exit(p, ret); 42 + xret = xrt_instance_create(NULL, &p->instance); 43 + if (xret != 0) { 44 + return do_exit(p, -1); 45 45 } 46 46 47 47 // Still need the prober to get video devices. 48 - ret = xrt_instance_get_prober(p->instance, &p->xp); 49 - if (ret != 0) { 50 - return do_exit(p, ret); 48 + xret = xrt_instance_get_prober(p->instance, &p->xp); 49 + if (xret != XRT_SUCCESS) { 50 + return do_exit(p, -1); 51 51 } 52 52 53 53 if (p->xp != NULL) { 54 54 // Need to prime the prober with devices before dumping and listing. 55 - ret = xrt_prober_probe(p->xp); 56 - if (ret != 0) { 57 - return do_exit(p, ret); 55 + xret = xrt_prober_probe(p->xp); 56 + if (xret != XRT_SUCCESS) { 57 + return do_exit(p, -1); 58 58 } 59 59 } 60 60
+2 -2
src/xrt/state_trackers/oxr/oxr_instance.c
··· 251 251 android_looper_poll_until_activity_resumed(); 252 252 #endif 253 253 254 - xinst_ret = xrt_instance_create(&i_info, &inst->xinst); 255 - if (xinst_ret != 0) { 254 + xret = xrt_instance_create(&i_info, &inst->xinst); 255 + if (xret != XRT_SUCCESS) { 256 256 ret = oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Failed to create prober"); 257 257 oxr_instance_destroy(log, &inst->handle); 258 258 return ret;
+27 -9
src/xrt/state_trackers/prober/p_prober.c
··· 657 657 { 658 658 struct xrt_prober_device **dev_list = NULL; 659 659 size_t dev_count = 0; 660 + xrt_result_t xret; 660 661 661 - xrt_prober_lock_list(&p->base, &dev_list, &dev_count); 662 + xret = xrt_prober_lock_list(&p->base, &dev_list, &dev_count); 663 + if (xret != XRT_SUCCESS) { 664 + P_ERROR(p, "Failed to lock list!"); 665 + return; 666 + } 662 667 663 668 // Loop over all devices and entries that might match them. 664 669 for (size_t i = 0; i < p->device_count; i++) { ··· 702 707 } 703 708 } 704 709 705 - xrt_prober_unlock_list(&p->base, &dev_list); 710 + xret = xrt_prober_unlock_list(&p->base, &dev_list); 711 + if (xret != XRT_SUCCESS) { 712 + P_ERROR(p, "Failed to unlock list!"); 713 + } 706 714 } 707 715 708 716 static void ··· 850 858 * 851 859 */ 852 860 853 - static int 861 + static xrt_result_t 854 862 p_probe(struct xrt_prober *xp) 855 863 { 856 864 XRT_TRACE_MARKER(); 857 865 858 866 struct prober *p = (struct prober *)xp; 859 867 XRT_MAYBE_UNUSED int ret = 0; 868 + 869 + if (p->list_locked) { 870 + return XRT_ERROR_PROBER_LIST_LOCKED; 871 + } 860 872 861 873 // Free old list first. 862 874 teardown_devices(p); ··· 865 877 ret = p_udev_probe(p); 866 878 if (ret != 0) { 867 879 P_ERROR(p, "Failed to enumerate udev devices\n"); 868 - return -1; 880 + return XRT_ERROR_PROBING_FAILED; 869 881 } 870 882 #endif 871 883 ··· 873 885 ret = p_libusb_probe(p); 874 886 if (ret != 0) { 875 887 P_ERROR(p, "Failed to enumerate libusb devices\n"); 876 - return -1; 888 + return XRT_ERROR_PROBING_FAILED; 877 889 } 878 890 #endif 879 891 ··· 881 893 ret = p_libuvc_probe(p); 882 894 if (ret != 0) { 883 895 P_ERROR(p, "Failed to enumerate libuvc devices\n"); 884 - return -1; 896 + return XRT_ERROR_PROBING_FAILED; 885 897 } 886 898 #endif 887 899 888 - return 0; 900 + return XRT_SUCCESS; 889 901 } 890 902 891 903 static xrt_result_t ··· 893 905 { 894 906 struct prober *p = (struct prober *)xp; 895 907 896 - assert(!p->list_locked); 908 + if (p->list_locked) { 909 + return XRT_ERROR_PROBER_LIST_LOCKED; 910 + } 911 + 897 912 assert(out_devices != NULL); 898 913 assert(*out_devices == NULL); 899 914 ··· 916 931 { 917 932 struct prober *p = (struct prober *)xp; 918 933 919 - assert(p->list_locked); 934 + if (!p->list_locked) { 935 + return XRT_ERROR_PROBER_LIST_NOT_LOCKED; 936 + } 937 + 920 938 assert(devices != NULL); 921 939 922 940 p->list_locked = false;
+3 -4
src/xrt/state_trackers/steamvr_drv/ovrd_driver.cpp
··· 1149 1149 1150 1150 //! @todo instance initialization is difficult to replicate 1151 1151 1152 - int ret; 1153 - ret = xrt_instance_create(NULL, &m_xinst); 1154 - if (ret < 0) { 1152 + xrt_result_t xret; 1153 + xret = xrt_instance_create(NULL, &m_xinst); 1154 + if (xret != XRT_SUCCESS) { 1155 1155 ovrd_log("Failed to create instance\n"); 1156 1156 return vr::VRInitError_Init_HmdNotFound; 1157 1157 } 1158 1158 1159 - xrt_result_t xret; 1160 1159 xret = xrt_instance_create_system(m_xinst, &m_xsysd, NULL); 1161 1160 if (xret < 0) { 1162 1161 ovrd_log("Failed to create system devices\n");
+7 -6
src/xrt/targets/cli/cli_cmd_calibrate.c
··· 29 29 static int 30 30 init(struct program *p) 31 31 { 32 + xrt_result_t xret; 32 33 int ret; 33 34 34 35 // Fist initialize the instance. ··· 41 42 // Get the prober pointer. 42 43 // In general, null probers are OK, but this module directly uses the 43 44 // prober. 44 - ret = xrt_instance_get_prober(p->xi, &p->xp); 45 - if (ret != 0) { 45 + xret = xrt_instance_get_prober(p->xi, &p->xp); 46 + if (xret != XRT_SUCCESS) { 46 47 fprintf(stderr, "Failed to get prober from instance.\n"); 47 - return ret; 48 + return -1; 48 49 } 49 50 if (p->xp == NULL) { 50 51 fprintf(stderr, "Null prober returned - cannot proceed.\n"); ··· 52 53 } 53 54 54 55 // Need to prime the prober before listing devices. 55 - ret = xrt_prober_probe(p->xp); 56 - if (ret != 0) { 56 + xret = xrt_prober_probe(p->xp); 57 + if (xret != XRT_SUCCESS) { 57 58 fprintf(stderr, "Failed to probe for devices.\n"); 58 - return ret; 59 + return -1; 59 60 } 60 61 61 62 return 0;
+5 -1
src/xrt/targets/cli/cli_cmd_probe.c
··· 62 62 } 63 63 64 64 struct xrt_prober *xp = NULL; 65 - xrt_instance_get_prober(xi, &xp); 65 + xret = xrt_instance_get_prober(xi, &xp); 66 + if (xret != XRT_SUCCESS) { 67 + printf("\tNo xrt_prober could be created!\n"); 68 + return do_exit(&xi, -1); 69 + } 66 70 67 71 size_t num_entries; 68 72 struct xrt_prober_entry **entries;
+5 -5
src/xrt/targets/cli/cli_cmd_test.c
··· 43 43 } 44 44 struct xrt_prober *xp = NULL; 45 45 46 - ret = xrt_instance_get_prober(xi, &xp); 47 - if (ret != 0) { 46 + xret = xrt_instance_get_prober(xi, &xp); 47 + if (xret != XRT_SUCCESS) { 48 48 do_exit(&xi, ret); 49 49 } 50 50 if (xp != NULL) { ··· 55 55 // listing. 56 56 printf(" :: Probing!\n"); 57 57 58 - ret = xrt_prober_probe(xp); 59 - if (ret != 0) { 60 - return do_exit(&xi, ret); 58 + xret = xrt_prober_probe(xp); 59 + if (xret != XRT_SUCCESS) { 60 + return do_exit(&xi, -1); 61 61 } 62 62 63 63 // So the user can see what we found.
+5 -4
src/xrt/targets/common/target_builder_legacy.c
··· 141 141 legacy_open_system(struct xrt_builder *xb, cJSON *config, struct xrt_prober *xp, struct xrt_system_devices **out_xsysd) 142 142 { 143 143 struct u_system_devices *usysd = u_system_devices_allocate(); 144 - int ret = 0; 144 + xrt_result_t xret; 145 + int ret; 145 146 146 147 assert(out_xsysd != NULL); 147 148 assert(*out_xsysd == NULL); ··· 151 152 * Create the devices. 152 153 */ 153 154 154 - ret = xrt_prober_probe(xp); 155 - if (ret < 0) { 156 - return XRT_ERROR_ALLOCATION; 155 + xret = xrt_prober_probe(xp); 156 + if (xret != XRT_SUCCESS) { 157 + return xret; 157 158 } 158 159 159 160 ret = xrt_prober_select(xp, usysd->base.xdevs, ARRAY_SIZE(usysd->base.xdevs));
+3 -3
src/xrt/targets/common/target_instance.c
··· 68 68 * 69 69 */ 70 70 71 - int 71 + xrt_result_t 72 72 xrt_instance_create(struct xrt_instance_info *ii, struct xrt_instance **out_xinst) 73 73 { 74 74 struct xrt_prober *xp = NULL; ··· 77 77 78 78 int ret = xrt_prober_create_with_lists(&xp, &target_lists); 79 79 if (ret < 0) { 80 - return ret; 80 + return XRT_ERROR_PROBER_CREATION_FAILED; 81 81 } 82 82 83 83 struct t_instance *tinst = U_TYPED_CALLOC(struct t_instance); ··· 88 88 89 89 *out_xinst = &tinst->base; 90 90 91 - return 0; 91 + return XRT_SUCCESS; 92 92 }
+2 -2
src/xrt/targets/openxr/target.c
··· 19 19 #include "xrt/xrt_instance.h" 20 20 21 21 // Forward declaration 22 - int 22 + xrt_result_t 23 23 ipc_instance_create(struct xrt_instance_info *i_info, struct xrt_instance **out_xinst); 24 24 25 - int 25 + xrt_result_t 26 26 xrt_instance_create(struct xrt_instance_info *ii, struct xrt_instance **out_xinst) 27 27 { 28 28 u_trace_marker_init();