Changeset 89d3946f in mainline for uspace/lib/hound/src/protocol.c


Ignore:
Timestamp:
2013-03-16T23:46:59Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
abaef81
Parents:
6b0cfa1
Message:

libhound: Add new client side API skeleton

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/hound/src/protocol.c

    r6b0cfa1 r89d3946f  
    3434 * Common USB functions.
    3535 */
     36#include <adt/list.h>
    3637#include <errno.h>
    3738#include <loc.h>
    3839#include <str.h>
    3940#include <stdlib.h>
     41#include <stdio.h>
     42#include <libarch/types.h>
    4043
    4144#include "client.h"
     
    4750 * CLIENT SIDE
    4851 ***/
     52
     53typedef struct hound_stream {
     54        link_t link;
     55        async_exch_t *exch;
     56} hound_stream_t;
     57
     58typedef struct hound_context {
     59        async_sess_t *session;
     60        const char *name;
     61        bool record;
     62        list_t stream_list;
     63        hound_stream_t *main_stream;
     64        struct {
     65                pcm_sample_format_t sample;
     66                unsigned channels;
     67                unsigned rate;
     68                size_t bsize;
     69        } main_format;
     70        unsigned id;
     71} hound_context_t;
     72
     73async_sess_t *hound_get_session(void)
     74{
     75        service_id_t id = 0;
     76        const int ret =
     77            loc_service_get_id(HOUND_SERVICE, &id, IPC_FLAG_BLOCKING);
     78        if (ret != EOK)
     79                return NULL;
     80        return loc_service_connect(EXCHANGE_SERIALIZE, id, IPC_FLAG_BLOCKING);
     81}
     82
     83void hound_release_session(async_sess_t *sess)
     84{
     85        if (sess)
     86                async_hangup(sess);
     87}
     88
     89static hound_context_t *hound_context_create(const char *name, bool record,
     90    unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize)
     91{
     92        hound_context_t *new_context = malloc(sizeof(hound_context_t));
     93        if (new_context) {
     94                char *cont_name;
     95                int ret = asprintf(&cont_name, "%llu:%s", task_get_id(), name);
     96                if (ret < 0) {
     97                        free(new_context);
     98                        return NULL;
     99                }
     100                list_initialize(&new_context->stream_list);
     101                new_context->name = cont_name;
     102                new_context->record = record;
     103                new_context->session = hound_get_session();
     104                new_context->main_stream = NULL;
     105                new_context->main_format.sample = format;
     106                new_context->main_format.rate = rate;
     107                new_context->main_format.channels = channels;
     108                new_context->main_format.bsize = bsize;
     109                if (!new_context->session) {
     110                        free(new_context->name);
     111                        free(new_context);
     112                        return NULL;
     113                }
     114                async_exch_t *exch = async_exchange_begin(new_context->session);
     115                //TODO: register context
     116                async_exchange_end(exch);
     117        }
     118        return new_context;
     119}
     120
     121hound_context_t * hound_context_create_playback(const char *name,
     122    unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize)
     123{
     124        return hound_context_create(name, false, channels, rate, format, bsize);
     125}
     126
     127hound_context_t * hound_context_create_capture(const char *name,
     128    unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize)
     129{
     130        return hound_context_create(name, true, channels, rate, format, bsize);
     131}
     132
     133void hound_context_destroy(hound_context_t *hound)
     134{
     135        assert(hound);
     136}
     137
     138int hound_context_enable(hound_context_t *hound)
     139{
     140        assert(hound);
     141        return ENOTSUP;
     142}
     143int hound_context_disable(hound_context_t *hound)
     144{
     145        assert(hound);
     146        return ENOTSUP;
     147}
     148
     149int hound_get_output_targets(const char **names, size_t *count)
     150{
     151        assert(names);
     152        assert(count);
     153        return ENOTSUP;
     154}
     155
     156int hound_get_input_targets(const char **names, size_t *count)
     157{
     158        assert(names);
     159        assert(count);
     160        return ENOTSUP;
     161}
     162
     163int hound_context_connect_target(hound_context_t *hound, const char* target)
     164{
     165        assert(hound);
     166        return ENOTSUP;
     167}
     168
     169int hound_context_disconnect_target(hound_context_t *hound, const char* target)
     170{
     171        assert(hound);
     172        return ENOTSUP;
     173}
     174
     175int hound_context_set_main_stream_format(hound_context_t *hound,
     176    unsigned channels, unsigned rate, pcm_sample_format_t format);
     177int hound_write_main_stream(hound_context_t *hound,
     178    const void *data, size_t size);
     179int hound_read_main_stream(hound_context_t *hound, void *data, size_t size);
     180int hound_write_replace_main_stream(hound_context_t *hound,
     181    const void *data, size_t size);
     182int hound_write_immediate_stream(hound_context_t *hound,
     183    const void *data, size_t size);
     184
     185
     186
     187
     188
     189
     190
    49191
    50192typedef struct {
     
    64206
    65207
    66 hound_sess_t *hound_get_session(void)
    67 {
    68         service_id_t id = 0;
    69         const int ret = loc_service_get_id(HOUND_SERVICE, &id, 0);
    70         if (ret != EOK)
    71                 return NULL;
    72         return loc_service_connect(EXCHANGE_SERIALIZE, id, 0);
    73 }
    74 void hound_release_session(hound_sess_t *sess)
    75 {
    76         if (sess)
    77                 async_hangup(sess);
    78 }
    79208int hound_register_playback(hound_sess_t *sess, const char *name,
    80209    unsigned channels, unsigned rate, pcm_sample_format_t format,
Note: See TracChangeset for help on using the changeset viewer.