Changeset fa60cd69 in mainline for uspace/srv/audio/hound/hound.c
- Timestamp:
- 2013-04-02T19:06:27Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 35ab943
- Parents:
- 39c4d1f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/audio/hound/hound.c
r39c4d1f rfa60cd69 43 43 #include "audio_sink.h" 44 44 #include "audio_source.h" 45 #include "connection.h" 45 46 #include "log.h" 46 47 #include "errno.h" … … 86 87 list_initialize(&hound->sources); 87 88 list_initialize(&hound->sinks); 89 list_initialize(&hound->connections); 88 90 return EOK; 89 91 } … … 207 209 return EEXISTS; 208 210 } 209 list_foreach(hound->sinks, it) {210 audio_sink_t *sink = audio_sink_list_instance(it);211 if (find_source_by_name(&sink->sources, source->name)) {212 log_debug("Source by that name already exists");213 fibril_mutex_unlock(&hound->list_guard);214 return EEXISTS;215 }216 }217 211 list_append(&source->link, &hound->sources); 218 212 fibril_mutex_unlock(&hound->list_guard); … … 245 239 log_verbose("Removing source '%s'.", source->name); 246 240 fibril_mutex_lock(&hound->list_guard); 247 if (!list_member(&source->link, &hound->sources)) { 248 assert(source->connected_sink); 249 hound_disconnect_internal(hound, source->name, 250 source->connected_sink->name); 251 } 241 252 242 list_remove(&source->link); 253 243 fibril_mutex_unlock(&hound->list_guard); … … 263 253 fibril_mutex_lock(&hound->list_guard); 264 254 265 if (!list_empty(&sink-> sources)) {255 if (!list_empty(&sink->connections)) { 266 256 // TODO disconnect instead 267 257 fibril_mutex_unlock(&hound->list_guard); … … 278 268 log_verbose("Connecting '%s' to '%s'.", source_name, sink_name); 279 269 fibril_mutex_lock(&hound->list_guard); 270 271 if (list_empty(&hound->sinks)) { 272 fibril_mutex_unlock(&hound->list_guard); 273 log_debug("No sinks available"); 274 return EINVAL; 275 } 276 277 if (list_empty(&hound->sources)) { 278 fibril_mutex_unlock(&hound->list_guard); 279 log_debug("No sinks available"); 280 return EINVAL; 281 } 280 282 281 283 audio_source_t *source = … … 294 296 return ENOENT; 295 297 } 296 list_remove(&source->link); 297 const int ret = audio_sink_add_source(sink, source); 298 if (ret != EOK) { 299 log_debug("Failed add source to sink list: %s", str_error(ret)); 300 list_append(&source->link, &hound->sources); 301 } 302 fibril_mutex_unlock(&hound->list_guard); 298 connection_t *conn = connection_create(source, sink); 299 if (!conn) { 300 fibril_mutex_unlock(&hound->list_guard); 301 log_debug("Failed to create connection"); 302 return ENOMEM; 303 } 304 list_append(&conn->hound_link, &hound->connections); 305 fibril_mutex_unlock(&hound->list_guard); 306 log_debug("CONNECTED: %s -> %s", source_name, sink_name); 303 307 return EOK; 304 308 } … … 317 321 assert(hound); 318 322 assert(fibril_mutex_is_locked(&hound->list_guard)); 319 log_verbose("Disconnecting '%s' to '%s'.", source_name, sink_name); 320 321 audio_sink_t *sink = 322 audio_sink_list_instance(list_first(&hound->sinks)); 323 if (str_cmp(sink_name, "default") != 0) 324 sink = find_sink_by_name(&hound->sinks, sink_name); 325 326 audio_source_t *source = 327 audio_source_list_instance(list_first(&hound->sources)); 328 if (str_cmp(source_name, "default") != 0) 329 source = sink ? find_source_by_name(&sink->sources, source_name) : NULL; 330 if (!source || !sink) { 331 log_debug("Source (%p), or sink (%p) not found", source, sink); 332 return ENOENT; 333 } 334 const int ret = audio_sink_remove_source(sink, source); 335 if (ret != EOK) { 336 log_debug("Failed remove source to sink list: %s", str_error(ret)); 337 } else { 338 list_append(&source->link, &hound->sources); 339 } 323 log_debug("Disconnecting '%s' to '%s'.", source_name, sink_name); 324 325 list_foreach_safe(hound->connections, it, next) { 326 connection_t *conn = connection_from_hound_list(it); 327 if (str_cmp(connection_source_name(conn), source_name) == 0 || 328 str_cmp(connection_sink_name(conn), sink_name) == 0) { 329 log_debug("Removing %s -> %s", connection_source_name(conn), 330 connection_sink_name(conn)); 331 list_remove(it); 332 connection_destroy(conn); 333 } 334 } 335 340 336 return EOK; 341 337 }
Note:
See TracChangeset
for help on using the changeset viewer.