OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chromeos/dbus/ibus/ibus_component.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "chromeos/dbus/ibus/ibus_object.h" | |
9 #include "dbus/message.h" | |
10 | |
11 namespace chromeos { | |
12 | |
13 namespace { | |
14 | |
15 bool PopIBusEngineDesc(dbus::MessageReader* reader, | |
16 IBusComponent::EngineDescription* engine_desc) { | |
17 IBusObjectReader ibus_object_reader("IBusEngineDesc", reader); | |
18 if (!ibus_object_reader.Init()) | |
19 return false; | |
20 if (!ibus_object_reader.PopString(&engine_desc->engine_id)) { | |
21 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: " | |
22 << "The 1st argument should be string."; | |
23 return false; | |
24 } | |
25 if (!ibus_object_reader.PopString(&engine_desc->display_name)) { | |
26 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: " | |
27 << "The 2nd argument should be string."; | |
28 return false; | |
29 } | |
30 if (!ibus_object_reader.PopString(&engine_desc->description)) { | |
31 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: " | |
32 << "The 3rd argument should be string."; | |
33 return false; | |
34 } | |
35 if (!ibus_object_reader.PopString(&engine_desc->language_code)) { | |
36 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: " | |
37 << "The 4th argument should be string."; | |
38 return false; | |
39 } | |
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."; | |
44 return false; | |
45 } | |
46 if (!ibus_object_reader.PopString(&engine_desc->author)) { | |
47 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: " | |
48 << "The 6th argument should be string."; | |
49 return false; | |
50 } | |
51 if (!ibus_object_reader.PopString(&unused_string_field)) { | |
52 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: " | |
53 << "The 7th argument should be string."; | |
54 return false; | |
55 } | |
56 if (!ibus_object_reader.PopString(&unused_string_field)) { | |
57 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: " | |
58 << "The 8th argument should be string."; | |
59 return false; | |
60 } | |
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."; | |
65 return false; | |
66 } | |
67 if (!ibus_object_reader.PopString(&unused_string_field)) { | |
68 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: " | |
69 << "The 10th argument should be string."; | |
70 return false; | |
71 } | |
72 if (!ibus_object_reader.PopString(&unused_string_field)) { | |
73 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: " | |
74 << "The 11th argument should be string."; | |
75 return false; | |
76 } | |
77 if (!ibus_object_reader.PopString(&unused_string_field)) { | |
78 LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: " | |
79 << "The 12th argument should be string."; | |
80 return false; | |
81 } | |
82 return true; | |
83 } | |
84 | |
85 void AppendIBusEngineDesc(const IBusComponent::EngineDescription& engine_desc, | |
86 dbus::MessageWriter* writer) { | |
87 IBusObjectWriter ibus_object_writer("IBusEngineDesc", | |
88 "ssssssssusss", | |
89 writer); | |
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(); | |
104 } | |
105 | |
106 } // namespace | |
107 | |
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()) | |
112 return false; | |
113 std::string name; | |
114 if (!ibus_object_reader.PopString(&name)) { | |
115 LOG(ERROR) << "Invalid variant structure[IBusComponent]: " | |
116 << "The 1st argument should be string."; | |
117 return false; | |
118 } | |
119 ibus_component->set_name(name); | |
120 | |
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."; | |
125 return false; | |
126 } | |
127 ibus_component->set_description(description); | |
128 | |
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."; | |
133 return false; | |
134 } | |
135 if (!ibus_object_reader.PopString(&unused_string_field)) { | |
136 LOG(ERROR) << "Invalid variant structure[IBusComponent]: " | |
137 << "The 4th argument should be string."; | |
138 return false; | |
139 } | |
140 | |
141 std::string author; | |
142 if (!ibus_object_reader.PopString(&author)) { | |
143 LOG(ERROR) << "Invalid variant structure[IBusComponent]: " | |
144 << "The 5th argument should be string."; | |
145 return false; | |
146 } | |
147 ibus_component->set_author(author); | |
148 | |
149 if (!ibus_object_reader.PopString(&unused_string_field)) { | |
150 LOG(ERROR) << "Invalid variant structure[IBusComponent]: " | |
151 << "The 6th argument should be string."; | |
152 return false; | |
153 } | |
154 if (!ibus_object_reader.PopString(&unused_string_field)) { | |
155 LOG(ERROR) << "Invalid variant structure[IBusComponent]: " | |
156 << "The 7th argument should be string."; | |
157 return false; | |
158 } | |
159 if (!ibus_object_reader.PopString(&unused_string_field)) { | |
160 LOG(ERROR) << "Invalid variant structure[IBusComponent]: " | |
161 << "The 8th argument should be string."; | |
162 return false; | |
163 } | |
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."; | |
168 return false; | |
169 } | |
170 | |
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"; | |
175 return false; | |
176 } | |
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"; | |
185 return false; | |
186 } | |
187 engine_description->push_back(engine_description_entry); | |
188 } | |
189 return true; | |
190 } | |
191 | |
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); | |
208 | |
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); | |
215 } | |
216 ibus_object_writer.CloseContainer(&engine_descs_writer); | |
217 ibus_object_writer.CloseAll(); | |
218 } | |
219 | |
220 /////////////////////////////////////////////////////////////////////////////// | |
221 // IBusComponent | |
222 IBusComponent::IBusComponent() { | |
223 } | |
224 | |
225 IBusComponent::~IBusComponent() { | |
226 } | |
227 | |
228 IBusComponent::EngineDescription::EngineDescription() { | |
229 } | |
230 | |
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), | |
241 author(author) { | |
242 } | |
243 | |
244 IBusComponent::EngineDescription::~EngineDescription() { | |
245 } | |
246 | |
247 } // namespace chromeos | |
OLD | NEW |