Fix handling of backspace key press
[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
25 #define CONFIG_CHECK_MESSAGE_ERRORS(_msg) \
26    do \
27      { \
28         const char *error, *error_msg; \
29         if (eldbus_message_error_get(_msg, &error, &error_msg)) \
30           { \
31              ERR("DBus message error: %s: %s", error, error_msg); \
32              return NULL; \
33           } \
34         DBG("Message '%s' with signature '%s'", eldbus_message_member_get(_msg), eldbus_message_signature_get(_msg)); \
35      } while (0);
36
37 static Eldbus_Message *
38 _config_set_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
39 {
40    const char *section, *name;
41    Eldbus_Message_Iter *value;
42
43    CONFIG_CHECK_MESSAGE_ERRORS(msg)
44
45    if (!eldbus_message_arguments_get(msg, "ssv", &section, &name, &value))
46      {
47         ERR("Error reading message arguments");
48         return NULL;
49      }
50
51    DBG("section: '%s', name: '%s', value: '%p'", section, name, value);
52
53    return NULL;
54 }
55
56 static Eldbus_Message *
57 _config_get_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
58 {
59    const char *section, *name;
60
61    CONFIG_CHECK_MESSAGE_ERRORS(msg)
62
63    if (!eldbus_message_arguments_get(msg, "ss", &section, &name))
64      {
65         ERR("Error reading message arguments");
66         return NULL;
67      }
68
69    DBG("section: '%s', name: '%s'", section, name);
70
71    return NULL;
72 }
73
74 static Eldbus_Message *
75 _config_get_values(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
76 {
77    const char *section;
78
79    CONFIG_CHECK_MESSAGE_ERRORS(msg)
80
81    if (!eldbus_message_arguments_get(msg, "s", &section))
82      {
83         ERR("Error reading message arguments");
84         return NULL;
85      }
86
87    DBG("section: '%s'", section);
88
89    return NULL;
90 }
91
92 static Eldbus_Message *
93 _config_unset_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
94 {
95    const char *section, *name;
96
97    CONFIG_CHECK_MESSAGE_ERRORS(msg)
98
99    if (!eldbus_message_arguments_get(msg, "ss", &section, &name))
100      {
101         ERR("Error reading message arguments");
102         return NULL;
103      }
104
105    DBG("section: '%s', name: '%s'", section, name);
106
107    return NULL;
108 }
109
110 static const Eldbus_Method _wkb_ibus_config_methods[] =
111 {
112 /* typedef struct _Eldbus_Method
113  * {
114  *    const char *member;
115  *    const Eldbus_Arg_Info *in;
116  *    const Eldbus_Arg_Info *out;
117  *    Eldbus_Method_Cb cb;
118  *    unsigned int flags;
119  * } Eldbus_Method;
120  */
121    { .member = "SetValue",
122      .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}, {"v", "value"}),
123      .cb = _config_set_value, },
124
125    { .member = "GetValue",
126      .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}),
127      .out = ELDBUS_ARGS({"v", "value"}),
128      .cb = _config_get_value, },
129
130    { .member = "GetValues",
131      .in = ELDBUS_ARGS({"s", "section"}),
132      .out = ELDBUS_ARGS({"a{sv}", "values"}),
133      .cb = _config_get_values, },
134
135    { .member = "UnsetValue",
136      .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}),
137      .cb = _config_unset_value, },
138
139    { NULL },
140 };
141
142 static const Eldbus_Signal _wkb_ibus_config_signals[] =
143 {
144 /* typedef struct _Eldbus_Signal
145  * {
146  *    const char *name;
147  *    const Eldbus_Arg_Info *args;
148  *    unsigned int flags;
149  * } Eldbus_Signal;
150  */
151    { .name = "ValueChanged",
152      .args = ELDBUS_ARGS({"s", "section"}, {"s", "name"}, {"v", "value"}),
153      .flags = 0, },
154
155    { NULL },
156 };
157
158 static const Eldbus_Service_Interface_Desc _wkb_ibus_config_interface =
159 {
160    .interface = IBUS_INTERFACE_CONFIG,
161    .methods = _wkb_ibus_config_methods,
162    .signals = _wkb_ibus_config_signals,
163 };
164
165 Eldbus_Service_Interface *
166 wkb_ibus_config_register(Eldbus_Connection *conn)
167 {
168    return eldbus_service_interface_register(conn, IBUS_PATH_CONFIG, &_wkb_ibus_config_interface);
169 }
170