summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authornona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-09 09:57:40 +0000
committernona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-09 09:57:40 +0000
commitf98713fa8071b33e462d6a1e8ef47aa1cde8c174 (patch)
tree21d6aebead7ee357b2091482e5005212ceea6e35 /chromeos
parentf2444986036a91262e601d7436950d134a7c7af4 (diff)
downloadchromium_src-f98713fa8071b33e462d6a1e8ef47aa1cde8c174.zip
chromium_src-f98713fa8071b33e462d6a1e8ef47aa1cde8c174.tar.gz
chromium_src-f98713fa8071b33e462d6a1e8ef47aa1cde8c174.tar.bz2
Implement IBusComponent.
IBusComponent is one of representation an obeject used in communication with ibus-daemon. IBusComponent is used when the engine object register itself to ibus-daemon. With this CL, ibus_component.cc will be comipled and tested but not in used production binary at this moment. BUG=126947 TEST=chromeos_unittests, unit_tests, dbus_unittests Review URL: https://chromiumcodereview.appspot.com/10692120 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145660 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/chromeos.gyp3
-rw-r--r--chromeos/dbus/ibus/ibus_component.cc250
-rw-r--r--chromeos/dbus/ibus/ibus_component.h151
-rw-r--r--chromeos/dbus/ibus/ibus_component_unittest.cc87
4 files changed, 491 insertions, 0 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index 9870c9e..a57f97f 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -74,6 +74,8 @@
'dbus/flimflam_service_client.h',
'dbus/ibus/ibus_client.cc',
'dbus/ibus/ibus_client.h',
+ 'dbus/ibus/ibus_component.cc',
+ 'dbus/ibus/ibus_component.h',
'dbus/ibus/ibus_constants.h',
'dbus/ibus/ibus_lookup_table.cc',
'dbus/ibus/ibus_lookup_table.h',
@@ -224,6 +226,7 @@
'dbus/flimflam_service_client_unittest.cc',
'dbus/gsm_sms_client_unittest.cc',
'dbus/ibus/ibus_client_unittest.cc',
+ 'dbus/ibus/ibus_component_unittest.cc',
'dbus/ibus/ibus_lookup_table_unittest.cc',
'dbus/ibus/ibus_object_unittest.cc',
'dbus/ibus/ibus_property_unittest.cc',
diff --git a/chromeos/dbus/ibus/ibus_component.cc b/chromeos/dbus/ibus/ibus_component.cc
new file mode 100644
index 0000000..0a606e4
--- /dev/null
+++ b/chromeos/dbus/ibus/ibus_component.cc
@@ -0,0 +1,250 @@
+// 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.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 nto 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.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
diff --git a/chromeos/dbus/ibus/ibus_component.h b/chromeos/dbus/ibus/ibus_component.h
new file mode 100644
index 0000000..4bbd1cc4
--- /dev/null
+++ b/chromeos/dbus/ibus/ibus_component.h
@@ -0,0 +1,151 @@
+// 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.
+
+#ifndef CHROMEOS_DBUS_IBUS_IBUS_COMPONENT_H_
+#define CHROMEOS_DBUS_IBUS_IBUS_COMPONENT_H_
+
+#include <string>
+#include <vector>
+#include "base/basictypes.h"
+#include "chromeos/chromeos_export.h"
+
+namespace dbus {
+class MessageWriter;
+class MessageReader;
+} // namespace dbus
+
+namespace chromeos {
+// TODO(nona): Remove ibus namespace after complete libibus removal.
+namespace ibus {
+
+// The IBusComponents is one of IBusObjects and it contains one or more
+// IBusEngineDesc object which describes details of engine information. This
+// object is in used an engine's initialization.
+//
+// DATA STRUCTURE OVERVIEW:
+//
+// IBusEngineDesc: (signature is "ssssssssusss")
+// variant struct {
+// string "IBusEngineDesc"
+// array []
+// string "_ext_ime" // The engine name.
+// string "Mock IME" // The long engine name.
+// string "Mock IME" // The engine description.
+// string "en" // The language identifier.
+// string "" // The license name field.(not in use).
+// string "MockExtensionIME" // The author name.
+// string "" // The icon path (not in use).
+// string "us" // The keyboard layout.
+// uint32 0 // The engine rank. (not in use).
+// string "" // The hotkey to switch IME.(not in use)
+// string "" // The symbol character of this engine (not in use).
+// string "" // The command line to execute this engine (not inuse).
+// }
+//
+// IBusComponent: (signature is "ssssssssavav")
+// variant struct {
+// string "IBusComponent"
+// array []
+// string "org.freedesktop.IBus._extension_ime" // The component name.
+// string "Mock IME with Extension API" // The component description.
+// string "" // The version of component.(not in use)
+// string "" // The license name field. (not in use).
+// string "MockExtensionIME" // The author name.
+// string "" // The URL to home page(not in use).
+// string "" // The executable path to component (not in use).
+// string "" // The text domain field(not in use).
+// array [] // The observed path object array(not in use).
+// array [
+// variant struct {
+// string "IBusEngineDesc"
+// array []
+// string "_ext_ime"
+// string "Mock IME with Extension API"
+// string "Mock IME with Extension API"
+// string "en"
+// string ""
+// string "MockExtensionIME"
+// string ""
+// string "us"
+// uint32 0
+// string ""
+// string ""
+// string ""
+// }
+// ]
+// }
+class IBusComponent;
+
+// Pops a IBusComponent from |reader|.
+// Returns false if an error occures.
+bool CHROMEOS_EXPORT PopIBusComponent(dbus::MessageReader* reader,
+ IBusComponent* ibus_component);
+
+// Appends a IBusComponent to |writer|.
+void CHROMEOS_EXPORT AppendIBusComponent(const IBusComponent& ibus_component,
+ dbus::MessageWriter* writer);
+
+// Handles IBusComponent object which is used in dbus communication with
+// ibus-daemon. The IBusComponent is one of IBusObjects and it contains array of
+// IBusEngineDesc. The IBusEngineDesc is another IBusObject, but it is
+// represented as member structure of IBusComponent because it is only used in
+// IBusComponent.
+class CHROMEOS_EXPORT IBusComponent {
+ public:
+ struct EngineDescription {
+ 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);
+ ~EngineDescription();
+ std::string engine_id; // The engine id.
+ std::string display_name; // The display name.
+ std::string description; // The engine description.
+ std::string language_code; // The engine's language(ex. "en").
+ std::string author; // The author of engine.
+ std::string layout; // The keyboard layout of engine.
+ };
+
+ IBusComponent();
+ virtual ~IBusComponent();
+
+ // The component name (ex. "org.freedesktop.IBus.Mozc").
+ const std::string& name() const { return name_; }
+ void set_name(const std::string& name) { name_ = name;}
+
+ // The component description.
+ const std::string& description() const { return description_; }
+ void set_description(const std::string& description) {
+ description_ = description;
+ }
+
+ // The component author (ex. "Google Inc.").
+ const std::string& author() const { return author_; }
+ void set_author(const std::string& author) { author_ = author; }
+
+ // The array of engine description data.
+ const std::vector<EngineDescription>& engine_description() const {
+ return engine_description_;
+ }
+ std::vector<EngineDescription>* mutable_engine_description() {
+ return &engine_description_;
+ }
+
+ private:
+ std::string name_;
+ std::string description_;
+ std::string author_;
+
+ std::vector<EngineDescription> engine_description_;
+
+ DISALLOW_COPY_AND_ASSIGN(IBusComponent);
+};
+
+} // namespace ibus
+} // namespace chromeos
+
+#endif // CHROMEOS_DBUS_IBUS_IBUS_COMPONENT_H_
diff --git a/chromeos/dbus/ibus/ibus_component_unittest.cc b/chromeos/dbus/ibus/ibus_component_unittest.cc
new file mode 100644
index 0000000..cc77e94
--- /dev/null
+++ b/chromeos/dbus/ibus/ibus_component_unittest.cc
@@ -0,0 +1,87 @@
+// 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 <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "dbus/message.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+namespace ibus {
+
+TEST(IBusComponentTest, WriteReadIBusComponentTest) {
+ const std::string kName = "Component Name";
+ const std::string kDescription = "Component Descriptoin";
+ const std::string kAuthor = "Component Author";
+
+ const std::string kEngineId1 = "Engine Id 1";
+ const std::string kEngineDisplayName1 = "Engine Display Name 1";
+ const std::string kEngineDescription1 = "Engine Description 1";
+ const std::string kEngineLanguageCode1 = "en";
+ const std::string kEngineAuthor1 = "Engine Author 1";
+ const std::string kEngineLayout1 = "us::eng";
+ const IBusComponent::EngineDescription engine_desc1(kEngineId1,
+ kEngineDisplayName1,
+ kEngineDescription1,
+ kEngineLanguageCode1,
+ kEngineAuthor1,
+ kEngineLayout1);
+
+ const std::string kEngineId2 = "Engine Id 2";
+ const std::string kEngineDisplayName2 = "Engine Display Name 2";
+ const std::string kEngineDescription2 = "Engine Description 2";
+ const std::string kEngineLanguageCode2 = "ja";
+ const std::string kEngineAuthor2 = "Engine Author 2";
+ const std::string kEngineLayout2 = "ja::jp";
+ const IBusComponent::EngineDescription engine_desc2(kEngineId2,
+ kEngineDisplayName2,
+ kEngineDescription2,
+ kEngineLanguageCode2,
+ kEngineAuthor2,
+ kEngineLayout2);
+
+ // Create a IBusComponent.
+ IBusComponent ibus_component;
+ ibus_component.set_name(kName);
+ ibus_component.set_description(kDescription);
+ ibus_component.set_author(kAuthor);
+ ibus_component.mutable_engine_description()->push_back(engine_desc1);
+ ibus_component.mutable_engine_description()->push_back(engine_desc2);
+
+ // Write a IBusComponent.
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+ dbus::MessageWriter writer(response.get());
+ AppendIBusComponent(ibus_component, &writer);
+
+ // Read a IBusComponent.
+ IBusComponent target_component;
+ dbus::MessageReader reader(response.get());
+ PopIBusComponent(&reader, &target_component);
+
+ // Check a result.
+ EXPECT_EQ(kName, target_component.name());
+ EXPECT_EQ(kDescription, target_component.description());
+ EXPECT_EQ(kAuthor, target_component.author());
+
+ const std::vector<IBusComponent::EngineDescription>& engine_descriptions =
+ ibus_component.engine_description();
+ EXPECT_EQ(kEngineId1, engine_descriptions[0].engine_id);
+ EXPECT_EQ(kEngineDisplayName1, engine_descriptions[0].display_name);
+ EXPECT_EQ(kEngineDescription1, engine_descriptions[0].description);
+ EXPECT_EQ(kEngineLanguageCode1, engine_descriptions[0].language_code);
+ EXPECT_EQ(kEngineAuthor1, engine_descriptions[0].author);
+ EXPECT_EQ(kEngineLayout1, engine_descriptions[0].layout);
+
+ EXPECT_EQ(kEngineId2, engine_descriptions[1].engine_id);
+ EXPECT_EQ(kEngineDisplayName2, engine_descriptions[1].display_name);
+ EXPECT_EQ(kEngineDescription2, engine_descriptions[1].description);
+ EXPECT_EQ(kEngineLanguageCode2, engine_descriptions[1].language_code);
+ EXPECT_EQ(kEngineAuthor2, engine_descriptions[1].author);
+ EXPECT_EQ(kEngineLayout2, engine_descriptions[1].layout);
+}
+
+} // namespace ibus
+} // namespace chromeos