[737b4c0] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Jan Vesely
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * @addtogroup audio
|
---|
| 31 | * @brief HelenOS sound server.
|
---|
| 32 | * @{
|
---|
| 33 | */
|
---|
| 34 | /** @file
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <async.h>
|
---|
| 38 | #include <errno.h>
|
---|
[e5bc912] | 39 | #include <inttypes.h>
|
---|
[737b4c0] | 40 | #include <stdio.h>
|
---|
| 41 | #include <stdlib.h>
|
---|
| 42 | #include <str_error.h>
|
---|
[eceb300] | 43 | #include <hound/server.h>
|
---|
[4389076] | 44 | #include <hound/protocol.h>
|
---|
[1c635d6] | 45 | #include <task.h>
|
---|
[737b4c0] | 46 |
|
---|
| 47 | #include "hound.h"
|
---|
| 48 |
|
---|
| 49 | #define NAMESPACE "audio"
|
---|
| 50 | #define NAME "hound"
|
---|
| 51 | #define CATEGORY "audio-pcm"
|
---|
| 52 |
|
---|
| 53 | #include "log.h"
|
---|
[1df3018a] | 54 |
|
---|
[4389076] | 55 | extern hound_server_iface_t hound_iface;
|
---|
| 56 |
|
---|
[1df3018a] | 57 | static hound_t hound;
|
---|
| 58 |
|
---|
[46577995] | 59 | static errno_t device_callback(service_id_t id, const char *name)
|
---|
[1df3018a] | 60 | {
|
---|
[eceb300] | 61 | return hound_add_device(&hound, id, name);
|
---|
[1df3018a] | 62 | }
|
---|
[737b4c0] | 63 |
|
---|
| 64 | static void scan_for_devices(void)
|
---|
| 65 | {
|
---|
[eceb300] | 66 | hound_server_devices_iterate(device_callback);
|
---|
[737b4c0] | 67 | }
|
---|
| 68 |
|
---|
| 69 | int main(int argc, char **argv)
|
---|
| 70 | {
|
---|
| 71 | printf("%s: HelenOS sound service\n", NAME);
|
---|
| 72 |
|
---|
[57a2208] | 73 | if (log_init(NAME) != EOK) {
|
---|
| 74 | printf(NAME ": Failed to initialize logging.\n");
|
---|
| 75 | return 1;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[46577995] | 78 | errno_t ret = hound_init(&hound);
|
---|
[737b4c0] | 79 | if (ret != EOK) {
|
---|
[1df3018a] | 80 | log_fatal("Failed to initialize hound structure: %s",
|
---|
| 81 | str_error(ret));
|
---|
[3b47db6] | 82 | return ret;
|
---|
[1df3018a] | 83 | }
|
---|
| 84 |
|
---|
[4389076] | 85 | hound_iface.server = &hound;
|
---|
| 86 | hound_service_set_server_iface(&hound_iface);
|
---|
[b688fd8] | 87 | async_set_fallback_port_handler(hound_connection_handler, NULL);
|
---|
[1df3018a] | 88 |
|
---|
| 89 | service_id_t id = 0;
|
---|
[eceb300] | 90 | ret = hound_server_register(NAME, &id);
|
---|
[1df3018a] | 91 | if (ret != EOK) {
|
---|
[eceb300] | 92 | log_fatal("Failed to register server: %s", str_error(ret));
|
---|
[3b47db6] | 93 | return ret;
|
---|
[737b4c0] | 94 | }
|
---|
| 95 |
|
---|
[eceb300] | 96 | ret = hound_server_set_device_change_callback(scan_for_devices);
|
---|
[1df3018a] | 97 | if (ret != EOK) {
|
---|
[eceb300] | 98 | log_fatal("Failed to register for device changes: %s",
|
---|
[1df3018a] | 99 | str_error(ret));
|
---|
[eceb300] | 100 | hound_server_unregister(id);
|
---|
[3b47db6] | 101 | return ret;
|
---|
[1df3018a] | 102 | }
|
---|
[e5bc912] | 103 | log_info("Running with service id %" PRIun, id);
|
---|
[737b4c0] | 104 |
|
---|
| 105 | scan_for_devices();
|
---|
[bb2a5b2] | 106 | task_retval(0);
|
---|
[737b4c0] | 107 | async_manager();
|
---|
| 108 | return 0;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | /**
|
---|
| 112 | * @}
|
---|
| 113 | */
|
---|