Changeset cc574511 in mainline for uspace/srv/loc


Ignore:
Timestamp:
2011-08-16T12:37:58Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
16dc887
Parents:
86ffa27f
Message:

Basic category support in location service. Devman adds device services
to categories. Switch over input server device discovery from using
/dev/class to loc categories.

Location:
uspace/srv/loc
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/loc/Makefile

    r86ffa27f rcc574511  
    3333
    3434SOURCES = \
     35        category.c \
    3536        loc.c
    3637
  • uspace/srv/loc/loc.c

    r86ffa27f rcc574511  
    4949#include <assert.h>
    5050
     51#include "category.h"
     52#include "loc.h"
     53
    5154#define NAME          "loc"
    5255#define NULL_SERVICES  256
    53 
    54 /** Representation of server (supplier).
    55  *
    56  * Each server supplies a set of services.
    57  *
    58  */
    59 typedef struct {
    60         /** Link to servers_list */
    61         link_t servers;
    62        
    63         /** List of services supplied by this server */
    64         list_t services;
    65        
    66         /** Session asociated with this server */
    67         async_sess_t *sess;
    68        
    69         /** Server name */
    70         char *name;
    71        
    72         /** Fibril mutex for list of services owned by this server */
    73         fibril_mutex_t services_mutex;
    74 } loc_server_t;
    75 
    76 /** Info about registered namespaces
    77  *
    78  */
    79 typedef struct {
    80         /** Link to namespaces_list */
    81         link_t namespaces;
    82        
    83         /** Unique namespace identifier */
    84         service_id_t id;
    85        
    86         /** Namespace name */
    87         char *name;
    88        
    89         /** Reference count */
    90         size_t refcnt;
    91 } loc_namespace_t;
    92 
    93 /** Info about registered service
    94  *
    95  */
    96 typedef struct {
    97         /** Link to global list of services (services_list) */
    98         link_t services;
    99         /** Link to server list of services (loc_server_t.services) */
    100         link_t server_services;
    101         /** Unique service identifier */
    102         service_id_t id;
    103         /** Service namespace */
    104         loc_namespace_t *namespace;
    105         /** Service name */
    106         char *name;
    107         /** Supplier of this service */
    108         loc_server_t *server;
    109         /** Use this interface when forwarding to server. */
    110         sysarg_t forward_interface;
    111 } loc_service_t;
    11256
    11357LIST_INITIALIZE(services_list);
     
    13781static LIST_INITIALIZE(dummy_null_services);
    13882
    139 static service_id_t loc_create_id(void)
     83/** Service directory ogranized by categories (yellow pages) */
     84static categ_dir_t cdir;
     85
     86service_id_t loc_create_id(void)
    14087{
    14188        /* TODO: allow reusing old ids after their unregistration
     
    734681}
    735682
     683/** Find ID for category specified by name.
     684 *
     685 * On success, answer will contain EOK int retval and service ID in arg1.
     686 * On failure, error code will be sent in retval.
     687 *
     688 */
     689static void loc_category_get_id(ipc_callid_t iid, ipc_call_t *icall)
     690{
     691        char *name;
     692        category_t *cat;
     693       
     694        /* Get service name */
     695        int rc = async_data_write_accept((void **) &name, true, 0,
     696            LOC_NAME_MAXLEN, 0, NULL);
     697        if (rc != EOK) {
     698                async_answer_0(iid, rc);
     699                return;
     700        }
     701       
     702        fibril_mutex_lock(&cdir.mutex);
     703
     704        cat = category_find_by_name(&cdir, name);
     705        if (cat == NULL) {
     706                /* Category not found */
     707                async_answer_0(iid, ENOENT);
     708                goto cleanup;
     709        }
     710       
     711        async_answer_1(iid, EOK, cat->id);
     712cleanup:
     713        fibril_mutex_unlock(&cdir.mutex);
     714        free(name);
     715}
     716
    736717static void loc_id_probe(ipc_callid_t iid, ipc_call_t *icall)
    737718{
     
    892873}
    893874
     875static void loc_category_get_svcs(ipc_callid_t iid, ipc_call_t *icall)
     876{
     877        ipc_callid_t callid;
     878        size_t size;
     879        size_t act_size;
     880        int rc;
     881       
     882        if (!async_data_read_receive(&callid, &size)) {
     883                async_answer_0(callid, EREFUSED);
     884                async_answer_0(iid, EREFUSED);
     885                return;
     886        }
     887       
     888        fibril_mutex_lock(&cdir.mutex);
     889       
     890        category_t *cat = category_get(&cdir, IPC_GET_ARG1(*icall));
     891        if (cat == NULL) {
     892                fibril_mutex_unlock(&cdir.mutex);
     893                async_answer_0(callid, ENOENT);
     894                async_answer_0(iid, ENOENT);
     895                return;
     896        }
     897       
     898        category_id_t *id_buf = (category_id_t *) malloc(size);
     899        if (id_buf == NULL) {
     900                fibril_mutex_unlock(&cdir.mutex);
     901                async_answer_0(callid, ENOMEM);
     902                async_answer_0(iid, ENOMEM);
     903                return;
     904        }
     905       
     906        fibril_mutex_lock(&cat->mutex);
     907       
     908        rc = category_get_services(cat, id_buf, size, &act_size);
     909        if (rc != EOK) {
     910                fibril_mutex_unlock(&cat->mutex);
     911                fibril_mutex_unlock(&cdir.mutex);
     912                async_answer_0(callid, rc);
     913                async_answer_0(iid, rc);
     914                return;
     915        }
     916       
     917        fibril_mutex_unlock(&cat->mutex);
     918        fibril_mutex_unlock(&cdir.mutex);
     919       
     920        sysarg_t retval = async_data_read_finalize(callid, id_buf, size);
     921        free(id_buf);
     922       
     923        async_answer_1(iid, retval, act_size);
     924}
     925
     926
    894927static void loc_null_create(ipc_callid_t iid, ipc_call_t *icall)
    895928{
     
    9911024}
    9921025
     1026static void loc_service_add_to_cat(ipc_callid_t iid, ipc_call_t *icall)
     1027{
     1028        category_t *cat;
     1029        loc_service_t *svc;
     1030        catid_t cat_id;
     1031        service_id_t svc_id;
     1032        sysarg_t retval;
     1033       
     1034        svc_id = IPC_GET_ARG1(*icall);
     1035        cat_id = IPC_GET_ARG2(*icall);
     1036       
     1037        fibril_mutex_lock(&services_list_mutex);
     1038        fibril_mutex_lock(&cdir.mutex);
     1039       
     1040        cat = category_get(&cdir, cat_id);
     1041        svc = loc_service_find_id(svc_id);
     1042       
     1043        fibril_mutex_lock(&cat->mutex);
     1044        retval = category_add_service(cat, svc);
     1045
     1046        fibril_mutex_unlock(&cat->mutex);
     1047        fibril_mutex_unlock(&cdir.mutex);
     1048        fibril_mutex_unlock(&services_list_mutex);
     1049
     1050        async_answer_0(iid, retval);
     1051}
     1052
     1053
    9931054/** Initialize location service.
    9941055 *
     
    9971058static bool loc_init(void)
    9981059{
    999         fibril_mutex_lock(&null_services_mutex);
    1000        
    10011060        unsigned int i;
     1061        category_t *cat;
     1062
    10021063        for (i = 0; i < NULL_SERVICES; i++)
    10031064                null_services[i] = NULL;
    10041065       
    1005         fibril_mutex_unlock(&null_services_mutex);
    1006        
     1066        categ_dir_init(&cdir);
     1067
     1068        cat = category_new("bd");
     1069        categ_dir_add_cat(&cdir, cat);
     1070
     1071        cat = category_new("keyboard");
     1072        categ_dir_add_cat(&cdir, cat);
     1073
     1074        cat = category_new("mouse");
     1075        categ_dir_add_cat(&cdir, cat);
     1076
     1077        cat = category_new("serial");
     1078        categ_dir_add_cat(&cdir, cat);
     1079
    10071080        return true;
    10081081}
     
    10341107                                async_answer_0(callid, EOK);
    10351108                        break;
     1109                case LOC_SERVICE_ADD_TO_CAT:
     1110                        /* Add service to category */
     1111                        loc_service_add_to_cat(callid, &call);
     1112                        break;
    10361113                case LOC_SERVICE_REGISTER:
    10371114                        /* Register one service */
     
    10831160                case LOC_NAMESPACE_GET_ID:
    10841161                        loc_namespace_get_id(callid, &call);
     1162                        break;
     1163                case LOC_CATEGORY_GET_ID:
     1164                        loc_category_get_id(callid, &call);
     1165                        break;
     1166                case LOC_CATEGORY_GET_SVCS:
     1167                        loc_category_get_svcs(callid, &call);
    10851168                        break;
    10861169                case LOC_ID_PROBE:
Note: See TracChangeset for help on using the changeset viewer.