The open source OpenXR runtime
0
fork

Configure Feed

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

t/ctl: Tidy printing

+49 -52
+49 -52
src/xrt/targets/ctl/main.c
··· 14 14 #include <sys/un.h> 15 15 #include <ctype.h> 16 16 #include <unistd.h> 17 + #include <errno.h> 17 18 #include <sys/mman.h> 18 19 20 + #define P(...) fprintf(stdout, __VA_ARGS__) 21 + #define PE(...) fprintf(stderr, __VA_ARGS__) 19 22 20 23 typedef enum op_mode 21 24 { ··· 38 41 39 42 r = ipc_call_system_get_clients(ipc_c, &clients); 40 43 if (r != XRT_SUCCESS) { 41 - printf("failed to get client list.\n"); 44 + PE("Failed to get client list.\n"); 42 45 exit(1); 43 46 } 44 47 45 - printf("Clients:\n"); 48 + P("Clients:\n"); 46 49 for (uint32_t i = 0; i < IPC_MAX_CLIENTS; i++) { 47 50 if (clients.ids[i] < 0) { 48 51 continue; ··· 51 54 struct ipc_app_state cs; 52 55 r = ipc_call_system_get_client_info(ipc_c, i, &cs); 53 56 if (r != XRT_SUCCESS) { 54 - printf( 55 - "failed to get client info " 56 - "for client %d.\n", 57 - i); 57 + PE("Failed to get client info for client %d.\n", i); 58 58 return 1; 59 59 } 60 60 61 - printf( 62 - "\tid: %d" 63 - "\tact: %d" 64 - "\tdisp: %d" 65 - "\tfoc: %d" 66 - "\tio: %d" 67 - "\tovly: %d" 68 - "\tz: %d" 69 - "\tpid: %d" 70 - "\t%s\n", 71 - clients.ids[i], // 72 - cs.session_active, // 73 - cs.session_visible, // 74 - cs.session_focused, // 75 - cs.io_active, // 76 - cs.session_overlay, // 77 - cs.z_order, // 78 - cs.pid, // 79 - cs.info.application_name); 61 + P("\tid: %d" 62 + "\tact: %d" 63 + "\tdisp: %d" 64 + "\tfoc: %d" 65 + "\tio: %d" 66 + "\tovly: %d" 67 + "\tz: %d" 68 + "\tpid: %d" 69 + "\t%s\n", 70 + clients.ids[i], // 71 + cs.session_active, // 72 + cs.session_visible, // 73 + cs.session_focused, // 74 + cs.io_active, // 75 + cs.session_overlay, // 76 + cs.z_order, // 77 + cs.pid, // 78 + cs.info.application_name); 80 79 } 81 80 82 - printf("\nDevices:\n"); 81 + P("\nDevices:\n"); 83 82 for (uint32_t i = 0; i < ipc_c->ism->num_isdevs; i++) { 84 83 struct ipc_shared_device *isdev = &ipc_c->ism->isdevs[i]; 85 - printf( 86 - "\tid: %d" 87 - "\tname: %d" 88 - "\t\"%s\"\n", 89 - i, // 90 - isdev->name, // 91 - isdev->str); // 84 + P("\tid: %d" 85 + "\tname: %d" 86 + "\t\"%s\"\n", 87 + i, // 88 + isdev->name, // 89 + isdev->str); // 92 90 } 93 91 94 92 return 0; ··· 101 99 102 100 r = ipc_call_system_set_primary_client(ipc_c, client_id); 103 101 if (r != XRT_SUCCESS) { 104 - printf("failed to set active client to %d.\n", client_id); 102 + PE("Failed to set active client to %d.\n", client_id); 105 103 return 1; 106 104 } 107 105 ··· 115 113 116 114 r = ipc_call_system_set_focused_client(ipc_c, client_id); 117 115 if (r != XRT_SUCCESS) { 118 - printf("failed to set focused client to %d.\n", client_id); 116 + PE("Failed to set focused client to %d.\n", client_id); 119 117 return 1; 120 118 } 121 119 ··· 129 127 130 128 r = ipc_call_system_toggle_io_device(ipc_c, client_id); 131 129 if (r != XRT_SUCCESS) { 132 - printf("failed to set focused client to %d.\n", client_id); 130 + PE("Failed to set focused client to %d.\n", client_id); 133 131 return 1; 134 132 } 135 133 ··· 168 166 break; 169 167 case '?': 170 168 if (optopt == 's') { 171 - fprintf(stderr, 172 - "Option -s requires an id to set.\n"); 169 + PE("Option -s requires an id to set.\n"); 173 170 } else if (isprint(optopt)) { 174 - fprintf(stderr, "Option `-%c' unknown.\n", 175 - optopt); 171 + PE("Option `-%c' unknown.\n", optopt); 176 172 } else { 177 - fprintf(stderr, "Option `\\x%x' unknown.\n", 178 - optopt); 173 + PE("Option `\\x%x' unknown.\n", optopt); 179 174 } 180 175 exit(1); 181 176 default: exit(0); ··· 194 189 case MODE_SET_PRIMARY: exit(set_primary(&ipc_c, s_val)); break; 195 190 case MODE_SET_FOCUSED: exit(set_focused(&ipc_c, s_val)); break; 196 191 case MODE_TOGGLE_IO: exit(toggle_io(&ipc_c, s_val)); break; 197 - default: printf("Unrecognised operation mode.\n"); exit(1); 192 + default: P("Unrecognised operation mode.\n"); exit(1); 198 193 } 199 194 200 195 return 0; ··· 212 207 213 208 ipc_c->imc.socket_fd = socket(PF_UNIX, SOCK_STREAM, 0); 214 209 if (ipc_c->imc.socket_fd < 0) { 215 - IPC_ERROR(ipc_c, "Socket Create Error!\n"); 210 + ret = ipc_c->imc.socket_fd; 211 + PE("Socket create error '%i'!\n", ret); 216 212 return -1; 217 213 } 218 214 ··· 224 220 (struct sockaddr *)&addr, // address 225 221 sizeof(addr)); // size 226 222 if (ret < 0) { 227 - IPC_ERROR(ipc_c, "Socket Connect error!\n"); 223 + PE("Socket connect error '%i'!\n", ret); 228 224 return -1; 229 225 } 230 226 ··· 238 234 snprintf(cs.info.application_name, sizeof(cs.info.application_name), 239 235 "%s", "monado-ctl"); 240 236 241 - xrt_result_t r = ipc_call_system_set_client_info(ipc_c, &cs); 242 - if (r != XRT_SUCCESS) { 243 - IPC_ERROR(ipc_c, "failed to set client info.\n"); 237 + xrt_result_t xret = ipc_call_system_set_client_info(ipc_c, &cs); 238 + if (xret != XRT_SUCCESS) { 239 + PE("Failed to set client info '%i'!\n", xret); 244 240 return -1; 245 241 } 246 242 ··· 250 246 */ 251 247 252 248 // get our xdev shm from the server and mmap it 253 - r = ipc_call_instance_get_shm_fd(ipc_c, &ipc_c->ism_handle, 1); 254 - if (r != XRT_SUCCESS) { 255 - IPC_ERROR(ipc_c, "Failed to retrieve shm fd"); 249 + xret = ipc_call_instance_get_shm_fd(ipc_c, &ipc_c->ism_handle, 1); 250 + if (xret != XRT_SUCCESS) { 251 + PE("Failed to retrieve shm fd '%i'!\n", xret); 256 252 return -1; 257 253 } 258 254 ··· 262 258 263 259 ipc_c->ism = mmap(NULL, size, access, flags, ipc_c->ism_handle, 0); 264 260 if (ipc_c->ism == NULL) { 265 - IPC_ERROR(ipc_c, "Failed to mmap shm "); 261 + ret = errno; 262 + PE("Failed to mmap shm '%i'!\n", ret); 266 263 return -1; 267 264 } 268 265