Changeset d0dd7b5 in mainline for uspace/srv/loc


Ignore:
Timestamp:
2011-08-18T20:10:47Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ef7052ec
Parents:
763e0cd
Message:

Work on device removal:

  • properly track service memberships in categories
  • implement loc_service_unregister()
  • ddf_fun_unbind() (limited to exposed functions for now)
Location:
uspace/srv/loc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/loc/category.c

    r763e0cd rd0dd7b5  
    9393        cat->id = loc_create_id();
    9494        link_initialize(&cat->cat_list);
    95         list_initialize(&cat->services);
     95        list_initialize(&cat->svc_memb);
    9696}
    9797
     
    113113{
    114114        assert(fibril_mutex_is_locked(&cat->mutex));
     115        assert(fibril_mutex_is_locked(&services_list_mutex));
    115116
    116117        /* Verify that category does not contain this service yet. */
    117         list_foreach(cat->services, item) {
    118 
    119                 loc_service_t *csvc = list_get_instance(item, loc_service_t,
    120                     cat_services);
    121                 if (csvc == svc) {
     118        list_foreach(cat->svc_memb, item) {
     119                svc_categ_t *memb = list_get_instance(item, svc_categ_t,
     120                    cat_link);
     121                if (memb->svc == svc) {
    122122                        return EEXIST;
    123123                }
    124124        }
    125125
    126         list_append(&svc->cat_services, &cat->services);
     126        svc_categ_t *nmemb = malloc(sizeof(svc_categ_t));
     127        if (nmemb == NULL)
     128                return ENOMEM;
     129
     130        nmemb->svc = svc;
     131        nmemb->cat = cat;
     132
     133        list_append(&nmemb->cat_link, &cat->svc_memb);
     134        list_append(&nmemb->svc_link, &svc->cat_memb);
     135
    127136        return EOK;
     137}
     138
     139/** Remove service from category. */
     140void category_remove_service(svc_categ_t *memb)
     141{
     142        assert(fibril_mutex_is_locked(&memb->cat->mutex));
     143        assert(fibril_mutex_is_locked(&services_list_mutex));
     144
     145        list_remove(&memb->cat_link);
     146        list_remove(&memb->svc_link);
     147
     148        free(memb);
    128149}
    129150
     
    169190        buf_cnt = buf_size / sizeof(service_id_t);
    170191
    171         act_cnt = list_count(&cat->services);
     192        act_cnt = list_count(&cat->svc_memb);
    172193        *act_size = act_cnt * sizeof(service_id_t);
    173194
     
    176197
    177198        size_t pos = 0;
    178         list_foreach(cat->services, item) {
    179                 loc_service_t *svc =
    180                     list_get_instance(item, loc_service_t, cat_services);
     199        list_foreach(cat->svc_memb, item) {
     200                svc_categ_t *memb =
     201                    list_get_instance(item, svc_categ_t, cat_link);
    181202
    182203                if (pos < buf_cnt)
    183                         id_buf[pos] = svc->id;
     204                        id_buf[pos] = memb->svc->id;
    184205                pos++;
    185206        }
  • uspace/srv/loc/category.h

    r763e0cd rd0dd7b5  
    5555        link_t cat_list;
    5656
    57         /** List of services in this category (loc_service_t) */
    58         list_t services;
     57        /** List of service memberships in this category (svc_categ_t) */
     58        list_t svc_memb;
    5959} category_t;
    6060
     
    6767} categ_dir_t;
    6868
     69/** Service in category membership. */
     70typedef struct {
     71        /** Link to category_t.svc_memb list */
     72        link_t cat_link;
     73        /** Link to loc_service_t.cat_memb list */
     74        link_t svc_link;
     75       
     76        /** Category */
     77        category_t *cat;
     78        /** Service */
     79        loc_service_t *svc;
     80} svc_categ_t;
     81
    6982extern void categ_dir_init(categ_dir_t *);
    7083extern void categ_dir_add_cat(categ_dir_t *, category_t *);
     
    7386extern category_t *category_new(const char *);
    7487extern int category_add_service(category_t *, loc_service_t *);
     88extern void category_remove_service(svc_categ_t *);
    7589extern category_t *category_get(categ_dir_t *, catid_t);
    7690extern category_t *category_find_by_name(categ_dir_t *, const char *);
  • uspace/srv/loc/loc.c

    r763e0cd rd0dd7b5  
    6767 **/
    6868
    69 static FIBRIL_MUTEX_INITIALIZE(services_list_mutex);
     69FIBRIL_MUTEX_INITIALIZE(services_list_mutex);
    7070static FIBRIL_CONDVAR_INITIALIZE(services_list_cv);
    7171static FIBRIL_MUTEX_INITIALIZE(servers_list_mutex);
     
    311311{
    312312        assert(fibril_mutex_is_locked(&services_list_mutex));
    313 
     313        assert(fibril_mutex_is_locked(&cdir.mutex));
     314       
    314315        loc_namespace_delref(service->namespace);
    315316        list_remove(&(service->services));
    316317        list_remove(&(service->server_services));
     318       
     319        /* Remove service from all categories. */
     320        while (!list_empty(&service->cat_memb)) {
     321                link_t *link = list_first(&service->cat_memb);
     322                svc_categ_t *memb = list_get_instance(link, svc_categ_t,
     323                    svc_link);
     324                fibril_mutex_lock(&memb->cat->mutex);
     325                category_remove_service(memb);
     326                fibril_mutex_unlock(&memb->cat->mutex);
     327        }
    317328       
    318329        free(service->name);
     
    415426        fibril_mutex_lock(&services_list_mutex);
    416427        fibril_mutex_lock(&server->services_mutex);
     428        fibril_mutex_lock(&cdir.mutex);
    417429       
    418430        while (!list_empty(&server->services)) {
     
    423435        }
    424436       
     437        fibril_mutex_unlock(&cdir.mutex);
    425438        fibril_mutex_unlock(&server->services_mutex);
    426439        fibril_mutex_unlock(&services_list_mutex);
     
    492505        link_initialize(&service->services);
    493506        link_initialize(&service->server_services);
     507        list_initialize(&service->cat_memb);
    494508       
    495509        /* Check that service is not already registered */
     
    529543 *
    530544 */
    531 static int loc_service_unregister(ipc_callid_t iid, ipc_call_t *icall,
     545static void loc_service_unregister(ipc_callid_t iid, ipc_call_t *icall,
    532546    loc_server_t *server)
    533547{
    534         /* TODO */
    535         return EOK;
     548        loc_service_t *svc;
     549       
     550        fibril_mutex_lock(&services_list_mutex);
     551        svc = loc_service_find_id(IPC_GET_ARG1(*icall));
     552        if (svc == NULL) {
     553                fibril_mutex_unlock(&services_list_mutex);
     554                async_answer_0(iid, ENOENT);
     555                return;
     556        }
     557       
     558        fibril_mutex_lock(&cdir.mutex);
     559        loc_service_unregister_core(svc);
     560        fibril_mutex_unlock(&cdir.mutex);
     561        fibril_mutex_unlock(&services_list_mutex);
     562        async_answer_0(iid, EOK);
    536563}
    537564
     
    11761203       
    11771204        fibril_mutex_lock(&services_list_mutex);
     1205        fibril_mutex_lock(&cdir.mutex);
    11781206        loc_service_unregister_core(null_services[i]);
     1207        fibril_mutex_unlock(&cdir.mutex);
    11791208        fibril_mutex_unlock(&services_list_mutex);
    11801209       
     
    12421271
    12431272        cat = category_new("usbhc");
     1273        categ_dir_add_cat(&cdir, cat);
     1274
     1275        cat = category_new("virtual");
    12441276        categ_dir_add_cat(&cdir, cat);
    12451277
  • uspace/srv/loc/loc.h

    r763e0cd rd0dd7b5  
    8989        /** Link to list of services in category (category_t.services) */
    9090        link_t cat_services;
     91        /** List of category memberships (svc_categ_t) */
     92        list_t cat_memb;
    9193        /** Unique service identifier */
    9294        service_id_t id;
     
    101103} loc_service_t;
    102104
     105extern fibril_mutex_t services_list_mutex;
     106
    103107extern service_id_t loc_create_id(void);
    104108extern void loc_category_change_event(void);
Note: See TracChangeset for help on using the changeset viewer.