1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2012 Intel Corporation
4  *
5  * This library is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12  * for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Authors: Tristan Van Berkom <tristanvb@openismus.com>
18  */
19 
20 /**
21  * SECTION: e-data-book-direct
22  * @include: libedata-book/libedata-book.h
23  * @short_description: An interface for implementing Direct Read Access
24  *
25  * This class should be created by an #EBookBackendClass.get_direct_book()
26  * implementation of a backend which supports direct read access.
27  *
28  * This will only be asked of the backend when instantiated on the server
29  * side. If the server side instance of an #EBookBackend does return
30  * an #EDataBookDirect, then a client side instance of the same backend
31  * will be created and #EBookBackendClass.configure_direct() will be
32  * called on the corresponding client side instance.
33  **/
34 #include "evolution-data-server-config.h"
35 
36 #include <string.h>
37 
38 #include <e-dbus-direct-book.h>
39 #include "e-data-book-direct.h"
40 
41 #define THRESHOLD_ITEMS   32	/* how many items can be hold in a cache, before propagated to UI */
42 #define THRESHOLD_SECONDS  2	/* how long to wait until notifications are propagated to UI; in seconds */
43 
44 struct _EDataBookDirectPrivate {
45 	EDBusDirectBook *gdbus_object;
46 };
47 
48 G_DEFINE_TYPE_WITH_PRIVATE (EDataBookDirect, e_data_book_direct, G_TYPE_OBJECT);
49 
50 /* GObjectClass */
51 static void
e_data_book_direct_dispose(GObject * object)52 e_data_book_direct_dispose (GObject *object)
53 {
54 	EDataBookDirect *direct = E_DATA_BOOK_DIRECT (object);
55 
56 	if (direct->priv->gdbus_object) {
57 		g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (direct->priv->gdbus_object));
58 		g_object_unref (direct->priv->gdbus_object);
59 		direct->priv->gdbus_object = NULL;
60 	}
61 
62 	G_OBJECT_CLASS (e_data_book_direct_parent_class)->dispose (object);
63 }
64 
65 static void
e_data_book_direct_init(EDataBookDirect * direct)66 e_data_book_direct_init (EDataBookDirect *direct)
67 {
68 	direct->priv = e_data_book_direct_get_instance_private (direct);
69 	direct->priv->gdbus_object = e_dbus_direct_book_skeleton_new ();
70 }
71 
72 static void
e_data_book_direct_class_init(EDataBookDirectClass * class)73 e_data_book_direct_class_init (EDataBookDirectClass *class)
74 {
75 	GObjectClass *object_class = G_OBJECT_CLASS (class);
76 
77 	object_class->dispose = e_data_book_direct_dispose;
78 }
79 
80 /**
81  * e_data_book_direct_new:
82  * @backend_path: Full path to the installed backend shared library
83  * @backend_factory_name: Type name of the EBookBackendFactory implemented by the library
84  * @config: A backend specific configuration string
85  *
86  * Creates an #EDataBookDirect to report configuration data needed for direct
87  * read access.
88  *
89  * This is returned by e_book_backend_get_direct_book() for backends
90  * which support direct read access mode.
91  *
92  * Returns: (transfer full): A newly created #EDataBookDirect
93  *
94  * Since: 3.8
95  */
96 EDataBookDirect *
e_data_book_direct_new(const gchar * backend_path,const gchar * backend_factory_name,const gchar * config)97 e_data_book_direct_new (const gchar *backend_path,
98                         const gchar *backend_factory_name,
99                         const gchar *config)
100 {
101 	EDataBookDirect *direct;
102 
103 	g_return_val_if_fail (backend_path && backend_path[0], NULL);
104 	g_return_val_if_fail (backend_factory_name && backend_factory_name[0], NULL);
105 
106 	direct = g_object_new (E_TYPE_DATA_BOOK_DIRECT, NULL);
107 
108 	e_dbus_direct_book_set_backend_path (direct->priv->gdbus_object, backend_path);
109 	e_dbus_direct_book_set_backend_name (direct->priv->gdbus_object, backend_factory_name);
110 	e_dbus_direct_book_set_backend_config (direct->priv->gdbus_object, config);
111 
112 	return direct;
113 }
114 
115 /**
116  * e_data_book_direct_register_gdbus_object:
117  * @direct: An #EDataBookDirect
118  * @connection: The #GDBusConnection to register with
119  * @object_path: The object path to place the direct access configuration data
120  * @error: A location to store any error which might occur while registering
121  *
122  * Places @direct on the @connection at @object_path
123  *
124  * Since: 3.8
125  **/
126 gboolean
e_data_book_direct_register_gdbus_object(EDataBookDirect * direct,GDBusConnection * connection,const gchar * object_path,GError ** error)127 e_data_book_direct_register_gdbus_object (EDataBookDirect *direct,
128                                           GDBusConnection *connection,
129                                           const gchar *object_path,
130                                           GError **error)
131 {
132 	g_return_val_if_fail (E_IS_DATA_BOOK_DIRECT (direct), FALSE);
133 	g_return_val_if_fail (connection != NULL, FALSE);
134 	g_return_val_if_fail (object_path != NULL, 0);
135 
136 	return g_dbus_interface_skeleton_export (
137 		G_DBUS_INTERFACE_SKELETON (direct->priv->gdbus_object),
138 		connection, object_path, error);
139 }
140