2 * Copyright © 2013 Intel Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include "wkb-ibus-defs.h"
25 #include "wkb-ibus-config-eet.h"
27 static struct wkb_ibus_config_eet *_conf_eet = NULL;
29 #define CONFIG_CHECK_MESSAGE_ERRORS(_msg) \
32 const char *error, *error_msg; \
33 if (eldbus_message_error_get(_msg, &error, &error_msg)) \
35 ERR("DBus message error: %s: %s", error, error_msg); \
38 DBG("Message '%s' with signature '%s'", eldbus_message_member_get(_msg), eldbus_message_signature_get(_msg)); \
41 static Eldbus_Message *
42 _config_set_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
44 const char *section, *name;
45 Eldbus_Message_Iter *value;
47 CONFIG_CHECK_MESSAGE_ERRORS(msg)
49 if (!eldbus_message_arguments_get(msg, "ssv", §ion, &name, &value))
51 ERR("Error reading message arguments");
55 DBG("section: '%s', name: '%s', value: '%p'", section, name, value);
60 static Eldbus_Message *
61 _config_get_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
63 const char *section, *name;
65 CONFIG_CHECK_MESSAGE_ERRORS(msg)
67 if (!eldbus_message_arguments_get(msg, "ss", §ion, &name))
69 ERR("Error reading message arguments");
73 DBG("section: '%s', name: '%s'", section, name);
78 static Eldbus_Message *
79 _config_get_values(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
83 CONFIG_CHECK_MESSAGE_ERRORS(msg)
85 if (!eldbus_message_arguments_get(msg, "s", §ion))
87 ERR("Error reading message arguments");
91 DBG("section: '%s'", section);
96 static Eldbus_Message *
97 _config_unset_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
99 const char *section, *name;
101 CONFIG_CHECK_MESSAGE_ERRORS(msg)
103 if (!eldbus_message_arguments_get(msg, "ss", §ion, &name))
105 ERR("Error reading message arguments");
109 DBG("section: '%s', name: '%s'", section, name);
114 static const Eldbus_Method _wkb_ibus_config_methods[] =
116 /* typedef struct _Eldbus_Method
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;
125 { .member = "SetValue",
126 .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}, {"v", "value"}),
127 .cb = _config_set_value, },
129 { .member = "GetValue",
130 .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}),
131 .out = ELDBUS_ARGS({"v", "value"}),
132 .cb = _config_get_value, },
134 { .member = "GetValues",
135 .in = ELDBUS_ARGS({"s", "section"}),
136 .out = ELDBUS_ARGS({"a{sv}", "values"}),
137 .cb = _config_get_values, },
139 { .member = "UnsetValue",
140 .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}),
141 .cb = _config_unset_value, },
146 static const Eldbus_Signal _wkb_ibus_config_signals[] =
148 /* typedef struct _Eldbus_Signal
151 * const Eldbus_Arg_Info *args;
152 * unsigned int flags;
155 { .name = "ValueChanged",
156 .args = ELDBUS_ARGS({"s", "section"}, {"s", "name"}, {"v", "value"}),
162 static const Eldbus_Service_Interface_Desc _wkb_ibus_config_interface =
164 .interface = IBUS_INTERFACE_CONFIG,
165 .methods = _wkb_ibus_config_methods,
166 .signals = _wkb_ibus_config_signals,
169 Eldbus_Service_Interface *
170 wkb_ibus_config_register(Eldbus_Connection *conn)
172 Eldbus_Service_Interface *ret = eldbus_service_interface_register(conn, IBUS_PATH_CONFIG, &_wkb_ibus_config_interface);
176 ERR("Unable to register IBusConfig interface\n");
182 WRN("wkb_config_eet already created\n");
186 _conf_eet = wkb_ibus_config_eet_new("");
193 wkb_ibus_config_unregister(void)
196 wkb_ibus_config_eet_free(_conf_eet);