mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-07 13:30:03 -05:00
dbusiface-card-profile: Implement the CardProfile D-Bus interface.
This commit is contained in:
parent
acad506328
commit
8c8df77d2a
4 changed files with 163 additions and 3 deletions
|
|
@ -23,26 +23,178 @@
|
|||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include <pulsecore/core-util.h>
|
||||
#include <pulsecore/dbus-util.h>
|
||||
|
||||
#include "iface-card-profile.h"
|
||||
|
||||
#define OBJECT_NAME "profile"
|
||||
|
||||
static void handle_get_index(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||
static void handle_get_name(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||
static void handle_get_description(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||
static void handle_get_sinks(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||
static void handle_get_sources(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||
static void handle_get_priority(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||
|
||||
static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdata);
|
||||
|
||||
struct pa_dbusiface_card_profile {
|
||||
uint32_t index;
|
||||
pa_card_profile *profile;
|
||||
char *path;
|
||||
pa_dbus_protocol *dbus_protocol;
|
||||
};
|
||||
|
||||
pa_dbusiface_card_profile *pa_dbusiface_card_profile_new(pa_dbusiface_card *card, pa_card_profile *profile, uint32_t idx) {
|
||||
enum property_handler_index {
|
||||
PROPERTY_HANDLER_INDEX,
|
||||
PROPERTY_HANDLER_NAME,
|
||||
PROPERTY_HANDLER_DESCRIPTION,
|
||||
PROPERTY_HANDLER_SINKS,
|
||||
PROPERTY_HANDLER_SOURCES,
|
||||
PROPERTY_HANDLER_PRIORITY,
|
||||
PROPERTY_HANDLER_MAX
|
||||
};
|
||||
|
||||
static pa_dbus_property_handler property_handlers[PROPERTY_HANDLER_MAX] = {
|
||||
[PROPERTY_HANDLER_INDEX] = { .property_name = "Index", .type = "u", .get_cb = handle_get_index, .set_cb = NULL },
|
||||
[PROPERTY_HANDLER_NAME] = { .property_name = "Name", .type = "s", .get_cb = handle_get_name, .set_cb = NULL },
|
||||
[PROPERTY_HANDLER_DESCRIPTION] = { .property_name = "Description", .type = "s", .get_cb = handle_get_description, .set_cb = NULL },
|
||||
[PROPERTY_HANDLER_SINKS] = { .property_name = "Sinks", .type = "u", .get_cb = handle_get_sinks, .set_cb = NULL },
|
||||
[PROPERTY_HANDLER_SOURCES] = { .property_name = "Sources", .type = "u", .get_cb = handle_get_sources, .set_cb = NULL },
|
||||
[PROPERTY_HANDLER_PRIORITY] = { .property_name = "Priority", .type = "u", .get_cb = handle_get_priority, .set_cb = NULL },
|
||||
};
|
||||
|
||||
static pa_dbus_interface_info profile_interface_info = {
|
||||
.name = PA_DBUSIFACE_CARD_PROFILE_INTERFACE,
|
||||
.method_handlers = NULL,
|
||||
.n_method_handlers = 0,
|
||||
.property_handlers = property_handlers,
|
||||
.n_property_handlers = PROPERTY_HANDLER_MAX,
|
||||
.get_all_properties_cb = handle_get_all,
|
||||
.signals = NULL,
|
||||
.n_signals = 0
|
||||
};
|
||||
|
||||
static void handle_get_index(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||
pa_dbusiface_card_profile *p = userdata;
|
||||
|
||||
pa_assert(conn);
|
||||
pa_assert(msg);
|
||||
pa_assert(p);
|
||||
|
||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &p->index);
|
||||
}
|
||||
|
||||
static void handle_get_name(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||
pa_dbusiface_card_profile *p = userdata;
|
||||
|
||||
pa_assert(conn);
|
||||
pa_assert(msg);
|
||||
pa_assert(p);
|
||||
|
||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_STRING, &p->profile->name);
|
||||
}
|
||||
|
||||
static void handle_get_description(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||
pa_dbusiface_card_profile *p = userdata;
|
||||
|
||||
pa_assert(conn);
|
||||
pa_assert(msg);
|
||||
pa_assert(p);
|
||||
|
||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_STRING, &p->profile->description);
|
||||
}
|
||||
|
||||
static void handle_get_sinks(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||
pa_dbusiface_card_profile *p = userdata;
|
||||
dbus_uint32_t sinks = 0;
|
||||
|
||||
pa_assert(conn);
|
||||
pa_assert(msg);
|
||||
pa_assert(p);
|
||||
|
||||
sinks = p->profile->n_sinks;
|
||||
|
||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &sinks);
|
||||
}
|
||||
|
||||
static void handle_get_sources(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||
pa_dbusiface_card_profile *p = userdata;
|
||||
dbus_uint32_t sources = 0;
|
||||
|
||||
pa_assert(conn);
|
||||
pa_assert(msg);
|
||||
pa_assert(p);
|
||||
|
||||
sources = p->profile->n_sources;
|
||||
|
||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &sources);
|
||||
}
|
||||
|
||||
static void handle_get_priority(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||
pa_dbusiface_card_profile *p = userdata;
|
||||
dbus_uint32_t priority = 0;
|
||||
|
||||
pa_assert(conn);
|
||||
pa_assert(msg);
|
||||
pa_assert(p);
|
||||
|
||||
priority = p->profile->priority;
|
||||
|
||||
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_UINT32, &priority);
|
||||
}
|
||||
|
||||
static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdata) {
|
||||
pa_dbusiface_card_profile *p = userdata;
|
||||
DBusMessage *reply = NULL;
|
||||
DBusMessageIter msg_iter;
|
||||
DBusMessageIter dict_iter;
|
||||
dbus_uint32_t sinks = 0;
|
||||
dbus_uint32_t sources = 0;
|
||||
dbus_uint32_t priority = 0;
|
||||
|
||||
pa_assert(conn);
|
||||
pa_assert(msg);
|
||||
pa_assert(p);
|
||||
|
||||
sinks = p->profile->n_sinks;
|
||||
sources = p->profile->n_sources;
|
||||
priority = p->profile->priority;
|
||||
|
||||
pa_assert_se((reply = dbus_message_new_method_return(msg)));
|
||||
|
||||
dbus_message_iter_init_append(reply, &msg_iter);
|
||||
pa_assert_se(dbus_message_iter_open_container(&msg_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter));
|
||||
|
||||
pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_INDEX].property_name, DBUS_TYPE_UINT32, &p->index);
|
||||
pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_NAME].property_name, DBUS_TYPE_STRING, &p->profile->name);
|
||||
pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_DESCRIPTION].property_name, DBUS_TYPE_STRING, &p->profile->description);
|
||||
pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_SINKS].property_name, DBUS_TYPE_UINT32, &sinks);
|
||||
pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_SOURCES].property_name, DBUS_TYPE_UINT32, &sources);
|
||||
pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_PRIORITY].property_name, DBUS_TYPE_UINT32, &priority);
|
||||
|
||||
pa_assert_se(dbus_message_iter_close_container(&msg_iter, &dict_iter));
|
||||
|
||||
pa_assert_se(dbus_connection_send(conn, reply, NULL));
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
pa_dbusiface_card_profile *pa_dbusiface_card_profile_new(pa_dbusiface_card *card, pa_core *core, pa_card_profile *profile, uint32_t idx) {
|
||||
pa_dbusiface_card_profile *p = NULL;
|
||||
|
||||
pa_assert(card);
|
||||
pa_assert(profile);
|
||||
|
||||
p = pa_xnew(pa_dbusiface_card_profile, 1);
|
||||
p->index = idx;
|
||||
p->profile = profile;
|
||||
p->path = pa_sprintf_malloc("%s/%s%u", pa_dbusiface_card_get_path(card), OBJECT_NAME, idx);
|
||||
p->dbus_protocol = pa_dbus_protocol_get(core);
|
||||
|
||||
pa_assert_se(pa_dbus_protocol_add_interface(p->dbus_protocol, p->path, &profile_interface_info, p) >= 0);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
|
@ -50,6 +202,10 @@ pa_dbusiface_card_profile *pa_dbusiface_card_profile_new(pa_dbusiface_card *card
|
|||
void pa_dbusiface_card_profile_free(pa_dbusiface_card_profile *p) {
|
||||
pa_assert(p);
|
||||
|
||||
pa_assert_se(pa_dbus_protocol_remove_interface(p->dbus_protocol, p->path, profile_interface_info.name) >= 0);
|
||||
|
||||
pa_dbus_protocol_unref(p->dbus_protocol);
|
||||
|
||||
pa_xfree(p->path);
|
||||
pa_xfree(p);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,12 +29,15 @@
|
|||
*/
|
||||
|
||||
#include <pulsecore/core-scache.h>
|
||||
#include <pulsecore/protocol-dbus.h>
|
||||
|
||||
#include "iface-card.h"
|
||||
|
||||
#define PA_DBUSIFACE_CARD_PROFILE_INTERFACE PA_DBUS_CORE_INTERFACE ".CardProfile"
|
||||
|
||||
typedef struct pa_dbusiface_card_profile pa_dbusiface_card_profile;
|
||||
|
||||
pa_dbusiface_card_profile *pa_dbusiface_card_profile_new(pa_dbusiface_card *card, pa_card_profile *profile, uint32_t idx);
|
||||
pa_dbusiface_card_profile *pa_dbusiface_card_profile_new(pa_dbusiface_card *card, pa_core *core, pa_card_profile *profile, uint32_t idx);
|
||||
void pa_dbusiface_card_profile_free(pa_dbusiface_card_profile *p);
|
||||
|
||||
const char *pa_dbusiface_card_profile_get_path(pa_dbusiface_card_profile *p);
|
||||
|
|
|
|||
|
|
@ -516,7 +516,7 @@ pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card)
|
|||
void *state = NULL;
|
||||
|
||||
PA_HASHMAP_FOREACH(profile, card->profiles, state) {
|
||||
pa_dbusiface_card_profile *p = pa_dbusiface_card_profile_new(c, profile, c->next_profile_index++);
|
||||
pa_dbusiface_card_profile *p = pa_dbusiface_card_profile_new(c, card->core, profile, c->next_profile_index++);
|
||||
pa_hashmap_put(c->profiles, pa_dbusiface_card_profile_get_name(p), p);
|
||||
}
|
||||
pa_assert_se(c->active_profile = card->active_profile);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
*/
|
||||
|
||||
#include <pulsecore/card.h>
|
||||
#include <pulsecore/protocol-dbus.h>
|
||||
|
||||
#include "iface-core.h"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue