source: mainline/uspace/lib/c/generic/devman_obsolete.c@ 9934f7d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9934f7d was 79ae36dd, checked in by Martin Decky <martin@…>, 14 years ago

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[79ae36dd]1/*
2 * Copyright (c) 2007 Josef Cejka
3 * Copyright (c) 2009 Jiri Svoboda
4 * Copyright (c) 2010 Lenka Trochtova
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup libc
32 * @{
33 */
34/** @file
35 */
36
37#include <str.h>
38#include <stdio.h>
39#include <ipc/services.h>
40#include <ipc/devman.h>
41#include <devman_obsolete.h>
42#include <async.h>
43#include <async_obsolete.h>
44#include <ns.h>
45#include <ns_obsolete.h>
46#include <fibril_synch.h>
47#include <errno.h>
48#include <malloc.h>
49#include <bool.h>
50#include <adt/list.h>
51
52static int devman_phone_driver = -1;
53static int devman_phone_client = -1;
54
55static FIBRIL_MUTEX_INITIALIZE(devman_phone_mutex);
56
57int devman_obsolete_get_phone(devman_interface_t iface, unsigned int flags)
58{
59 switch (iface) {
60 case DEVMAN_DRIVER:
61 fibril_mutex_lock(&devman_phone_mutex);
62 if (devman_phone_driver >= 0) {
63 fibril_mutex_unlock(&devman_phone_mutex);
64 return devman_phone_driver;
65 }
66
67 if (flags & IPC_FLAG_BLOCKING)
68 devman_phone_driver = service_obsolete_connect_blocking(
69 SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
70 else
71 devman_phone_driver = service_obsolete_connect(SERVICE_DEVMAN,
72 DEVMAN_DRIVER, 0);
73
74 fibril_mutex_unlock(&devman_phone_mutex);
75 return devman_phone_driver;
76 case DEVMAN_CLIENT:
77 fibril_mutex_lock(&devman_phone_mutex);
78 if (devman_phone_client >= 0) {
79 fibril_mutex_unlock(&devman_phone_mutex);
80 return devman_phone_client;
81 }
82
83 if (flags & IPC_FLAG_BLOCKING) {
84 devman_phone_client = service_obsolete_connect_blocking(
85 SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
86 } else {
87 devman_phone_client = service_obsolete_connect(SERVICE_DEVMAN,
88 DEVMAN_CLIENT, 0);
89 }
90
91 fibril_mutex_unlock(&devman_phone_mutex);
92 return devman_phone_client;
93 default:
94 return -1;
95 }
96}
97
98void devman_obsolete_hangup_phone(devman_interface_t iface)
99{
100 switch (iface) {
101 case DEVMAN_DRIVER:
102 if (devman_phone_driver >= 0) {
103 async_obsolete_hangup(devman_phone_driver);
104 devman_phone_driver = -1;
105 }
106 break;
107 case DEVMAN_CLIENT:
108 if (devman_phone_client >= 0) {
109 async_obsolete_hangup(devman_phone_client);
110 devman_phone_client = -1;
111 }
112 break;
113 default:
114 break;
115 }
116}
117
118int devman_obsolete_device_connect(devman_handle_t handle, unsigned int flags)
119{
120 int phone;
121
122 if (flags & IPC_FLAG_BLOCKING) {
123 phone = service_obsolete_connect_blocking(SERVICE_DEVMAN,
124 DEVMAN_CONNECT_TO_DEVICE, handle);
125 } else {
126 phone = service_obsolete_connect(SERVICE_DEVMAN,
127 DEVMAN_CONNECT_TO_DEVICE, handle);
128 }
129
130 return phone;
131}
132
133int devman_obsolete_parent_device_connect(devman_handle_t handle, unsigned int flags)
134{
135 int phone;
136
137 if (flags & IPC_FLAG_BLOCKING) {
138 phone = service_obsolete_connect_blocking(SERVICE_DEVMAN,
139 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);
140 } else {
141 phone = service_obsolete_connect(SERVICE_DEVMAN,
142 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);
143 }
144
145 return phone;
146}
147
148/** @}
149 */
Note: See TracBrowser for help on using the repository browser.