Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset d8b4082c in mainline


Ignore:
Timestamp:
2020-03-11T21:40:49Z (3 weeks ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
569642f
Parents:
3b37395
git-author:
Matthieu Riolo <matthieu.riolo@…> (2019-10-07 18:10:19)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2020-03-11 21:40:49)
Message:

Relocating IPC calls in the layout to io/input

The IPC calls for changing the layout was located in
the application layout. Now they have been relocated
into the library io/input. This commit also changes
the behaviour of layout when called without any
parameters (no error status is returned)

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/layout/layout.c

    r3b37395 rd8b4082c  
    4040#include <ipc/services.h>
    4141#include <ipc/input.h>
     42#include <io/input.h>
    4243#include <abi/ipc/interfaces.h>
    4344#include <loc.h>
     
    5253        printf(
    5354            "Usage: %s\n"
    54             "\t%s list\tlists all layouts\n"
    55             "\t%s get\t displays 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",
    5758            cmdname, cmdname, cmdname, cmdname);
     59}
     60
     61static 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;
    5881}
    5982
     
    7598static errno_t get_layout(void)
    7699{
    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));
    83114        }
    84115
    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);
    121116        async_hangup(sess);
    122 
    123117        return rc;
    124 
    125118}
    126119
    127120/* changes the keyboard layout */
    128 static errno_t set_layout(char *layout)
     121static errno_t set_layout(char *layout_name)
    129122{
    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;
    137126
    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);
    143128
    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));
    145134
    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);
    154135        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 
    160136        return rc;
    161137}
     
    163139int main(int argc, char *argv[])
    164140{
    165         if (argc == 2) {
     141        errno_t rc = EINVAL;
     142        if (argc == 1) {
     143                rc = EOK;
     144        } else if (argc == 2) {
    166145                if (str_cmp(argv[1], "list") == 0) {
    167146                        return list_layout();
     
    176155
    177156        print_help();
    178         return 1;
     157        return rc;
    179158}
  • uspace/lib/c/generic/io/input.c

    r3b37395 rd8b4082c  
    4242#include <ipc/input.h>
    4343#include <stdlib.h>
     44#include <str.h>
    4445
    4546static void input_cb_conn(ipc_call_t *icall, void *arg);
     
    202203}
    203204
     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 */
     213errno_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
     239error:
     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 */
     250errno_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
    204266/** @}
    205267 */
  • uspace/lib/c/include/io/input.h

    r3b37395 rd8b4082c  
    6060extern errno_t input_activate(input_t *);
    6161
     62extern errno_t input_layout_get(async_sess_t *sess, char **layout_name);
     63extern errno_t input_layout_set(async_sess_t *sess, const char *layout_name);
    6264#endif
    6365
Note: See TracChangeset for help on using the changeset viewer.