Ignore:
File:
1 edited

Legend:

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

    rfeeac0d rc799138  
    4747#include "str_error.h"
    4848
     49#define FIND_BY_NAME(type) \
     50do { \
     51        assert(list); \
     52        assert(name); \
     53        list_foreach(*list, it) { \
     54                audio_ ## type ## _t *dev = \
     55                    audio_ ## type ## _list_instance(it); \
     56                if (str_cmp(name, dev->name) == 0) { \
     57                        log_debug("%s with name '%s' is in the list", \
     58                            #type, name); \
     59                        return dev; \
     60                } \
     61        } \
     62        return NULL; \
     63} while (0)
     64
    4965/**
    5066 * Search devices by name.
     
    5268 * @return Pointer to the found device, NULL on failure.
    5369 */
    54 static audio_device_t *find_device_by_name(list_t *list, const char *name)
    55 {
    56         assert(list);
    57         assert(name);
    58 
    59         list_foreach(*list, link, audio_device_t, dev) {
    60                 if (str_cmp(name, dev->name) == 0) {
    61                         log_debug("device with name '%s' is in the list",
    62                             name);
    63                         return dev;
    64                 }
    65         }
    66 
    67         return NULL;
     70static audio_device_t * find_device_by_name(list_t *list, const char *name)
     71{
     72        FIND_BY_NAME(device);
    6873}
    6974
     
    7378 * @return Pointer to the found source, NULL on failure.
    7479 */
    75 static audio_source_t *find_source_by_name(list_t *list, const char *name)
    76 {
    77         assert(list);
    78         assert(name);
    79 
    80         list_foreach(*list, link, audio_source_t, dev) {
    81                 if (str_cmp(name, dev->name) == 0) {
    82                         log_debug("source with name '%s' is in the list",
    83                             name);
    84                         return dev;
    85                 }
    86         }
    87 
    88         return NULL;
     80static audio_source_t * find_source_by_name(list_t *list, const char *name)
     81{
     82        FIND_BY_NAME(source);
    8983}
    9084
     
    9488 * @return Pointer to the found sink, NULL on failure.
    9589 */
    96 static audio_sink_t *find_sink_by_name(list_t *list, const char *name)
    97 {
    98         assert(list);
    99         assert(name);
    100 
    101         list_foreach(*list, link, audio_sink_t, dev) {
    102                 if (str_cmp(name, dev->name) == 0) {
    103                         log_debug("sink with name '%s' is in the list",
    104                             name);
    105                         return dev;
    106                 }
    107         }
    108 
    109         return NULL;
     90static audio_sink_t * find_sink_by_name(list_t *list, const char *name)
     91{
     92        FIND_BY_NAME(sink);
    11093}
    11194
     
    128111                log_warning("Removing sink '%s' while still connected.", sink->name);
    129112        while (!list_empty(&sink->connections)) {
    130                 connection_t *conn = list_get_instance(
    131                     list_first(&sink->connections), connection_t, sink_link);
     113                connection_t *conn =
     114                    connection_from_sink_list(list_first(&sink->connections));
    132115                list_remove(&conn->hound_link);
    133116                connection_destroy(conn);
     
    145128static void hound_remove_source_internal(hound_t *hound, audio_source_t *source)
    146129{
     130        assert(hound);
     131        assert(source);
    147132        log_verbose("Removing source '%s'.", source->name);
    148133        if (!list_empty(&source->connections))
    149134                log_warning("Removing source '%s' while still connected.", source->name);
    150135        while (!list_empty(&source->connections)) {
    151                 connection_t *conn = list_get_instance(
    152                     list_first(&source->connections), connection_t, source_link);
     136                connection_t *conn =
     137                    connection_from_source_list(list_first(&source->connections));
     138                assert(conn);
    153139                list_remove(&conn->hound_link);
    154140                connection_destroy(conn);
     
    237223        fibril_mutex_lock(&hound->list_guard);
    238224        hound_ctx_t *res = NULL;
    239         list_foreach(hound->contexts, link, hound_ctx_t, ctx) {
     225        list_foreach(hound->contexts, it) {
     226                hound_ctx_t *ctx = hound_ctx_from_link(it);
    240227                if (hound_ctx_get_id(ctx) == id) {
    241228                        res = ctx;
     
    264251        }
    265252
    266         list_foreach(hound->devices, link, audio_device_t, dev) {
     253        list_foreach(hound->devices, it) {
     254                audio_device_t *dev = audio_device_list_instance(it);
    267255                if (dev->id == id) {
    268256                        log_debug("Device with id %zu is already present", id);
Note: See TracChangeset for help on using the changeset viewer.