Browse Source

jackdbus: fix slave driver support

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@4292 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.9.8
nedko 11 years ago
parent
commit
49dffe6226
5 changed files with 158 additions and 34 deletions
  1. +92
    -18
      dbus/controller.c
  2. +32
    -14
      dbus/controller_iface_control.c
  3. +11
    -2
      dbus/controller_internal.h
  4. +1
    -0
      dbus/jackdbus.h
  5. +22
    -0
      example-clients/jack_control

+ 92
- 18
dbus/controller.c View File

@@ -64,6 +64,56 @@ jack_controller_find_driver(
return NULL;
}

bool
jack_controller_add_slave_drivers(
struct jack_controller * controller_ptr)
{
struct list_head * node_ptr;
struct jack_controller_slave_driver * driver_ptr;

list_for_each(node_ptr, &controller_ptr->slave_drivers)
{
driver_ptr = list_entry(node_ptr, struct jack_controller_slave_driver, siblings);
driver_ptr->handle = jack_controller_find_driver(controller_ptr->server, driver_ptr->name);

if (driver_ptr->handle == NULL)
{
jack_error("Unknown driver \"%s\"", driver_ptr->name);
goto fail;
}

if (!jackctl_server_add_slave(controller_ptr->server, driver_ptr->handle))
{
jack_error("Driver \"%s\" cannot be loaded", driver_ptr->name);
goto fail;
}
}

return true;

fail:
driver_ptr->handle = NULL;
return false;
}

void
jack_controller_remove_slave_drivers(
struct jack_controller * controller_ptr)
{
struct list_head * node_ptr;
struct jack_controller_slave_driver * driver_ptr;

list_for_each(node_ptr, &controller_ptr->slave_drivers)
{
driver_ptr = list_entry(node_ptr, struct jack_controller_slave_driver, siblings);
if (driver_ptr->handle != NULL)
{
jackctl_server_remove_slave(controller_ptr->server, driver_ptr->handle);
driver_ptr->handle = NULL;
}
}
}

jackctl_internal_t *
jack_controller_find_internal(
jackctl_server_t *server,
@@ -161,6 +211,8 @@ jack_controller_start_server(
goto fail;
}

jack_controller_add_slave_drivers(controller_ptr);

if (!jackctl_server_start(
controller_ptr->server))
{
@@ -221,6 +273,8 @@ fail_stop_server:
}

fail_close_server:
jack_controller_remove_slave_drivers(controller_ptr);

if (!jackctl_server_close(controller_ptr->server))
{
jack_error("failed to close jack server");
@@ -263,6 +317,8 @@ jack_controller_stop_server(
return FALSE;
}

jack_controller_remove_slave_drivers(controller_ptr);

if (!jackctl_server_close(controller_ptr->server))
{
jack_dbus_error(dbus_call_context_ptr, JACK_DBUS_ERROR_GENERIC, "Failed to close server");
@@ -387,6 +443,7 @@ jack_controller_create(
controller_ptr->started = false;
controller_ptr->driver = NULL;
controller_ptr->driver_set = false;
INIT_LIST_HEAD(&controller_ptr->slave_drivers);

drivers = (JSList *)jackctl_server_get_drivers_list(controller_ptr->server);
controller_ptr->drivers_count = jack_slist_length(drivers);
@@ -465,41 +522,58 @@ fail:
}

bool
jack_controller_add_slave(
struct jack_controller *controller_ptr,
jack_controller_add_slave_driver(
struct jack_controller * controller_ptr,
const char * driver_name)
{
jackctl_driver_t *driver;
struct jack_controller_slave_driver * driver_ptr;

driver = jack_controller_find_driver(controller_ptr->server, driver_name);
if (driver == NULL)
driver_ptr = malloc(sizeof(struct jack_controller_slave_driver));
if (driver_ptr == NULL)
{
jack_error("malloc() failed to allocate jack_controller_slave_driver struct");
return false;
}

jack_info("driver \"%s\" selected", driver_name);
driver_ptr->name = strdup(driver_name);
if (driver_ptr->name == NULL)
{
jack_error("strdup() failed for slave driver name \"%s\"", driver_name);
free(driver_ptr);
return false;
}

driver_ptr->handle = NULL;

return jackctl_server_add_slave(controller_ptr->server, driver);
jack_info("slave driver \"%s\" added", driver_name);

list_add_tail(&driver_ptr->siblings, &controller_ptr->slave_drivers);

return true;
}

bool
jack_controller_remove_slave(
struct jack_controller *controller_ptr,
jack_controller_remove_slave_driver(
struct jack_controller * controller_ptr,
const char * driver_name)
{
jackctl_driver_t *driver;
struct list_head * node_ptr;
struct jack_controller_slave_driver * driver_ptr;

driver = jack_controller_find_driver(controller_ptr->server, driver_name);
if (driver == NULL)
list_for_each(node_ptr, &controller_ptr->slave_drivers)
{
return false;
driver_ptr = list_entry(node_ptr, struct jack_controller_slave_driver, siblings);
if (strcmp(driver_ptr->name, driver_name) == 0)
{
jack_info("slave driver \"%s\" removed", driver_name);
list_del(&driver_ptr->siblings);
free(driver_ptr->name);
free(driver_ptr);
return true;
}
}

jack_info("driver \"%s\" selected", driver_name);

return jackctl_server_remove_slave(controller_ptr->server, driver);
return false;
}

bool


+ 32
- 14
dbus/controller_iface_control.c View File

@@ -229,10 +229,15 @@ jack_control_run_method(
"jack_controller_load_internal failed for internal (%s)", internal_name);
}
}
else if (strcmp (call->method_name, "AddSlave") == 0)
else if (strcmp (call->method_name, "AddSlaveDriver") == 0)
{
const char *driver_name;

if (controller_ptr->started)
{
goto fail_started;
}

if (!jack_dbus_get_method_args(call, DBUS_TYPE_STRING, &driver_name, DBUS_TYPE_INVALID))
{
/* The method call had invalid arguments meaning that
@@ -241,17 +246,22 @@ jack_control_run_method(
goto exit;
}
if (!jack_controller_add_slave(controller_ptr, driver_name)) {
if (!jack_controller_add_slave_driver(controller_ptr, driver_name)) {
jack_dbus_error(
call,
JACK_DBUS_ERROR_GENERIC,
"jack_controller_add_slave failed for driver (%s)", driver_name);
"jack_controller_add_slave_driver failed for driver (%s)", driver_name);
}
}
else if (strcmp (call->method_name, "RemoveSlave") == 0)
else if (strcmp (call->method_name, "RemoveSlaveDriver") == 0)
{
const char *driver_name;

if (controller_ptr->started)
{
goto fail_started;
}

if (!jack_dbus_get_method_args(call, DBUS_TYPE_STRING, &driver_name, DBUS_TYPE_INVALID))
{
/* The method call had invalid arguments meaning that
@@ -260,11 +270,11 @@ jack_control_run_method(
goto exit;
}
if (!jack_controller_remove_slave(controller_ptr, driver_name)) {
if (!jack_controller_remove_slave_driver(controller_ptr, driver_name)) {
jack_dbus_error(
call,
JACK_DBUS_ERROR_GENERIC,
"jack_controller_remove_slave failed for driver (%s)", driver_name);
"jack_controller_remove_slave_driver failed for driver (%s)", driver_name);
}
}
else if (strcmp (call->method_name, "UnloadInternal") == 0)
@@ -293,8 +303,7 @@ jack_control_run_method(
}

jack_dbus_construct_method_return_single(call, type, arg);

return true;
goto exit;

not_started:
jack_dbus_only_error(
@@ -302,6 +311,15 @@ not_started:
JACK_DBUS_ERROR_SERVER_NOT_RUNNING,
"Can't execute method '%s' with stopped JACK server",
call->method_name);
goto exit;

fail_started:
jack_dbus_only_error(
call,
JACK_DBUS_ERROR_SERVER_RUNNING,
"Can't execute method '%s' with started JACK server",
call->method_name);
goto exit;

exit:
return true;
@@ -361,12 +379,12 @@ JACK_DBUS_METHOD_ARGUMENTS_BEGIN(UnloadInternal)
JACK_DBUS_METHOD_ARGUMENT("internal", "s", false)
JACK_DBUS_METHOD_ARGUMENTS_END

JACK_DBUS_METHOD_ARGUMENTS_BEGIN(AddSlave)
JACK_DBUS_METHOD_ARGUMENT("internal", "s", false)
JACK_DBUS_METHOD_ARGUMENTS_BEGIN(AddSlaveDriver)
JACK_DBUS_METHOD_ARGUMENT("driver_name", "s", false)
JACK_DBUS_METHOD_ARGUMENTS_END

JACK_DBUS_METHOD_ARGUMENTS_BEGIN(RemoveSlave)
JACK_DBUS_METHOD_ARGUMENT("internal", "s", false)
JACK_DBUS_METHOD_ARGUMENTS_BEGIN(RemoveSlaveDriver)
JACK_DBUS_METHOD_ARGUMENT("driver_name", "s", false)
JACK_DBUS_METHOD_ARGUMENTS_END

JACK_DBUS_METHODS_BEGIN
@@ -384,8 +402,8 @@ JACK_DBUS_METHODS_BEGIN
JACK_DBUS_METHOD_DESCRIBE(ResetXruns, NULL)
JACK_DBUS_METHOD_DESCRIBE(LoadInternal, NULL)
JACK_DBUS_METHOD_DESCRIBE(UnloadInternal, NULL)
JACK_DBUS_METHOD_DESCRIBE(AddSlave, NULL)
JACK_DBUS_METHOD_DESCRIBE(RemoveSlave, NULL)
JACK_DBUS_METHOD_DESCRIBE(AddSlaveDriver, NULL)
JACK_DBUS_METHOD_DESCRIBE(RemoveSlaveDriver, NULL)
JACK_DBUS_METHODS_END

JACK_DBUS_SIGNAL_ARGUMENTS_BEGIN(ServerStarted)


+ 11
- 2
dbus/controller_internal.h View File

@@ -26,6 +26,14 @@
#include "jack/control.h"
#include "jack/jack.h"
#include "jackdbus.h"
#include "list.h"

struct jack_controller_slave_driver
{
struct list_head siblings;
char * name;
jackctl_driver_t * handle;
};

struct jack_controller
{
@@ -45,6 +53,7 @@ struct jack_controller

jackctl_driver_t *driver;
bool driver_set; /* whether driver is manually set, if false - DEFAULT_DRIVER is auto set */
struct list_head slave_drivers;

struct jack_dbus_object_descriptor dbus_descriptor;
};
@@ -87,12 +96,12 @@ jack_controller_switch_master(
void *dbus_call_context_ptr);
bool
jack_controller_add_slave(
jack_controller_add_slave_driver(
struct jack_controller *controller_ptr,
const char * driver_name);
bool
jack_controller_remove_slave(
jack_controller_remove_slave_driver(
struct jack_controller *controller_ptr,
const char * driver_name);



+ 1
- 0
dbus/jackdbus.h View File

@@ -46,6 +46,7 @@ jack_controller_settings_uninit();

#define JACK_DBUS_ERROR_UNKNOWN_METHOD "org.jackaudio.Error.UnknownMethod"
#define JACK_DBUS_ERROR_SERVER_NOT_RUNNING "org.jackaudio.Error.ServerNotRunning"
#define JACK_DBUS_ERROR_SERVER_RUNNING "org.jackaudio.Error.ServerRunning"
#define JACK_DBUS_ERROR_UNKNOWN_DRIVER "org.jackaudio.Error.UnknownDriver"
#define JACK_DBUS_ERROR_UNKNOWN_INTERNAL "org.jackaudio.Error.UnknownInternal"
#define JACK_DBUS_ERROR_UNKNOWN_PARAMETER "org.jackaudio.Error.UnknownParameter"


+ 22
- 0
example-clients/jack_control View File

@@ -116,6 +116,8 @@ def main():
print " dp - get parameters of currently selected driver"
print " dpd <param> - get long description for driver parameter"
print " dps <param> <value> - set driver parameter"
print " asd <driver> - add slave driver"
print " rsd <driver> - remove slave driver"
print " il - get list of available internals"
print " ip <name> - get parameters of given internal"
print " ipd <name> <param> - get long description for internal parameter"
@@ -305,6 +307,26 @@ def main():
name = sys.argv[index]
index += 1
result = control_iface.UnloadInternal(name)
elif arg == 'asd':
print "--- add slave driver"

if index >= len(sys.argv):
print "add slave driver command requires driver name argument"
sys.exit()

name = sys.argv[index]
index += 1
result = control_iface.AddSlaveDriver(name)
elif arg == 'rsd':
print "--- remove slave driver"

if index >= len(sys.argv):
print "remove slave driver command requires driver name argument"
sys.exit()

name = sys.argv[index]
index += 1
result = control_iface.RemoveSlaveDriver(name)
else:
print "Unknown command '%s'" % arg
except dbus.DBusException, e:


Loading…
Cancel
Save