Changeset 4c6fd56 in mainline for uspace/lib/c/generic/loc.c


Ignore:
Timestamp:
2023-09-16T19:58:18Z (16 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7d7f5e3
Parents:
6a0b2cc
git-author:
Jiri Svoboda <jiri@…> (2023-09-16 19:48:07)
git-committer:
Jiri Svoboda <jiri@…> (2023-09-16 19:58:18)
Message:

loc_server_register() should be callable more than once (API only)

Now loc_server_register() returns a pointer to a loc_srv_t object,
that is then passed to loc_service_register() and
loc_service_add_to_cat().

Added loc_server_unregister() that unregisters the server
and frees the loc_srv_t object.

Updated all callers. The implementation, however, is a stub.
It is not actually possible to call loc_server_register() more
than once, yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/loc.c

    r6a0b2cc r4c6fd56  
    11/*
     2 * Copyright (c) 2023 Jiri Svoboda
    23 * Copyright (c) 2007 Josef Cejka
    3  * Copyright (c) 2011 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    239239}
    240240
    241 /** Register new server with loc. */
    242 errno_t loc_server_register(const char *name)
    243 {
    244         async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
     241/** Register new server with loc.
     242 *
     243 * XXX Proper impementation - currently cannot actually call
     244 * this function more than once.
     245 *
     246 * @param name Server name
     247 * @param rsrv Place to store new server object on success
     248 * @return EOK on succes or an error code
     249 */
     250errno_t loc_server_register(const char *name, loc_srv_t **rsrv)
     251{
     252        async_exch_t *exch;
     253        loc_srv_t *srv;
     254
     255        srv = calloc(1, sizeof(loc_srv_t));
     256        if (srv == NULL)
     257                return ENOMEM;
     258
     259        exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
    245260
    246261        ipc_call_t answer;
     
    251266                async_forget(req);
    252267                loc_exchange_end(exch);
     268                free(srv);
    253269                return retval;
    254270        }
     
    264280        loc_exchange_end(exch);
    265281
     282        if (retval != EOK) {
     283                free(srv);
     284                return retval;
     285        }
     286
     287        *rsrv = srv;
    266288        return retval;
    267289}
    268290
     291/** Unregister server from loc.
     292 *
     293 * Unregister server and free server object.
     294 *
     295 * XXX Proper implementation
     296 *
     297 * @param srv Server object
     298 */
     299void loc_server_unregister(loc_srv_t *srv)
     300{
     301        free(srv);
     302}
     303
    269304/** Register new service.
    270305 *
    271  * @param      fqsn  Fully qualified service name
    272  * @param[out] sid   Service ID of new service
    273  *
    274  */
    275 errno_t loc_service_register(const char *fqsn, service_id_t *sid)
     306 * @param srv Server object
     307 * @param fqsn Fully qualified service name
     308 * @param sid  Service ID of new service
     309 *
     310 */
     311errno_t loc_service_register(loc_srv_t *srv, const char *fqsn,
     312    service_id_t *sid)
    276313{
    277314        async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
     315
     316        (void)srv;
    278317
    279318        ipc_call_t answer;
     
    310349/** Unregister service.
    311350 *
    312  * @param sid   Service ID
    313  */
    314 errno_t loc_service_unregister(service_id_t sid)
     351 * @param srv Server object
     352 * @param sid Service ID
     353 */
     354errno_t loc_service_unregister(loc_srv_t *srv, service_id_t sid)
    315355{
    316356        async_exch_t *exch;
    317357        errno_t retval;
     358
     359        (void)srv;
    318360
    319361        exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
     
    611653/** Add service to category.
    612654 *
    613  * @param svc_id        Service ID
    614  * @param cat_id        Category ID
    615  * @return              EOK on success or an error code
    616  */
    617 errno_t loc_service_add_to_cat(service_id_t svc_id, service_id_t cat_id)
     655 * @param srv    Server object
     656 * @param svc_id Service ID
     657 * @param cat_id Category ID
     658 *
     659 * @return EOK on success or an error code
     660 */
     661errno_t loc_service_add_to_cat(loc_srv_t *srv, service_id_t svc_id,
     662    service_id_t cat_id)
    618663{
    619664        async_exch_t *exch;
Note: See TracChangeset for help on using the changeset viewer.