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.
25 #define CONFIG_CHECK_MESSAGE_ERRORS(_msg) \
28 const char *error, *error_msg; \
29 if (eldbus_message_error_get(_msg, &error, &error_msg)) \
31 ERR("DBus message error: %s: %s", error, error_msg); \
34 DBG("Message '%s' with signature '%s'", eldbus_message_member_get(_msg), eldbus_message_signature_get(_msg)); \
37 static Eldbus_Message *
38 _config_set_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
40 const char *section, *name;
41 Eldbus_Message_Iter *value;
43 CONFIG_CHECK_MESSAGE_ERRORS(msg)
45 if (!eldbus_message_arguments_get(msg, "ssv", §ion, &name, &value))
47 ERR("Error reading message arguments");
51 DBG("section: '%s', name: '%s', value: '%p'", section, name, value);
56 static Eldbus_Message *
57 _config_get_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
59 const char *section, *name;
61 CONFIG_CHECK_MESSAGE_ERRORS(msg)
63 if (!eldbus_message_arguments_get(msg, "ss", §ion, &name))
65 ERR("Error reading message arguments");
69 DBG("section: '%s', name: '%s'", section, name);
74 static Eldbus_Message *
75 _config_get_values(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
79 CONFIG_CHECK_MESSAGE_ERRORS(msg)
81 if (!eldbus_message_arguments_get(msg, "s", §ion))
83 ERR("Error reading message arguments");
87 DBG("section: '%s'", section);
92 static Eldbus_Message *
93 _config_unset_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
95 const char *section, *name;
97 CONFIG_CHECK_MESSAGE_ERRORS(msg)
99 if (!eldbus_message_arguments_get(msg, "ss", §ion, &name))
101 ERR("Error reading message arguments");
105 DBG("section: '%s', name: '%s'", section, name);
110 static const Eldbus_Method _wkb_ibus_config_methods[] =
112 /* typedef struct _Eldbus_Method
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;
121 { .member = "SetValue",
122 .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}, {"v", "value"}),
123 .cb = _config_set_value, },
125 { .member = "GetValue",
126 .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}),
127 .out = ELDBUS_ARGS({"v", "value"}),
128 .cb = _config_get_value, },
130 { .member = "GetValues",
131 .in = ELDBUS_ARGS({"s", "section"}),
132 .out = ELDBUS_ARGS({"a{sv}", "values"}),
133 .cb = _config_get_values, },
135 { .member = "UnsetValue",
136 .in = ELDBUS_ARGS({"s", "section"}, {"s", "name"}),
137 .cb = _config_unset_value, },
142 static const Eldbus_Signal _wkb_ibus_config_signals[] =
144 /* typedef struct _Eldbus_Signal
147 * const Eldbus_Arg_Info *args;
148 * unsigned int flags;
151 { .name = "ValueChanged",
152 .args = ELDBUS_ARGS({"s", "section"}, {"s", "name"}, {"v", "value"}),
158 static const Eldbus_Service_Interface_Desc _wkb_ibus_config_interface =
160 .interface = IBUS_INTERFACE_CONFIG,
161 .methods = _wkb_ibus_config_methods,
162 .signals = _wkb_ibus_config_signals,
165 Eldbus_Service_Interface *
166 wkb_ibus_config_register(Eldbus_Connection *conn)
168 return eldbus_service_interface_register(conn, IBUS_PATH_CONFIG, &_wkb_ibus_config_interface);