Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: chromeos/dbus/ibus/ibus_object.h

Issue 11361210: Extends IBusObject to handle attachment field. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Making constant for attachment key. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/dbus/ibus/ibus_lookup_table.cc ('k') | chromeos/dbus/ibus/ibus_object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/ibus/ibus_object.h
diff --git a/chromeos/dbus/ibus/ibus_object.h b/chromeos/dbus/ibus/ibus_object.h
index b6cf45cf8d007024355b559ba5548e57efdb3fed..044aa0105e4bfb418e48aa8985067f1e51687a17 100644
--- a/chromeos/dbus/ibus/ibus_object.h
+++ b/chromeos/dbus/ibus/ibus_object.h
@@ -6,16 +6,21 @@
#define CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_
#include <string>
+#include <map>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/ibus/ibus_property.h"
#include "chromeos/dbus/ibus/ibus_text.h"
+namespace base {
+class Value;
+} // namespace base
+
namespace dbus {
class MessageReader;
class MessageWriter;
-} // dbus
+} // namespace dbus
namespace chromeos {
// TODO(nona): Remove ibus namespace after complete libibus removal.
@@ -75,6 +80,13 @@ namespace ibus {
// // Craetes reader for IBusText
// IBusObjectReader object_reader("IBusText", &reader);
//
+// // Initialize for reading attachment field.
+// object_reader.Init();
+//
+// // Get attachment field.
+// base::Value* value;
+// object_reader.GetAttachment("annotation", &value);
+//
// std::string text;
// reader.PopString(&text); // Reading 1st value as string.
//
@@ -93,10 +105,6 @@ class CHROMEOS_EXPORT IBusObjectReader {
// to read attachment field.
bool Init();
- // Reads IBusObject headers and checks if the type name is valid.
- // Returns true and sets up reader for attachment reading on success.
- bool InitWithAttachmentReader(dbus::MessageReader* reader);
-
// Reads IBusOBject with |reader| and checks if the type name is valid.
bool InitWithParentReader(dbus::MessageReader* reader);
@@ -129,6 +137,10 @@ class CHROMEOS_EXPORT IBusObjectReader {
// Pops a IBusPropertyList.
bool PopIBusPropertyList(ibus::IBusPropertyList* property_list);
+ // Gets attachment entry corresponding to |key|. Do not free |value|.
+ // Returns false if there is no entry.
+ bool GetAttachment(const std::string& key, base::Value** value);
satorux1 2012/11/13 04:37:37 What about returning a "const base::Value*". We ca
Seigo Nonaka 2012/11/13 06:22:17 Done.
+
private:
enum CheckResult {
IBUS_OBJECT_VALID, // Already checked and valid type.
@@ -136,15 +148,12 @@ class CHROMEOS_EXPORT IBusObjectReader {
IBUS_OBJECT_NOT_CHECKED, // Not checked yet.
};
- // Reads IBusObject headers without attachment and checks if the type name
- // is valid.
- bool InitWithoutAttachment();
-
std::string type_name_;
dbus::MessageReader* original_reader_;
scoped_ptr<dbus::MessageReader> top_variant_reader_;
scoped_ptr<dbus::MessageReader> contents_reader_;
CheckResult check_result_;
+ std::map<std::string, base::Value*> attachments_;
DISALLOW_COPY_AND_ASSIGN(IBusObjectReader);
};
@@ -158,6 +167,13 @@ class CHROMEOS_EXPORT IBusObjectReader {
// // Creates writer for IBusText
// IBusObjectWriter object_writer("IBusText", "sv", &writer);
//
+// // Add some attachments.
+// base::Value* value = base::Value::CreateStringValue("Noun");
+// object_writer.AddAttachment("annotation", *value);
+//
+// // Close header section.
+// object_writer.CloseHeader();
+//
// const std::string text = "Sample Text";
// writer.AppendString(text);
//
@@ -170,15 +186,28 @@ class CHROMEOS_EXPORT IBusObjectReader {
// object_writer.CloseAll();
class CHROMEOS_EXPORT IBusObjectWriter {
public:
+ enum WriterState {
+ NOT_INITIALZED, // Created but not initialized.
+ HEADER_OPEN, // Ready for writing attachment field.
+ INITIALIZED // Ready for writing content values.
+ };
+
// |writer| must be released by caller.
IBusObjectWriter(const std::string& type_name,
const std::string& signature,
dbus::MessageWriter* writer);
virtual ~IBusObjectWriter();
+ // Closes header to write content values.
+ void CloseHeader();
+
// Appends IBusObject headers with |writer|, should be called once.
void InitWithParentWriter(dbus::MessageWriter* writer);
+ // Adds an attachment, this function can be called only before CloseHeader
+ // function call.
+ bool AddAttachment(const std::string& key, const base::Value& value);
+
// The following functions delegate dbus::MessageReader's functions.
void AppendString(const std::string& input);
void AppendUint32(uint32 value);
@@ -194,9 +223,6 @@ class CHROMEOS_EXPORT IBusObjectWriter {
// Closes all opened containers.
void CloseAll();
- // Returns true if writer is initialized.
- bool IsInitialized() const;
-
// Appends a IBusText.
void AppendIBusText(const ibus::IBusText& text);
@@ -217,8 +243,10 @@ class CHROMEOS_EXPORT IBusObjectWriter {
std::string type_name_;
std::string signature_;
dbus::MessageWriter* original_writer_;
+ WriterState state_;
scoped_ptr<dbus::MessageWriter> top_variant_writer_;
scoped_ptr<dbus::MessageWriter> contents_writer_;
+ scoped_ptr<dbus::MessageWriter> attachment_writer_;
DISALLOW_COPY_AND_ASSIGN(IBusObjectWriter);
};
« no previous file with comments | « chromeos/dbus/ibus/ibus_lookup_table.cc ('k') | chromeos/dbus/ibus/ibus_object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698