4
* Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
6
* Copyright 2010-2012 Canonical Ltd.
8
* This program is free software: you can redistribute it and/or modify it
9
* under the terms of the GNU General Public License version 3, as published
10
* by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranties of
14
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
* PURPOSE. See the GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License along
18
* with this program. If not, see <http://www.gnu.org/licenses/>.
20
* In addition, as a special exception, the copyright holders give
21
* permission to link the code of portions of this program with the
22
* OpenSSL library under certain conditions as described in each
23
* individual source file, and distribute linked combinations
25
* You must obey the GNU General Public License in all respects
26
* for all of the code used other than OpenSSL. If you modify
27
* file(s) with this exception, you may extend this exception to your
28
* version of the file(s), but you are not obligated to do so. If you
29
* do not wish to do so, delete this exception statement from your
30
* version. If you delete this exception statement from all source
31
* files in the program, then also delete it here.
38
#include <dbus/dbus-glib.h>
40
#include "syncdaemon-filesystem-interface.h"
42
G_DEFINE_TYPE(SyncdaemonFilesystemInterface, syncdaemon_filesystem_interface, SYNCDAEMON_TYPE_INTERFACE)
44
struct _SyncdaemonFilesystemInterfacePrivate {
49
syncdaemon_filesystem_interface_finalize (GObject *object)
51
SyncdaemonFilesystemInterface *interface = SYNCDAEMON_FILESYSTEM_INTERFACE (object);
53
if (interface->priv != NULL) {
54
g_free (interface->priv);
57
G_OBJECT_CLASS (syncdaemon_filesystem_interface_parent_class)->finalize (object);
61
syncdaemon_filesystem_interface_class_init (SyncdaemonFilesystemInterfaceClass *klass)
63
GObjectClass *object_class = G_OBJECT_CLASS (klass);
65
object_class->finalize = syncdaemon_filesystem_interface_finalize;
69
syncdaemon_filesystem_interface_init (SyncdaemonFilesystemInterface *interface)
71
interface->priv = g_new0 (SyncdaemonFilesystemInterfacePrivate, 1);
73
/* Setup DBus proxy */
74
interface->priv->proxy = syncdaemon_interface_setup_proxy (SYNCDAEMON_INTERFACE (interface),
75
"com.ubuntuone.SyncDaemon",
76
"/filesystem", "com.ubuntuone.SyncDaemon.FileSystem");
80
* syncdaemon_filesystem_interface_new:
82
SyncdaemonFilesystemInterface *
83
syncdaemon_filesystem_interface_new (SyncdaemonDaemon *daemon)
85
g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
87
return g_object_new (SYNCDAEMON_TYPE_FILESYSTEM_INTERFACE, "daemon", daemon, NULL);
91
* syncdaemon_filesystem_interface_get_metadata:
94
syncdaemon_filesystem_interface_get_metadata (SyncdaemonFilesystemInterface *interface,
96
gboolean with_subtree_sync_check)
102
g_return_val_if_fail (SYNCDAEMON_IS_FILESYSTEM_INTERFACE (interface), NULL);
104
if (with_subtree_sync_check)
105
method = "get_metadata_and_quick_tree_synced";
107
method = "get_metadata";
109
if (!dbus_g_proxy_call (DBUS_G_PROXY (interface->priv->proxy), method, &error,
112
dbus_g_type_get_map ("GHashTable",
114
G_TYPE_STRING), &hash,
116
g_warning ("Failed calling %s: %s", method, error->message);
117
g_error_free (error);
122
return syncdaemon_metadata_new_from_hash_table (hash);
126
SyncdaemonFilesystemInterface *interface;
127
SyncdaemonGotMetadataFunc callback;
132
got_metadata_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
135
GError *error = NULL;
136
GotMetadataData *gmd = (GotMetadataData *) user_data;
138
if (dbus_g_proxy_end_call (proxy, call_id, &error,
139
dbus_g_type_get_map ("GHashTable",
141
G_TYPE_STRING), &hash,
143
SyncdaemonMetadata *metadata;
145
metadata = syncdaemon_metadata_new_from_hash_table (hash);
146
gmd->callback (gmd->interface, TRUE, metadata, gmd->user_data);
149
g_object_unref (G_OBJECT (metadata));
150
g_hash_table_destroy (hash);
152
g_warning ("Error getting metadata: %s", error->message);
153
g_error_free (error);
154
gmd->callback (gmd->interface, FALSE, NULL, gmd->user_data);
161
* syncdaemon_filesystem_interface_get_metadata_async:
164
syncdaemon_filesystem_interface_get_metadata_async (SyncdaemonFilesystemInterface *interface,
166
gboolean with_subtree_sync_check,
167
SyncdaemonGotMetadataFunc callback,
170
GotMetadataData *gmd;
173
g_return_if_fail (SYNCDAEMON_IS_FILESYSTEM_INTERFACE (interface));
175
if (with_subtree_sync_check)
176
method = "get_metadata_and_quick_tree_synced";
178
method = "get_metadata";
180
gmd = g_new0 (GotMetadataData, 1);
181
gmd->interface = interface;
182
gmd->callback = callback;
183
gmd->user_data = user_data;
185
dbus_g_proxy_begin_call (DBUS_G_PROXY (interface->priv->proxy),
187
got_metadata_cb, gmd, NULL,