diff options
-rw-r--r-- | contrib/colord.spec.in | 1 | ||||
-rw-r--r-- | data/org.freedesktop.ColorManager.conf | 2 | ||||
-rw-r--r-- | src/.gitignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 12 | ||||
-rw-r--r-- | src/cd-common.h | 34 | ||||
-rw-r--r-- | src/cd-main.c | 685 | ||||
-rw-r--r-- | src/cd-util.c | 224 | ||||
-rw-r--r-- | src/org.freedesktop.ColorManager.Device.xml | 11 | ||||
-rw-r--r-- | src/org.freedesktop.ColorManager.Profile.xml | 11 | ||||
-rw-r--r-- | src/org.freedesktop.ColorManager.xml | 30 |
10 files changed, 977 insertions, 34 deletions
diff --git a/contrib/colord.spec.in b/contrib/colord.spec.in index 46d5071..648004a 100644 --- a/contrib/colord.spec.in +++ b/contrib/colord.spec.in @@ -37,6 +37,7 @@ make install DESTDIR=$RPM_BUILD_ROOT %defattr(-,root,root,-) %doc README AUTHORS NEWS COPYING %{_libexecdir}/colord +%{_libexecdir}/colormgr %{_sysconfdir}/dbus-1/system.d/org.freedesktop.ColorManager.conf %{_datadir}/dbus-1/interfaces/org.freedesktop.ColorManager*.xml %{_datadir}/polkit-1/actions/org.freedesktop.color.policy diff --git a/data/org.freedesktop.ColorManager.conf b/data/org.freedesktop.ColorManager.conf index 31b93bb..e1f8b07 100644 --- a/data/org.freedesktop.ColorManager.conf +++ b/data/org.freedesktop.ColorManager.conf @@ -20,7 +20,7 @@ <allow send_destination="org.freedesktop.ColorManager" send_interface="org.freedesktop.ColorManager.Profile"/> <allow send_destination="org.freedesktop.ColorManager" - send_interface="org.freedesktop.ColorManager.device"/> + send_interface="org.freedesktop.ColorManager.Device"/> <allow send_destination="org.freedesktop.ColorManager" send_interface="org.freedesktop.DBus.Properties"/> <allow send_destination="org.freedesktop.ColorManager" diff --git a/src/.gitignore b/src/.gitignore index a46ec61..804bb55 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,3 +1,4 @@ colord +colormgr .deps *.o diff --git a/src/Makefile.am b/src/Makefile.am index 010837a..381677d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,3 +24,15 @@ colord_LDADD = \ colord_CFLAGS = \ $(WARNINGFLAGS_C) + +bin_PROGRAMS = \ + colormgr + +colormgr_SOURCES = \ + cd-util.c + +colormgr_LDADD = \ + $(GLIB_LIBS) + +colormgr_CFLAGS = \ + $(WARNINGFLAGS_C) diff --git a/src/cd-common.h b/src/cd-common.h new file mode 100644 index 0000000..23d1cbd --- /dev/null +++ b/src/cd-common.h @@ -0,0 +1,34 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2010 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU General Public License Version 2 + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __CD_COMMON_H__ +#define __CD_COMMON_H__ + +#include "config.h" + +#define COLORD_DBUS_SERVICE "org.freedesktop.ColorManager" +#define COLORD_DBUS_PATH "/org/freedesktop/ColorManager" +#define COLORD_DBUS_INTERFACE "org.freedesktop.ColorManager" +#define COLORD_DBUS_INTERFACE_DEVICE "org.freedesktop.ColorManager.Device" +#define COLORD_DBUS_INTERFACE_PROFILE "org.freedesktop.ColorManager.Profile" + +#endif /* __CD_COMMON_H__ */ + diff --git a/src/cd-main.c b/src/cd-main.c index 8100a0e..5f8d29e 100644 --- a/src/cd-main.c +++ b/src/cd-main.c @@ -25,19 +25,493 @@ #include <gio/gio.h> #include <locale.h> +#include "cd-common.h" + static GMainLoop *loop = NULL; -static GDBusNodeInfo *introspection = NULL; +static GDBusNodeInfo *introspection_daemon = NULL; +static GDBusNodeInfo *introspection_device = NULL; +static GDBusNodeInfo *introspection_profile = NULL; static GDBusConnection *connection = NULL; static GPtrArray *devices_array = NULL; +static GPtrArray *profiles_array = NULL; + +typedef struct { + gchar *device_id; + gchar *object_path; + guint registration_id; + GPtrArray *profiles; +} CdDeviceItem; + +typedef struct { + gchar *filename; + gchar *object_path; + gchar *profile_id; + guint registration_id; +} CdProfileItem; + +/** + * cd_main_device_item_free: + **/ +static void +cd_main_device_item_free (CdDeviceItem *item) +{ + if (item->registration_id > 0) { + g_dbus_connection_unregister_object (connection, + item->registration_id); + } + g_ptr_array_unref (item->profiles); + g_free (item->object_path); + g_free (item->device_id); + g_free (item); +} + +/** + * cd_main_profile_item_free: + **/ +static void +cd_main_profile_item_free (CdProfileItem *item) +{ + if (item->registration_id > 0) { + g_dbus_connection_unregister_object (connection, + item->registration_id); + } + g_free (item->object_path); + g_free (item->profile_id); + g_free (item->filename); + g_free (item); +} + +/** + * cd_main_device_find_by_object_path: + **/ +static CdDeviceItem * +cd_main_device_find_by_object_path (const gchar *object_path) +{ + CdDeviceItem *item = NULL; + CdDeviceItem *item_tmp; + guint i; + + /* find item */ + for (i=0; i<devices_array->len; i++) { + item_tmp = g_ptr_array_index (devices_array, i); + if (g_strcmp0 (item_tmp->object_path, object_path) == 0) { + item = item_tmp; + break; + } + } + return item; +} + +/** + * cd_main_profile_find_by_object_path: + **/ +static CdProfileItem * +cd_main_profile_find_by_object_path (const gchar *object_path) +{ + CdProfileItem *item = NULL; + CdProfileItem *item_tmp; + guint i; + + /* find item */ + for (i=0; i<profiles_array->len; i++) { + item_tmp = g_ptr_array_index (profiles_array, i); + if (g_strcmp0 (item_tmp->object_path, object_path) == 0) { + item = item_tmp; + break; + } + } + return item; +} + +/** + * cd_main_device_find_by_id: + **/ +static CdDeviceItem * +cd_main_device_find_by_id (const gchar *device_id) +{ + CdDeviceItem *item = NULL; + CdDeviceItem *item_tmp; + guint i; + + /* find item */ + for (i=0; i<devices_array->len; i++) { + item_tmp = g_ptr_array_index (devices_array, i); + if (g_strcmp0 (item_tmp->device_id, device_id) == 0) { + item = item_tmp; + break; + } + } + return item; +} + +/** + * cd_main_profile_find_by_id: + **/ +static CdProfileItem * +cd_main_profile_find_by_id (const gchar *profile_id) +{ + CdProfileItem *item = NULL; + CdProfileItem *item_tmp; + guint i; + + /* find item */ + for (i=0; i<profiles_array->len; i++) { + item_tmp = g_ptr_array_index (profiles_array, i); + if (g_strcmp0 (item_tmp->profile_id, profile_id) == 0) { + item = item_tmp; + break; + } + } + return item; +} + +/** + * cd_main_profile_emit_changed: + **/ +static void +cd_main_profile_emit_changed (CdProfileItem *item) +{ + gboolean ret; + GError *error = NULL; + + /* emit signal */ + ret = g_dbus_connection_emit_signal (connection, + NULL, + item->object_path, + COLORD_DBUS_INTERFACE_PROFILE, + "Changed", + NULL, + &error); + if (!ret) { + g_warning ("failed to send signal %s", error->message); + g_error_free (error); + } +} + +/** + * cd_main_profile_method_call: + **/ +static void +cd_main_profile_method_call (GDBusConnection *connection_, const gchar *sender, + const gchar *object_path, const gchar *interface_name, + const gchar *method_name, GVariant *parameters, + GDBusMethodInvocation *invocation, gpointer user_data) +{ + GVariant *tuple = NULL; + GVariant *value = NULL; + gchar **profiles = NULL; +// guint i; + gchar *filename = NULL; + CdProfileItem *item; + + /* return '' */ + if (g_strcmp0 (method_name, "ParseFilename") == 0) { + + /* copy the profile path */ + item = cd_main_profile_find_by_object_path (object_path); + if (item != NULL) { + g_dbus_method_invocation_return_error (invocation, + 1, //FIXME + 0, + "profile object path '%s' does not exist", + object_path); + goto out; + } + + /* check the profile_object_path exists */ + g_variant_get (parameters, "(s)", + &filename); + + /* add to the array */ + item->filename = g_strdup (filename); + + /* emit */ + cd_main_profile_emit_changed (item); + + g_dbus_method_invocation_return_value (invocation, NULL); + goto out; + } + + /* we suck */ + g_critical ("failed to process method %s", method_name); +out: + g_free (filename); + if (tuple != NULL) + g_variant_unref (tuple); + if (value != NULL) + g_variant_unref (value); + g_strfreev (profiles); + return; +} + +/** + * cd_main_profile_get_property: + **/ +static GVariant * +cd_main_profile_get_property (GDBusConnection *connection_, const gchar *sender, + const gchar *object_path, const gchar *interface_name, + const gchar *property_name, GError **error, + gpointer user_data) +{ + CdProfileItem *item; +// const gchar *profile; + gchar **profiles = NULL; +// guint i; + GVariant *retval = NULL; + + if (g_strcmp0 (property_name, "Title") == 0) { + retval = g_variant_new_string ("hello dave"); + goto out; + } + if (g_strcmp0 (property_name, "ProfileId") == 0) { + item = cd_main_profile_find_by_object_path (object_path); + retval = g_variant_new_string (item->profile_id); + goto out; + } + if (g_strcmp0 (property_name, "Filename") == 0) { + item = cd_main_profile_find_by_object_path (object_path); + retval = g_variant_new_string (item->filename); + goto out; + } + + g_critical ("failed to set property %s", property_name); +out: + g_strfreev (profiles); + return retval; +} + +/** + * cd_main_create_profile: + **/ +static CdProfileItem * +cd_main_create_profile (const gchar *profile_id, GError **error) +{ + gboolean ret; + CdProfileItem *item; + static const GDBusInterfaceVTable interface_vtable = { + cd_main_profile_method_call, + cd_main_profile_get_property, + NULL + }; + + g_assert (connection != NULL); + + /* create an object */ + item = g_new0 (CdProfileItem, 1); + item->profile_id = g_strdup (profile_id); + item->object_path = g_build_filename (COLORD_DBUS_PATH, profile_id, NULL); + g_ptr_array_add (profiles_array, item); + g_debug ("Adding profile %s", item->object_path); + item->registration_id = g_dbus_connection_register_object (connection, + item->object_path, + introspection_profile->interfaces[0], + &interface_vtable, + NULL, /* user_data */ + NULL, /* user_data_free_func */ + NULL); /* GError** */ + g_assert (item->registration_id > 0); + + /* emit signal */ + ret = g_dbus_connection_emit_signal (connection, + NULL, + COLORD_DBUS_PATH, + COLORD_DBUS_INTERFACE_PROFILE, + "ProfileAdded", + g_variant_new ("(s)", + item->object_path), + error); + if (!ret) + goto out; +out: + return item; +} + +/** + * cd_main_device_emit_changed: + **/ +static void +cd_main_device_emit_changed (CdDeviceItem *item) +{ + gboolean ret; + GError *error = NULL; + + /* emit signal */ + ret = g_dbus_connection_emit_signal (connection, + NULL, + item->object_path, + COLORD_DBUS_INTERFACE_DEVICE, + "Changed", + NULL, + &error); + if (!ret) { + g_warning ("failed to send signal %s", error->message); + g_error_free (error); + } +} + +/** + * cd_main_device_method_call: + **/ +static void +cd_main_device_method_call (GDBusConnection *connection_, const gchar *sender, + const gchar *object_path, const gchar *interface_name, + const gchar *method_name, GVariant *parameters, + GDBusMethodInvocation *invocation, gpointer user_data) +{ + GVariant *tuple = NULL; + GVariant *value = NULL; + gchar **devices = NULL; +// guint i; + gchar *profile_object_path = NULL; + CdDeviceItem *item; + CdProfileItem *item_profile; + + /* return '' */ + if (g_strcmp0 (method_name, "AddProfile") == 0) { + + /* copy the device path */ + item = cd_main_device_find_by_object_path (object_path); + if (item != NULL) { + g_dbus_method_invocation_return_error (invocation, + 1, //FIXME + 0, + "device object path '%s' does not exist", + object_path); + goto out; + } + + /* check the profile_object_path exists */ + g_variant_get (parameters, "(s)", + &profile_object_path); + item_profile = cd_main_profile_find_by_object_path (profile_object_path); + if (item_profile != NULL) { + g_dbus_method_invocation_return_error (invocation, + 1, //FIXME + 0, + "profile object path '%s' does not exist", + object_path); + goto out; + } + + /* add to the array */ + g_ptr_array_add (item->profiles, g_strdup (profile_object_path)); + + /* emit */ + cd_main_device_emit_changed (item); + + g_dbus_method_invocation_return_value (invocation, NULL); + goto out; + } + + /* we suck */ + g_critical ("failed to process method %s", method_name); +out: + g_free (profile_object_path); + if (tuple != NULL) + g_variant_unref (tuple); + if (value != NULL) + g_variant_unref (value); + g_strfreev (devices); + return; +} + +/** + * cd_main_device_get_property: + **/ +static GVariant * +cd_main_device_get_property (GDBusConnection *connection_, const gchar *sender, + const gchar *object_path, const gchar *interface_name, + const gchar *property_name, GError **error, + gpointer user_data) +{ + CdDeviceItem *item; + const gchar *profile; + gchar **profiles = NULL; + guint i; + GVariant *retval = NULL; + + if (g_strcmp0 (property_name, "Created") == 0) { + retval = g_variant_new_uint64 (0); + goto out; + } + if (g_strcmp0 (property_name, "Model") == 0) { + retval = g_variant_new_string ("hello dave"); + goto out; + } + if (g_strcmp0 (property_name, "DeviceId") == 0) { + item = cd_main_device_find_by_object_path (object_path); + retval = g_variant_new_string (item->device_id); + goto out; + } + if (g_strcmp0 (property_name, "Profiles") == 0) { + item = cd_main_device_find_by_object_path (object_path); + profiles = g_new0 (gchar *, item->profiles->len + 1); + for (i=0; i<item->profiles->len; i++) { + profile = g_ptr_array_index (item->profiles, i); + profiles[i] = g_strdup (profile); + } + retval = g_variant_new_strv ((const gchar * const*) profiles, -1); + goto out; + } + + g_critical ("failed to set property %s", property_name); +out: + g_strfreev (profiles); + return retval; +} + +/** + * cd_main_create_device: + **/ +static CdDeviceItem * +cd_main_create_device (const gchar *device_id, GError **error) +{ + gboolean ret; + CdDeviceItem *item; + static const GDBusInterfaceVTable interface_vtable = { + cd_main_device_method_call, + cd_main_device_get_property, + NULL + }; + + g_assert (connection != NULL); -#define COLORD_SERVICE "org.freedesktop.ColorManager" -#define COLORD_PATH "/org/freedesktop/ColorManager" + /* create an object */ + item = g_new0 (CdDeviceItem, 1); + item->device_id = g_strdup (device_id); + item->object_path = g_build_filename (COLORD_DBUS_PATH, device_id, NULL); + item->profiles = g_ptr_array_new_with_free_func (g_free); + g_ptr_array_add (devices_array, item); + g_debug ("Adding device %s", item->object_path); + item->registration_id = g_dbus_connection_register_object (connection, + item->object_path, + introspection_device->interfaces[0], + &interface_vtable, + NULL, /* user_data */ + NULL, /* user_data_free_func */ + NULL); /* GError** */ + g_assert (item->registration_id > 0); + + /* emit signal */ + ret = g_dbus_connection_emit_signal (connection, + NULL, + COLORD_DBUS_PATH, + COLORD_DBUS_INTERFACE_DEVICE, + "DeviceAdded", + g_variant_new ("(s)", + item->object_path), + error); + if (!ret) + goto out; +out: + return item; +} /** - * cd_main_handle_method_call: + * cd_main_daemon_method_call: **/ static void -cd_main_handle_method_call (GDBusConnection *connection_, const gchar *sender, +cd_main_daemon_method_call (GDBusConnection *connection_, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data) @@ -46,16 +520,38 @@ cd_main_handle_method_call (GDBusConnection *connection_, const gchar *sender, GVariant *value = NULL; gchar **devices = NULL; guint i; - const gchar *device; +// const gchar *device; + gchar *device_id = NULL; + CdDeviceItem *item_device; + CdProfileItem *item_profile; +// gboolean ret; + GError *error = NULL; /* return 'as' */ if (g_strcmp0 (method_name, "GetDevices") == 0) { - /* copy the device path */ + /* copy the object paths */ devices = g_new0 (gchar *, devices_array->len + 1); for (i=0; i<devices_array->len; i++) { - device = g_ptr_array_index (devices_array, i); - devices[i] = g_strdup (device); + item_device = g_ptr_array_index (devices_array, i); + devices[i] = g_strdup (item_device->object_path); + } + + /* format the value */ + value = g_variant_new_strv ((const gchar * const *) devices, -1); + tuple = g_variant_new_tuple (&value, 1); + g_dbus_method_invocation_return_value (invocation, tuple); + goto out; + } + + /* return 'as' */ + if (g_strcmp0 (method_name, "GetProfiles") == 0) { + + /* copy the object paths */ + devices = g_new0 (gchar *, profiles_array->len + 1); + for (i=0; i<profiles_array->len; i++) { + item_profile = g_ptr_array_index (profiles_array, i); + devices[i] = g_strdup (item_profile->object_path); } /* format the value */ @@ -65,6 +561,68 @@ cd_main_handle_method_call (GDBusConnection *connection_, const gchar *sender, goto out; } + /* return 's' */ + if (g_strcmp0 (method_name, "CreateDevice") == 0) { + + /* does already exist */ + g_variant_get (parameters, "(s)", &device_id); + item_device = cd_main_device_find_by_id (device_id); + if (item_device != NULL) { + g_dbus_method_invocation_return_error (invocation, + 1, //FIXME + 0, + "device object path '%s' already exists", + item_device->object_path); + goto out; + } + + /* copy the device path */ + item_device = cd_main_create_device (device_id, &error); + if (item_device == NULL) { + g_dbus_method_invocation_return_gerror (invocation, + error); + goto out; + } + + /* format the value */ + value = g_variant_new_string (item_device->object_path); + tuple = g_variant_new_tuple (&value, 1); + g_dbus_method_invocation_return_value (invocation, tuple); + goto out; + } + + /* return 's' */ + if (g_strcmp0 (method_name, "CreateProfile") == 0) { + + /* does already exist */ + g_variant_get (parameters, "(s)", &device_id); + item_profile = cd_main_profile_find_by_id (device_id); + if (item_profile != NULL) { + g_dbus_method_invocation_return_error (invocation, + 1, //FIXME + 0, + "profile object path '%s' already exists", + item_profile->object_path); + goto out; + } + + /* copy the device path */ + item_profile = cd_main_create_profile (device_id, &error); + if (item_profile == NULL) { + g_dbus_method_invocation_return_gerror (invocation, + error); + goto out; + } + + /* format the value */ + value = g_variant_new_string (item_profile->object_path); + tuple = g_variant_new_tuple (&value, 1); + g_dbus_method_invocation_return_value (invocation, tuple); + goto out; + } + + /* we suck */ + g_critical ("failed to process method %s", method_name); out: if (tuple != NULL) g_variant_unref (tuple); @@ -75,18 +633,21 @@ out: } /** - * cd_main_handle_get_property: + * cd_main_daemon_get_property: **/ static GVariant * -cd_main_handle_get_property (GDBusConnection *connection_, const gchar *sender, +cd_main_daemon_get_property (GDBusConnection *connection_, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data) { GVariant *retval = NULL; - if (g_strcmp0 (property_name, "FubarXXX") == 0) { - retval = g_variant_new_boolean (TRUE); + if (g_strcmp0 (property_name, "DaemonVersion") == 0) { + retval = g_variant_new_string (VERSION); + } else { + g_critical ("failed to get property %s", + property_name); } return retval; @@ -102,14 +663,14 @@ cd_main_on_bus_acquired_cb (GDBusConnection *connection_, { guint registration_id; static const GDBusInterfaceVTable interface_vtable = { - cd_main_handle_method_call, - cd_main_handle_get_property, + cd_main_daemon_method_call, + cd_main_daemon_get_property, NULL }; registration_id = g_dbus_connection_register_object (connection_, - COLORD_PATH, - introspection->interfaces[0], + COLORD_DBUS_PATH, + introspection_daemon->interfaces[0], &interface_vtable, NULL, /* user_data */ NULL, /* user_data_free_func */ @@ -152,8 +713,12 @@ main (int argc, char *argv[]) gboolean ret; guint retval = 1; guint owner_id = 0; - GFile *file = NULL; - gchar *introspection_data = NULL; + GFile *file_daemon = NULL; + GFile *file_device = NULL; + GFile *file_profile = NULL; + gchar *introspection_daemon_data = NULL; + gchar *introspection_device_data = NULL; + gchar *introspection_profile_data = NULL; setlocale (LC_ALL, ""); @@ -161,8 +726,6 @@ main (int argc, char *argv[]) bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); - if (! g_thread_supported ()) - g_thread_init (NULL); g_type_init (); /* TRANSLATORS: program name */ @@ -174,11 +737,37 @@ main (int argc, char *argv[]) /* create new objects */ loop = g_main_loop_new (NULL, FALSE); - devices_array = g_ptr_array_new_with_free_func (g_free); + devices_array = g_ptr_array_new_with_free_func ((GDestroyNotify) + cd_main_device_item_free); + profiles_array = g_ptr_array_new_with_free_func ((GDestroyNotify) + cd_main_profile_item_free); /* load introspection from file */ - file = g_file_new_for_path (DATADIR "/dbus-1/interfaces/org.freedesktop.ColorManager.xml"); - ret = g_file_load_contents (file, NULL, &introspection_data, NULL, NULL, &error); + file_daemon = g_file_new_for_path (DATADIR "/dbus-1/interfaces/" + COLORD_DBUS_INTERFACE ".xml"); + ret = g_file_load_contents (file_daemon, NULL, + &introspection_daemon_data, + NULL, NULL, &error); + if (!ret) { + g_warning ("failed to load introspection: %s", error->message); + g_error_free (error); + goto out; + } + file_device = g_file_new_for_path (DATADIR "/dbus-1/interfaces/" + COLORD_DBUS_INTERFACE_DEVICE ".xml"); + ret = g_file_load_contents (file_device, NULL, + &introspection_device_data, + NULL, NULL, &error); + if (!ret) { + g_warning ("failed to load introspection: %s", error->message); + g_error_free (error); + goto out; + } + file_profile = g_file_new_for_path (DATADIR "/dbus-1/interfaces/" + COLORD_DBUS_INTERFACE_PROFILE ".xml"); + ret = g_file_load_contents (file_profile, NULL, + &introspection_profile_data, + NULL, NULL, &error); if (!ret) { g_warning ("failed to load introspection: %s", error->message); g_error_free (error); @@ -186,16 +775,34 @@ main (int argc, char *argv[]) } /* build introspection from XML */ - introspection = g_dbus_node_info_new_for_xml (introspection_data, &error); - if (introspection == NULL) { - g_warning ("failed to load introspection: %s", error->message); + introspection_daemon = g_dbus_node_info_new_for_xml (introspection_daemon_data, + &error); + if (introspection_daemon == NULL) { + g_warning ("failed to load daemon introspection: %s", + error->message); + g_error_free (error); + goto out; + } + introspection_device = g_dbus_node_info_new_for_xml (introspection_device_data, + &error); + if (introspection_device == NULL) { + g_warning ("failed to load device introspection: %s", + error->message); + g_error_free (error); + goto out; + } + introspection_profile = g_dbus_node_info_new_for_xml (introspection_profile_data, + &error); + if (introspection_profile == NULL) { + g_warning ("failed to load profile introspection: %s", + error->message); g_error_free (error); goto out; } /* own the object */ owner_id = g_bus_own_name (G_BUS_TYPE_SYSTEM, - COLORD_SERVICE, + COLORD_DBUS_SERVICE, G_BUS_NAME_OWNER_FLAGS_NONE, cd_main_on_bus_acquired_cb, cd_main_on_name_acquired_cb, @@ -208,17 +815,29 @@ main (int argc, char *argv[]) /* success */ retval = 0; out: - g_free (introspection_data); + g_free (introspection_daemon_data); + g_free (introspection_device_data); + g_free (introspection_profile_data); if (devices_array != NULL) g_ptr_array_unref (devices_array); - if (file != NULL) - g_object_unref (file); + if (profiles_array != NULL) + g_ptr_array_unref (profiles_array); + if (file_daemon != NULL) + g_object_unref (file_daemon); + if (file_device != NULL) + g_object_unref (file_device); + if (file_profile != NULL) + g_object_unref (file_profile); if (owner_id > 0) g_bus_unown_name (owner_id); if (connection != NULL) g_object_unref (connection); - if (introspection != NULL) - g_dbus_node_info_unref (introspection); + if (introspection_daemon != NULL) + g_dbus_node_info_unref (introspection_daemon); + if (introspection_device != NULL) + g_dbus_node_info_unref (introspection_device); + if (introspection_profile != NULL) + g_dbus_node_info_unref (introspection_profile); g_main_loop_unref (loop); return retval; } diff --git a/src/cd-util.c b/src/cd-util.c new file mode 100644 index 0000000..f9cd3b3 --- /dev/null +++ b/src/cd-util.c @@ -0,0 +1,224 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2010 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU General Public License Version 2 + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include <glib/gi18n.h> +#include <gio/gio.h> +#include <locale.h> + +#include "cd-common.h" + +/** + * main: + **/ +int +main (int argc, char *argv[]) +{ + const gchar **devices; + const gchar *object_path; + //gboolean ret; + GDBusConnection *connection; + GError *error = NULL; + GOptionContext *context; + guint i; + guint retval = 1; + GVariant *response_child = NULL; + GVariant *response = NULL; + + setlocale (LC_ALL, ""); + + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + + g_type_init (); + + /* TRANSLATORS: program name */ + g_set_application_name (_("Color Management")); + context = g_option_context_new (NULL); + g_option_context_set_summary (context, _("Color Management Utility")); + g_option_context_parse (context, &argc, &argv, NULL); + g_option_context_free (context); + + /* get a session bus connection */ + connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); + if (connection == NULL) { + /* TRANSLATORS: no DBus system bus */ + g_print ("%s %s\n", _("Failed to connect to system bus:"), error->message); + g_error_free (error); + goto out; + } + + if (argc < 2) { + g_print ("Not enough arguments\n"); + goto out; + } + + /* find the commands */ + if (g_strcmp0 (argv[1], "get-devices") == 0) { + + /* execute sync method */ + response = g_dbus_connection_call_sync (connection, + COLORD_DBUS_SERVICE, + COLORD_DBUS_PATH, + COLORD_DBUS_INTERFACE, + "GetDevices", + NULL, + G_VARIANT_TYPE ("(as)"), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (response == NULL) { + /* TRANSLATORS: the DBus method failed */ + g_print ("%s %s\n", _("The request failed:"), error->message); + g_error_free (error); + goto out; + } + + /* print each device */ + response_child = g_variant_get_child_value (response, 0); + devices = g_variant_get_strv (response_child, NULL); + for (i=0; devices[i] != NULL; i++) { + g_print ("%i.\t%s\n", i+1, devices[i]); + } + + } else if (g_strcmp0 (argv[1], "get-profiles") == 0) { + + /* execute sync method */ + response = g_dbus_connection_call_sync (connection, + COLORD_DBUS_SERVICE, + COLORD_DBUS_PATH, + COLORD_DBUS_INTERFACE, + "GetProfiles", + NULL, + G_VARIANT_TYPE ("(as)"), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (response == NULL) { + /* TRANSLATORS: the DBus method failed */ + g_print ("%s %s\n", _("The request failed:"), error->message); + g_error_free (error); + goto out; + } + + /* print each device */ + response_child = g_variant_get_child_value (response, 0); + devices = g_variant_get_strv (response_child, NULL); + for (i=0; devices[i] != NULL; i++) { + g_print ("%i.\t%s\n", i+1, devices[i]); + } + + } else if (g_strcmp0 (argv[1], "create-device") == 0) { + + if (argc < 3) { + g_print ("Not enough arguments\n"); + goto out; + } + + /* execute sync method */ + response = g_dbus_connection_call_sync (connection, + COLORD_DBUS_SERVICE, + COLORD_DBUS_PATH, + COLORD_DBUS_INTERFACE, + "CreateDevice", + g_variant_new ("(s)", argv[2]), + G_VARIANT_TYPE ("(s)"), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (response == NULL) { + /* TRANSLATORS: the DBus method failed */ + g_print ("%s %s\n", _("The request failed:"), error->message); + g_error_free (error); + goto out; + } + + /* print the device */ + response_child = g_variant_get_child_value (response, 0); + object_path = g_variant_get_string (response_child, NULL); + g_print ("Created device %s\n", object_path); + + } else if (g_strcmp0 (argv[1], "create-profile") == 0) { + + if (argc < 3) { + g_print ("Not enough arguments\n"); + goto out; + } + + /* execute sync method */ + response = g_dbus_connection_call_sync (connection, + COLORD_DBUS_SERVICE, + COLORD_DBUS_PATH, + COLORD_DBUS_INTERFACE, + "CreateProfile", + g_variant_new ("(s)", argv[2]), + G_VARIANT_TYPE ("(s)"), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (response == NULL) { + /* TRANSLATORS: the DBus method failed */ + g_print ("%s %s\n", _("The request failed:"), error->message); + g_error_free (error); + goto out; + } + + /* print the device */ + response_child = g_variant_get_child_value (response, 0); + object_path = g_variant_get_string (response_child, NULL); + g_print ("Created profile %s\n", object_path); + + } else if (g_strcmp0 (argv[1], "device-add-profile") == 0) { + + if (argc < 3) { + g_print ("Not enough arguments\n"); + goto out; + } + + /* execute sync method */ + response = g_dbus_connection_call_sync (connection, + COLORD_DBUS_SERVICE, + argv[2], + COLORD_DBUS_INTERFACE_DEVICE, + "AddProfile", + g_variant_new ("(s)", argv[3]), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (response == NULL) { + /* TRANSLATORS: the DBus method failed */ + g_print ("%s %s\n", _("The request failed:"), error->message); + g_error_free (error); + goto out; + } + + } else { + + g_print ("Command '%s' not known\n", argv[1]); + goto out; + } + + /* success */ + retval = 0; +out: + if (response != NULL) + g_variant_unref (response); + return retval; +} + diff --git a/src/org.freedesktop.ColorManager.Device.xml b/src/org.freedesktop.ColorManager.Device.xml index b9e25dd..c5acd8b 100644 --- a/src/org.freedesktop.ColorManager.Device.xml +++ b/src/org.freedesktop.ColorManager.Device.xml @@ -34,6 +34,17 @@ </property> <!--*****************************************************************************************--> + <property name='DeviceId' type='s' access='read'> + <doc:doc> + <doc:description> + <doc:para> + The device id string. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <!--*****************************************************************************************--> <property name='Profiles' type='as' access='read'> <doc:doc> <doc:description> diff --git a/src/org.freedesktop.ColorManager.Profile.xml b/src/org.freedesktop.ColorManager.Profile.xml index e824d43..7639bf8 100644 --- a/src/org.freedesktop.ColorManager.Profile.xml +++ b/src/org.freedesktop.ColorManager.Profile.xml @@ -12,6 +12,17 @@ </doc:doc> <!--*****************************************************************************************--> + <property name='ProfileId' type='s' access='read'> + <doc:doc> + <doc:description> + <doc:para> + The identification hash of the profile. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <!--*****************************************************************************************--> <property name='Title' type='s' access='read'> <doc:doc> <doc:description> diff --git a/src/org.freedesktop.ColorManager.xml b/src/org.freedesktop.ColorManager.xml index 2ec894c..f8b585a 100644 --- a/src/org.freedesktop.ColorManager.xml +++ b/src/org.freedesktop.ColorManager.xml @@ -12,6 +12,17 @@ </doc:doc> <!--*****************************************************************************************--> + <property name='DaemonVersion' type='s' access='read'> + <doc:doc> + <doc:description> + <doc:para> + The daemon version. + </doc:para> + </doc:description> + </doc:doc> + </property> + + <!--*****************************************************************************************--> <method name='GetProfilesForDevice'> <annotation name='org.freedesktop.DBus.GLib.Async' value=''/> <doc:doc> @@ -181,6 +192,16 @@ </doc:para> </doc:description> </doc:doc> + <arg type='s' name='profile_id' direction='in'> + <doc:doc> + <doc:summary> + <doc:para> + A unique profile ID that is used to map to the profile. + This is normally the MD5 hash of the disk profile. + </doc:para> + </doc:summary> + </doc:doc> + </arg> <arg type='s' name='profile_path' direction='out'> <doc:doc> <doc:summary> @@ -202,6 +223,15 @@ </doc:para> </doc:description> </doc:doc> + <arg type='s' name='device_id' direction='in'> + <doc:doc> + <doc:summary> + <doc:para> + A device ID that is used to map to the device path. + </doc:para> + </doc:summary> + </doc:doc> + </arg> <arg type='s' name='device_path' direction='out'> <doc:doc> <doc:summary> |