Changeset a76ba5f3 in mainline
- Timestamp:
- 2020-12-31T21:27:13Z (4 years ago)
- Children:
- 6a208fc
- Parents:
- 19f60a38
- git-author:
- Matthieu Riolo <matthieu.riolo@…> (2019-10-07 18:10:19)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2020-12-31 21:27:13)
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/layout/layout.c
r19f60a38 ra76ba5f3 40 40 #include <ipc/services.h> 41 41 #include <ipc/input.h> 42 #include <io/input.h> 42 43 #include <abi/ipc/interfaces.h> 43 44 #include <loc.h> … … 52 53 printf( 53 54 "Usage: %s\n" 54 "\t%s list \tlists all layouts\n"55 "\t%s get \tdisplays currently set layout\n"56 "\t%s set <layout> \tchanges to the new layout\n",55 "\t%s list lists all layouts\n" 56 "\t%s get displays currently set layout\n" 57 "\t%s set <layout> changes to the new layout\n", 57 58 cmdname, cmdname, cmdname, cmdname); 59 } 60 61 static async_sess_t *hid_exchange_start() 62 { 63 service_id_t svcid; 64 errno_t rc = loc_service_get_id(SERVICE_NAME_HID_INPUT, &svcid, 0); 65 if (rc != EOK) { 66 printf("%s: Failing to find service `%s` (%s)\n", 67 cmdname, 68 SERVICE_NAME_HID_INPUT, 69 str_error(rc)); 70 return NULL; 71 } 72 73 async_sess_t *sess = loc_service_connect(svcid, INTERFACE_ANY, 0); 74 if (sess == NULL) { 75 printf("%s: Failing to connect to service `%s`\n", 76 cmdname, 77 SERVICE_NAME_HID_INPUT); 78 } 79 80 return sess; 58 81 } 59 82 … … 75 98 static errno_t get_layout(void) 76 99 { 77 service_id_t svcid; 78 ipc_call_t call; 79 errno_t rc = loc_service_get_id(SERVICE_NAME_HID_INPUT, &svcid, 0); 80 if (rc != EOK) { 81 printf("%s: Failing to find service `%s`\n", cmdname, SERVICE_NAME_HID_INPUT); 82 return rc; 100 async_sess_t *sess = hid_exchange_start(); 101 if (sess == NULL) 102 return EREFUSED; 103 104 char *layout_name; 105 errno_t rc = input_layout_get(sess, &layout_name); 106 107 if (rc == EOK) { 108 printf("%s\n", layout_name); 109 free(layout_name); 110 } else { 111 printf("%s: Failing to retrive keyboard layout (%s)\n", 112 cmdname, 113 str_error(rc)); 83 114 } 84 115 85 async_sess_t *sess = loc_service_connect(svcid, INTERFACE_ANY, 0);86 if (sess == NULL) {87 printf("%s: Failing to connect to service `%s`\n", cmdname, SERVICE_NAME_HID_INPUT);88 return rc;89 }90 91 void *layout_name = NULL;92 async_exch_t *exch = async_exchange_begin(sess);93 aid_t mid = async_send_0(exch, INPUT_GET_LAYOUT, &call);94 async_wait_for(mid, &rc);95 96 if (rc != EOK) {97 goto error;98 }99 100 size_t length = ipc_get_arg1(&call);101 102 layout_name = malloc(length * sizeof(char *));103 if (layout_name == NULL) {104 printf("%s: Failing to allocate memory for keyboard layout\n", cmdname);105 rc = ENOMEM;106 goto error;107 }108 109 rc = async_data_read_start(exch, layout_name, length);110 111 if (rc == EOK) {112 printf("%s\n", (char *)layout_name);113 } else {114 printf("%s: Failing to get activated keyboard layout\n (%s)\n", cmdname, str_error(rc));115 goto error;116 }117 118 error:119 free(layout_name);120 async_exchange_end(exch);121 116 async_hangup(sess); 122 123 117 return rc; 124 125 118 } 126 119 127 120 /* changes the keyboard layout */ 128 static errno_t set_layout(char *layout )121 static errno_t set_layout(char *layout_name) 129 122 { 130 service_id_t svcid; 131 ipc_call_t call; 132 errno_t rc = loc_service_get_id(SERVICE_NAME_HID_INPUT, &svcid, 0); 133 if (rc != EOK) { 134 printf("%s: Failing to find service `%s`\n", cmdname, SERVICE_NAME_HID_INPUT); 135 return rc; 136 } 123 async_sess_t *sess = hid_exchange_start(); 124 if (sess == NULL) 125 return EREFUSED; 137 126 138 async_sess_t *sess = loc_service_connect(svcid, INTERFACE_ANY, 0); 139 if (sess == NULL) { 140 printf("%s: Failing to connect to service `%s`\n", cmdname, SERVICE_NAME_HID_INPUT); 141 return rc; 142 } 127 errno_t rc = input_layout_set(sess, layout_name); 143 128 144 async_exch_t *exch = async_exchange_begin(sess); 129 if (rc != EOK) 130 printf("%s: Cannot activate keyboard layout `%s`\n (%s)\n", 131 cmdname, 132 layout_name, 133 str_error(rc)); 145 134 146 aid_t mid = async_send_0(exch, INPUT_CHANGE_LAYOUT, &call);147 rc = async_data_write_start(exch, layout, str_size(layout));148 149 if (rc == EOK) {150 async_wait_for(mid, &rc);151 }152 153 async_exchange_end(exch);154 135 async_hangup(sess); 155 156 if (rc != EOK) {157 printf("%s: Cannot activate keyboard layout `%s`\n (%s)\n", cmdname, layout, str_error(rc));158 }159 160 136 return rc; 161 137 } … … 163 139 int main(int argc, char *argv[]) 164 140 { 165 if (argc == 2) { 141 errno_t rc = EINVAL; 142 if (argc == 1) { 143 rc = EOK; 144 } else if (argc == 2) { 166 145 if (str_cmp(argv[1], "list") == 0) { 167 146 return list_layout(); … … 176 155 177 156 print_help(); 178 return 1;157 return rc; 179 158 } -
uspace/lib/c/generic/io/input.c
r19f60a38 ra76ba5f3 42 42 #include <ipc/input.h> 43 43 #include <stdlib.h> 44 #include <str.h> 44 45 45 46 static void input_cb_conn(ipc_call_t *icall, void *arg); … … 202 203 } 203 204 205 /** 206 * Retrieves the active keyboard layout 207 * @param sess Active session to the input server 208 * @param layout The name of the currently active layout, 209 * needs to be freed by the caller 210 * @return EOK if sucessful or the corresponding error code. 211 * If a failure occurs the param layout is already freed 212 */ 213 errno_t input_layout_get(async_sess_t *sess, char **layout) 214 { 215 errno_t rc; 216 ipc_call_t call; 217 async_exch_t *exch = async_exchange_begin(sess); 218 aid_t mid = async_send_0(exch, INPUT_GET_LAYOUT, &call); 219 async_wait_for(mid, &rc); 220 221 if (rc != EOK) { 222 goto error; 223 } 224 225 size_t length = ipc_get_arg1(&call); 226 227 *layout = malloc(length * sizeof(char *)); 228 if (layout == NULL) { 229 rc = ENOMEM; 230 free(*layout); 231 goto error; 232 } 233 234 rc = async_data_read_start(exch, *layout, length); 235 236 if (rc != EOK) 237 free(*layout); 238 239 error: 240 async_exchange_end(exch); 241 return rc; 242 } 243 244 /** 245 * Changes the keyboard layout 246 * @param sess Active session to the input server 247 * @param layout The name of the layout which should be activated 248 * @return EOK if sucessful or the corresponding error code. 249 */ 250 errno_t input_layout_set(async_sess_t *sess, const char *layout) 251 { 252 errno_t rc; 253 ipc_call_t call; 254 async_exch_t *exch = async_exchange_begin(sess); 255 256 aid_t mid = async_send_0(exch, INPUT_CHANGE_LAYOUT, &call); 257 rc = async_data_write_start(exch, layout, str_size(layout)); 258 259 if (rc == EOK) 260 async_wait_for(mid, &rc); 261 262 async_exchange_end(exch); 263 return rc; 264 } 265 204 266 /** @} 205 267 */ -
uspace/lib/c/include/io/input.h
r19f60a38 ra76ba5f3 60 60 extern errno_t input_activate(input_t *); 61 61 62 extern errno_t input_layout_get(async_sess_t *sess, char **layout_name); 63 extern errno_t input_layout_set(async_sess_t *sess, const char *layout_name); 62 64 #endif 63 65
Note:
See TracChangeset
for help on using the changeset viewer.