1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/dbus/ibus/ibus_component.h"
#include "base/logging.h"
#include "chromeos/dbus/ibus/ibus_object.h"
#include "dbus/message.h"
namespace chromeos {
// TODO(nona): Remove ibus namespace after complete libibus removal.
namespace ibus {
namespace {
bool PopIBusEngineDesc(dbus::MessageReader* reader,
IBusComponent::EngineDescription* engine_desc) {
IBusObjectReader ibus_object_reader("IBusEngineDesc", reader);
if (!ibus_object_reader.Init())
return false;
if (!ibus_object_reader.PopString(&engine_desc->engine_id)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 1st argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&engine_desc->display_name)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 2nd argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&engine_desc->description)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 3rd argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&engine_desc->language_code)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 4th argument should be string.";
return false;
}
std::string unused_string_field;
if (!ibus_object_reader.PopString(&unused_string_field)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 5th argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&engine_desc->author)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 6th argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&unused_string_field)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 7th argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&engine_desc->layout)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 8th argument should be string.";
return false;
}
uint32 unused_uint_field = 0;
if (!ibus_object_reader.PopUint32(&unused_uint_field)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 9th argument should be unsigned integer.";
return false;
}
if (!ibus_object_reader.PopString(&unused_string_field)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 10th argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&unused_string_field)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 11th argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&unused_string_field)) {
LOG(ERROR) << "Invalid variant structure[IBusEngineDesc]: "
<< "The 12th argument should be string.";
return false;
}
return true;
}
void AppendIBusEngineDesc(const IBusComponent::EngineDescription& engine_desc,
dbus::MessageWriter* writer) {
IBusObjectWriter ibus_object_writer("IBusEngineDesc",
"ssssssssusss",
writer);
ibus_object_writer.CloseHeader();
ibus_object_writer.AppendString(engine_desc.engine_id);
ibus_object_writer.AppendString(engine_desc.display_name);
ibus_object_writer.AppendString(engine_desc.description);
ibus_object_writer.AppendString(engine_desc.language_code);
ibus_object_writer.AppendString(""); // The license field is not used.
ibus_object_writer.AppendString(engine_desc.author);
ibus_object_writer.AppendString(""); // The icon path field is not used.
ibus_object_writer.AppendString(engine_desc.layout);
ibus_object_writer.AppendUint32(0); // The engine rank is not used.
ibus_object_writer.AppendString(""); // The hotkey field is not used.
ibus_object_writer.AppendString(""); // The symbol field is not used.
ibus_object_writer.AppendString(""); // The command line field is not used.
ibus_object_writer.CloseAll();
}
} // namespace
bool CHROMEOS_EXPORT PopIBusComponent(dbus::MessageReader* reader,
IBusComponent* ibus_component) {
IBusObjectReader ibus_object_reader("IBusComponent", reader);
if (!ibus_object_reader.Init())
return false;
std::string name;
if (!ibus_object_reader.PopString(&name)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 1st argument should be string.";
return false;
}
ibus_component->set_name(name);
std::string description;
if (!ibus_object_reader.PopString(&description)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 2nd argument should be string.";
return false;
}
ibus_component->set_description(description);
std::string unused_string_field;
if (!ibus_object_reader.PopString(&unused_string_field)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 3rd argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&unused_string_field)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 4th argument should be string.";
return false;
}
std::string author;
if (!ibus_object_reader.PopString(&author)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 5th argument should be string.";
return false;
}
ibus_component->set_author(author);
if (!ibus_object_reader.PopString(&unused_string_field)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 6th argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&unused_string_field)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 7th argument should be string.";
return false;
}
if (!ibus_object_reader.PopString(&unused_string_field)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 8th argument should be string.";
return false;
}
dbus::MessageReader observer_reader(NULL);
if (!ibus_object_reader.PopArray(&observer_reader)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 9th argument should be array of variant.";
return false;
}
dbus::MessageReader engine_array_reader(NULL);
if (!ibus_object_reader.PopArray(&engine_array_reader)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 10th argument should be array of IBusEngineDesc";
return false;
}
std::vector<IBusComponent::EngineDescription>* engine_description =
ibus_component->mutable_engine_description();
engine_description->clear();
while (engine_array_reader.HasMoreData()) {
IBusComponent::EngineDescription engine_description_entry;
if (!PopIBusEngineDesc(&engine_array_reader, &engine_description_entry)) {
LOG(ERROR) << "Invalid variant structure[IBusComponent]: "
<< "The 11th argument should be array of IBusEngineDesc";
return false;
}
engine_description->push_back(engine_description_entry);
}
return true;
}
void CHROMEOS_EXPORT AppendIBusComponent(const IBusComponent& ibus_component,
dbus::MessageWriter* writer) {
IBusObjectWriter ibus_object_writer("IBusComponent", "ssssssssavav", writer);
ibus_object_writer.CloseHeader();
ibus_object_writer.AppendString(ibus_component.name());
ibus_object_writer.AppendString(ibus_component.description());
ibus_object_writer.AppendString(""); // The version string is not used.
ibus_object_writer.AppendString(""); // The license field is not used.
ibus_object_writer.AppendString(ibus_component.author());
ibus_object_writer.AppendString(""); // The URL field is not used.
ibus_object_writer.AppendString(""); // The exec path field is not used.
ibus_object_writer.AppendString(""); // The text domain field is not used.
// The observed object field is not used.
dbus::MessageWriter empty_array_writer(NULL);
ibus_object_writer.OpenArray("v", &empty_array_writer);
ibus_object_writer.CloseContainer(&empty_array_writer);
dbus::MessageWriter engine_descs_writer(NULL);
const std::vector<IBusComponent::EngineDescription> engine_description =
ibus_component.engine_description();
ibus_object_writer.OpenArray("v", &engine_descs_writer);
for (size_t i = 0; i < engine_description.size(); ++i) {
AppendIBusEngineDesc(engine_description[i], &engine_descs_writer);
}
ibus_object_writer.CloseContainer(&engine_descs_writer);
ibus_object_writer.CloseAll();
}
///////////////////////////////////////////////////////////////////////////////
// IBusComponent
IBusComponent::IBusComponent() {
}
IBusComponent::~IBusComponent() {
}
IBusComponent::EngineDescription::EngineDescription() {
}
IBusComponent::EngineDescription::EngineDescription(
const std::string& engine_id,
const std::string& display_name,
const std::string& description,
const std::string& language_code,
const std::string& author,
const std::string& layout)
: engine_id(engine_id),
display_name(display_name),
description(description),
language_code(language_code),
author(author),
layout(layout) {
}
IBusComponent::EngineDescription::~EngineDescription() {
}
} // namespace ibus
} // namespace chromeos
|