Changeset 7a252ec8 in mainline for uspace/lib/drv/generic/remote_char.c
- Timestamp:
- 2010-10-21T20:13:40Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 848e3d15
- Parents:
- a79d88d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/remote_char.c
ra79d88d r7a252ec8 1 1 /* 2 * Copyright (c) 2010 Lenka Trochtova 2 * Copyright (c) 2010 Lenka Trochtova 3 3 * All rights reserved. 4 4 * … … 42 42 #define MAX_CHAR_RW_COUNT 256 43 43 44 static void remote_char_read(device_t * dev, void *iface, ipc_callid_t callid, ipc_call_t *call);45 static void remote_char_write(device_t * dev, void *iface, ipc_callid_t callid, ipc_call_t *call);44 static void remote_char_read(device_t *, void *, ipc_callid_t, ipc_call_t *); 45 static void remote_char_write(device_t *, void *, ipc_callid_t, ipc_call_t *); 46 46 47 /** Remote character interface operations. 48 */ 47 /** Remote character interface operations. */ 49 48 static remote_iface_func_ptr_t remote_char_iface_ops [] = { 50 49 &remote_char_read, 51 &remote_char_write 52 }; 53 54 /** Remote character interface structure. 55 * Interface for processing request from remote clients addressed to the character interface. 50 &remote_char_write 51 }; 52 53 /** Remote character interface structure. 54 * 55 * Interface for processing request from remote clients addressed to the 56 * character interface. 56 57 */ 57 58 remote_iface_t remote_char_iface = { 58 .method_count = sizeof(remote_char_iface_ops) / sizeof(remote_iface_func_ptr_t), 59 .method_count = sizeof(remote_char_iface_ops) / 60 sizeof(remote_iface_func_ptr_t), 59 61 .methods = remote_char_iface_ops 60 62 }; 61 63 62 64 /** Process the read request from the remote client. 63 * 64 * Receive the read request's parameters from the remote client and pass them to the local interface. 65 * Return the result of the operation processed by the local interface to the remote client. 66 * 67 * @param dev the device from which the data are read. 68 * @param iface the local interface structure. 65 * 66 * Receive the read request's parameters from the remote client and pass them 67 * to the local interface. Return the result of the operation processed by the 68 * local interface to the remote client. 69 * 70 * @param dev The device from which the data are read. 71 * @param iface The local interface structure. 69 72 */ 70 static void remote_char_read(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call) 73 static void 74 remote_char_read(device_t *dev, void *iface, ipc_callid_t callid, 75 ipc_call_t *call) 71 76 { 72 char_iface_t *char_iface = (char_iface_t *) iface;77 char_iface_t *char_iface = (char_iface_t *) iface; 73 78 ipc_callid_t cid; 74 79 75 80 size_t len; 76 81 if (!async_data_read_receive(&cid, &len)) { 77 / / TODO handle protocol error82 /* TODO handle protocol error. */ 78 83 ipc_answer_0(callid, EINVAL); 79 84 return; … … 86 91 } 87 92 88 if (len > MAX_CHAR_RW_COUNT) {93 if (len > MAX_CHAR_RW_COUNT) 89 94 len = MAX_CHAR_RW_COUNT; 90 }91 95 92 96 char buf[MAX_CHAR_RW_COUNT]; 93 97 int ret = (*char_iface->read)(dev, buf, len); 94 98 95 if (ret < 0) { // some error occured 99 if (ret < 0) { 100 /* Some error occured. */ 96 101 async_data_read_finalize(cid, buf, 0); 97 102 ipc_answer_0(callid, ret); … … 99 104 } 100 105 101 / / the operation was successful, return the number of data read106 /* The operation was successful, return the number of data read. */ 102 107 async_data_read_finalize(cid, buf, ret); 103 ipc_answer_1(callid, EOK, ret); 108 ipc_answer_1(callid, EOK, ret); 104 109 } 105 110 106 111 /** Process the write request from the remote client. 107 * 108 * Receive the write request's parameters from the remote client and pass them to the local interface. 109 * Return the result of the operation processed by the local interface to the remote client. 110 * 111 * @param dev the device to which the data are written. 112 * @param iface the local interface structure. 112 * 113 * Receive the write request's parameters from the remote client and pass them 114 * to the local interface. Return the result of the operation processed by the 115 * local interface to the remote client. 116 * 117 * @param dev The device to which the data are written. 118 * @param iface The local interface structure. 113 119 */ 114 static void remote_char_write(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call) 120 static void 121 remote_char_write(device_t *dev, void *iface, ipc_callid_t callid, 122 ipc_call_t *call) 115 123 { 116 char_iface_t *char_iface = (char_iface_t *) iface;124 char_iface_t *char_iface = (char_iface_t *) iface; 117 125 ipc_callid_t cid; 118 126 size_t len; 119 127 120 128 if (!async_data_write_receive(&cid, &len)) { 121 / / TODO handle protocol error129 /* TODO handle protocol error. */ 122 130 ipc_answer_0(callid, EINVAL); 123 131 return; 124 132 } 125 133 126 134 if (!char_iface->write) { … … 130 138 } 131 139 132 if (len > MAX_CHAR_RW_COUNT) {140 if (len > MAX_CHAR_RW_COUNT) 133 141 len = MAX_CHAR_RW_COUNT; 134 }135 142 136 143 char buf[MAX_CHAR_RW_COUNT]; … … 139 146 140 147 int ret = (*char_iface->write)(dev, buf, len); 141 if (ret < 0) { // some error occured 148 if (ret < 0) { 149 /* Some error occured. */ 142 150 ipc_answer_0(callid, ret); 143 151 } else { 144 // the operation was successful, return the number of data written 152 /* 153 * The operation was successful, return the number of data 154 * written. 155 */ 145 156 ipc_answer_1(callid, EOK, ret); 146 157 } 147 158 } 148 159 149 160 /** 150 161 * @} 151 162 */
Note:
See TracChangeset
for help on using the changeset viewer.