Changeset 9940ce0 in mainline for uspace/srv/hid/output/port/chardev.c


Ignore:
Timestamp:
2017-11-26T01:03:40Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5f4c41b2
Parents:
96258fc
Message:

Move sending side of Ski driver out of output server.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/output/port/chardev.c

    r96258fc r9940ce0  
    11/*
    22 * Copyright (c) 2016 Jakub Jermar
     3 * Copyright (c) 2017 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    5051static chardev_t *chardev;
    5152static service_id_t serial_cat_id;
     53static service_id_t console_cat_id;
    5254
    5355static FIBRIL_MUTEX_INITIALIZE(discovery_lock);
     
    6870        chardev_write(chardev, (void *) str, str_size(str), &nwr);
    6971        /* XXX Handle error */
     72}
     73
     74static bool find_output_dev(service_id_t *svcid)
     75{
     76        service_id_t *svc;
     77        size_t svcs;
     78        int rc;
     79
     80        rc = loc_category_get_svcs(serial_cat_id, &svc, &svcs);
     81        if (rc != EOK) {
     82                fibril_mutex_unlock(&discovery_lock);
     83                printf("%s: Failed to get services\n", NAME);
     84                return false;
     85        }
     86
     87        for (size_t i = 0; i < svcs; i++) {
     88                char *name;
     89
     90                rc = loc_service_get_name(svc[i], &name);
     91                if (rc != EOK)
     92                        continue;
     93
     94                if (!str_cmp(console, name)) {
     95                        /*
     96                         * This is the serial console service that the user
     97                         * wanted to use.
     98                         */
     99                        *svcid = svc[i];
     100                        free(svc);
     101                        return true;
     102                }
     103
     104                free(name);
     105        }
     106
     107        free(svc);
     108
     109        /* Look for any service in the 'console' category */
     110
     111        rc = loc_category_get_svcs(console_cat_id, &svc, &svcs);
     112        if (rc != EOK) {
     113                fibril_mutex_unlock(&discovery_lock);
     114                printf("%s: Failed to get services\n", NAME);
     115                return false;
     116        }
     117
     118        if (svcs > 0) {
     119                *svcid = svc[0];
     120                free(svc);
     121                return true;
     122        }
     123
     124        free(svc);
     125        return false;
    70126}
    71127
     
    79135{
    80136        int rc;
     137        bool found;
     138        service_id_t sid;
    81139
    82140        fibril_mutex_lock(&discovery_lock);
     
    87145        }
    88146
    89         service_id_t *svc;
    90         size_t svcs;
    91         rc = loc_category_get_svcs(serial_cat_id, &svc, &svcs);
    92         if (rc != EOK) {
    93                 fibril_mutex_unlock(&discovery_lock);
    94                 printf("%s: Failed to get services\n", NAME);
    95                 return;
    96         }
    97 
    98         service_id_t sid;
    99         bool found = false;
    100 
    101         for (size_t i = 0; i < svcs && !found; i++) {
    102                 char *name;
    103                
    104                 rc = loc_service_get_name(svc[i], &name);
    105                 if (rc != EOK)
    106                         continue;
    107 
    108                 if (!str_cmp(console, name)) {
    109                         /*
    110                          * This is the serial console service that the user
    111                          * wanted to use.
    112                          */
    113                         found = true;
    114                         sid = svc[i];
    115                 }
    116                        
    117                 free(name);
    118         }
    119 
    120         free(svc);
    121 
     147        found = find_output_dev(&sid);
    122148        if (!found) {
    123149                fibril_mutex_unlock(&discovery_lock);
     
    148174int chardev_init(void)
    149175{
    150         console = config_get_value("console");
    151         if (!console) {
    152                 /*
    153                  * The system is not configured to use serial console.
    154                  */
     176        if (!config_key_exists("console")) {
     177                console = NULL;
     178#ifndef MACHINE_ski
    155179                return EOK;
     180#endif
     181        } else {
     182                console = config_get_value("console");
     183                if (!console)
     184                        return EOK;
    156185        }
    157186
     
    162191        }
    163192
     193        rc = loc_category_get_id("console", &console_cat_id, IPC_FLAG_BLOCKING);
     194        if (rc != EOK) {
     195                printf("%s: Failed to get \"console\" category ID.\n", NAME);
     196                return rc;
     197        }
     198
    164199        rc = loc_register_cat_change_cb(check_for_dev);
    165200        if (rc != EOK) {
     
    168203                return rc;
    169204        }
     205
     206        check_for_dev();
    170207
    171208        fibril_mutex_lock(&discovery_lock);
Note: See TracChangeset for help on using the changeset viewer.