basic room object creation and enum of rooms
This commit is contained in:
parent
fb5f17037f
commit
b6fe91e830
112
daemon/control.c
112
daemon/control.c
|
@ -31,9 +31,86 @@
|
|||
#include "control.h"
|
||||
#include "../dbus_constants.h"
|
||||
#include "studio_internal.h"
|
||||
#include "room.h"
|
||||
#include "../lib/wkports.h"
|
||||
|
||||
#define INTERFACE_NAME IFACE_CONTROL
|
||||
|
||||
/* c603f2a0-d96a-493e-a8cf-55581d950aa9 */
|
||||
UUID_DEFINE(basic_room,0xC6,0x03,0xF2,0xA0,0xD9,0x6A,0x49,0x3E,0xA8,0xCF,0x55,0x58,0x1D,0x95,0x0A,0xA9);
|
||||
|
||||
static struct list_head g_rooms;
|
||||
|
||||
bool create_builtin_rooms(void)
|
||||
{
|
||||
ladish_room_handle room;
|
||||
|
||||
if (!ladish_room_create(basic_room, "Basic", &room))
|
||||
{
|
||||
log_error("ladish_room_create() failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
list_add_tail(ladish_room_get_list_node(room), &g_rooms);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool create_rooms(void)
|
||||
{
|
||||
if (!create_builtin_rooms())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void maybe_create_rooms(void)
|
||||
{
|
||||
if (list_empty(&g_rooms))
|
||||
{
|
||||
create_rooms();
|
||||
}
|
||||
}
|
||||
|
||||
bool rooms_init(void)
|
||||
{
|
||||
INIT_LIST_HEAD(&g_rooms);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void rooms_uninit(void)
|
||||
{
|
||||
struct list_head * node_ptr;
|
||||
ladish_room_handle room;
|
||||
|
||||
while (!list_empty(&g_rooms))
|
||||
{
|
||||
node_ptr = g_rooms.next;
|
||||
list_del(node_ptr);
|
||||
room = ladish_room_from_list_node(node_ptr);
|
||||
ladish_room_destroy(room);
|
||||
}
|
||||
}
|
||||
|
||||
bool rooms_enum(void * context, bool (* callback)(void * context, ladish_room_handle room))
|
||||
{
|
||||
struct list_head * node_ptr;
|
||||
|
||||
maybe_create_rooms();
|
||||
|
||||
list_for_each(node_ptr, &g_rooms)
|
||||
{
|
||||
if (!callback(context, ladish_room_from_list_node(node_ptr)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ladish_is_studio_loaded(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
DBusMessageIter iter;
|
||||
|
@ -280,6 +357,36 @@ fail:
|
|||
return;
|
||||
}
|
||||
|
||||
#define array_iter_ptr ((DBusMessageIter *)context)
|
||||
|
||||
bool room_list_filler(void * context, ladish_room_handle room)
|
||||
{
|
||||
DBusMessageIter struct_iter;
|
||||
DBusMessageIter dict_iter;
|
||||
const char * name;
|
||||
|
||||
name = ladish_room_get_name(room);
|
||||
|
||||
if (!dbus_message_iter_open_container(array_iter_ptr, DBUS_TYPE_STRUCT, NULL, &struct_iter))
|
||||
return false;
|
||||
|
||||
if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &name))
|
||||
return false;
|
||||
|
||||
if (!dbus_message_iter_open_container(&struct_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter))
|
||||
return false;
|
||||
|
||||
if (!dbus_message_iter_close_container(&struct_iter, &dict_iter))
|
||||
return false;
|
||||
|
||||
if (!dbus_message_iter_close_container(array_iter_ptr, &struct_iter))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#undef array_iter_ptr
|
||||
|
||||
static void ladish_get_room_list(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
DBusMessageIter iter, array_iter;
|
||||
|
@ -297,6 +404,11 @@ static void ladish_get_room_list(struct dbus_method_call * call_ptr)
|
|||
goto fail_unref;
|
||||
}
|
||||
|
||||
if (!rooms_enum(&array_iter, room_list_filler))
|
||||
{
|
||||
goto fail_unref;
|
||||
}
|
||||
|
||||
if (!dbus_message_iter_close_container(&iter, &array_iter))
|
||||
{
|
||||
goto fail_unref;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008, 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
|
||||
*
|
||||
**************************************************************************
|
||||
|
@ -34,4 +34,7 @@ void emit_studio_appeared(void);
|
|||
void emit_studio_disappeared(void);
|
||||
void emit_clean_exit(void);
|
||||
|
||||
bool rooms_init(void);
|
||||
void rooms_uninit(void);
|
||||
|
||||
#endif /* __LASHD_DBUS_IFACE_CONTROL_H__ */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008, 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
|
||||
* Copyright (C) 2002 Robert Ham <rah@bash.sh>
|
||||
*
|
||||
|
@ -269,10 +269,15 @@ int main(int argc, char ** argv, char ** envp)
|
|||
|
||||
loader_init(studio_on_child_exit);
|
||||
|
||||
if (!rooms_init())
|
||||
{
|
||||
goto uninit_loader;
|
||||
}
|
||||
|
||||
if (!connect_dbus())
|
||||
{
|
||||
log_error("Failed to connecto to D-Bus");
|
||||
goto uninit_loader;
|
||||
goto uninit_rooms;
|
||||
}
|
||||
|
||||
/* install the signal handlers */
|
||||
|
@ -314,6 +319,9 @@ int main(int argc, char ** argv, char ** envp)
|
|||
uninit_dbus:
|
||||
disconnect_dbus();
|
||||
|
||||
uninit_rooms:
|
||||
rooms_uninit();
|
||||
|
||||
uninit_loader:
|
||||
loader_uninit();
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
struct ladish_room
|
||||
{
|
||||
struct list_head siblings;
|
||||
uuid_t uuid;
|
||||
char * name;
|
||||
};
|
||||
|
@ -78,4 +79,19 @@ ladish_room_destroy(
|
|||
free(room_ptr);
|
||||
}
|
||||
|
||||
struct list_head * ladish_room_get_list_node(ladish_room_handle room_handle)
|
||||
{
|
||||
return &room_ptr->siblings;
|
||||
}
|
||||
|
||||
const char * ladish_room_get_name(ladish_room_handle room_handle)
|
||||
{
|
||||
return room_ptr->name;
|
||||
}
|
||||
|
||||
#undef room_ptr
|
||||
|
||||
ladish_room_handle ladish_room_from_list_node(struct list_head * node_ptr)
|
||||
{
|
||||
return (ladish_room_handle)list_entry(node_ptr, struct ladish_room, siblings);
|
||||
}
|
||||
|
|
|
@ -41,4 +41,9 @@ void
|
|||
ladish_room_destroy(
|
||||
ladish_room_handle room_handle);
|
||||
|
||||
struct list_head * ladish_room_get_list_node(ladish_room_handle room_handle);
|
||||
ladish_room_handle ladish_room_from_list_node(struct list_head * node_ptr);
|
||||
|
||||
const char * ladish_room_get_name(ladish_room_handle room_handle);
|
||||
|
||||
#endif /* #ifndef ROOM_H__9A1CF253_0A17_402A_BDF8_9BD72B467118__INCLUDED */
|
||||
|
|
|
@ -188,8 +188,7 @@ def main():
|
|||
print("--- room list")
|
||||
for studio in control_iface.GetRoomList():
|
||||
name = studio[0]
|
||||
mtime = studio[1]['Modification Time']
|
||||
print('"%s" last modified on %s' % (name, time.ctime(mtime)))
|
||||
print('"%s"' % name)
|
||||
elif arg == 'rnew':
|
||||
print("--- room new")
|
||||
if index >= len(sys.argv):
|
||||
|
|
Loading…
Reference in New Issue