~ubuntu-branches/ubuntu/saucy/ubuntuone-client/saucy-proposed

« back to all changes in this revision

Viewing changes to libsyncdaemon/syncdaemon-filesystem-interface.c

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2013-07-11 15:11:07 UTC
  • mfrom: (1.1.83)
  • Revision ID: package-import@ubuntu.com-20130711151107-6tbv4n9er446e2yy
Tags: 13.07-0ubuntu1
* New upstream release.
  - Remove libsyncdaemon and convert to pure python project.
* debian/control:
  - Update dependencies for changes.
  - Drop libsyncdaemon packages. (LP: #1196684)
* debian/rules:
  - Convert to pure dh and update for build system changes.
* debian/tests:
  - Add autopkgtest configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Syncdaemon API
3
 
 *
4
 
 * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
5
 
 *
6
 
 * Copyright 2010-2012 Canonical Ltd.
7
 
 *
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.
11
 
 *
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.
16
 
 *
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/>.
19
 
 *
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
24
 
 * including the two.
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.
32
 
 *
33
 
 */
34
 
 
35
 
#include "config.h"
36
 
#ifdef HAVE_GDBUS
37
 
#else
38
 
#include <dbus/dbus-glib.h>
39
 
#endif
40
 
#include "syncdaemon-filesystem-interface.h"
41
 
 
42
 
G_DEFINE_TYPE(SyncdaemonFilesystemInterface, syncdaemon_filesystem_interface, SYNCDAEMON_TYPE_INTERFACE)
43
 
 
44
 
struct _SyncdaemonFilesystemInterfacePrivate {
45
 
        GObject *proxy;
46
 
};
47
 
 
48
 
static void
49
 
syncdaemon_filesystem_interface_finalize (GObject *object)
50
 
{
51
 
        SyncdaemonFilesystemInterface *interface = SYNCDAEMON_FILESYSTEM_INTERFACE (object);
52
 
 
53
 
        if (interface->priv != NULL) {
54
 
                g_free (interface->priv);
55
 
        }
56
 
 
57
 
        G_OBJECT_CLASS (syncdaemon_filesystem_interface_parent_class)->finalize (object);
58
 
}
59
 
 
60
 
static void
61
 
syncdaemon_filesystem_interface_class_init (SyncdaemonFilesystemInterfaceClass *klass)
62
 
{
63
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
64
 
 
65
 
        object_class->finalize = syncdaemon_filesystem_interface_finalize;
66
 
}
67
 
 
68
 
static void
69
 
syncdaemon_filesystem_interface_init (SyncdaemonFilesystemInterface *interface)
70
 
{
71
 
        interface->priv = g_new0 (SyncdaemonFilesystemInterfacePrivate, 1);
72
 
 
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");
77
 
}
78
 
 
79
 
/**
80
 
 * syncdaemon_filesystem_interface_new:
81
 
 */
82
 
SyncdaemonFilesystemInterface *
83
 
syncdaemon_filesystem_interface_new (SyncdaemonDaemon *daemon)
84
 
{
85
 
        g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
86
 
 
87
 
        return g_object_new (SYNCDAEMON_TYPE_FILESYSTEM_INTERFACE, "daemon", daemon, NULL);
88
 
}
89
 
 
90
 
/**
91
 
 * syncdaemon_filesystem_interface_get_metadata:
92
 
 */
93
 
SyncdaemonMetadata *
94
 
syncdaemon_filesystem_interface_get_metadata (SyncdaemonFilesystemInterface *interface,
95
 
                                              const gchar *path,
96
 
                                              gboolean with_subtree_sync_check)
97
 
{
98
 
        GError *error = NULL;
99
 
        GHashTable *hash;
100
 
        const char *method;
101
 
 
102
 
        g_return_val_if_fail (SYNCDAEMON_IS_FILESYSTEM_INTERFACE (interface), NULL);
103
 
 
104
 
        if (with_subtree_sync_check)
105
 
                method = "get_metadata_and_quick_tree_synced";
106
 
        else
107
 
                method = "get_metadata";
108
 
 
109
 
        if (!dbus_g_proxy_call (DBUS_G_PROXY (interface->priv->proxy), method, &error,
110
 
                               G_TYPE_STRING, path,
111
 
                               G_TYPE_INVALID,
112
 
                               dbus_g_type_get_map ("GHashTable",
113
 
                                                    G_TYPE_STRING,
114
 
                                                    G_TYPE_STRING), &hash,
115
 
                               G_TYPE_INVALID)) {
116
 
                g_warning ("Failed calling %s: %s", method, error->message);
117
 
                g_error_free (error);
118
 
 
119
 
                return NULL;
120
 
        }
121
 
 
122
 
        return syncdaemon_metadata_new_from_hash_table (hash);
123
 
}
124
 
 
125
 
typedef struct {
126
 
        SyncdaemonFilesystemInterface *interface;
127
 
        SyncdaemonGotMetadataFunc callback;
128
 
        gpointer user_data;
129
 
} GotMetadataData;
130
 
 
131
 
static void
132
 
got_metadata_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data)
133
 
{
134
 
        GHashTable *hash;
135
 
        GError *error = NULL;
136
 
        GotMetadataData *gmd = (GotMetadataData *) user_data;
137
 
 
138
 
        if (dbus_g_proxy_end_call (proxy, call_id, &error,
139
 
                                   dbus_g_type_get_map ("GHashTable",
140
 
                                                        G_TYPE_STRING,
141
 
                                                        G_TYPE_STRING), &hash,
142
 
                                   G_TYPE_INVALID)) {
143
 
                SyncdaemonMetadata *metadata;
144
 
 
145
 
                metadata = syncdaemon_metadata_new_from_hash_table (hash);
146
 
                gmd->callback (gmd->interface, TRUE, metadata, gmd->user_data);
147
 
 
148
 
                /* Free memory */
149
 
                g_object_unref (G_OBJECT (metadata));
150
 
                g_hash_table_destroy (hash);
151
 
        } else {
152
 
                g_warning ("Error getting metadata: %s", error->message);
153
 
                g_error_free (error);
154
 
                gmd->callback (gmd->interface, FALSE, NULL, gmd->user_data);
155
 
        }
156
 
 
157
 
        g_free (gmd);
158
 
}
159
 
 
160
 
/**
161
 
 * syncdaemon_filesystem_interface_get_metadata_async:
162
 
 */
163
 
void
164
 
syncdaemon_filesystem_interface_get_metadata_async (SyncdaemonFilesystemInterface *interface,
165
 
                                                    const gchar *path,
166
 
                                                    gboolean with_subtree_sync_check,
167
 
                                                    SyncdaemonGotMetadataFunc callback,
168
 
                                                    gpointer user_data)
169
 
{
170
 
        GotMetadataData *gmd;
171
 
        const gchar *method;
172
 
 
173
 
        g_return_if_fail (SYNCDAEMON_IS_FILESYSTEM_INTERFACE (interface));
174
 
 
175
 
        if (with_subtree_sync_check)
176
 
                method = "get_metadata_and_quick_tree_synced";
177
 
        else
178
 
                method = "get_metadata";
179
 
 
180
 
        gmd = g_new0 (GotMetadataData, 1);
181
 
        gmd->interface = interface;
182
 
        gmd->callback = callback;
183
 
        gmd->user_data = user_data;
184
 
 
185
 
        dbus_g_proxy_begin_call (DBUS_G_PROXY (interface->priv->proxy),
186
 
                                 method,
187
 
                                 got_metadata_cb, gmd, NULL,
188
 
                                 G_TYPE_STRING, path,
189
 
                                 G_TYPE_INVALID);
190
 
}