Changeset a8171b86 in mainline
- Timestamp:
- 2019-05-18T06:42:01Z (6 years ago)
- Parents:
- f9edc7b
- git-author:
- Matthieu Riolo <matthieu.riolo@…> (2019-05-16 09:48:08)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-05-18 06:42:01)
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/layout/entry.h
rf9edc7b ra8171b86 7 7 8 8 #endif /* LAYOUT_ENTRY_H */ 9 -
uspace/app/bdsh/cmds/modules/layout/layout.c
rf9edc7b ra8171b86 30 30 #include <stdlib.h> 31 31 #include <str.h> 32 #include <str_error.h> 32 33 #include <dirent.h> 33 34 #include <ipc/services.h> … … 46 47 static const char *path_layouts = "/lib/layouts/"; 47 48 48 49 49 /* Dispays help for layout in various levels */ 50 50 void help_cmd_layout(unsigned int level) … … 54 54 if (level != HELP_SHORT) { 55 55 printf( 56 57 58 59 60 56 "Usage: %s\n" 57 "\t%s list\tlists all layouts\n" 58 "\t%s get\t displays currently set layout\n" 59 "\t%s set <layout>\tchanges to the new layout\n", 60 cmdname, cmdname, cmdname, cmdname); 61 61 } 62 62 … … 102 102 } 103 103 104 /* displays active keyboard layout */ 104 105 static int cmd_layout_get(void) 105 106 { 106 return CMD_FAILURE; 107 } 108 109 107 service_id_t svcid; 108 ipc_call_t call; 109 errno_t rc = loc_service_get_id(SERVICE_NAME_HID_INPUT, &svcid, 0); 110 if (rc != EOK) { 111 cli_error(CL_ENOENT, "%s: Failing to find service `%s`\n", cmdname, SERVICE_NAME_HID_INPUT); 112 return CMD_FAILURE; 113 } 114 115 async_sess_t *sess = loc_service_connect(svcid, INTERFACE_ANY, 0); 116 if (sess == NULL) { 117 cli_error(CL_ENOENT, "%s: Failing to connect to service `%s`\n", cmdname, SERVICE_NAME_HID_INPUT); 118 return CMD_FAILURE; 119 } 120 121 void *layout_name = NULL; 122 async_exch_t *exch = async_exchange_begin(sess); 123 aid_t mid = async_send_0(exch, INPUT_GET_LAYOUT, &call); 124 async_wait_for(mid, &rc); 125 126 if (rc != EOK) { 127 goto error; 128 } 129 130 size_t length = ipc_get_arg1(&call); 131 132 layout_name = malloc(length * sizeof(char *)); 133 if (layout_name == NULL) { 134 cli_error(CL_ENOMEM, "%s: Failing to allocate memory for keyboard layout\n", cmdname); 135 rc = ENOMEM; 136 goto error; 137 } 138 139 rc = async_data_read_start(exch, layout_name, length); 140 141 if (rc == EOK) { 142 printf("%s\n", (char *)layout_name); 143 } else { 144 printf("%s: Failing to get activated keyboard layout\n (%s)\n", cmdname, str_error(rc)); 145 goto error; 146 } 147 148 error: 149 free(layout_name); 150 async_exchange_end(exch); 151 async_hangup(sess); 152 153 return rc == EOK ? CMD_SUCCESS : CMD_FAILURE; 154 155 } 156 157 /* changes the keyboard layout */ 110 158 static int cmd_layout_set(char *layout) 111 159 { … … 129 177 aid_t mid = async_send_0(exch, INPUT_CHANGE_LAYOUT, &call); 130 178 rc = async_data_write_start(exch, layout, str_size(layout)); 131 132 if (rc == EOK) 179 180 if (rc == EOK) { 133 181 async_wait_for(mid, &rc); 134 182 } 183 135 184 async_exchange_end(exch); 136 185 async_hangup(sess); 186 187 if (rc != EOK) { 188 printf("%s: Cannot activate keyboard layout `%s`\n (%s)\n", cmdname, layout, str_error(rc)); 189 } 137 190 138 191 return rc == EOK ? CMD_SUCCESS : CMD_FAILURE; … … 155 208 } else if (str_cmp(argv[1], "set") == 0 && argc == 3) { 156 209 return cmd_layout_set(argv[2]); 157 } 210 } 158 211 } 159 212 … … 161 214 return CMD_FAILURE; 162 215 } 163 -
uspace/app/bdsh/cmds/modules/layout/layout.h
rf9edc7b ra8171b86 4 4 /* Prototypes for the layout command, excluding entry points */ 5 5 6 7 6 #endif /* LAYOUT_H */ 8 -
uspace/lib/c/include/ipc/input.h
rf9edc7b ra8171b86 40 40 typedef enum { 41 41 INPUT_ACTIVATE = IPC_FIRST_USER_METHOD, 42 INPUT_CHANGE_LAYOUT 42 INPUT_CHANGE_LAYOUT, 43 INPUT_GET_LAYOUT 43 44 } input_request_t; 44 45 -
uspace/srv/hid/input/input.c
rf9edc7b ra8171b86 120 120 length += str_size(layout_name); 121 121 char *path = malloc(sizeof(char) * (length + 1)); 122 122 123 123 if (path == NULL) { 124 124 printf("%s: Error allocating layout path. Out of memory.\n", NAME); … … 130 130 str_append(path, length, layout_name); 131 131 str_append(path, length, suffix); 132 printf("%s\n", path);133 132 134 133 void *handle = dlopen(path, 0); … … 340 339 } 341 340 341 /* Handler for IPC call INPUT_CHANGE_LAYOUT */ 342 static void client_change_layout_handler(ipc_call_t *call) 343 { 344 void *layout_name; 345 errno_t ret = async_data_write_accept(&layout_name, true, 0, 0, 0, 0); 346 if (ret != EOK) { 347 async_answer_0(call, ret); 348 return; 349 } 350 351 errno_t retval = layout_load((char *)layout_name); 352 free(layout_name); 353 async_answer_0(call, retval); 354 } 355 356 /* Handler for IPC call INPUT_GET_LAYOUT */ 357 static void client_get_layout_handler(ipc_call_t *call) 358 { 359 const char *layout_name = layout_active.get_name(); 360 size_t length = str_size(layout_name) + 1; 361 ipc_call_t id; 362 363 async_answer_1(call, EOK, length); 364 if (async_data_read_receive(&id, NULL)) { 365 async_data_read_finalize(&id, layout_name, length); 366 } 367 } 368 342 369 /** New client connection */ 343 370 static void client_connection(ipc_call_t *icall, void *arg) … … 380 407 async_answer_0(&call, EOK); 381 408 break; 382 case INPUT_CHANGE_LAYOUT: { 383 void * layout_name; 384 errno_t ret = async_data_write_accept(&layout_name, true, 0, 0, 0, 0); 385 if (ret != EOK) { 386 async_answer_0(&call, ret); 387 break; 388 } 389 390 errno_t retval = layout_load((char *)layout_name); 391 free(layout_name); 392 async_answer_0(&call, retval); 409 case INPUT_CHANGE_LAYOUT: 410 client_change_layout_handler(&call); 393 411 break; 394 } 412 case INPUT_GET_LAYOUT: 413 client_get_layout_handler(&call); 414 break; 395 415 default: 396 416 async_answer_0(&call, EINVAL); -
uspace/srv/hid/input/layout/us_qwerty.c
rf9edc7b ra8171b86 68 68 #endif 69 69 70 71 70 static const char *us_qwerty_name(void) 72 71 {
Note:
See TracChangeset
for help on using the changeset viewer.