GetStudioList implemented
This commit is contained in:
parent
b67aad8c67
commit
186b8ac84e
|
@ -64,12 +64,48 @@ fail:
|
|||
lash_error("Ran out of memory trying to construct method return");
|
||||
}
|
||||
|
||||
#define array_iter_ptr ((DBusMessageIter *)context)
|
||||
|
||||
static bool get_studio_list_callback(void * call_ptr, void * context, const char * studio, uint32_t modtime)
|
||||
{
|
||||
DBusMessageIter struct_iter;
|
||||
DBusMessageIter dict_iter;
|
||||
bool ret;
|
||||
|
||||
ret = false;
|
||||
|
||||
if (!dbus_message_iter_open_container(array_iter_ptr, DBUS_TYPE_STRUCT, NULL, &struct_iter))
|
||||
goto exit;
|
||||
|
||||
if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &studio))
|
||||
goto close_struct;
|
||||
|
||||
if (!dbus_message_iter_open_container(&struct_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter))
|
||||
goto close_struct;
|
||||
|
||||
/* if (!maybe_add_dict_entry_string(&dict_iter, "Description", xxx)) */
|
||||
/* goto close_dict; */
|
||||
|
||||
if (!dbus_add_dict_entry_uint32(&dict_iter, "Modification Time", modtime))
|
||||
goto close_dict;
|
||||
|
||||
ret = true;
|
||||
|
||||
close_dict:
|
||||
if (!dbus_message_iter_close_container(&struct_iter, &dict_iter))
|
||||
ret = false;
|
||||
|
||||
close_struct:
|
||||
if (!dbus_message_iter_close_container(array_iter_ptr, &struct_iter))
|
||||
ret = false;
|
||||
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ladish_get_studio_list(method_call_t * call_ptr)
|
||||
{
|
||||
DBusMessageIter iter, array_iter;
|
||||
//DBusMessageIter struct_iter, dict_iter;
|
||||
//struct list_head * node_ptr;
|
||||
//project_t * project_ptr;
|
||||
|
||||
call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
|
||||
if (call_ptr->reply == NULL)
|
||||
|
@ -84,36 +120,15 @@ static void ladish_get_studio_list(method_call_t * call_ptr)
|
|||
goto fail_unref;
|
||||
}
|
||||
|
||||
#if 0
|
||||
list_for_each (node_ptr, &g_server->all_projects)
|
||||
if (!studios_iterate(call_ptr, &array_iter, get_studio_list_callback))
|
||||
{
|
||||
project_ptr = list_entry(node_ptr, project_t, siblings_all);
|
||||
|
||||
if (!dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter))
|
||||
dbus_message_iter_close_container(&iter, &array_iter);
|
||||
if (call_ptr->reply == NULL)
|
||||
goto fail_unref;
|
||||
|
||||
if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &project_ptr->name))
|
||||
{
|
||||
dbus_message_iter_close_container(&iter, &array_iter);
|
||||
goto fail_unref;
|
||||
}
|
||||
|
||||
if (!dbus_message_iter_open_container(&struct_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter))
|
||||
goto fail_unref;
|
||||
|
||||
if (!maybe_add_dict_entry_string(&dict_iter, "Description", project_ptr->description))
|
||||
goto fail_unref;
|
||||
|
||||
if (!add_dict_entry_uint32(&dict_iter, "Modification Time", project_ptr->last_modify_time))
|
||||
goto fail_unref;
|
||||
|
||||
if (!dbus_message_iter_close_container(&struct_iter, &dict_iter))
|
||||
goto fail_unref;
|
||||
|
||||
if (!dbus_message_iter_close_container(&array_iter, &struct_iter))
|
||||
goto fail_unref;
|
||||
/* studios_iterate or get_studio_list_callback() composed error reply */
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!dbus_message_iter_close_container(&iter, &array_iter))
|
||||
{
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "../jack_proxy.h"
|
||||
#include "patchbay.h"
|
||||
|
@ -39,7 +40,7 @@
|
|||
#include "../dbus/error.h"
|
||||
#include "dirhelpers.h"
|
||||
|
||||
#define STUDIOS_DIR "/studios"
|
||||
#define STUDIOS_DIR "/studios/"
|
||||
char * g_studios_dir;
|
||||
|
||||
#define STUDIO_HEADER_TEXT BASE_NAME " Studio configuration.\n"
|
||||
|
@ -988,6 +989,59 @@ exit:
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool studios_iterate(void * call_ptr, void * context, bool (* callback)(void * call_ptr, void * context, const char * studio, uint32_t modtime))
|
||||
{
|
||||
DIR * dir;
|
||||
struct dirent * dentry;
|
||||
size_t len;
|
||||
struct stat st;
|
||||
char * path;
|
||||
|
||||
dir = opendir(g_studios_dir);
|
||||
if (dir == NULL)
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "Cannot open directory '%s': %d (%s)", g_studios_dir, errno, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
while ((dentry = readdir(dir)) != NULL)
|
||||
{
|
||||
if (dentry->d_type != DT_REG)
|
||||
continue;
|
||||
|
||||
len = strlen(dentry->d_name);
|
||||
if (len < 4 || strcmp(dentry->d_name + (len - 4), ".xml"))
|
||||
continue;
|
||||
|
||||
path = catdup(g_studios_dir, dentry->d_name);
|
||||
if (path == NULL)
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "catdup() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
dentry->d_name[len - 4] = 0;
|
||||
|
||||
if (stat(path, &st) != 0)
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "failed to stat '%s': %d (%s)", path, errno, strerror(errno));
|
||||
free(path);
|
||||
return false;
|
||||
}
|
||||
|
||||
free(path);
|
||||
|
||||
if (!callback(call_ptr, context, dentry->d_name, st.st_mtime))
|
||||
{
|
||||
closedir(dir);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool studio_load(const char * file_path)
|
||||
{
|
||||
return false; /* not implemented yet */
|
||||
|
|
|
@ -32,4 +32,6 @@ void studio_uninit(void);
|
|||
void studio_run(void);
|
||||
bool studio_is_loaded(void);
|
||||
|
||||
bool studios_iterate(void * call_ptr, void * context, bool (* callback)(void * call_ptr, void * context, const char * studio, uint32_t modtime));
|
||||
|
||||
#endif /* #ifndef STUDIO_H__0BEDE85E_4FB3_4D74_BC08_C373A22409C0__INCLUDED */
|
||||
|
|
21
dbus/error.c
21
dbus/error.c
|
@ -2,7 +2,7 @@
|
|||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2008 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
|
||||
*
|
||||
**************************************************************************
|
||||
|
@ -51,15 +51,16 @@ lash_dbus_error(method_call_t *call_ptr,
|
|||
|
||||
va_end(ap);
|
||||
|
||||
interface_name = (call_ptr->interface
|
||||
&& call_ptr->interface->name
|
||||
&& call_ptr->interface->name[0])
|
||||
? call_ptr->interface->name
|
||||
: "<unknown>";
|
||||
if (call_ptr != NULL)
|
||||
{
|
||||
interface_name = (call_ptr->interface && call_ptr->interface->name && call_ptr->interface->name[0]) ? call_ptr->interface->name : "<unknown>";
|
||||
|
||||
lash_error("In method %s.%s: %s", interface_name,
|
||||
call_ptr->method_name, message);
|
||||
lash_error("In method %s.%s: %s", interface_name, call_ptr->method_name, message);
|
||||
|
||||
call_ptr->reply = dbus_message_new_error(call_ptr->message, err_name,
|
||||
message);
|
||||
call_ptr->reply = dbus_message_new_error(call_ptr->message, err_name, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
lash_error("%s", message);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue