source: mainline/uspace/srv/devman/loc.c@ e5556e4a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e5556e4a was a60e90b, checked in by Jiri Svoboda <jiri@…>, 12 years ago

Move rest of functionality from devman.c to other modules.

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