Changeset b66d43b in mainline
- Timestamp:
- 2013-03-17T19:09:56Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6bd0216
- Parents:
- bd5860f
- Location:
- uspace/lib/hound
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/hound/include/hound/protocol.h
rbd5860f rb66d43b 49 49 50 50 hound_context_id_t hound_service_register_context(hound_sess_t *sess, 51 const char *name );51 const char *name, bool record); 52 52 int hound_service_unregister_context(hound_sess_t *sess, hound_context_id_t id); 53 53 … … 60 60 int hound_service_stream_read(async_exch_t *exch, void *data, size_t size); 61 61 62 /* Server */ 63 typedef struct hound_server_iface { 64 int (*add_context)(void *, hound_context_id_t *, const char *, bool); 65 int (*rem_context)(void *, hound_context_id_t); 66 int (*add_stream)(void *, hound_context_id_t, int, pcm_format_t, size_t, 67 void **); 68 int (*rem_stream)(void *, void *); 69 int (*stream_data_write)(void *, const void *, size_t); 70 int (*stream_data_read)(void *, void *, size_t); 71 void *server; 72 } hound_server_iface_t; 73 74 void hound_service_set_server_iface(hound_server_iface_t *iface); 75 76 void hound_connection_handler(ipc_callid_t iid, ipc_call_t *icall, void *arg); 62 77 63 78 #endif -
uspace/lib/hound/include/hound/server.h
rbd5860f rb66d43b 40 40 #include <stdbool.h> 41 41 #include <loc.h> 42 #include <pcm/sample_format.h> 42 #include <pcm/format.h> 43 44 43 45 44 46 enum { -
uspace/lib/hound/src/protocol.c
rbd5860f rb66d43b 49 49 IPC_M_HOUND_CONTEXT_REGISTER = IPC_FIRST_USER_METHOD, 50 50 IPC_M_HOUND_CONTEXT_UNREGISTER, 51 IPC_M_HOUND_STREAM_ START,52 IPC_M_HOUND_STREAM_ STOP,51 IPC_M_HOUND_STREAM_ENTER, 52 IPC_M_HOUND_STREAM_EXIT, 53 53 IPC_M_HOUND_STREAM_DRAIN, 54 IPC_M_HOUND_STREAM_WRITE,55 IPC_M_HOUND_STREAM_READ,56 54 }; 55 56 /**** 57 * CLIENT 58 ****/ 57 59 58 60 const char *HOUND_SERVICE = "audio/hound"; … … 75 77 76 78 hound_context_id_t hound_service_register_context(hound_sess_t *sess, 77 const char *name )79 const char *name, bool record) 78 80 { 79 81 assert(sess); 80 82 assert(name); 81 83 async_exch_t *exch = async_exchange_begin(sess); 82 const int ret = 83 async_req_1_0(exch, IPC_M_HOUND_CONTEXT_REGISTER, str_size(name)); 84 //TODO send the string 84 sysarg_t id; 85 int ret = 86 async_req_1_1(exch, IPC_M_HOUND_CONTEXT_REGISTER, record, &id); 87 if (ret == EOK) 88 ret = async_data_write_start(exch, name, str_size(name)); 85 89 async_exchange_end(exch); 86 return ret ;90 return ret == EOK ? (hound_context_id_t)id : ret; 87 91 } 88 92 … … 100 104 int flags, pcm_format_t format, size_t bsize) 101 105 { 106 union { 107 sysarg_t arg; 108 pcm_format_t format; 109 } convert = { .format = format }; 110 return async_req_4_0(exch, IPC_M_HOUND_STREAM_ENTER, id, flags, 111 convert.arg, bsize); 112 } 113 114 int hound_service_stream_exit(async_exch_t *exch) 115 { 116 return async_req_0_0(exch, IPC_M_HOUND_STREAM_EXIT); 117 } 118 119 int hound_service_stream_drain(async_exch_t *exch) 120 { 121 //TODO implement 102 122 return ENOTSUP; 103 123 } 104 124 105 int hound_service_stream_exit(async_exch_t *exch) 106 { 125 int hound_service_stream_write(async_exch_t *exch, const void *data, size_t size) 126 { 127 return async_data_write_start(exch, data, size); 128 } 129 130 int hound_service_stream_read(async_exch_t *exch, void *data, size_t size) 131 { 132 //TODO implement 107 133 return ENOTSUP; 108 134 } 109 135 110 int hound_service_stream_drain(async_exch_t *exch) 111 { 112 return ENOTSUP; 113 } 114 115 int hound_service_stream_write(async_exch_t *exch, const void *data, size_t size) 116 { 117 return ENOTSUP; 118 } 119 120 int hound_service_stream_read(async_exch_t *exch, void *data, size_t size) 121 { 122 return ENOTSUP; 123 } 124 136 /**** 137 * SERVER 138 ****/ 139 140 static int hound_server_read_data(void *stream); 141 static hound_server_iface_t *server_iface; 142 143 void hound_service_set_server_iface(hound_server_iface_t *iface) 144 { 145 server_iface = iface; 146 } 147 148 void hound_connection_handler(ipc_callid_t iid, ipc_call_t *icall, void *arg) 149 { 150 /* Accept connection if there is a valid iface*/ 151 if (server_iface) { 152 async_answer_0(iid, EOK); 153 } else { 154 async_answer_0(iid, ENOTSUP); 155 return; 156 } 157 158 while (1) { 159 ipc_call_t call; 160 ipc_callid_t callid = async_get_call(&call); 161 switch(IPC_GET_IMETHOD(call)) { 162 case IPC_M_HOUND_CONTEXT_REGISTER: { 163 if (!server_iface || !server_iface->add_context) { 164 async_answer_0(callid, ENOTSUP); 165 break; 166 } 167 bool record = IPC_GET_ARG1(call); 168 void *name; 169 int ret = 170 async_data_write_accept(&name, true, 0, 0, 0, 0); 171 if (ret != EOK) { 172 async_answer_0(callid, ret); 173 break; 174 } 175 hound_context_id_t id = 0; 176 ret = server_iface->add_context(server_iface->server, 177 &id, name, record); 178 if (ret != EOK) { 179 free(name); 180 async_answer_0(callid, ret); 181 break; 182 } 183 async_answer_1(callid, EOK, id); 184 } 185 case IPC_M_HOUND_STREAM_ENTER: { 186 if (!server_iface || !server_iface->add_stream) { 187 async_answer_0(callid, ENOTSUP); 188 break; 189 } 190 191 hound_context_id_t id = IPC_GET_ARG1(call); 192 int flags = IPC_GET_ARG2(call); 193 union { 194 sysarg_t arg; 195 pcm_format_t format; 196 } convert = { .arg = IPC_GET_ARG3(call) }; 197 size_t bsize = IPC_GET_ARG4(call); 198 void *stream; 199 int ret = server_iface->add_stream(server_iface->server, 200 id, flags, convert.format, bsize, &stream); 201 if (ret != EOK) { 202 async_answer_0(callid, ret); 203 break; 204 } 205 hound_server_read_data(stream); 206 break; 207 } 208 case IPC_M_HOUND_CONTEXT_UNREGISTER: 209 case IPC_M_HOUND_STREAM_EXIT: 210 case IPC_M_HOUND_STREAM_DRAIN: 211 default: 212 async_answer_0(callid, ENOTSUP); 213 return; 214 } 215 } 216 } 217 218 static int hound_server_read_data(void *stream) 219 { 220 if (!server_iface || !server_iface->stream_data_write) 221 return ENOTSUP; 222 223 ipc_callid_t callid; 224 size_t size = 0; 225 while (async_data_write_receive(&callid, &size)) { 226 char *buffer = malloc(size); 227 if (!buffer) { 228 async_answer_0(callid, ENOMEM); 229 continue; 230 } 231 int ret = async_data_write_finalize(callid, buffer, size); 232 if (ret == EOK) { 233 server_iface->stream_data_write(stream, buffer, size); 234 } else { 235 // TODO did answering fail? 236 async_answer_0(callid, ret); 237 } 238 } 239 //TODO we assume that the fail was caused by IPC_M_HOUND_STREAM_EXIT 240 async_answer_0(callid, EOK); 241 return EOK; 242 } 125 243 126 244 /*** 127 * CLIENT SIDE 245 * CLIENT SIDE -DEPRECATED 128 246 ***/ 129 247 … … 348 466 349 467 /*** 350 * SERVER SIDE 468 * SERVER SIDE - DEPRECATED 351 469 ***/ 470 352 471 static const char * get_name(void); 353 472
Note:
See TracChangeset
for help on using the changeset viewer.