1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
#include <config.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <glib.h>
#include <dbus/dbus.h>
#include <glib/gi18n.h>
#include "gvfsbackend.h"
#include "gvfsjobsource.h"
#include "gvfsdaemonprotocol.h"
#include <gvfsjobopenforread.h>
#include <gvfsjobopenforwrite.h>
#include <gvfsjobqueryinfo.h>
#include <gvfsjobqueryfsinfo.h>
#include <gvfsjobsetdisplayname.h>
#include <gvfsjobenumerate.h>
#include <gvfsjobdelete.h>
#include <gvfsjobtrash.h>
#include <gvfsjobmountmountable.h>
#include <gvfsjobmakedirectory.h>
#include <gvfsjobmakesymlink.h>
#include <gvfsjobcreatemonitor.h>
#include <gvfsjobcopy.h>
#include <gvfsjobmove.h>
#include <gvfsjobsetattribute.h>
#include <gvfsjobqueryattributes.h>
#include <gdbusutils.h>
enum {
PROP_0,
PROP_OBJECT_PATH,
PROP_DAEMON
};
struct _GVfsBackendPrivate
{
GVfsDaemon *daemon;
char *object_path;
char *display_name;
char *icon;
char *prefered_filename_encoding;
gboolean user_visible;
GMountSpec *mount_spec;
};
/* TODO: Real P_() */
#define P_(_x) (_x)
static void g_vfs_backend_job_source_iface_init (GVfsJobSourceIface *iface);
static void g_vfs_backend_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void g_vfs_backend_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static GObject* g_vfs_backend_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_params);
static DBusHandlerResult backend_dbus_handler (DBusConnection *connection,
DBusMessage *message,
void *user_data);
G_DEFINE_TYPE_WITH_CODE (GVfsBackend, g_vfs_backend, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_VFS_TYPE_JOB_SOURCE,
g_vfs_backend_job_source_iface_init))
static GHashTable *registered_backends = NULL;
void
g_vfs_register_backend (GType backend_type,
const char *type)
{
if (registered_backends == NULL)
registered_backends = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
g_hash_table_insert (registered_backends,
g_strdup (type), (void *)backend_type);
}
GType
g_vfs_lookup_backend (const char *type)
{
gpointer res;
if (registered_backends != NULL)
{
res = g_hash_table_lookup (registered_backends, type);
if (res != NULL)
return (GType)res;
}
return G_TYPE_INVALID;
}
static void
g_vfs_backend_finalize (GObject *object)
{
GVfsBackend *backend;
backend = G_VFS_BACKEND (object);
g_vfs_daemon_unregister_path (backend->priv->daemon, backend->priv->object_path);
g_object_unref (backend->priv->daemon);
g_free (backend->priv->object_path);
g_free (backend->priv->display_name);
g_free (backend->priv->icon);
g_free (backend->priv->prefered_filename_encoding);
if (backend->priv->mount_spec)
g_mount_spec_unref (backend->priv->mount_spec);
if (G_OBJECT_CLASS (g_vfs_backend_parent_class)->finalize)
(*G_OBJECT_CLASS (g_vfs_backend_parent_class)->finalize) (object);
}
static void
g_vfs_backend_job_source_iface_init (GVfsJobSourceIface *iface)
{
}
static void
g_vfs_backend_class_init (GVfsBackendClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (GVfsBackendPrivate));
gobject_class->constructor = g_vfs_backend_constructor;
gobject_class->finalize = g_vfs_backend_finalize;
gobject_class->set_property = g_vfs_backend_set_property;
gobject_class->get_property = g_vfs_backend_get_property;
g_object_class_install_property (gobject_class,
PROP_OBJECT_PATH,
g_param_spec_string ("object-path",
P_("Backend object path"),
P_("The dbus object path for the backend object."),
"",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
g_object_class_install_property (gobject_class,
PROP_DAEMON,
g_param_spec_object ("daemon",
P_("Daemon"),
P_("The daemon this backend is handled by."),
G_VFS_TYPE_DAEMON,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
}
static void
g_vfs_backend_init (GVfsBackend *backend)
{
backend->priv = G_TYPE_INSTANCE_GET_PRIVATE (backend, G_VFS_TYPE_BACKEND, GVfsBackendPrivate);
backend->priv->icon = g_strdup ("");
backend->priv->prefered_filename_encoding = g_strdup ("");
backend->priv->display_name = g_strdup ("");
backend->priv->user_visible = TRUE;
}
static void
g_vfs_backend_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GVfsBackend *backend = G_VFS_BACKEND (object);
switch (prop_id)
{
case PROP_OBJECT_PATH:
backend->priv->object_path = g_value_dup_string (value);
break;
case PROP_DAEMON:
backend->priv->daemon = G_VFS_DAEMON (g_value_dup_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
g_vfs_backend_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GVfsBackend *backend = G_VFS_BACKEND (object);
switch (prop_id)
{
case PROP_OBJECT_PATH:
g_value_set_string (value, backend->priv->object_path);
break;
case PROP_DAEMON:
g_value_set_object (value, backend->priv->daemon);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static GObject*
g_vfs_backend_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_params)
{
GObject *object;
GVfsBackend *backend;
object = (* G_OBJECT_CLASS (g_vfs_backend_parent_class)->constructor) (type,
n_construct_properties,
construct_params);
backend = G_VFS_BACKEND (object);
g_vfs_daemon_register_path (backend->priv->daemon,
backend->priv->object_path,
backend_dbus_handler,
backend);
return object;
}
GVfsDaemon *
g_vfs_backend_get_daemon (GVfsBackend *backend)
{
return backend->priv->daemon;
}
void
g_vfs_backend_set_display_name (GVfsBackend *backend,
const char *display_name)
{
g_free (backend->priv->display_name);
backend->priv->display_name = g_strdup (display_name);
}
void
g_vfs_backend_set_icon_name (GVfsBackend *backend,
const char *icon)
{
g_free (backend->priv->icon);
backend->priv->icon = g_strdup (icon);
}
void
g_vfs_backend_set_prefered_filename_encoding (GVfsBackend *backend,
const char *prefered_filename_encoding)
{
g_free (backend->priv->prefered_filename_encoding);
backend->priv->prefered_filename_encoding = g_strdup (prefered_filename_encoding);
}
void
g_vfs_backend_set_user_visible (GVfsBackend *backend,
gboolean user_visible)
{
backend->priv->user_visible = user_visible;
}
void
g_vfs_backend_set_mount_spec (GVfsBackend *backend,
GMountSpec *mount_spec)
{
if (backend->priv->mount_spec)
g_mount_spec_unref (backend->priv->mount_spec);
backend->priv->mount_spec = g_mount_spec_ref (mount_spec);
}
const char *
g_vfs_backend_get_backend_type (GVfsBackend *backend)
{
if (backend->priv->mount_spec)
return g_mount_spec_get_type (backend->priv->mount_spec);
return NULL;
}
const char *
g_vfs_backend_get_display_name (GVfsBackend *backend)
{
return backend->priv->display_name;
}
const char *
g_vfs_backend_get_icon_name (GVfsBackend *backend)
{
return backend->priv->icon;
}
GMountSpec *
g_vfs_backend_get_mount_spec (GVfsBackend *backend)
{
return backend->priv->mount_spec;
}
static DBusHandlerResult
backend_dbus_handler (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{
GVfsBackend *backend = user_data;
GVfsJob *job;
job = NULL;
g_print ("backend_dbus_handler %s:%s\n",
dbus_message_get_interface (message),
dbus_message_get_member (message));
if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_OPEN_FOR_READ))
job = g_vfs_job_open_for_read_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_QUERY_INFO))
job = g_vfs_job_query_info_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_QUERY_FILESYSTEM_INFO))
job = g_vfs_job_query_fs_info_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_ENUMERATE))
job = g_vfs_job_enumerate_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_OPEN_FOR_WRITE))
job = g_vfs_job_open_for_write_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_MOUNT_MOUNTABLE))
job = g_vfs_job_mount_mountable_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_SET_DISPLAY_NAME))
job = g_vfs_job_set_display_name_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_DELETE))
job = g_vfs_job_delete_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_TRASH))
job = g_vfs_job_trash_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_MAKE_DIRECTORY))
job = g_vfs_job_make_directory_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_MAKE_SYMBOLIC_LINK))
job = g_vfs_job_make_symlink_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_COPY))
job = g_vfs_job_copy_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_MOVE))
job = g_vfs_job_move_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_SET_ATTRIBUTE))
job = g_vfs_job_set_attribute_new (connection, message, backend);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_QUERY_SETTABLE_ATTRIBUTES))
job = g_vfs_job_query_attributes_new (connection, message, backend, FALSE);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_QUERY_WRITABLE_NAMESPACES))
job = g_vfs_job_query_attributes_new (connection, message, backend, TRUE);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_CREATE_DIR_MONITOR))
job = g_vfs_job_create_monitor_new (connection, message, backend, TRUE);
else if (dbus_message_is_method_call (message,
G_VFS_DBUS_MOUNT_INTERFACE,
G_VFS_DBUS_MOUNT_OP_CREATE_FILE_MONITOR))
job = g_vfs_job_create_monitor_new (connection, message, backend, FALSE);
if (job)
{
g_vfs_job_source_new_job (G_VFS_JOB_SOURCE (backend), job);
g_object_unref (job);
return DBUS_HANDLER_RESULT_HANDLED;
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
void
g_vfs_backend_register_mount (GVfsBackend *backend,
GAsyncDBusCallback callback,
gpointer user_data)
{
DBusMessage *message;
DBusMessageIter iter;
dbus_bool_t user_visible;
message = dbus_message_new_method_call (G_VFS_DBUS_DAEMON_NAME,
G_VFS_DBUS_MOUNTTRACKER_PATH,
G_VFS_DBUS_MOUNTTRACKER_INTERFACE,
G_VFS_DBUS_MOUNTTRACKER_OP_REGISTER_MOUNT);
if (message == NULL)
_g_dbus_oom ();
user_visible = backend->priv->user_visible;
if (!dbus_message_append_args (message,
DBUS_TYPE_OBJECT_PATH, &backend->priv->object_path,
DBUS_TYPE_STRING, &backend->priv->display_name,
DBUS_TYPE_STRING, &backend->priv->icon,
DBUS_TYPE_STRING, &backend->priv->prefered_filename_encoding,
DBUS_TYPE_BOOLEAN, &user_visible,
0))
_g_dbus_oom ();
dbus_message_iter_init_append (message, &iter);
g_mount_spec_to_dbus (&iter, backend->priv->mount_spec);
dbus_message_set_auto_start (message, TRUE);
_g_dbus_connection_call_async (NULL, message, -1,
callback, user_data);
dbus_message_unref (message);
}
|