~binli/ubuntu/vivid/pulseaudio/load-extcon-module

« back to all changes in this revision

Viewing changes to .pc/0409-Trust-store-patch.patch/src/pulsecore/client.c

  • Committer: Bin Li
  • Date: 2016-01-23 15:04:48 UTC
  • Revision ID: bin.li@canonical.com-20160123150448-5ockvw4p5xxntda4
init the 1:6.0-0ubuntu9.15 from silo 12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***
 
2
  This file is part of PulseAudio.
 
3
 
 
4
  Copyright 2004-2006 Lennart Poettering
 
5
  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
 
6
 
 
7
  PulseAudio is free software; you can redistribute it and/or modify
 
8
  it under the terms of the GNU Lesser General Public License as published
 
9
  by the Free Software Foundation; either version 2.1 of the License,
 
10
  or (at your option) any later version.
 
11
 
 
12
  PulseAudio is distributed in the hope that it will be useful, but
 
13
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
15
  General Public License for more details.
 
16
 
 
17
  You should have received a copy of the GNU Lesser General Public License
 
18
  along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
 
19
***/
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
 
24
 
 
25
#include <stdio.h>
 
26
#include <stdlib.h>
 
27
#include <string.h>
 
28
 
 
29
#include <pulse/xmalloc.h>
 
30
#include <pulse/util.h>
 
31
 
 
32
#include <pulsecore/core-subscribe.h>
 
33
#include <pulsecore/log.h>
 
34
#include <pulsecore/macro.h>
 
35
#include <pulsecore/core-util.h>
 
36
 
 
37
#include "client.h"
 
38
 
 
39
pa_client_new_data* pa_client_new_data_init(pa_client_new_data *data) {
 
40
    pa_assert(data);
 
41
 
 
42
    memset(data, 0, sizeof(*data));
 
43
    data->proplist = pa_proplist_new();
 
44
 
 
45
    return data;
 
46
}
 
47
 
 
48
void pa_client_new_data_done(pa_client_new_data *data) {
 
49
    pa_assert(data);
 
50
 
 
51
    pa_proplist_free(data->proplist);
 
52
}
 
53
 
 
54
pa_client *pa_client_new(pa_core *core, pa_client_new_data *data) {
 
55
    pa_client *c;
 
56
 
 
57
    pa_core_assert_ref(core);
 
58
    pa_assert(data);
 
59
 
 
60
    if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_NEW], data) < 0)
 
61
        return NULL;
 
62
 
 
63
    c = pa_xnew(pa_client, 1);
 
64
    c->core = core;
 
65
    c->proplist = pa_proplist_copy(data->proplist);
 
66
    c->driver = pa_xstrdup(pa_path_get_filename(data->driver));
 
67
    c->module = data->module;
 
68
 
 
69
    c->sink_inputs = pa_idxset_new(NULL, NULL);
 
70
    c->source_outputs = pa_idxset_new(NULL, NULL);
 
71
 
 
72
    c->userdata = NULL;
 
73
    c->kill = NULL;
 
74
    c->send_event = NULL;
 
75
 
 
76
    pa_assert_se(pa_idxset_put(core->clients, c, &c->index) >= 0);
 
77
 
 
78
    pa_log_info("Created %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
 
79
    pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
 
80
 
 
81
    pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_PUT], c);
 
82
 
 
83
    pa_core_check_idle(core);
 
84
 
 
85
    return c;
 
86
}
 
87
 
 
88
void pa_client_free(pa_client *c) {
 
89
    pa_core *core;
 
90
 
 
91
    pa_assert(c);
 
92
    pa_assert(c->core);
 
93
 
 
94
    core = c->core;
 
95
 
 
96
    pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_UNLINK], c);
 
97
 
 
98
    pa_idxset_remove_by_data(c->core->clients, c, NULL);
 
99
 
 
100
    pa_log_info("Freed %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
 
101
    pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
 
102
 
 
103
    pa_assert(pa_idxset_isempty(c->sink_inputs));
 
104
    pa_idxset_free(c->sink_inputs, NULL);
 
105
    pa_assert(pa_idxset_isempty(c->source_outputs));
 
106
    pa_idxset_free(c->source_outputs, NULL);
 
107
 
 
108
    pa_proplist_free(c->proplist);
 
109
    pa_xfree(c->driver);
 
110
    pa_xfree(c);
 
111
 
 
112
    pa_core_check_idle(core);
 
113
}
 
114
 
 
115
void pa_client_kill(pa_client *c) {
 
116
    pa_assert(c);
 
117
 
 
118
    if (!c->kill) {
 
119
        pa_log_warn("kill() operation not implemented for client %u", c->index);
 
120
        return;
 
121
    }
 
122
 
 
123
    c->kill(c);
 
124
}
 
125
 
 
126
void pa_client_set_name(pa_client *c, const char *name) {
 
127
    pa_assert(c);
 
128
    pa_assert(name);
 
129
 
 
130
    pa_log_info("Client %u changed name from \"%s\" to \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)), name);
 
131
    pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
 
132
 
 
133
    pa_client_update_proplist(c, 0, NULL);
 
134
}
 
135
 
 
136
void pa_client_update_proplist(pa_client *c, pa_update_mode_t mode, pa_proplist *p) {
 
137
    pa_assert(c);
 
138
 
 
139
    if (p)
 
140
        pa_proplist_update(c->proplist, mode, p);
 
141
 
 
142
    pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], c);
 
143
    pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
 
144
}
 
145
 
 
146
void pa_client_send_event(pa_client *c, const char *event, pa_proplist *data) {
 
147
    pa_proplist *pl = NULL;
 
148
    pa_client_send_event_hook_data hook_data;
 
149
 
 
150
    pa_assert(c);
 
151
    pa_assert(event);
 
152
 
 
153
    if (!c->send_event)
 
154
        return;
 
155
 
 
156
    if (!data)
 
157
        data = pl = pa_proplist_new();
 
158
 
 
159
    hook_data.client = c;
 
160
    hook_data.data = data;
 
161
    hook_data.event = event;
 
162
 
 
163
    if (pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_SEND_EVENT], &hook_data) < 0)
 
164
        goto finish;
 
165
 
 
166
    c->send_event(c, event, data);
 
167
 
 
168
finish:
 
169
 
 
170
    if (pl)
 
171
        pa_proplist_free(pl);
 
172
}