Changeset 5ffcbaf in mainline


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

hound: Implement source and sink listings

Location:
uspace/srv/audio/hound
Files:
2 edited

Legend:

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

    r35ab943 r5ffcbaf  
    9797        if (!ctx)
    9898                return EINVAL;
     99        fibril_mutex_lock(&hound->list_guard);
    99100        list_append(&ctx->link, &hound->contexts);
    100101        //TODO register sinks/sources
     102        fibril_mutex_unlock(&hound->list_guard);
    101103        return EOK;
    102104}
     
    107109        if (!ctx)
    108110                return EINVAL;
     111        fibril_mutex_lock(&hound->list_guard);
    109112        list_remove(&ctx->link);
     113        fibril_mutex_unlock(&hound->list_guard);
    110114        return EOK;
    111115}
     
    115119        assert(hound);
    116120
    117         //TODO locking
    118 
     121        fibril_mutex_lock(&hound->list_guard);
     122        hound_ctx_t *res = NULL;
    119123        list_foreach(hound->contexts, it) {
    120124                hound_ctx_t *ctx = hound_ctx_from_link(it);
    121                 if (hound_ctx_get_id(ctx) == id)
    122                         return ctx;
    123         }
    124         return NULL;
     125                if (hound_ctx_get_id(ctx) == id) {
     126                        res = ctx;
     127                        break;
     128                }
     129        }
     130        fibril_mutex_unlock(&hound->list_guard);
     131        return res;
    125132}
    126133
     
    263270}
    264271
     272int hound_list_sources(hound_t *hound, const char ***list, size_t *size)
     273{
     274        assert(hound);
     275        if (!list || !size)
     276                return EINVAL;
     277
     278        fibril_mutex_lock(&hound->list_guard);
     279        const size_t count = list_count(&hound->sources);
     280        if (count == 0) {
     281                *list = NULL;
     282                *size = 0;
     283                fibril_mutex_unlock(&hound->list_guard);
     284                return EOK;
     285        }
     286        const char **names = calloc(count, sizeof(char *));
     287        int ret = names ? EOK : ENOMEM;
     288        for (size_t i = 0; i < count && ret == EOK; ++i) {
     289                link_t *slink = list_nth(&hound->sources, i);
     290                audio_source_t *source = audio_source_list_instance(slink);
     291                names[i] = str_dup(source->name);
     292                if (names[i])
     293                        ret = ENOMEM;
     294        }
     295        if (ret == EOK) {
     296                *size = count;
     297                *list = names;
     298        } else {
     299                for (size_t i = 0; i < count; ++i)
     300                        free(names[i]);
     301                free(names);
     302        }
     303        fibril_mutex_unlock(&hound->list_guard);
     304        return ret;
     305}
     306
     307int hound_list_sinks(hound_t *hound, const char ***list, size_t *size)
     308{
     309        assert(hound);
     310        log_verbose("Hound list sinks: %p %p %p", hound, list, size);
     311        if (!list || !size)
     312                return EINVAL;
     313
     314        fibril_mutex_lock(&hound->list_guard);
     315        const size_t count = list_count(&hound->sinks);
     316        if (count == 0) {
     317                printf("ZERO SINKS!\n");
     318                *list = NULL;
     319                *size = 0;
     320                fibril_mutex_unlock(&hound->list_guard);
     321                return EOK;
     322        }
     323        const char **names = calloc(count, sizeof(char *));
     324        int ret = names ? EOK : ENOMEM;
     325        for (size_t i = 0; i < count && ret == EOK; ++i) {
     326                link_t *slink = list_nth(&hound->sinks, i);
     327                audio_sink_t *sink = audio_sink_list_instance(slink);
     328                names[i] = str_dup(sink->name);
     329                if (!names[i])
     330                        ret = ENOMEM;
     331        }
     332        if (ret == EOK) {
     333                *size = count;
     334                *list = names;
     335                printf("%zu SINKS %s!\n", count, names[0]);
     336        } else {
     337                for (size_t i = 0; i < count; ++i)
     338                        free(names[i]);
     339                free(names);
     340        }
     341        fibril_mutex_unlock(&hound->list_guard);
     342        return ret;
     343}
     344
     345int hound_list_connections(hound_t *hound, const char ***sources,
     346    const char ***sinks, size_t *size)
     347{
     348        fibril_mutex_lock(&hound->list_guard);
     349        fibril_mutex_unlock(&hound->list_guard);
     350        return ENOTSUP;
     351}
     352
    265353int hound_connect(hound_t *hound, const char* source_name, const char* sink_name)
    266354{
  • uspace/srv/audio/hound/hound.h

    r35ab943 r5ffcbaf  
    6767int hound_add_source(hound_t *hound, audio_source_t *source);
    6868int hound_add_sink(hound_t *hound, audio_sink_t *sink);
     69int hound_list_sources(hound_t *hound, const char ***list, size_t *size);
     70int hound_list_sinks(hound_t *hound, const char ***list, size_t *size);
     71int hound_list_connections(hound_t *hound, const char ***sources,
     72    const char ***sinks, size_t *size);
    6973int hound_remove_source(hound_t *hound, audio_source_t *source);
    7074int hound_remove_sink(hound_t *hound, audio_sink_t *sink);
Note: See TracChangeset for help on using the changeset viewer.