rename daemon/dbus_iface_control to daemon/control
[ladish.git] / daemon / control.c
blob14e104447cd9419592cedcee32370e69759ee09a
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
8 **************************************************************************
9 * This file contains code of the D-Bus control interface helpers
10 **************************************************************************
12 * LADI Session Handler is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * LADI Session Handler is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
24 * or write to the Free Software Foundation, Inc.,
25 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "common.h"
30 #include "../dbus/interface.h"
31 #include "../dbus/error.h"
32 #include "control.h"
34 #define INTERFACE_NAME DBUS_NAME_BASE ".Control"
36 static void ladish_is_studio_loaded(method_call_t * call_ptr)
38 DBusMessageIter iter;
39 dbus_bool_t is_loaded;
41 is_loaded = g_studio != NULL;
43 call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
44 if (call_ptr->reply == NULL)
46 goto fail;
49 dbus_message_iter_init_append(call_ptr->reply, &iter);
51 if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &is_loaded))
53 goto fail_unref;
56 return;
58 fail_unref:
59 dbus_message_unref(call_ptr->reply);
60 call_ptr->reply = NULL;
62 fail:
63 lash_error("Ran out of memory trying to construct method return");
66 static void ladish_get_studio_list(method_call_t * call_ptr)
68 DBusMessageIter iter, array_iter;
69 //DBusMessageIter struct_iter, dict_iter;
70 //struct list_head * node_ptr;
71 //project_t * project_ptr;
73 call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
74 if (call_ptr->reply == NULL)
76 goto fail;
79 dbus_message_iter_init_append(call_ptr->reply, &iter);
81 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sa{sv})", &array_iter))
83 goto fail_unref;
86 #if 0
87 list_for_each (node_ptr, &g_server->all_projects)
89 project_ptr = list_entry(node_ptr, project_t, siblings_all);
91 if (!dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter))
92 goto fail_unref;
94 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &project_ptr->name))
96 dbus_message_iter_close_container(&iter, &array_iter);
97 goto fail_unref;
100 if (!dbus_message_iter_open_container(&struct_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter))
101 goto fail_unref;
103 if (!maybe_add_dict_entry_string(&dict_iter, "Description", project_ptr->description))
104 goto fail_unref;
106 if (!add_dict_entry_uint32(&dict_iter, "Modification Time", project_ptr->last_modify_time))
107 goto fail_unref;
109 if (!dbus_message_iter_close_container(&struct_iter, &dict_iter))
110 goto fail_unref;
112 if (!dbus_message_iter_close_container(&array_iter, &struct_iter))
113 goto fail_unref;
115 #endif
117 if (!dbus_message_iter_close_container(&iter, &array_iter))
119 goto fail_unref;
122 return;
124 fail_unref:
125 dbus_message_unref(call_ptr->reply);
126 call_ptr->reply = NULL;
128 fail:
129 lash_error("Ran out of memory trying to construct method return");
132 static void ladish_load_studio(method_call_t * call_ptr)
134 const char * name;
136 dbus_error_init(&g_dbus_error);
138 if (!dbus_message_get_args(call_ptr->message, &g_dbus_error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID))
140 lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message);
141 dbus_error_free(&g_dbus_error);
142 return;
145 lash_info("Loading studio '%s'", name);
148 static void ladish_get_application_list(method_call_t * call_ptr)
150 DBusMessageIter iter;
151 DBusMessageIter array_iter;
152 #if 0
153 DBusMessageIter struct_iter;
154 DBusMessageIter dict_iter;
155 struct list_head * node_ptr;
156 struct lash_appdb_entry * entry_ptr;
157 #endif
159 lash_info("Getting applications list");
161 call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
162 if (call_ptr->reply == NULL)
164 goto fail;
167 dbus_message_iter_init_append(call_ptr->reply, &iter);
169 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(sa{sv})", &array_iter))
171 goto fail_unref;
174 #if 0
175 list_for_each(node_ptr, &g_server->appdb)
177 entry_ptr = list_entry(node_ptr, struct lash_appdb_entry, siblings);
179 if (!dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter))
180 goto fail_unref;
182 if (!dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, (const void *) &entry_ptr->name))
184 dbus_message_iter_close_container(&iter, &array_iter);
185 goto fail_unref;
188 if (!dbus_message_iter_open_container(&struct_iter, DBUS_TYPE_ARRAY, "{sv}", &dict_iter))
189 goto fail_unref;
191 if (!maybe_add_dict_entry_string(&dict_iter, "GenericName", entry_ptr->generic_name))
192 goto fail_unref;
194 if (!maybe_add_dict_entry_string(&dict_iter, "Comment", entry_ptr->comment))
195 goto fail_unref;
197 if (!maybe_add_dict_entry_string(&dict_iter, "Icon", entry_ptr->icon))
198 goto fail_unref;
200 if (!dbus_message_iter_close_container(&struct_iter, &dict_iter))
201 goto fail_unref;
203 if (!dbus_message_iter_close_container(&array_iter, &struct_iter))
204 goto fail_unref;
206 #endif
208 if (!dbus_message_iter_close_container(&iter, &array_iter))
210 goto fail_unref;
213 return;
215 fail_unref:
216 dbus_message_unref(call_ptr->reply);
217 call_ptr->reply = NULL;
218 fail:
219 return;
222 static void ladish_exit(method_call_t * call_ptr)
224 lash_info("Exit command received through D-Bus");
225 g_quit = true;
228 void emit_studio_appeared()
230 signal_new_valist(g_dbus_connection, CONTROL_OBJECT_PATH, INTERFACE_NAME, "StudioAppeared", DBUS_TYPE_INVALID);
233 void emit_studio_disappeared()
235 signal_new_valist(g_dbus_connection, CONTROL_OBJECT_PATH, INTERFACE_NAME, "StudioDisappeared", DBUS_TYPE_INVALID);
238 METHOD_ARGS_BEGIN(IsStudioLoaded, "Check whether studio D-Bus object is present")
239 METHOD_ARG_DESCRIBE_OUT("present", "b", "Whether studio D-Bus object is present")
240 METHOD_ARGS_END
242 METHOD_ARGS_BEGIN(GetStudioList, "Get list of studios")
243 METHOD_ARG_DESCRIBE_OUT("studio_list", "a(sa{sv})", "List of studios, name and properties")
244 METHOD_ARGS_END
246 METHOD_ARGS_BEGIN(LoadStudio, "Load studio")
247 METHOD_ARG_DESCRIBE_IN("studio_name", "s", "Name of studio to load")
248 METHOD_ARG_DESCRIBE_IN("options", "a{sv}", "Load options")
249 METHOD_ARGS_END
251 METHOD_ARGS_BEGIN(GetApplicationList, "Get list of applications that can be launched")
252 METHOD_ARG_DESCRIBE_OUT("applications", "a(sa{sv})", "List of applications, name and properties")
253 METHOD_ARGS_END
255 METHOD_ARGS_BEGIN(Exit, "Tell ladish D-Bus service to exit")
256 METHOD_ARGS_END
258 METHODS_BEGIN
259 METHOD_DESCRIBE(IsStudioLoaded, ladish_is_studio_loaded)
260 METHOD_DESCRIBE(GetStudioList, ladish_get_studio_list)
261 METHOD_DESCRIBE(LoadStudio, ladish_load_studio)
262 METHOD_DESCRIBE(GetApplicationList, ladish_get_application_list)
263 METHOD_DESCRIBE(Exit, ladish_exit)
264 METHODS_END
266 SIGNAL_ARGS_BEGIN(StudioAppeared, "Studio D-Bus object appeared")
267 SIGNAL_ARGS_END
269 SIGNAL_ARGS_BEGIN(StudioDisappeared, "Studio D-Bus object disappeared")
270 SIGNAL_ARGS_END
272 SIGNALS_BEGIN
273 SIGNAL_DESCRIBE(StudioAppeared)
274 SIGNAL_DESCRIBE(StudioDisappeared)
275 SIGNALS_END
278 * Interface description.
281 INTERFACE_BEGIN(g_lashd_interface_control, INTERFACE_NAME)
282 INTERFACE_DEFAULT_HANDLER
283 INTERFACE_EXPOSE_METHODS
284 INTERFACE_EXPOSE_SIGNALS
285 INTERFACE_END