1 /*
2  * Copyright © 2014  Red Hat, Inc. All rights reserved.
3  * Copyright © 2014  Ding-Yi Chen <dchen@redhat.com>
4  *
5  * This file is part of the ibus-chewing Project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  */
21 
22 /**
23  * SECTION:MakerDialogBackend
24  * @short_description: An interface to configuration service
25  * @title: MakerDialog Backend
26  * @stability: Stable
27  * @include: MakerDailogBackend.h
28  *
29  * A MakerDialog backend provides an interface to configuration service like GConf2 or dconf
30  */
31 #ifndef _MAKER_DIALOG_BACKEND_H_
32 #define _MAKER_DIALOG_BACKEND_H_
33 #include <glib.h>
34 #include <glib-object.h>
35 
36 typedef struct MkdgBackend_ MkdgBackend;
37 
38 
39 /**
40  * MkdgBackendFlag:
41  * @MKDG_BACKEND_FLAG_DISCONNECTED: Disconnect from backend, so the backend works without connect to real service.
42  *
43  * MakerDialog backend flags.
44  *
45  */
46 typedef enum {
47     MKDG_BACKEND_FLAG_DISCONNECTED = 1
48 } MkdgBackendFlag;
49 
50 typedef gchar *(*BackendGetKeyFunc) (MkdgBackend * backend,
51 				     const gchar * section,
52 				     const gchar * key, gpointer userData);
53 
54 typedef GValue *(*BackendReadFunc) (MkdgBackend * backend, GValue * value,
55 				    const gchar * section,
56 				    const gchar * key, gpointer userData);
57 
58 typedef gboolean(*BackendWriteFunc) (MkdgBackend * backend, GValue * value,
59 				     const gchar * section,
60 				     const gchar * key, gpointer userData);
61 
62 /**
63  * MkdgBackend:
64  * @id: A string that identify the backend.
65  * @config: A configuration service
66  * @basePath: All keys and sub-sections of this project should be put under this path (with trailing '/')
67  * @readFunc: Callback function for load
68  * @writeFunc: Callback function for save
69  * @auxData:  Auxiliary data that might be useful.
70  *
71  * A MkdgBackend object.
72  */
73 struct MkdgBackend_ {
74     const gchar *id;
75     gpointer config;
76     const gchar *basePath;
77     BackendGetKeyFunc getKeyFunc;
78     BackendReadFunc readFunc;
79     BackendWriteFunc writeFunc;
80     MkdgBackendFlag flags;
81     gpointer auxData;
82 };
83 
84 MkdgBackend *mkdg_backend_new(const gchar * id, gpointer config,
85 			      const gchar * basePath, gpointer auxData);
86 
87 gchar *mkdg_backend_get_key(MkdgBackend * backend,
88 			    const gchar * section, const gchar * key,
89 			    gpointer userData);
90 
91 GValue *mkdg_backend_read(MkdgBackend * backend, GValue * value,
92 			  const gchar * section, const gchar * key,
93 			  gpointer userData);
94 
95 gboolean mkdg_backend_write(MkdgBackend * backend, GValue * value,
96 			    const gchar * section, const gchar * key,
97 			    gpointer userData);
98 
99 #endif				/* _MAKER_DIALOG_BACKEND_H_ */
100