Changeset f465461 in mainline
- Timestamp:
- 2013-04-05T16:50:55Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7e7def5
- Parents:
- 60e5696d
- Location:
- uspace/lib/hound
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/hound/include/hound/client.h
r60e5696d rf465461 43 43 #define HOUND_DEFAULT_TARGET "default" 44 44 #define HOUND_ALL_TARGETS "all" 45 #define DEFAULT_SINK "default" //DEPRECATED46 45 47 46 typedef struct hound_context hound_context_t; … … 80 79 pcm_format_t format, const void *data, size_t size); 81 80 82 83 84 85 86 typedef async_sess_t hound_sess_t;87 88 typedef void (*data_callback_t)(void *, void *, ssize_t);89 90 hound_sess_t *hound_get_session(void);91 void hound_release_session(hound_sess_t *sess);92 int hound_register_playback(hound_sess_t *sess, const char *name,93 unsigned channels, unsigned rate, pcm_sample_format_t format,94 data_callback_t data_callback, void *arg);95 int hound_register_recording(hound_sess_t *sess, const char *name,96 unsigned channels, unsigned rate, pcm_sample_format_t format,97 data_callback_t data_callback, void *arg);98 int hound_unregister_playback(hound_sess_t *sess, const char *name);99 int hound_unregister_recording(hound_sess_t *sess, const char *name);100 int hound_create_connection(hound_sess_t *sess, const char *source, const char *sink);101 int hound_destroy_connection(hound_sess_t *sess, const char *source, const char *sink);102 103 81 #endif -
uspace/lib/hound/src/protocol.c
r60e5696d rf465461 555 555 556 556 /*** 557 * CLIENT SIDE -DEPRECATED558 ***/559 560 typedef struct {561 data_callback_t cb;562 void *arg;563 } callback_t;564 565 hound_sess_t *hound_get_session(void)566 {567 return hound_service_connect(HOUND_SERVICE);568 }569 570 void hound_release_session(hound_sess_t *sess)571 {572 hound_service_disconnect(sess);573 }574 575 576 static int hound_register(hound_sess_t *sess, unsigned cmd, const char *name,577 unsigned channels, unsigned rate, pcm_sample_format_t format,578 data_callback_t data_callback, void *arg);579 static int hound_unregister(hound_sess_t *sess, unsigned cmd, const char *name);580 static int hound_connection(hound_sess_t *sess, unsigned cmd,581 const char *source, const char *sink);582 static void callback_pb(ipc_callid_t iid, ipc_call_t *call, void *arg);583 static void callback_rec(ipc_callid_t iid, ipc_call_t *call, void *arg);584 585 586 int hound_register_playback(hound_sess_t *sess, const char *name,587 unsigned channels, unsigned rate, pcm_sample_format_t format,588 data_callback_t data_callback, void *arg)589 {590 return hound_register(sess, HOUND_REGISTER_PLAYBACK, name, channels,591 rate, format, data_callback, arg);592 }593 int hound_register_recording(hound_sess_t *sess, const char *name,594 unsigned channels, unsigned rate, pcm_sample_format_t format,595 data_callback_t data_callback, void *arg)596 {597 return hound_register(sess, HOUND_REGISTER_RECORDING, name, channels,598 rate, format, data_callback, arg);599 600 }601 int hound_unregister_playback(hound_sess_t *sess, const char *name)602 {603 return hound_unregister(sess, HOUND_UNREGISTER_PLAYBACK, name);604 }605 int hound_unregister_recording(hound_sess_t *sess, const char *name)606 {607 return hound_unregister(sess, HOUND_UNREGISTER_RECORDING, name);608 }609 int hound_create_connection(hound_sess_t *sess, const char *source, const char *sink)610 {611 return hound_connection(sess, HOUND_CONNECT, source, sink);612 }613 int hound_destroy_connection(hound_sess_t *sess, const char *source, const char *sink)614 {615 return hound_connection(sess, HOUND_DISCONNECT, source, sink);616 }617 618 static int hound_register(hound_sess_t *sess, unsigned cmd, const char *name,619 unsigned channels, unsigned rate, pcm_sample_format_t format,620 data_callback_t data_callback, void *arg)621 {622 assert(cmd == HOUND_REGISTER_PLAYBACK || cmd == HOUND_REGISTER_RECORDING);623 if (!name || !data_callback || !sess)624 return EINVAL;625 626 async_exch_t *exch = async_exchange_begin(sess);627 if (!exch)628 return ENOMEM;629 630 aid_t id = async_send_0(exch, cmd, NULL);631 632 int ret = async_data_write_start(exch, name, str_size(name));633 if (ret != EOK) {634 async_forget(id);635 async_exchange_end(exch);636 return ret;637 }638 639 callback_t *cb = malloc(sizeof(callback_t));640 if (!cb) {641 async_forget(id);642 async_exchange_end(exch);643 return ENOMEM;644 }645 646 cb->cb = data_callback;647 cb->arg = arg;648 async_client_conn_t callback =649 (cmd == HOUND_REGISTER_PLAYBACK) ? callback_pb : callback_rec;650 651 ret = async_connect_to_me(exch, channels, rate, format, callback, cb);652 if (ret != EOK) {653 async_forget(id);654 async_exchange_end(exch);655 free(cb);656 return ret;657 }658 659 async_wait_for(id, (sysarg_t*)&ret);660 if (ret != EOK) {661 async_exchange_end(exch);662 free(cb);663 return ret;664 }665 666 async_exchange_end(exch);667 return EOK;668 }669 670 static int hound_unregister(hound_sess_t *sess, unsigned cmd, const char *name)671 {672 assert(cmd == HOUND_UNREGISTER_PLAYBACK || cmd == HOUND_UNREGISTER_RECORDING);673 if (!name || !sess)674 return EINVAL;675 676 async_exch_t *exch = async_exchange_begin(sess);677 if (!exch)678 return ENOMEM;679 aid_t id = async_send_0(exch, cmd, NULL);680 sysarg_t ret = async_data_write_start(exch, name, str_size(name));681 if (ret != EOK) {682 async_forget(id);683 async_exchange_end(exch);684 return ret;685 }686 687 async_wait_for(id, &ret);688 async_exchange_end(exch);689 return ret;690 }691 692 static int hound_connection(hound_sess_t *sess, unsigned cmd,693 const char *source, const char *sink)694 {695 assert(cmd == HOUND_CONNECT || cmd == HOUND_DISCONNECT);696 if (!source || !sink || !sess)697 return EINVAL;698 699 async_exch_t *exch = async_exchange_begin(sess);700 if (!exch)701 return ENOMEM;702 703 aid_t id = async_send_0(exch, cmd, NULL);704 sysarg_t ret = async_data_write_start(exch, source, str_size(source));705 if (ret != EOK) {706 async_forget(id);707 async_exchange_end(exch);708 return ret;709 }710 ret = async_data_write_start(exch, sink, str_size(sink));711 if (ret != EOK) {712 async_forget(id);713 async_exchange_end(exch);714 return ret;715 }716 async_wait_for(id, &ret);717 async_exchange_end(exch);718 return ret;719 }720 static void callback_gen(ipc_callid_t iid, ipc_call_t *call, void *arg,721 bool read)722 {723 async_answer_0(iid, EOK);724 callback_t *cb = arg;725 assert(cb);726 void *buffer = NULL;727 size_t buffer_size = 0;728 729 bool (*receive)(ipc_callid_t *, size_t *) = read ?730 async_data_read_receive : async_data_write_receive;731 732 while (1) {733 size_t size = 0;734 ipc_callid_t id = 0;735 if (!receive(&id, &size)) {736 ipc_call_t failed_call;737 async_get_call(&failed_call);738 /* Protocol error or hangup */739 if (IPC_GET_IMETHOD(failed_call) != 0)740 cb->cb(cb->arg, NULL, EIO);741 free(cb);742 return;743 }744 745 if (buffer_size < size) {746 buffer = realloc(buffer, size);747 if (!buffer) {748 cb->cb(cb->arg, NULL, ENOMEM);749 free(cb);750 return;751 }752 buffer_size = size;753 }754 if (read)755 cb->cb(cb->arg, buffer, size);756 const int ret = read ?757 async_data_read_finalize(id, buffer, size):758 async_data_write_finalize(id, buffer, size);759 if (ret != EOK) {760 cb->cb(cb->arg, NULL, ret);761 free(cb);762 return;763 }764 if (!read)765 cb->cb(cb->arg, buffer, size);766 }767 }768 769 static void callback_pb(ipc_callid_t iid, ipc_call_t *call, void *arg)770 {771 callback_gen(iid, call, arg, true);772 }773 774 static void callback_rec(ipc_callid_t iid, ipc_call_t *call, void *arg)775 {776 callback_gen(iid, call, arg, false);777 }778 779 /***780 557 * SERVER SIDE - DEPRECATED 781 558 ***/
Note:
See TracChangeset
for help on using the changeset viewer.