]>
code.delx.au - pulseaudio/blob - src/modules/howl-wrap.c
e56fca3e76ad7027d90b2977b477f327b7533394
4 This file is part of PulseAudio.
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 #include <pulse/xmalloc.h>
26 #include <pulsecore/log.h>
27 #include <pulsecore/props.h>
29 #include "howl-wrap.h"
31 #define HOWL_PROPERTY "howl"
33 struct pa_howl_wrapper
{
37 pa_io_event
*io_event
;
38 sw_discovery discovery
;
41 static void howl_io_event(pa_mainloop_api
*m
, pa_io_event
*e
, int fd
, pa_io_event_flags_t f
, void *userdata
) {
42 pa_howl_wrapper
*w
= userdata
;
43 assert(m
&& e
&& fd
>= 0 && w
&& w
->ref
>= 1);
45 if (f
& (PA_IO_EVENT_HANGUP
|PA_IO_EVENT_ERROR
))
48 if (sw_discovery_read_socket(w
->discovery
) != SW_OKAY
)
54 pa_log_error(__FILE__
": howl connection died.");
55 w
->core
->mainloop
->io_free(w
->io_event
);
59 static pa_howl_wrapper
* howl_wrapper_new(pa_core
*c
) {
64 if (sw_discovery_init(&session
) != SW_OKAY
) {
65 pa_log_error(__FILE__
": sw_discovery_init() failed.");
69 h
= pa_xmalloc(sizeof(pa_howl_wrapper
));
72 h
->discovery
= session
;
74 h
->io_event
= c
->mainloop
->io_new(c
->mainloop
, sw_discovery_socket(session
), PA_IO_EVENT_INPUT
, howl_io_event
, h
);
79 static void howl_wrapper_free(pa_howl_wrapper
*h
) {
82 sw_discovery_fina(h
->discovery
);
85 h
->core
->mainloop
->io_free(h
->io_event
);
90 pa_howl_wrapper
* pa_howl_wrapper_get(pa_core
*c
) {
94 if ((h
= pa_property_get(c
, HOWL_PROPERTY
)))
95 return pa_howl_wrapper_ref(h
);
97 return howl_wrapper_new(c
);
100 pa_howl_wrapper
* pa_howl_wrapper_ref(pa_howl_wrapper
*h
) {
101 assert(h
&& h
->ref
>= 1);
106 void pa_howl_wrapper_unref(pa_howl_wrapper
*h
) {
107 assert(h
&& h
->ref
>= 1);
109 howl_wrapper_free(h
);
112 sw_discovery
pa_howl_wrapper_get_discovery(pa_howl_wrapper
*h
) {
113 assert(h
&& h
->ref
>= 1);