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 { |
19 | 20 |
20 // The data structure of IBusObject is represented as variant in "(sav...)" | 21 // The data structure of IBusObject is represented as variant in "(sav...)" |
21 // signatur. The IBusObject is constructed with two sections, header and | 22 // signatur. The IBusObject is constructed with two sections, header and |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 bool PopString(std::string* out); | 93 bool PopString(std::string* out); |
93 bool PopUint32(uint32* out); | 94 bool PopUint32(uint32* out); |
94 bool PopArray(dbus::MessageReader* reader); | 95 bool PopArray(dbus::MessageReader* reader); |
95 bool PopBool(bool* out); | 96 bool PopBool(bool* out); |
96 bool PopInt32(int32* out); | 97 bool PopInt32(int32* out); |
97 bool HasMoreData(); | 98 bool HasMoreData(); |
98 | 99 |
99 // Sets up |reader| for reading an IBusObject entry. | 100 // Sets up |reader| for reading an IBusObject entry. |
100 bool PopIBusObject(IBusObjectReader* reader); | 101 bool PopIBusObject(IBusObjectReader* reader); |
101 | 102 |
102 // Returns main reader if the specified IBusObject is valid, otherwise returns | 103 // Pops a IBusText. |
103 // NULL. This reader corresponds to second depth struct field(see above | 104 // Returns true on success. |
104 // description). This function is useful in the case of adding other | 105 bool PopIBusText(ibus::IBusText* text); |
105 // IBusObjects. | 106 |
106 dbus::MessageReader* GetContentsReader(); | 107 // Pops a IBusText and store it's text field into |text|. Use PopIBusText |
| 108 // instead in the case of using any attribute entries in IBusText. |
| 109 // Return true on success. |
| 110 bool PopStringFromIBusText(std::string* text); |
107 | 111 |
108 private: | 112 private: |
109 enum CheckResult { | 113 enum CheckResult { |
110 IBUS_OBJECT_VALID, // Already checked and valid type. | 114 IBUS_OBJECT_VALID, // Already checked and valid type. |
111 IBUS_OBJECT_INVALID, // Already checked but invalid type. | 115 IBUS_OBJECT_INVALID, // Already checked but invalid type. |
112 IBUS_OBJECT_NOT_CHECKED, // Not checked yet. | 116 IBUS_OBJECT_NOT_CHECKED, // Not checked yet. |
113 }; | 117 }; |
114 | 118 |
115 std::string type_name_; | 119 std::string type_name_; |
116 dbus::MessageReader* original_reader_; | 120 dbus::MessageReader* original_reader_; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 164 |
161 // Sets up |writer| for writing new IBusObject entry. | 165 // Sets up |writer| for writing new IBusObject entry. |
162 void AppendIBusObject(IBusObjectWriter* writer); | 166 void AppendIBusObject(IBusObjectWriter* writer); |
163 | 167 |
164 // Closes all opened containers. | 168 // Closes all opened containers. |
165 void CloseAll(); | 169 void CloseAll(); |
166 | 170 |
167 // Returns true if writer is initialized. | 171 // Returns true if writer is initialized. |
168 bool IsInitialized() const; | 172 bool IsInitialized() const; |
169 | 173 |
170 // Returns main contents writer if it is initialized, otherwise returns NULL. | 174 // Appends a IBusText. |
171 // this writer corresponds to second depth struct(see above description). This | 175 void AppendIBusText(const ibus::IBusText& text); |
172 // function is useful in the case of appeding other IBusObjects. | 176 |
173 dbus::MessageWriter* GetContentsWriter(); | 177 // Appends a string as IBusText without any attributes. Use AppendIBusText |
| 178 // instead in the case of using any attribute entries. |
| 179 void AppendStringAsIBusText(const std::string& text); |
174 | 180 |
175 private: | 181 private: |
176 friend class TestableIBusObjectWriter; | |
177 // Appends IBusObject headers, should be called once. | 182 // Appends IBusObject headers, should be called once. |
178 void Init(); | 183 void Init(); |
179 | 184 |
180 std::string type_name_; | 185 std::string type_name_; |
181 std::string signature_; | 186 std::string signature_; |
182 dbus::MessageWriter* original_writer_; | 187 dbus::MessageWriter* original_writer_; |
183 scoped_ptr<dbus::MessageWriter> top_variant_writer_; | 188 scoped_ptr<dbus::MessageWriter> top_variant_writer_; |
184 scoped_ptr<dbus::MessageWriter> contents_writer_; | 189 scoped_ptr<dbus::MessageWriter> contents_writer_; |
185 | 190 |
186 DISALLOW_COPY_AND_ASSIGN(IBusObjectWriter); | 191 DISALLOW_COPY_AND_ASSIGN(IBusObjectWriter); |
187 }; | 192 }; |
188 | 193 |
189 } // namespace chromeos | 194 } // namespace chromeos |
190 | 195 |
191 #endif // CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_ | 196 #endif // CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_ |
OLD | NEW |