Separate d-bus object paths for control and studio objects

This commit is contained in:
Nedko Arnaudov 2009-08-01 19:07:16 +03:00
parent 396385bf0e
commit 4b93feb267
9 changed files with 91 additions and 34 deletions

View File

@ -129,6 +129,8 @@ struct studio
bool jack_conf_stable:1; /* JACK server configuration obtained successfully */
struct list_head jack_conf;
object_path_t * dbus_object;
};
struct jack_parameter_variant

View File

@ -430,6 +430,7 @@ on_jack_server_started(
{
g_studio_ptr->jack_conf_stable = true;
lash_info("jack conf successfully retrieved");
studio_activate(g_studio_ptr);
return;
}
}

View File

@ -153,7 +153,7 @@ static bool connect_dbus(void)
goto unref_connection;
}
g_control_object = object_path_new("/", NULL, 1, &g_lashd_interface_control, NULL);
g_control_object = object_path_new(DBUS_BASE_PATH "/Control", NULL, 1, &g_lashd_interface_control, NULL);
if (g_control_object == NULL)
{
goto unref_connection;
@ -167,7 +167,7 @@ static bool connect_dbus(void)
return true;
destroy_control_object:
object_path_destroy(g_control_object);
object_path_destroy(g_dbus_connection, g_control_object);
unref_connection:
dbus_connection_unref(g_dbus_connection);
@ -177,8 +177,8 @@ fail:
static void disconnect_dbus(void)
{
object_path_destroy(g_dbus_connection, g_control_object);
dbus_connection_unref(g_dbus_connection);
object_path_destroy(g_control_object);
}
static void on_child_exit(pid_t pid)

View File

@ -59,6 +59,8 @@ studio_create(
INIT_LIST_HEAD(&studio_ptr->jack_conf);
studio_ptr->dbus_object = NULL;
*studio_ptr_ptr = studio_ptr;
return true;
@ -70,6 +72,11 @@ studio_destroy(
{
struct list_head * node_ptr;
if (studio_ptr->dbus_object != NULL)
{
object_path_destroy(g_dbus_connection, studio_ptr->dbus_object);
}
while (!list_empty(&studio_ptr->jack_conf))
{
node_ptr = studio_ptr->jack_conf.next;
@ -80,3 +87,30 @@ studio_destroy(
free(studio_ptr);
lash_info("studio object destroy");
}
bool
studio_activate(
struct studio * studio_ptr)
{
object_path_t * object;
object = object_path_new(DBUS_BASE_PATH "/Studio", NULL, 0, NULL);
if (object == NULL)
{
lash_error("object_path_new() failed");
return false;
}
if (!object_path_register(g_dbus_connection, object))
{
lash_error("object_path_register() failed");
object_path_destroy(g_dbus_connection, object);
return false;
}
lash_info("Studio D-Bus object created.");
studio_ptr->dbus_object = object;
return true;
}

View File

@ -37,4 +37,8 @@ void
studio_destroy(
struct studio * studio_ptr);
bool
studio_activate(
struct studio * studio_ptr);
#endif /* #ifndef STUDIO_H__0BEDE85E_4FB3_4D74_BC08_C373A22409C0__INCLUDED */

View File

@ -1,8 +1,8 @@
/*
* LASH
*
* Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
* Copyright (C) 2008 Nedko Arnaudov
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -44,8 +44,9 @@ object_path_new(const char *name,
int num_ifaces,
...)
{
if (!name || !name[0] || num_ifaces < 1) {
lash_debug("Invalid arguments");
if (!name || !name[0] || num_ifaces < 0)
{
lash_error("Invalid arguments");
return NULL;
}
@ -75,7 +76,7 @@ object_path_new(const char *name,
}
lash_error("Failed to create object path");
object_path_destroy(path);
object_path_destroy(NULL, path);
return NULL;
}
@ -104,27 +105,37 @@ object_path_register(DBusConnection *conn,
return true;
}
void
object_path_destroy(object_path_t *path)
void object_path_destroy(DBusConnection * connection_ptr, object_path_t * path_ptr)
{
lash_debug("Destroying object path");
if (path) {
if (path->name) {
free(path->name);
path->name = NULL;
if (path_ptr)
{
if (connection_ptr != NULL && !dbus_connection_unregister_object_path(connection_ptr, path_ptr->name))
{
lash_error("dbus_connection_unregister_object_path() failed.");
}
if (path->interfaces) {
free(path->interfaces);
path->interfaces = NULL;
if (path_ptr->name)
{
free(path_ptr->name);
path_ptr->name = NULL;
}
introspection_destroy(path);
free(path);
path = NULL;
if (path_ptr->interfaces)
{
free(path_ptr->interfaces);
path_ptr->interfaces = NULL;
}
introspection_destroy(path_ptr);
free(path_ptr);
}
#ifdef LASH_DEBUG
else
{
lash_debug("Nothing to destroy");
}
#endif
}

View File

@ -49,6 +49,6 @@ object_path_register(DBusConnection *conn,
object_path_t *path);
void
object_path_destroy(object_path_t *path);
object_path_destroy(DBusConnection * connection_ptr, object_path_t *path);
#endif /* __LASH_DBUS_OBJECT_PATH_H__ */

View File

@ -123,23 +123,27 @@ service_destroy(service_t *service)
if (service) {
/* cut the bus connection */
if (service->connection) {
if (service->connection)
{
/* reap the object path(s) */
if (service->object_paths)
{
object_path_t **path_pptr;
for (path_pptr = service->object_paths; *path_pptr != NULL; ++path_pptr)
{
object_path_destroy(service->connection, *path_pptr);
*path_pptr = NULL;
}
free(service->object_paths);
service->object_paths = NULL;
}
dbus_connection_unref(service->connection);
service->connection = NULL;
}
/* reap the object path(s) */
if (service->object_paths) {
object_path_t **path_pptr;
for (path_pptr = service->object_paths;
*path_pptr; ++path_pptr) {
object_path_destroy(*path_pptr);
*path_pptr = NULL;
}
free(service->object_paths);
service->object_paths = NULL;
}
/* other stuff */
if (service->name) {
free(service->name);

View File

@ -25,6 +25,7 @@
control_interface_name = 'org.ladish.Control'
service_name = 'org.ladish'
dbus_object_path = "/org/ladish/Control"
import sys
import os
@ -108,7 +109,7 @@ def main():
index += 1
try:
if not lash:
lash = bus.get_object(service_name, "/")
lash = bus.get_object(service_name, dbus_object_path)
control_iface = dbus.Interface(lash, control_interface_name)
if arg == "exit":