diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2009-05-04 15:47:38 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2009-05-05 12:17:58 +0100 |
commit | b06a18982a0c6e9e3ef315a64f8e9120e5a469bc (patch) | |
tree | 6006a136aea71d1b13c13281137c2249a017f324 | |
parent | 7c3015a53a96f2bcebd318a830a5301d9defe0a1 (diff) |
McdAccountManager: fold -creation.c into main .c (no code changes)
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/mcd-account-manager-creation.c | 158 | ||||
-rw-r--r-- | src/mcd-account-manager-creation.h | 42 | ||||
-rw-r--r-- | src/mcd-account-manager.c | 125 |
4 files changed, 124 insertions, 203 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index a1dafc6e..a2421337 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,6 @@ mission_control_include_HEADERS = \ mcd-account-connection.h \ mcd-account-requests.h \ mcd-account-manager.h \ - mcd-account-manager-creation.h \ mcd-account-manager-query.h \ mcd-account-stats.h \ mcd-dbusprop.h \ @@ -119,7 +118,6 @@ libmissioncontrol_server_la_SOURCES = \ mcd-account-requests.c \ mcd-account-stats.c \ mcd-account-manager.c \ - mcd-account-manager-creation.c \ mcd-account-manager-priv.h \ mcd-account-manager-query.c \ mcd-account-priv.h \ diff --git a/src/mcd-account-manager-creation.c b/src/mcd-account-manager-creation.c deleted file mode 100644 index 3c0f834f..00000000 --- a/src/mcd-account-manager-creation.c +++ /dev/null @@ -1,158 +0,0 @@ -/* vi: set et sw=4 ts=8 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */ -/* - * This file is part of mission-control - * - * Copyright (C) 2008 Nokia Corporation. - * - * Contact: Alberto Mardegan <alberto.mardegan@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <string.h> -#include <glib/gstdio.h> -#include <glib/gi18n.h> -#include <config.h> - -#include <telepathy-glib/svc-generic.h> -#include <telepathy-glib/gtypes.h> -#include <telepathy-glib/util.h> -#include "mcd-account.h" -#include "mcd-account-manager.h" -#include "mcd-account-manager-creation.h" -#include "mcd-account-manager-priv.h" -#include "_gen/interfaces.h" - -typedef struct -{ - GHashTable *properties; - DBusGMethodInvocation *context; -} McdCreationData; - -const McdDBusProp account_manager_creation_properties[] = { - { 0 }, -}; - - -static inline void -mcd_creation_data_free (McdCreationData *cd) -{ - g_hash_table_unref (cd->properties); - g_slice_free (McdCreationData, cd); -} - -static gboolean -set_new_account_properties (McdAccount *account, - GHashTable *properties, - GError **error) -{ - GHashTableIter iter; - gpointer key, value; - gboolean ok = TRUE; - - g_hash_table_iter_init (&iter, properties); - - while (g_hash_table_iter_next (&iter, &key, &value)) - { - gchar *name = key; - gchar *dot, *iface, *pname; - - if ((dot = strrchr (name, '.')) != NULL) - { - iface = g_strndup (name, dot - name); - pname = dot + 1; - mcd_dbusprop_set_property (TP_SVC_DBUS_PROPERTIES (account), - iface, pname, value, error); - g_free (iface); - } - else - { - g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, - "Malformed property name: %s", name); - ok = FALSE; - break; - } - } - - return ok; -} - -static void -create_account_with_properties_cb (McdAccountManager *account_manager, - McdAccount *account, - const GError *error, - gpointer user_data) -{ - McdCreationData *cd = user_data; - const gchar *object_path; - GError *err = NULL; - - if (G_UNLIKELY (error)) - { - dbus_g_method_return_error (cd->context, (GError *)error); - return; - } - - g_return_if_fail (MCD_IS_ACCOUNT (account)); - - if (!set_new_account_properties (account, cd->properties, &err)) - { - dbus_g_method_return_error (cd->context, err); - g_error_free (err); - return; - } - - object_path = mcd_account_get_object_path (account); - mc_svc_account_manager_interface_creation_return_from_create_account - (cd->context, object_path); -} - -static void -account_manager_create_account_with_properties ( - McSvcAccountManagerInterfaceCreation *self, - const gchar *manager, - const gchar *protocol, - const gchar *display_name, - GHashTable *parameters, - GHashTable *properties, - DBusGMethodInvocation *context) -{ - McdCreationData *cd; - - cd = g_slice_new (McdCreationData); - cd->properties = g_hash_table_ref (properties); - cd->context = context; - _mcd_account_manager_create_account (MCD_ACCOUNT_MANAGER (self), - manager, protocol, display_name, - parameters, properties, - create_account_with_properties_cb, cd, - (GDestroyNotify)mcd_creation_data_free); -} - - -void -account_manager_creation_iface_init (McSvcAccountManagerInterfaceCreationClass *iface, - gpointer iface_data) -{ -#define IMPLEMENT(x, suffix) \ - mc_svc_account_manager_interface_creation_implement_##x (\ - iface, account_manager_##x##suffix) - IMPLEMENT(create_account, _with_properties); -#undef IMPLEMENT -} - diff --git a/src/mcd-account-manager-creation.h b/src/mcd-account-manager-creation.h index 68ef8390..e69de29b 100644 --- a/src/mcd-account-manager-creation.h +++ b/src/mcd-account-manager-creation.h @@ -1,42 +0,0 @@ -/* vi: set et sw=4 ts=8 cino=t0,(0: */ -/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 8 -*- */ -/* - * mcd-account.h - the Telepathy Account D-Bus interface (service side) - * - * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2008 Nokia Corporation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __MCD_ACCOUNT_MANAGER_CREATION_H__ -#define __MCD_ACCOUNT_MANAGER_CREATION_H__ - -#include <telepathy-glib/dbus.h> -#include <telepathy-glib/enums.h> -/* auto-generated stubs */ -#include "_gen/svc-Account_Manager_Interface_Creation.h" - -#include "mcd-dbusprop.h" - -G_BEGIN_DECLS - -extern const McdDBusProp account_manager_creation_properties[]; - -void account_manager_creation_iface_init (McSvcAccountManagerInterfaceCreationClass *iface, - gpointer iface_data); - -G_END_DECLS -#endif diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c index 19cd065e..0ce792e6 100644 --- a/src/mcd-account-manager.c +++ b/src/mcd-account-manager.c @@ -32,11 +32,12 @@ #include <dbus/dbus-glib-lowlevel.h> #include <dbus/dbus.h> +#include <telepathy-glib/dbus.h> +#include <telepathy-glib/enums.h> #include <telepathy-glib/svc-generic.h> #include <telepathy-glib/util.h> #include <telepathy-glib/errors.h> #include "mcd-account-manager-query.h" -#include "mcd-account-manager-creation.h" #include "mcd-account-manager-priv.h" #include "mcd-account.h" #include "mcd-account-config.h" @@ -44,7 +45,9 @@ #include "mcd-connection-priv.h" #include "mcd-dbusprop.h" #include "mcd-misc.h" + #include "_gen/interfaces.h" +#include "_gen/svc-Account_Manager_Interface_Creation.h" #define WRITE_CONF_DELAY 500 #define INITIAL_CONFIG_FILE_CONTENTS "# Telepathy accounts\n" @@ -54,10 +57,13 @@ static void account_manager_iface_init (McSvcAccountManagerClass *iface, gpointer iface_data); +static void account_manager_creation_iface_init ( + McSvcAccountManagerInterfaceCreationClass *iface, gpointer iface_data); static void properties_iface_init (TpSvcDBusPropertiesClass *iface, gpointer iface_data); static const McdDBusProp account_manager_properties[]; +static const McdDBusProp account_manager_creation_properties[]; static const McdInterfaceData account_manager_interfaces[] = { MCD_IMPLEMENT_IFACE (mc_svc_account_manager_get_type, @@ -105,6 +111,13 @@ typedef struct GDestroyNotify destroy; } McdCreateAccountData; +/* Used by the Creation.DRAFT interface */ +typedef struct +{ + GHashTable *properties; + DBusGMethodInvocation *context; +} McdCreationData; + enum { PROP_0, @@ -322,6 +335,79 @@ mcd_create_account_data_free (McdCreateAccountData *cad) g_slice_free (McdCreateAccountData, cad); } +static inline void +mcd_creation_data_free (McdCreationData *cd) +{ + g_hash_table_unref (cd->properties); + g_slice_free (McdCreationData, cd); +} + +static gboolean +set_new_account_properties (McdAccount *account, + GHashTable *properties, + GError **error) +{ + GHashTableIter iter; + gpointer key, value; + gboolean ok = TRUE; + + g_hash_table_iter_init (&iter, properties); + + while (g_hash_table_iter_next (&iter, &key, &value)) + { + gchar *name = key; + gchar *dot, *iface, *pname; + + if ((dot = strrchr (name, '.')) != NULL) + { + iface = g_strndup (name, dot - name); + pname = dot + 1; + mcd_dbusprop_set_property (TP_SVC_DBUS_PROPERTIES (account), + iface, pname, value, error); + g_free (iface); + } + else + { + g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, + "Malformed property name: %s", name); + ok = FALSE; + break; + } + } + + return ok; +} + +static void +create_account_with_properties_cb (McdAccountManager *account_manager, + McdAccount *account, + const GError *error, + gpointer user_data) +{ + McdCreationData *cd = user_data; + const gchar *object_path; + GError *err = NULL; + + if (G_UNLIKELY (error)) + { + dbus_g_method_return_error (cd->context, (GError *)error); + return; + } + + g_return_if_fail (MCD_IS_ACCOUNT (account)); + + if (!set_new_account_properties (account, cd->properties, &err)) + { + dbus_g_method_return_error (cd->context, err); + g_error_free (err); + return; + } + + object_path = mcd_account_get_object_path (account); + mc_svc_account_manager_interface_creation_return_from_create_account + (cd->context, object_path); +} + static void complete_account_creation (McdAccount *account, const GError *cb_error, @@ -514,6 +600,39 @@ account_manager_iface_init (McSvcAccountManagerClass *iface, } static void +account_manager_create_account_with_properties ( + McSvcAccountManagerInterfaceCreation *self, + const gchar *manager, + const gchar *protocol, + const gchar *display_name, + GHashTable *parameters, + GHashTable *properties, + DBusGMethodInvocation *context) +{ + McdCreationData *cd; + + cd = g_slice_new (McdCreationData); + cd->properties = g_hash_table_ref (properties); + cd->context = context; + _mcd_account_manager_create_account (MCD_ACCOUNT_MANAGER (self), + manager, protocol, display_name, + parameters, properties, + create_account_with_properties_cb, cd, + (GDestroyNotify)mcd_creation_data_free); +} + +static void +account_manager_creation_iface_init (McSvcAccountManagerInterfaceCreationClass *iface, + gpointer iface_data) +{ +#define IMPLEMENT(x, suffix) \ + mc_svc_account_manager_interface_creation_implement_##x (\ + iface, account_manager_##x##suffix) + IMPLEMENT(create_account, _with_properties); +#undef IMPLEMENT +} + +static void accounts_to_gvalue (GHashTable *accounts, gboolean valid, GValue *value) { static GType ao_type = G_TYPE_INVALID; @@ -570,6 +689,10 @@ static const McdDBusProp account_manager_properties[] = { { 0 }, }; +static const McdDBusProp account_manager_creation_properties[] = { + { 0 }, +}; + static void properties_iface_init (TpSvcDBusPropertiesClass *iface, gpointer iface_data) { |