~diwic/ubuntu/lucid/pulseaudio/bugfixes

« back to all changes in this revision

Viewing changes to src/pulsecore/protocol-cli.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2008-11-04 15:46:00 UTC
  • mfrom: (1.2.1 upstream) (1.1.6 lenny)
  • Revision ID: james.westby@ubuntu.com-20081104154600-hlzknpcazaam0nxm
Tags: 0.9.13-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Don't build against, and create jack package. Jack is not in main.
  - Remove --disable-per-user-esound-socket from configure flags, as we still
    want per user esound sockets.
  - Remove stop links from rc0 and rc6.
  - Change default resample algorithm and bubffer size.
  - Add alsa configuration files to route alsa applications via pulseaudio.
  - Move libasound2-plugins from Recommends to Depends.
* debian/pulseaudio.preinst: When upgrading from intrepid, remove
  /etc/X11/Xsession.d/70pulseaudio, as this was used to minimize a race
  condition when starting GNOME in intrepid. This race should not exist in
  jaunty once libcanberra is built to use pulseaudio as a backend.
* Do not spawn a pulseaudio server if clients fail to find a running server.
* Remove explicit version dependency for libspeex-dev to allow the package
  to be built for now.
* Regenerate autotools files to work with Ubuntu's newer libtool/libltdl.
* debian/control: libpulsecore5 -> libpulsecore8 to match the library
  soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: protocol-cli.c 1971 2007-10-28 19:13:50Z lennart $ */
2
 
 
3
1
/***
4
2
  This file is part of PulseAudio.
5
3
 
32
30
#include <pulsecore/cli.h>
33
31
#include <pulsecore/log.h>
34
32
#include <pulsecore/macro.h>
 
33
#include <pulsecore/shared.h>
35
34
 
36
35
#include "protocol-cli.h"
37
36
 
38
37
/* Don't allow more than this many concurrent connections */
39
38
#define MAX_CONNECTIONS 25
40
39
 
41
 
struct pa_protocol_cli {
42
 
    pa_module *module;
 
40
struct pa_cli_protocol {
 
41
    PA_REFCNT_DECLARE;
 
42
 
43
43
    pa_core *core;
44
 
    pa_socket_server*server;
45
44
    pa_idxset *connections;
46
45
};
47
46
 
48
 
static void cli_eof_cb(pa_cli*c, void*userdata) {
49
 
    pa_protocol_cli *p = userdata;
 
47
static void cli_unlink(pa_cli_protocol *p, pa_cli *c) {
50
48
    pa_assert(p);
 
49
    pa_assert(c);
51
50
 
52
51
    pa_idxset_remove_by_data(p->connections, c, NULL);
53
52
    pa_cli_free(c);
54
53
}
55
54
 
56
 
static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) {
57
 
    pa_protocol_cli *p = userdata;
 
55
static void cli_eof_cb(pa_cli*c, void*userdata) {
 
56
    pa_cli_protocol *p = userdata;
 
57
    pa_assert(p);
 
58
 
 
59
    cli_unlink(p, c);
 
60
}
 
61
 
 
62
void pa_cli_protocol_connect(pa_cli_protocol *p, pa_iochannel *io, pa_module *m) {
58
63
    pa_cli *c;
59
64
 
60
 
    pa_assert(s);
 
65
    pa_assert(p);
61
66
    pa_assert(io);
62
 
    pa_assert(p);
 
67
    pa_assert(m);
63
68
 
64
69
    if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
65
70
        pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
67
72
        return;
68
73
    }
69
74
 
70
 
    c = pa_cli_new(p->core, io, p->module);
 
75
    c = pa_cli_new(p->core, io, m);
71
76
    pa_cli_set_eof_callback(c, cli_eof_cb, p);
72
77
 
73
78
    pa_idxset_put(p->connections, c, NULL);
74
79
}
75
80
 
76
 
pa_protocol_cli* pa_protocol_cli_new(pa_core *core, pa_socket_server *server, pa_module *m, PA_GCC_UNUSED pa_modargs *ma) {
77
 
    pa_protocol_cli* p;
78
 
 
79
 
    pa_core_assert_ref(core);
80
 
    pa_assert(server);
81
 
 
82
 
    p = pa_xnew(pa_protocol_cli, 1);
83
 
    p->module = m;
84
 
    p->core = core;
85
 
    p->server = server;
 
81
void pa_cli_protocol_disconnect(pa_cli_protocol *p, pa_module *m) {
 
82
    pa_cli *c;
 
83
    void *state = NULL;
 
84
 
 
85
    pa_assert(p);
 
86
    pa_assert(m);
 
87
 
 
88
    while ((c = pa_idxset_iterate(p->connections, &state, NULL)))
 
89
        if (pa_cli_get_module(c) == m)
 
90
            cli_unlink(p, c);
 
91
}
 
92
 
 
93
static pa_cli_protocol* cli_protocol_new(pa_core *c) {
 
94
    pa_cli_protocol *p;
 
95
 
 
96
    pa_assert(c);
 
97
 
 
98
    p = pa_xnew(pa_cli_protocol, 1);
 
99
    PA_REFCNT_INIT(p);
 
100
    p->core = c;
86
101
    p->connections = pa_idxset_new(NULL, NULL);
87
102
 
88
 
    pa_socket_server_set_callback(p->server, on_connection, p);
89
 
 
90
 
    return p;
91
 
}
92
 
 
93
 
static void free_connection(void *p, PA_GCC_UNUSED void *userdata) {
94
 
    pa_assert(p);
95
 
 
96
 
    pa_cli_free(p);
97
 
}
98
 
 
99
 
void pa_protocol_cli_free(pa_protocol_cli *p) {
100
 
    pa_assert(p);
101
 
 
102
 
    pa_idxset_free(p->connections, free_connection, NULL);
103
 
    pa_socket_server_unref(p->server);
 
103
    pa_assert_se(pa_shared_set(c, "cli-protocol", p) >= 0);
 
104
 
 
105
    return p;
 
106
}
 
107
 
 
108
pa_cli_protocol* pa_cli_protocol_get(pa_core *c) {
 
109
    pa_cli_protocol *p;
 
110
 
 
111
    if ((p = pa_shared_get(c, "cli-protocol")))
 
112
        return pa_cli_protocol_ref(p);
 
113
 
 
114
    return cli_protocol_new(c);
 
115
}
 
116
 
 
117
pa_cli_protocol* pa_cli_protocol_ref(pa_cli_protocol *p) {
 
118
    pa_assert(p);
 
119
    pa_assert(PA_REFCNT_VALUE(p) >= 1);
 
120
 
 
121
    PA_REFCNT_INC(p);
 
122
 
 
123
    return p;
 
124
}
 
125
 
 
126
void pa_cli_protocol_unref(pa_cli_protocol *p) {
 
127
    pa_cli *c;
 
128
    pa_assert(p);
 
129
    pa_assert(PA_REFCNT_VALUE(p) >= 1);
 
130
 
 
131
    if (PA_REFCNT_DEC(p) > 0)
 
132
        return;
 
133
 
 
134
    while ((c = pa_idxset_first(p->connections, NULL)))
 
135
        cli_unlink(p, c);
 
136
 
 
137
    pa_idxset_free(p->connections, NULL, NULL);
 
138
 
 
139
    pa_assert_se(pa_shared_remove(p->core, "cli-protocol") >= 0);
 
140
 
104
141
    pa_xfree(p);
105
142
}