source: mainline/uspace/srv/devman/loc.c@ 659ebd86

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 659ebd86 was f9b2cb4c, checked in by Martin Decky <martin@…>, 10 years ago

unify interface API

  • introduce new interfaces
  • unify location service clients to always expect service ID as the second argument
  • remove obsolete methods that take explicit exchange management arguments (first phase)
  • use interfaces in device drivers, devman, location service, logger, inet
  • Property mode set to 100644
File size: 2.7 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(loc_pathname, &fun->service_id);
62
63 tree_add_loc_function(tree, fun);
64
65 free(loc_name);
66 free(loc_pathname);
67}
68
69fun_node_t *find_loc_tree_function(dev_tree_t *tree, service_id_t service_id)
70{
71 fun_node_t *fun = NULL;
72
73 fibril_rwlock_read_lock(&tree->rwlock);
74 ht_link_t *link = hash_table_find(&tree->loc_functions, &service_id);
75 if (link != NULL) {
76 fun = hash_table_get_inst(link, fun_node_t, loc_fun);
77 fun_add_ref(fun);
78 }
79 fibril_rwlock_read_unlock(&tree->rwlock);
80
81 return fun;
82}
83
84void tree_add_loc_function(dev_tree_t *tree, fun_node_t *fun)
85{
86 assert(fibril_rwlock_is_write_locked(&tree->rwlock));
87
88 hash_table_insert(&tree->loc_functions, &fun->loc_fun);
89}
90
91/** @}
92 */
Note: See TracBrowser for help on using the repository browser.