Changeset a8171b86 in mainline for uspace/app/bdsh/cmds/modules/layout/layout.c
- Timestamp:
- 2019-05-18T06:42:01Z (5 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.