1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromeos/dbus/ibus/ibus_component.h"
7 #include "base/logging.h"
8 #include "chromeos/dbus/ibus/ibus_object.h"
9 #include "dbus/message.h"
15 bool PopIBusEngineDesc(dbus::MessageReader* reader,
16 IBusComponent::EngineDescription* engine_desc) {
17 IBusObjectReader ibus_object_reader("IBusEngineDesc", reader);
18 if (!ibus_object_reader.Init())
20 if (!ibus_object_reader.PopString(&engine_desc->engine_id)) {
21 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
22 << "The 1st argument should be string.";
25 if (!ibus_object_reader.PopString(&engine_desc->display_name)) {
26 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
27 << "The 2nd argument should be string.";
30 if (!ibus_object_reader.PopString(&engine_desc->description)) {
31 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
32 << "The 3rd argument should be string.";
35 if (!ibus_object_reader.PopString(&engine_desc->language_code)) {
36 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
37 << "The 4th argument should be string.";
40 std::string unused_string_field;
41 if (!ibus_object_reader.PopString(&unused_string_field)) {
42 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
43 << "The 5th argument should be string.";
46 if (!ibus_object_reader.PopString(&engine_desc->author)) {
47 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
48 << "The 6th argument should be string.";
51 if (!ibus_object_reader.PopString(&unused_string_field)) {
52 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
53 << "The 7th argument should be string.";
56 if (!ibus_object_reader.PopString(&unused_string_field)) {
57 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
58 << "The 8th argument should be string.";
61 uint32 unused_uint_field = 0;
62 if (!ibus_object_reader.PopUint32(&unused_uint_field)) {
63 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
64 << "The 9th argument should be unsigned integer.";
67 if (!ibus_object_reader.PopString(&unused_string_field)) {
68 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
69 << "The 10th argument should be string.";
72 if (!ibus_object_reader.PopString(&unused_string_field)) {
73 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
74 << "The 11th argument should be string.";
77 if (!ibus_object_reader.PopString(&unused_string_field)) {
78 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
79 << "The 12th argument should be string.";
85 void AppendIBusEngineDesc(const IBusComponent::EngineDescription& engine_desc,
86 dbus::MessageWriter* writer) {
87 IBusObjectWriter ibus_object_writer("IBusEngineDesc",
90 ibus_object_writer.CloseHeader();
91 ibus_object_writer.AppendString(engine_desc.engine_id);
92 ibus_object_writer.AppendString(engine_desc.display_name);
93 ibus_object_writer.AppendString(engine_desc.description);
94 ibus_object_writer.AppendString(engine_desc.language_code);
95 ibus_object_writer.AppendString(""); // The license field is not used.
96 ibus_object_writer.AppendString(engine_desc.author);
97 ibus_object_writer.AppendString(""); // The icon path field is not used.
98 ibus_object_writer.AppendString(""); // The layout field is not used.
99 ibus_object_writer.AppendUint32(0); // The engine rank is not used.
100 ibus_object_writer.AppendString(""); // The hotkey field is not used.
101 ibus_object_writer.AppendString(""); // The symbol field is not used.
102 ibus_object_writer.AppendString(""); // The command line field is not used.
103 ibus_object_writer.CloseAll();
108 bool CHROMEOS_EXPORT PopIBusComponent(dbus::MessageReader* reader,
109 IBusComponent* ibus_component) {
110 IBusObjectReader ibus_object_reader("IBusComponent", reader);
111 if (!ibus_object_reader.Init())
114 if (!ibus_object_reader.PopString(&name)) {
115 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
116 << "The 1st argument should be string.";
119 ibus_component->set_name(name);
121 std::string description;
122 if (!ibus_object_reader.PopString(&description)) {
123 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
124 << "The 2nd argument should be string.";
127 ibus_component->set_description(description);
129 std::string unused_string_field;
130 if (!ibus_object_reader.PopString(&unused_string_field)) {
131 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
132 << "The 3rd argument should be string.";
135 if (!ibus_object_reader.PopString(&unused_string_field)) {
136 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
137 << "The 4th argument should be string.";
142 if (!ibus_object_reader.PopString(&author)) {
143 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
144 << "The 5th argument should be string.";
147 ibus_component->set_author(author);
149 if (!ibus_object_reader.PopString(&unused_string_field)) {
150 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
151 << "The 6th argument should be string.";
154 if (!ibus_object_reader.PopString(&unused_string_field)) {
155 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
156 << "The 7th argument should be string.";
159 if (!ibus_object_reader.PopString(&unused_string_field)) {
160 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
161 << "The 8th argument should be string.";
164 dbus::MessageReader observer_reader(NULL);
165 if (!ibus_object_reader.PopArray(&observer_reader)) {
166 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
167 << "The 9th argument should be array of variant.";
171 dbus::MessageReader engine_array_reader(NULL);
172 if (!ibus_object_reader.PopArray(&engine_array_reader)) {
173 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
174 << "The 10th argument should be array of IBusEngineDesc";
177 std::vector<IBusComponent::EngineDescription>* engine_description =
178 ibus_component->mutable_engine_description();
179 engine_description->clear();
180 while (engine_array_reader.HasMoreData()) {
181 IBusComponent::EngineDescription engine_description_entry;
182 if (!PopIBusEngineDesc(&engine_array_reader, &engine_description_entry)) {
183 LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
184 << "The 11th argument should be array of IBusEngineDesc";
187 engine_description->push_back(engine_description_entry);
192 void CHROMEOS_EXPORT AppendIBusComponent(const IBusComponent& ibus_component,
193 dbus::MessageWriter* writer) {
194 IBusObjectWriter ibus_object_writer("IBusComponent", "ssssssssavav", writer);
195 ibus_object_writer.CloseHeader();
196 ibus_object_writer.AppendString(ibus_component.name());
197 ibus_object_writer.AppendString(ibus_component.description());
198 ibus_object_writer.AppendString(""); // The version string is not used.
199 ibus_object_writer.AppendString(""); // The license field is not used.
200 ibus_object_writer.AppendString(ibus_component.author());
201 ibus_object_writer.AppendString(""); // The URL field is not used.
202 ibus_object_writer.AppendString(""); // The exec path field is not used.
203 ibus_object_writer.AppendString(""); // The text domain field is not used.
204 // The observed object field is not used.
205 dbus::MessageWriter empty_array_writer(NULL);
206 ibus_object_writer.OpenArray("v", &empty_array_writer);
207 ibus_object_writer.CloseContainer(&empty_array_writer);
209 dbus::MessageWriter engine_descs_writer(NULL);
210 const std::vector<IBusComponent::EngineDescription> engine_description =
211 ibus_component.engine_description();
212 ibus_object_writer.OpenArray("v", &engine_descs_writer);
213 for (size_t i = 0; i < engine_description.size(); ++i) {
214 AppendIBusEngineDesc(engine_description[i], &engine_descs_writer);
216 ibus_object_writer.CloseContainer(&engine_descs_writer);
217 ibus_object_writer.CloseAll();
220 ///////////////////////////////////////////////////////////////////////////////
222 IBusComponent::IBusComponent() {
225 IBusComponent::~IBusComponent() {
228 IBusComponent::EngineDescription::EngineDescription() {
231 IBusComponent::EngineDescription::EngineDescription(
232 const std::string& engine_id,
233 const std::string& display_name,
234 const std::string& description,
235 const std::string& language_code,
236 const std::string& author)
237 : engine_id(engine_id),
238 display_name(display_name),
239 description(description),
240 language_code(language_code),
244 IBusComponent::EngineDescription::~EngineDescription() {
247 } // namespace chromeos