| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_ | 5 #ifndef CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_ |
| 6 #define CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_ | 6 #define CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chromeos/chromeos_export.h" | 11 #include "chromeos/chromeos_export.h" |
| 12 #include "chromeos/dbus/ibus/ibus_text.h" |
| 12 | 13 |
| 13 namespace dbus { | 14 namespace dbus { |
| 14 class MessageReader; | 15 class MessageReader; |
| 15 class MessageWriter; | 16 class MessageWriter; |
| 16 } // dbus | 17 } // dbus |
| 17 | 18 |
| 18 namespace chromeos { | 19 namespace chromeos { |
| 20 // TODO(nona): Remove ibus namespace after complete libibus removal. |
| 21 namespace ibus { |
| 19 | 22 |
| 20 // The data structure of IBusObject is represented as variant in "(sav...)" | 23 // The data structure of IBusObject is represented as variant in "(sav...)" |
| 21 // signatur. The IBusObject is constructed with two sections, header and | 24 // signatur. The IBusObject is constructed with two sections, header and |
| 22 // contents. The header section is represent as "sav" which contains type name | 25 // contents. The header section is represent as "sav" which contains type name |
| 23 // and attachement array. The contents section is corresponding to "..." in | 26 // and attachement array. The contents section is corresponding to "..." in |
| 24 // above signature, which can store arbitary type values including IBusObject. | 27 // above signature, which can store arbitary type values including IBusObject. |
| 25 // | 28 // |
| 26 // DATA STRUCTURE OVERVIEW: | 29 // DATA STRUCTURE OVERVIEW: |
| 27 // | 30 // |
| 28 // variant struct { | 31 // variant // Handle with top_variant_writer_/top_variant_reader_. |
| 32 // struct { // Handle with contents_writer_/contents_reader_. |
| 29 // // Header section | 33 // // Header section |
| 30 // string typename // The type name of object, like "IBusText" | 34 // string typename // The type name of object, like "IBusText" |
| 31 // array [] // attachement array. | 35 // array [] // attachement array. |
| 32 // | 36 // |
| 33 // // Contents section | 37 // // Contents section |
| 34 // ... // The contents area. | 38 // ... // The contents area. |
| 35 // } | 39 // } |
| 36 // | 40 // |
| 37 // EXAMPLE: IBusText | 41 // EXAMPLE: IBusText |
| 38 // | 42 // |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Reads IBusOBject with |reader| and checks if the type name is valid. | 88 // Reads IBusOBject with |reader| and checks if the type name is valid. |
| 85 bool InitWithParentReader(dbus::MessageReader* reader); | 89 bool InitWithParentReader(dbus::MessageReader* reader); |
| 86 | 90 |
| 87 // Returns true if the IBusObject is valid. | 91 // Returns true if the IBusObject is valid. |
| 88 bool IsValid() const; | 92 bool IsValid() const; |
| 89 | 93 |
| 90 // The following functions delegate dbus::MessageReader's functions. | 94 // The following functions delegate dbus::MessageReader's functions. |
| 91 bool PopString(std::string* out); | 95 bool PopString(std::string* out); |
| 92 bool PopUint32(uint32* out); | 96 bool PopUint32(uint32* out); |
| 93 bool PopArray(dbus::MessageReader* reader); | 97 bool PopArray(dbus::MessageReader* reader); |
| 98 bool PopBool(bool* out); |
| 99 bool PopInt32(int32* out); |
| 100 bool HasMoreData(); |
| 101 |
| 102 // Sets up |reader| for reading an IBusObject entry. |
| 94 bool PopIBusObject(IBusObjectReader* reader); | 103 bool PopIBusObject(IBusObjectReader* reader); |
| 95 bool HasMoreData(); | 104 |
| 105 // Pops a IBusText. |
| 106 // Returns true on success. |
| 107 bool PopIBusText(ibus::IBusText* text); |
| 108 |
| 109 // Pops a IBusText and store it's text field into |text|. Use PopIBusText |
| 110 // instead in the case of using any attribute entries in IBusText. |
| 111 // Return true on success. |
| 112 bool PopStringFromIBusText(std::string* text); |
| 96 | 113 |
| 97 private: | 114 private: |
| 98 enum CheckResult { | 115 enum CheckResult { |
| 99 IBUS_OBJECT_VALID, // Already checked and valid type. | 116 IBUS_OBJECT_VALID, // Already checked and valid type. |
| 100 IBUS_OBJECT_INVALID, // Already checked but invalid type. | 117 IBUS_OBJECT_INVALID, // Already checked but invalid type. |
| 101 IBUS_OBJECT_NOT_CHECKED, // Not checked yet. | 118 IBUS_OBJECT_NOT_CHECKED, // Not checked yet. |
| 102 }; | 119 }; |
| 103 | 120 |
| 104 std::string type_name_; | 121 std::string type_name_; |
| 105 dbus::MessageReader* original_reader_; | 122 dbus::MessageReader* original_reader_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 134 const std::string& signature, | 151 const std::string& signature, |
| 135 dbus::MessageWriter* writer); | 152 dbus::MessageWriter* writer); |
| 136 virtual ~IBusObjectWriter(); | 153 virtual ~IBusObjectWriter(); |
| 137 | 154 |
| 138 // Appends IBusObject headers with |writer|, should be called once. | 155 // Appends IBusObject headers with |writer|, should be called once. |
| 139 void InitWithParentWriter(dbus::MessageWriter* writer); | 156 void InitWithParentWriter(dbus::MessageWriter* writer); |
| 140 | 157 |
| 141 // The following functions delegate dbus::MessageReader's functions. | 158 // The following functions delegate dbus::MessageReader's functions. |
| 142 void AppendString(const std::string& input); | 159 void AppendString(const std::string& input); |
| 143 void AppendUint32(uint32 value); | 160 void AppendUint32(uint32 value); |
| 161 void AppendInt32(int32 value); |
| 162 void AppendBool(bool value); |
| 144 void OpenArray(const std::string& signature, | 163 void OpenArray(const std::string& signature, |
| 145 dbus::MessageWriter* writer); | 164 dbus::MessageWriter* writer); |
| 146 void CloseContainer(dbus::MessageWriter* writer); | 165 void CloseContainer(dbus::MessageWriter* writer); |
| 147 | 166 |
| 148 // Sets up |writer| for writing new IBusObject entry. | 167 // Sets up |writer| for writing new IBusObject entry. |
| 149 void AppendIBusObject(IBusObjectWriter* writer); | 168 void AppendIBusObject(IBusObjectWriter* writer); |
| 150 | 169 |
| 151 // Closes all opened containers. | 170 // Closes all opened containers. |
| 152 void CloseAll(); | 171 void CloseAll(); |
| 153 | 172 |
| 154 // Returns true if writer is initialized. | 173 // Returns true if writer is initialized. |
| 155 bool IsInitialized() const; | 174 bool IsInitialized() const; |
| 156 | 175 |
| 176 // Appends a IBusText. |
| 177 void AppendIBusText(const ibus::IBusText& text); |
| 178 |
| 179 // Appends a string as IBusText without any attributes. Use AppendIBusText |
| 180 // instead in the case of using any attribute entries. |
| 181 void AppendStringAsIBusText(const std::string& text); |
| 182 |
| 157 private: | 183 private: |
| 158 friend class TestableIBusObjectWriter; | |
| 159 // Appends IBusObject headers, should be called once. | 184 // Appends IBusObject headers, should be called once. |
| 160 void Init(); | 185 void Init(); |
| 161 | 186 |
| 162 std::string type_name_; | 187 std::string type_name_; |
| 163 std::string signature_; | 188 std::string signature_; |
| 164 dbus::MessageWriter* original_writer_; | 189 dbus::MessageWriter* original_writer_; |
| 165 scoped_ptr<dbus::MessageWriter> top_variant_writer_; | 190 scoped_ptr<dbus::MessageWriter> top_variant_writer_; |
| 166 scoped_ptr<dbus::MessageWriter> contents_writer_; | 191 scoped_ptr<dbus::MessageWriter> contents_writer_; |
| 167 | 192 |
| 168 DISALLOW_COPY_AND_ASSIGN(IBusObjectWriter); | 193 DISALLOW_COPY_AND_ASSIGN(IBusObjectWriter); |
| 169 }; | 194 }; |
| 170 | 195 |
| 196 } // namespace ibus |
| 171 } // namespace chromeos | 197 } // namespace chromeos |
| 172 | 198 |
| 173 #endif // CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_ | 199 #endif // CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_ |
| OLD | NEW |