Changeset fa60cd69 in mainline for uspace/srv/audio/hound/hound.c


Ignore:
Timestamp:
2013-04-02T19:06:27Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
35ab943
Parents:
39c4d1f
Message:

hound: add connection class

This will enable N to M routing in the future

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/audio/hound/hound.c

    r39c4d1f rfa60cd69  
    4343#include "audio_sink.h"
    4444#include "audio_source.h"
     45#include "connection.h"
    4546#include "log.h"
    4647#include "errno.h"
     
    8687        list_initialize(&hound->sources);
    8788        list_initialize(&hound->sinks);
     89        list_initialize(&hound->connections);
    8890        return EOK;
    8991}
     
    207209                return EEXISTS;
    208210        }
    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         }
    217211        list_append(&source->link, &hound->sources);
    218212        fibril_mutex_unlock(&hound->list_guard);
     
    245239        log_verbose("Removing source '%s'.", source->name);
    246240        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
    252242        list_remove(&source->link);
    253243        fibril_mutex_unlock(&hound->list_guard);
     
    263253        fibril_mutex_lock(&hound->list_guard);
    264254
    265         if (!list_empty(&sink->sources)) {
     255        if (!list_empty(&sink->connections)) {
    266256                // TODO disconnect instead
    267257                fibril_mutex_unlock(&hound->list_guard);
     
    278268        log_verbose("Connecting '%s' to '%s'.", source_name, sink_name);
    279269        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        }
    280282
    281283        audio_source_t *source =
     
    294296                return ENOENT;
    295297        }
    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);
    303307        return EOK;
    304308}
     
    317321        assert(hound);
    318322        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
    340336        return EOK;
    341337}
Note: See TracChangeset for help on using the changeset viewer.