Skip to content

Commit

Permalink
loc_server_register() should be callable more than once (API only)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jiri Svoboda committed Sep 16, 2023
1 parent 6a0b2cc commit 4c6fd56
Show file tree
Hide file tree
Showing 46 changed files with 823 additions and 396 deletions.
9 changes: 7 additions & 2 deletions uspace/app/display-cfg/test/seats.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ PCUT_TEST(seats_list_populate)
errno_t rc;
service_id_t sid;
test_response_t resp;
loc_srv_t *srv;

async_set_fallback_port_handler(test_dispcfg_conn, &resp);

// FIXME This causes this test to be non-reentrant!
rc = loc_server_register(test_dispcfg_server);
rc = loc_server_register(test_dispcfg_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);

rc = loc_service_register(test_dispcfg_svc, &sid);
rc = loc_service_register(srv, test_dispcfg_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);

rc = display_cfg_create(UI_DISPLAY_NULL, &dcfg);
Expand Down Expand Up @@ -134,6 +135,10 @@ PCUT_TEST(seats_list_populate)

dcfg_seats_destroy(seats);
display_cfg_destroy(dcfg);

rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}

/** dcfg_devices_insert() inserts an entry into the device list */
Expand Down
8 changes: 5 additions & 3 deletions uspace/app/taskbar/test/wndlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,17 @@ PCUT_TEST(open_wm)
ui_window_t *window = NULL;
ui_fixed_t *fixed = NULL;
wndlist_t *wndlist;
loc_srv_t *srv;

/* Set up a test WM service */

async_set_fallback_port_handler(test_wndmgt_conn, NULL);

// FIXME This causes this test to be non-reentrant!
rc = loc_server_register(test_wndmgt_server);
rc = loc_server_register(test_wndmgt_server, &srv);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);

rc = loc_service_register(test_wndmgt_svc, &sid);
rc = loc_service_register(srv, test_wndmgt_svc, &sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);

/* Create window list and connect it to our test service */
Expand Down Expand Up @@ -176,8 +177,9 @@ PCUT_TEST(open_wm)
ui_window_destroy(window);
ui_destroy(ui);

rc = loc_service_unregister(sid);
rc = loc_service_unregister(srv, sid);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
loc_server_unregister(srv);
}

/** Test appending new entry */
Expand Down
8 changes: 6 additions & 2 deletions uspace/app/terminal/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ errno_t terminal_create(const char *display_spec, sysarg_t width,
term->srvs.ops = &con_ops;
term->srvs.sarg = term;

rc = loc_server_register(NAME);
rc = loc_server_register(NAME, &term->srv);
if (rc != EOK) {
printf("Error registering server.\n");
rc = EIO;
Expand All @@ -1032,7 +1032,7 @@ errno_t terminal_create(const char *display_spec, sysarg_t width,
snprintf(vc, LOC_NAME_MAXLEN, "%s/%" PRIu64, NAMESPACE,
task_get_id());

rc = loc_service_register(vc, &term->dsid);
rc = loc_service_register(term->srv, vc, &term->dsid);
if (rc != EOK) {
printf("Error registering service.\n");
rc = EIO;
Expand Down Expand Up @@ -1062,6 +1062,10 @@ errno_t terminal_create(const char *display_spec, sysarg_t width,
*rterm = term;
return EOK;
error:
if (term->dsid != 0)
loc_service_unregister(term->srv, term->dsid);
if (term->srv != NULL)
loc_server_unregister(term->srv);
if (term->window != NULL)
ui_window_destroy(term->window);
if (term->ui != NULL)
Expand Down
3 changes: 2 additions & 1 deletion uspace/app/terminal/terminal.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Jiri Svoboda
* Copyright (c) 2023 Jiri Svoboda
* Copyright (c) 2012 Petr Koupy
* All rights reserved.
*
Expand Down Expand Up @@ -90,6 +90,7 @@ typedef struct {
sysarg_t urows;
charfield_t *ubuf;

loc_srv_t *srv;
service_id_t dsid;
con_srvs_t srvs;

Expand Down
71 changes: 58 additions & 13 deletions uspace/lib/c/generic/loc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2023 Jiri Svoboda
* Copyright (c) 2007 Josef Cejka
* Copyright (c) 2011 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -238,10 +238,25 @@ void loc_exchange_end(async_exch_t *exch)
async_exchange_end(exch);
}

/** Register new server with loc. */
errno_t loc_server_register(const char *name)
/** Register new server with loc.
*
* XXX Proper impementation - currently cannot actually call
* this function more than once.
*
* @param name Server name
* @param rsrv Place to store new server object on success
* @return EOK on succes or an error code
*/
errno_t loc_server_register(const char *name, loc_srv_t **rsrv)
{
async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
async_exch_t *exch;
loc_srv_t *srv;

srv = calloc(1, sizeof(loc_srv_t));
if (srv == NULL)
return ENOMEM;

exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);

ipc_call_t answer;
aid_t req = async_send_2(exch, LOC_SERVER_REGISTER, 0, 0, &answer);
Expand All @@ -250,6 +265,7 @@ errno_t loc_server_register(const char *name)
if (retval != EOK) {
async_forget(req);
loc_exchange_end(exch);
free(srv);
return retval;
}

Expand All @@ -263,19 +279,42 @@ errno_t loc_server_register(const char *name)
async_wait_for(req, &retval);
loc_exchange_end(exch);

if (retval != EOK) {
free(srv);
return retval;
}

*rsrv = srv;
return retval;
}

/** Unregister server from loc.
*
* Unregister server and free server object.
*
* XXX Proper implementation
*
* @param srv Server object
*/
void loc_server_unregister(loc_srv_t *srv)
{
free(srv);
}

/** Register new service.
*
* @param fqsn Fully qualified service name
* @param[out] sid Service ID of new service
* @param srv Server object
* @param fqsn Fully qualified service name
* @param sid Service ID of new service
*
*/
errno_t loc_service_register(const char *fqsn, service_id_t *sid)
errno_t loc_service_register(loc_srv_t *srv, const char *fqsn,
service_id_t *sid)
{
async_exch_t *exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);

(void)srv;

ipc_call_t answer;
aid_t req = async_send_0(exch, LOC_SERVICE_REGISTER, &answer);
errno_t retval = async_data_write_start(exch, fqsn, str_size(fqsn));
Expand Down Expand Up @@ -309,13 +348,16 @@ errno_t loc_service_register(const char *fqsn, service_id_t *sid)

/** Unregister service.
*
* @param sid Service ID
* @param srv Server object
* @param sid Service ID
*/
errno_t loc_service_unregister(service_id_t sid)
errno_t loc_service_unregister(loc_srv_t *srv, service_id_t sid)
{
async_exch_t *exch;
errno_t retval;

(void)srv;

exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
retval = async_req_1_0(exch, LOC_SERVICE_UNREGISTER, sid);
loc_exchange_end(exch);
Expand Down Expand Up @@ -610,11 +652,14 @@ static size_t loc_count_namespaces_internal(async_exch_t *exch)

/** Add service to category.
*
* @param svc_id Service ID
* @param cat_id Category ID
* @return EOK on success or an error code
* @param srv Server object
* @param svc_id Service ID
* @param cat_id Category ID
*
* @return EOK on success or an error code
*/
errno_t loc_service_add_to_cat(service_id_t svc_id, service_id_t cat_id)
errno_t loc_service_add_to_cat(loc_srv_t *srv, service_id_t svc_id,
service_id_t cat_id)
{
async_exch_t *exch;
errno_t retval;
Expand Down
12 changes: 7 additions & 5 deletions uspace/lib/c/include/loc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009 Jiri Svoboda
* Copyright (c) 2023 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -38,17 +38,19 @@
#include <ipc/loc.h>
#include <async.h>
#include <stdbool.h>
#include <types/loc.h>

typedef void (*loc_cat_change_cb_t)(void *);

extern async_exch_t *loc_exchange_begin_blocking(iface_t);
extern async_exch_t *loc_exchange_begin(iface_t);
extern void loc_exchange_end(async_exch_t *);

extern errno_t loc_server_register(const char *);
extern errno_t loc_service_register(const char *, service_id_t *);
extern errno_t loc_service_unregister(service_id_t);
extern errno_t loc_service_add_to_cat(service_id_t, category_id_t);
extern errno_t loc_server_register(const char *, loc_srv_t **);
extern void loc_server_unregister(loc_srv_t *);
extern errno_t loc_service_register(loc_srv_t *, const char *, service_id_t *);
extern errno_t loc_service_unregister(loc_srv_t *, service_id_t);
extern errno_t loc_service_add_to_cat(loc_srv_t *, service_id_t, category_id_t);

extern errno_t loc_service_get_id(const char *, service_id_t *,
unsigned int);
Expand Down
46 changes: 46 additions & 0 deletions uspace/lib/c/include/types/loc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/** @addtogroup libc
* @{
*/
/** @file
*/

#ifndef _LIBC_TYPES_LOC_H_
#define _LIBC_TYPES_LOC_H_

/** Server register with location service */
typedef struct {
int dummy;
} loc_srv_t;

#endif

/** @}
*/

0 comments on commit 4c6fd56

Please sign in to comment.