Ignore:
Timestamp:
2019-05-18T06:42:01Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
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)
Message:

Implementing layout get

The command layout can now display the current active
keyboard layout. The service hid/input has been extended
for the IPC call INPUT_GET_LAYOUT

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/layout/layout.c

    rf9edc7b ra8171b86  
    3030#include <stdlib.h>
    3131#include <str.h>
     32#include <str_error.h>
    3233#include <dirent.h>
    3334#include <ipc/services.h>
     
    4647static const char *path_layouts = "/lib/layouts/";
    4748
    48 
    4949/* Dispays help for layout in various levels */
    5050void help_cmd_layout(unsigned int level)
     
    5454        if (level != HELP_SHORT) {
    5555                printf(
    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);
     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);
    6161        }
    6262
     
    102102}
    103103
     104/* displays active keyboard layout */
    104105static int cmd_layout_get(void)
    105106{
    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
     148error:
     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 */
    110158static int cmd_layout_set(char *layout)
    111159{
     
    129177        aid_t mid = async_send_0(exch, INPUT_CHANGE_LAYOUT, &call);
    130178        rc = async_data_write_start(exch, layout, str_size(layout));
    131        
    132         if (rc == EOK)
     179
     180        if (rc == EOK) {
    133181                async_wait_for(mid, &rc);
    134        
     182        }
     183
    135184        async_exchange_end(exch);
    136185        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        }
    137190
    138191        return rc == EOK ? CMD_SUCCESS : CMD_FAILURE;
     
    155208                } else if (str_cmp(argv[1], "set") == 0 && argc == 3) {
    156209                        return cmd_layout_set(argv[2]);
    157                 }       
     210                }
    158211        }
    159212
     
    161214        return CMD_FAILURE;
    162215}
    163 
Note: See TracChangeset for help on using the changeset viewer.