5ed7535461a476e4696216486e3ad49bdf1e65a3
[profile/ivi/weekeyboard.git] / src / wkb-ibus-config.c
1 /*
2  * Copyright © 2013 Intel Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20
21 #include <Eldbus.h>
22
23 #include "wkb-ibus.h"
24 #include "wkb-ibus-defs.h"
25 #include "wkb-ibus-config-eet.h"
26
27 static struct wkb_ibus_config_eet *_conf_eet = NULL;
28
29 #define CONFIG_CHECK_MESSAGE_ERRORS(_msg) \
30    do \
31      { \
32         const char *error, *error_msg; \
33         if (eldbus_message_error_get(_msg, &error, &error_msg)) \
34           { \
35              ERR("DBus message error: %s: %s", error, error_msg); \
36              return NULL; \
37           } \
38         DBG("Message '%s' with signature '%s'", eldbus_message_member_get(_msg), eldbus_message_signature_get(_msg)); \
39      } while (0);
40
41 static Eldbus_Message *
42 _config_set_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
43 {
44    const char *section, *name;
45    Eldbus_Message_Iter *value;
46
47    CONFIG_CHECK_MESSAGE_ERRORS(msg)
48
49    if (!eldbus_message_arguments_get(msg, "ssv", &section, &name, &value))
50      {
51         ERR("Error reading message arguments");
52         return NULL;
53      }
54
55    DBG("section: '%s', name: '%s', value: '%p'", section, name, value);
56
57    return NULL;
58 }
59
60 static Eldbus_Message *
61 _config_get_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
62 {
63    const char *section, *name;
64
65    CONFIG_CHECK_MESSAGE_ERRORS(msg)
66
67    if (!eldbus_message_arguments_get(msg, "ss", &section, &name))
68      {
69         ERR("Error reading message arguments");
70         return NULL;
71      }
72
73    DBG("section: '%s', name: '%s'", section, name);
74
75    return NULL;
76 }
77
78 static Eldbus_Message *
79 _config_get_values(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
80 {
81    const char *section;
82
83    CONFIG_CHECK_MESSAGE_ERRORS(msg)
84
85    if (!eldbus_message_arguments_get(msg, "s", &section))
86      {
87         ERR("Error reading message arguments");
88         return NULL;
89      }
90
91    DBG("section: '%s'", section);
92
93    return NULL;
94 }
95
96 static Eldbus_Message *
97 _config_unset_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
98 {
99    const char *section, *name;
100
101    CONFIG_CHECK_MESSAGE_ERRORS(msg)
102
103    if (!eldbus_message_arguments_get(msg, "ss", &section, &name))
104      {
105         ERR("Error reading message arguments");
106         return NULL;
107      }
108
109    DBG("section: '%s', name: '%s'", section, name);
110
111    return NULL;
112 }
113
114 static const Eldbus_Method _wkb_ibus_config_methods[] =
115 {
116 /* typedef struct _Eldbus_Method
117  * {
118  *    const char *member;
119  *    const Eldbus_Arg_Info *in;
120  *    const Eldbus_Arg_Info *out;
121  *    Eldbus_Method_Cb cb;
122  *    unsigned int flags;
123  * } Eldbus_Method;
124  */
125    { .member = "SetValue",
126      .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}, {"v", "value"}),
127      .cb = _config_set_value, },
128
129    { .member = "GetValue",
130      .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}),
131      .out = ELDBUS_ARGS({"v", "value"}),
132      .cb = _config_get_value, },
133
134    { .member = "GetValues",
135      .in = ELDBUS_ARGS({"s", "section"}),
136      .out = ELDBUS_ARGS({"a{sv}", "values"}),
137      .cb = _config_get_values, },
138
139    { .member = "UnsetValue",
140      .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}),
141      .cb = _config_unset_value, },
142
143    { NULL },
144 };
145
146 static const Eldbus_Signal _wkb_ibus_config_signals[] =
147 {
148 /* typedef struct _Eldbus_Signal
149  * {
150  *    const char *name;
151  *    const Eldbus_Arg_Info *args;
152  *    unsigned int flags;
153  * } Eldbus_Signal;
154  */
155    { .name = "ValueChanged",
156      .args = ELDBUS_ARGS({"s", "section"}, {"s", "name"}, {"v", "value"}),
157      .flags = 0, },
158
159    { NULL },
160 };
161
162 static const Eldbus_Service_Interface_Desc _wkb_ibus_config_interface =
163 {
164    .interface = IBUS_INTERFACE_CONFIG,
165    .methods = _wkb_ibus_config_methods,
166    .signals = _wkb_ibus_config_signals,
167 };
168
169 Eldbus_Service_Interface *
170 wkb_ibus_config_register(Eldbus_Connection *conn)
171 {
172    Eldbus_Service_Interface *ret = eldbus_service_interface_register(conn, IBUS_PATH_CONFIG, &_wkb_ibus_config_interface);
173
174    if (!ret)
175      {
176         ERR("Unable to register IBusConfig interface\n");
177         goto end;
178      }
179
180    if (_conf_eet)
181      {
182         WRN("wkb_config_eet already created\n");
183         goto end;
184      }
185
186    _conf_eet = wkb_ibus_config_eet_new("");
187
188 end:
189    return ret;
190 }
191
192 static void
193 wkb_ibus_config_unregister(void)
194 {
195    if (_conf_eet)
196       wkb_ibus_config_eet_free(_conf_eet);
197 }