Changeset b66d43b in mainline


Ignore:
Timestamp:
2013-03-17T19:09:56Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6bd0216
Parents:
bd5860f
Message:

libhound: Make protocol.h public, add server side iface skeleton.

Implement few more client side functions.

Location:
uspace/lib/hound
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/hound/include/hound/protocol.h

    rbd5860f rb66d43b  
    4949
    5050hound_context_id_t hound_service_register_context(hound_sess_t *sess,
    51     const char *name);
     51    const char *name, bool record);
    5252int hound_service_unregister_context(hound_sess_t *sess, hound_context_id_t id);
    5353
     
    6060int hound_service_stream_read(async_exch_t *exch, void *data, size_t size);
    6161
     62/* Server */
     63typedef struct hound_server_iface {
     64        int (*add_context)(void *, hound_context_id_t *, const char *, bool);
     65        int (*rem_context)(void *, hound_context_id_t);
     66        int (*add_stream)(void *, hound_context_id_t, int, pcm_format_t, size_t,
     67            void **);
     68        int (*rem_stream)(void *, void *);
     69        int (*stream_data_write)(void *, const void *, size_t);
     70        int (*stream_data_read)(void *, void *, size_t);
     71        void *server;
     72} hound_server_iface_t;
     73
     74void hound_service_set_server_iface(hound_server_iface_t *iface);
     75
     76void hound_connection_handler(ipc_callid_t iid, ipc_call_t *icall, void *arg);
    6277
    6378#endif
  • uspace/lib/hound/include/hound/server.h

    rbd5860f rb66d43b  
    4040#include <stdbool.h>
    4141#include <loc.h>
    42 #include <pcm/sample_format.h>
     42#include <pcm/format.h>
     43
     44
    4345
    4446enum {
  • uspace/lib/hound/src/protocol.c

    rbd5860f rb66d43b  
    4949        IPC_M_HOUND_CONTEXT_REGISTER = IPC_FIRST_USER_METHOD,
    5050        IPC_M_HOUND_CONTEXT_UNREGISTER,
    51         IPC_M_HOUND_STREAM_START,
    52         IPC_M_HOUND_STREAM_STOP,
     51        IPC_M_HOUND_STREAM_ENTER,
     52        IPC_M_HOUND_STREAM_EXIT,
    5353        IPC_M_HOUND_STREAM_DRAIN,
    54         IPC_M_HOUND_STREAM_WRITE,
    55         IPC_M_HOUND_STREAM_READ,
    5654};
     55
     56/****
     57 * CLIENT
     58 ****/
    5759
    5860const char *HOUND_SERVICE = "audio/hound";
     
    7577
    7678hound_context_id_t hound_service_register_context(hound_sess_t *sess,
    77     const char *name)
     79    const char *name, bool record)
    7880{
    7981        assert(sess);
    8082        assert(name);
    8183        async_exch_t *exch = async_exchange_begin(sess);
    82         const int ret =
    83             async_req_1_0(exch, IPC_M_HOUND_CONTEXT_REGISTER, str_size(name));
    84         //TODO send the string
     84        sysarg_t id;
     85        int ret =
     86            async_req_1_1(exch, IPC_M_HOUND_CONTEXT_REGISTER, record, &id);
     87        if (ret == EOK)
     88                ret = async_data_write_start(exch, name, str_size(name));
    8589        async_exchange_end(exch);
    86         return ret;
     90        return ret == EOK ? (hound_context_id_t)id : ret;
    8791}
    8892
     
    100104    int flags, pcm_format_t format, size_t bsize)
    101105{
     106        union {
     107                sysarg_t arg;
     108                pcm_format_t format;
     109        } convert = { .format = format };
     110        return async_req_4_0(exch, IPC_M_HOUND_STREAM_ENTER, id, flags,
     111            convert.arg, bsize);
     112}
     113
     114int hound_service_stream_exit(async_exch_t *exch)
     115{
     116        return async_req_0_0(exch, IPC_M_HOUND_STREAM_EXIT);
     117}
     118
     119int hound_service_stream_drain(async_exch_t *exch)
     120{
     121        //TODO implement
    102122        return ENOTSUP;
    103123}
    104124
    105 int hound_service_stream_exit(async_exch_t *exch)
    106 {
     125int hound_service_stream_write(async_exch_t *exch, const void *data, size_t size)
     126{
     127        return async_data_write_start(exch, data, size);
     128}
     129
     130int hound_service_stream_read(async_exch_t *exch, void *data, size_t size)
     131{
     132        //TODO implement
    107133        return ENOTSUP;
    108134}
    109135
    110 int hound_service_stream_drain(async_exch_t *exch)
    111 {
    112         return ENOTSUP;
    113 }
    114 
    115 int hound_service_stream_write(async_exch_t *exch, const void *data, size_t size)
    116 {
    117         return ENOTSUP;
    118 }
    119 
    120 int hound_service_stream_read(async_exch_t *exch, void *data, size_t size)
    121 {
    122         return ENOTSUP;
    123 }
    124 
     136/****
     137 * SERVER
     138 ****/
     139
     140static int hound_server_read_data(void *stream);
     141static hound_server_iface_t *server_iface;
     142
     143void hound_service_set_server_iface(hound_server_iface_t *iface)
     144{
     145        server_iface = iface;
     146}
     147
     148void hound_connection_handler(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     149{
     150        /* Accept connection if there is a valid iface*/
     151        if (server_iface) {
     152                async_answer_0(iid, EOK);
     153        } else {
     154                async_answer_0(iid, ENOTSUP);
     155                return;
     156        }
     157
     158        while (1) {
     159                ipc_call_t call;
     160                ipc_callid_t callid = async_get_call(&call);
     161                switch(IPC_GET_IMETHOD(call)) {
     162                case IPC_M_HOUND_CONTEXT_REGISTER: {
     163                        if (!server_iface || !server_iface->add_context) {
     164                                async_answer_0(callid, ENOTSUP);
     165                                break;
     166                        }
     167                        bool record = IPC_GET_ARG1(call);
     168                        void *name;
     169                        int ret =
     170                            async_data_write_accept(&name, true, 0, 0, 0, 0);
     171                        if (ret != EOK) {
     172                                async_answer_0(callid, ret);
     173                                break;
     174                        }
     175                        hound_context_id_t id = 0;
     176                        ret = server_iface->add_context(server_iface->server,
     177                            &id, name, record);
     178                        if (ret != EOK) {
     179                                free(name);
     180                                async_answer_0(callid, ret);
     181                                break;
     182                        }
     183                        async_answer_1(callid, EOK, id);
     184                }
     185                case IPC_M_HOUND_STREAM_ENTER: {
     186                        if (!server_iface || !server_iface->add_stream) {
     187                                async_answer_0(callid, ENOTSUP);
     188                                break;
     189                        }
     190
     191                        hound_context_id_t id = IPC_GET_ARG1(call);
     192                        int flags = IPC_GET_ARG2(call);
     193                        union {
     194                                sysarg_t arg;
     195                                pcm_format_t format;
     196                        } convert = { .arg = IPC_GET_ARG3(call) };
     197                        size_t bsize = IPC_GET_ARG4(call);
     198                        void *stream;
     199                        int ret = server_iface->add_stream(server_iface->server,
     200                            id, flags, convert.format, bsize, &stream);
     201                        if (ret != EOK) {
     202                                async_answer_0(callid, ret);
     203                                break;
     204                        }
     205                        hound_server_read_data(stream);
     206                        break;
     207                }
     208                case IPC_M_HOUND_CONTEXT_UNREGISTER:
     209                case IPC_M_HOUND_STREAM_EXIT:
     210                case IPC_M_HOUND_STREAM_DRAIN:
     211                default:
     212                        async_answer_0(callid, ENOTSUP);
     213                        return;
     214                }
     215        }
     216}
     217
     218static int hound_server_read_data(void *stream)
     219{
     220        if (!server_iface || !server_iface->stream_data_write)
     221                return ENOTSUP;
     222
     223        ipc_callid_t callid;
     224        size_t size = 0;
     225        while (async_data_write_receive(&callid, &size)) {
     226                char *buffer = malloc(size);
     227                if (!buffer) {
     228                        async_answer_0(callid, ENOMEM);
     229                        continue;
     230                }
     231                int ret = async_data_write_finalize(callid, buffer, size);
     232                if (ret == EOK) {
     233                        server_iface->stream_data_write(stream, buffer, size);
     234                } else {
     235                        // TODO did answering fail?
     236                        async_answer_0(callid, ret);
     237                }
     238        }
     239        //TODO we assume that the fail was caused by IPC_M_HOUND_STREAM_EXIT
     240        async_answer_0(callid, EOK);
     241        return EOK;
     242}
    125243
    126244/***
    127  * CLIENT SIDE
     245 * CLIENT SIDE -DEPRECATED
    128246 ***/
    129247
     
    348466
    349467/***
    350  * SERVER SIDE
     468 * SERVER SIDE - DEPRECATED
    351469 ***/
     470
    352471static const char * get_name(void);
    353472
Note: See TracChangeset for help on using the changeset viewer.