source: mainline/uspace/srv/devman/loc.c@ 0db0df2

Last change on this file since 0db0df2 was 4c6fd56, checked in by Jiri Svoboda <jiri@…>, 22 months ago

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.

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[a60e90b]1/*
[4c6fd56]2 * Copyright (c) 2023 Jiri Svoboda
[a60e90b]3 * Copyright (c) 2010 Lenka Trochtova
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup devman
31 * @{
32 */
33
34#include <loc.h>
35#include <stdio.h>
36
37#include "devman.h"
38#include "fun.h"
39#include "loc.h"
[4c6fd56]40#include "main.h"
[a60e90b]41
42/** Create loc path and name for the function. */
43void loc_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
44{
45 char *loc_pathname = NULL;
46 char *loc_name = NULL;
[a35b458]47
[a60e90b]48 assert(fibril_rwlock_is_locked(&tree->rwlock));
[a35b458]49
[a60e90b]50 asprintf(&loc_name, "%s", fun->pathname);
51 if (loc_name == NULL)
52 return;
[a35b458]53
[a60e90b]54 replace_char(loc_name, '/', LOC_SEPARATOR);
[a35b458]55
[a60e90b]56 asprintf(&loc_pathname, "%s/%s", LOC_DEVICE_NAMESPACE,
57 loc_name);
58 if (loc_pathname == NULL) {
59 free(loc_name);
60 return;
61 }
[a35b458]62
[4c6fd56]63 loc_service_register(devman_srv, loc_pathname, &fun->service_id);
[a35b458]64
[a60e90b]65 tree_add_loc_function(tree, fun);
[a35b458]66
[a60e90b]67 free(loc_name);
68 free(loc_pathname);
69}
70
[b7fd2a0]71errno_t loc_unregister_tree_function(fun_node_t *fun, dev_tree_t *tree)
[96ef672]72{
[4c6fd56]73 errno_t rc = loc_service_unregister(devman_srv, fun->service_id);
[96ef672]74 tree_rem_loc_function(tree, fun);
75 return rc;
76}
77
[a60e90b]78fun_node_t *find_loc_tree_function(dev_tree_t *tree, service_id_t service_id)
79{
80 fun_node_t *fun = NULL;
[a35b458]81
[a60e90b]82 fibril_rwlock_read_lock(&tree->rwlock);
83 ht_link_t *link = hash_table_find(&tree->loc_functions, &service_id);
84 if (link != NULL) {
85 fun = hash_table_get_inst(link, fun_node_t, loc_fun);
86 fun_add_ref(fun);
87 }
88 fibril_rwlock_read_unlock(&tree->rwlock);
[a35b458]89
[a60e90b]90 return fun;
91}
92
93void tree_add_loc_function(dev_tree_t *tree, fun_node_t *fun)
94{
95 assert(fibril_rwlock_is_write_locked(&tree->rwlock));
[a35b458]96
[a60e90b]97 hash_table_insert(&tree->loc_functions, &fun->loc_fun);
98}
99
[96ef672]100void tree_rem_loc_function(dev_tree_t *tree, fun_node_t *fun)
101{
102 assert(fibril_rwlock_is_write_locked(&tree->rwlock));
[a35b458]103
[96ef672]104 hash_table_remove(&tree->loc_functions, &fun->service_id);
105}
106
[a60e90b]107/** @}
108 */
Note: See TracBrowser for help on using the repository browser.