2 This file is part of PulseAudio.
4 Copyright 2009 Lennart Poettering
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 published
8 by the Free Software Foundation; either version 2 of the License,
9 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 License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <pulse/xmalloc.h>
32 #include <pulsecore/log.h>
33 #include <pulsecore/macro.h>
34 #include <pulsecore/core-util.h>
35 #include <pulsecore/namereg.h>
39 pa_card_profile
*pa_card_profile_new(const char *name
) {
44 c
= pa_xnew0(pa_card_profile
, 1);
45 c
->name
= pa_xstrdup(name
);
50 void pa_card_profile_free(pa_card_profile
*c
) {
57 pa_card_new_data
* pa_card_new_data_init(pa_card_new_data
*data
) {
60 memset(data
, 0, sizeof(*data
));
61 data
->proplist
= pa_proplist_new();
66 void pa_card_new_data_set_name(pa_card_new_data
*data
, const char *name
) {
70 data
->name
= pa_xstrdup(name
);
73 void pa_card_new_data_done(pa_card_new_data
*data
) {
77 pa_proplist_free(data
->proplist
);
82 while ((c
= pa_hashmap_steal_first(data
->profiles
)))
83 pa_card_profile_free(c
);
85 pa_hashmap_free(data
->profiles
, NULL
, NULL
);
91 pa_card
*pa_card_new(pa_core
*core
, pa_card_new_data
*data
) {
95 pa_core_assert_ref(core
);
97 pa_assert(data
->name
);
99 c
= pa_xnew(pa_card
, 1);
101 if (!(name
= pa_namereg_register(core
, data
->name
, PA_NAMEREG_CARD
, c
, data
->namereg_fail
))) {
106 pa_card_new_data_set_name(data
, name
);
108 if (pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_CARD_NEW
], data
) < 0) {
110 pa_namereg_unregister(core
, name
);
115 c
->name
= pa_xstrdup(data
->name
);
116 c
->proplist
= pa_proplist_copy(data
->proplist
);
117 c
->driver
= pa_xstrdup(data
->driver
);
118 c
->module
= data
->module
;
120 c
->sinks
= pa_idxset_new(NULL
, NULL
);
121 c
->sources
= pa_idxset_new(NULL
, NULL
);
123 c
->profiles
= data
->profiles
;
124 data
->profiles
= NULL
;
125 c
->active_profile
= data
->active_profile
;
126 data
->active_profile
= NULL
;
129 c
->set_profile
= NULL
;
131 pa_assert_se(pa_idxset_put(core
->cards
, c
, &c
->index
) >= 0);
133 pa_log_info("Created %u \"%s\"", c
->index
, c
->name
);
134 pa_subscription_post(core
, PA_SUBSCRIPTION_EVENT_CARD
|PA_SUBSCRIPTION_EVENT_NEW
, c
->index
);
136 pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_CARD_PUT
], c
);
140 void pa_card_free(pa_card
*c
) {
142 pa_card_profile
*profile
;
149 pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_CARD_UNLINK
], c
);
151 pa_namereg_unregister(core
, c
->name
);
153 pa_idxset_remove_by_data(c
->core
->cards
, c
, NULL
);
155 pa_log_info("Freed %u \"%s\"", c
->index
, c
->name
);
157 pa_subscription_post(c
->core
, PA_SUBSCRIPTION_EVENT_CARD
|PA_SUBSCRIPTION_EVENT_REMOVE
, c
->index
);
159 pa_assert(pa_idxset_isempty(c
->sinks
));
160 pa_idxset_free(c
->sinks
, NULL
, NULL
);
161 pa_assert(pa_idxset_isempty(c
->sources
));
162 pa_idxset_free(c
->sources
, NULL
, NULL
);
164 while ((profile
= pa_hashmap_steal_first(c
->profiles
)))
165 pa_card_profile_free(profile
);
167 pa_hashmap_free(c
->profiles
, NULL
, NULL
);
169 pa_proplist_free(c
->proplist
);
174 pa_core_check_idle(core
);
177 int pa_card_set_profile(pa_card
*c
, const char *name
) {
178 pa_card_profile
*profile
;
181 if (!c
->set_profile
) {
182 pa_log_warn("set_profile() operation not implemented for card %u", c
->index
);
189 if (!(profile
= pa_hashmap_get(c
->profiles
, name
)))
192 if (c
->set_profile(c
, profile
) < 0)
195 pa_subscription_post(c
->core
, PA_SUBSCRIPTION_EVENT_CARD
|PA_SUBSCRIPTION_EVENT_CHANGE
, c
->index
);