dbus-protocol: Connection handling for local connections.

This commit is contained in:
Tanu Kaskinen 2009-06-16 19:03:22 +03:00
parent 5babbaafb2
commit c8d819a5ad
11 changed files with 644 additions and 69 deletions

View file

@ -42,6 +42,13 @@ typedef struct pa_core pa_core;
#include <pulsecore/sink-input.h>
#include <pulsecore/msgobject.h>
typedef enum pa_server_type {
PA_SERVER_TYPE_UNSET,
PA_SERVER_TYPE_USER,
PA_SERVER_TYPE_SYSTEM,
PA_SERVER_TYPE_NONE
} pa_server_type_t;
typedef enum pa_core_state {
PA_CORE_STARTUP,
PA_CORE_RUNNING,
@ -152,6 +159,8 @@ struct pa_core {
pa_resample_method_t resample_method;
int realtime_priority;
pa_server_type_t server_type;
/* hooks */
pa_hook hooks[PA_CORE_HOOK_MAX];
};

View file

@ -0,0 +1,73 @@
/***
This file is part of PulseAudio.
Copyright 2009 Tanu Kaskinen
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <dbus/dbus.h>
#include <pulsecore/core-util.h>
#include "dbus-common.h"
char *pa_get_dbus_address_from_server_type(pa_server_type_t server_type) {
char *address = NULL;
char *runtime_path = NULL;
char *escaped_path = NULL;
switch (server_type) {
case PA_SERVER_TYPE_USER:
if (!(runtime_path = pa_runtime_path(PA_DBUS_SOCKET_NAME))) {
pa_log("pa_runtime_path() failed.");
break;
}
if (!(escaped_path = dbus_address_escape_value(runtime_path))) {
pa_log("dbus_address_escape_value() failed.");
break;
}
address = pa_sprintf_malloc("unix:path=%s", escaped_path);
break;
case PA_SERVER_TYPE_SYSTEM:
if (!(escaped_path = dbus_address_escape_value(PA_DBUS_SYSTEM_SOCKET_PATH))) {
pa_log("dbus_address_escape_value() failed.");
break;
}
address = pa_sprintf_malloc("unix:path=%s", escaped_path);
break;
case PA_SERVER_TYPE_NONE:
address = pa_xnew0(char, 1);
break;
default:
pa_assert_not_reached();
}
pa_xfree(runtime_path);
pa_xfree(escaped_path);
return address;
}

View file

@ -0,0 +1,39 @@
#ifndef foodbuscommonhfoo
#define foodbuscommonhfoo
/***
This file is part of PulseAudio.
Copyright 2009 Tanu Kaskinen
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#include <pulsecore/core.h>
#include <pulsecore/macro.h>
#define PA_DBUS_DEFAULT_PORT 24883
#define PA_DBUS_SOCKET_NAME "dbus_socket"
#define PA_DBUS_SYSTEM_SOCKET_PATH PA_SYSTEM_RUNTIME_PATH PA_PATH_SEP PA_DBUS_SOCKET_NAME
/* Returns the default address of the server type in the escaped form. For
* PA_SERVER_TYPE_NONE an empty string is returned. The caller frees the
* string. This function may fail in some rare cases, in which case NULL is
* returned. */
char *pa_get_dbus_address_from_server_type(pa_server_type_t server_type);
#endif

View file

@ -276,6 +276,27 @@ pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *m, DBusBus
return pconn;
}
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new_from_existing(pa_mainloop_api *m, DBusConnection *conn) {
pa_dbus_wrap_connection *pconn;
pa_assert(m);
pa_assert(conn);
pconn = pa_xnew(pa_dbus_wrap_connection, 1);
pconn->mainloop = m;
pconn->connection = dbus_connection_ref(conn);
dbus_connection_set_exit_on_disconnect(conn, FALSE);
dbus_connection_set_dispatch_status_function(conn, dispatch_status, pconn, NULL);
dbus_connection_set_watch_functions(conn, add_watch, remove_watch, toggle_watch, pconn, NULL);
dbus_connection_set_timeout_functions(conn, add_timeout, remove_timeout, toggle_timeout, pconn, NULL);
dbus_connection_set_wakeup_main_function(conn, wakeup_main, pconn, NULL);
pconn->dispatch_event = pconn->mainloop->defer_new(pconn->mainloop, dispatch_cb, conn);
return pconn;
}
void pa_dbus_wrap_connection_free(pa_dbus_wrap_connection* c) {
pa_assert(c);

View file

@ -31,6 +31,7 @@
typedef struct pa_dbus_wrap_connection pa_dbus_wrap_connection;
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new(pa_mainloop_api *mainloop, DBusBusType type, DBusError *error);
pa_dbus_wrap_connection* pa_dbus_wrap_connection_new_from_existing(pa_mainloop_api *mainloop, DBusConnection *conn);
void pa_dbus_wrap_connection_free(pa_dbus_wrap_connection* conn);
DBusConnection* pa_dbus_wrap_connection_get(pa_dbus_wrap_connection *conn);