Changeset a1769ee in mainline for uspace/lib/libdrv/generic/driver.c
- Timestamp:
- 2010-03-31T20:30:54Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 52b7b1bb
- Parents:
- eff1a590
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libdrv/generic/driver.c
reff1a590 ra1769ee 58 58 LIST_INITIALIZE(devices); 59 59 60 static device_t * driver_create_device()60 static device_t * driver_create_device() 61 61 { 62 62 device_t *dev = (device_t *)malloc(sizeof(device_t)); … … 65 65 } 66 66 return dev; 67 } 68 69 static device_t * driver_get_device(link_t *devices, device_handle_t handle) 70 { 71 device_t *dev = NULL; 72 link_t *link = devices->next; 73 74 while (link != devices) { 75 dev = list_get_instance(link, device_t, link); 76 if (handle == dev->handle) { 77 return dev; 78 } 79 } 80 81 return NULL; 67 82 } 68 83 … … 82 97 printf("%s: new device with handle = %x was added.\n", driver->name, dev_handle); 83 98 84 ipc arg_t r = ipc_answer_1(iid, EOK, ret);99 ipc_answer_1(iid, EOK, ret); 85 100 } 86 101 … … 111 126 } 112 127 128 /** 129 * Generic client connection handler both for applications and drivers. 130 * 131 * @param driver true for driver client, false for other clients (applications, services etc.). 132 */ 133 static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool driver) { 134 /* 135 * Answer the first IPC_M_CONNECT_ME_TO call and remember the handle of the device to which the client connected. 136 */ 137 device_handle_t handle = IPC_GET_ARG1(*icall); 138 device_t *dev = driver_get_device(&devices, handle); 139 140 if (dev == NULL) { 141 ipc_answer_0(iid, ENOENT); 142 return; 143 } 144 145 // TODO introduce generic device interface for opening and closing devices 146 // and call its open callback here to find out wheter the device can be used by the connecting client 147 148 149 ipc_answer_0(iid, EOK); 150 151 while (1) { 152 ipc_callid_t callid; 153 ipc_call_t call; 154 155 callid = async_get_call(&call); 156 ipcarg_t method = IPC_GET_METHOD(call); 157 switch (method) { 158 case IPC_M_PHONE_HUNGUP: 159 // TODO close the device 160 ipc_answer_0(callid, EOK); 161 return; 162 default: 163 if (DEV_IFACE_FIRST <= method && method < DEV_IFACE_MAX) { 164 // TODO - try to find interface, if supported 165 // otherwise return ENOTSUP 166 } else { 167 ipc_answer_0(callid, ENOTSUP); 168 } 169 break; 170 } 171 } 172 } 173 113 174 static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall) 114 175 { 115 // TODO later176 driver_connection_gen(iid, icall, true); 116 177 } 117 178 118 179 static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall) 119 180 { 120 // TODO later181 driver_connection_gen(iid, icall, false); 121 182 } 122 183
Note:
See TracChangeset
for help on using the changeset viewer.