Chromium Code Reviews| 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 | 12 |
| 13 namespace dbus { | 13 namespace dbus { |
| 14 class MessageReader; | 14 class MessageReader; |
| 15 class MessageWriter; | 15 class MessageWriter; |
| 16 } // dbus | 16 } // dbus |
| 17 | 17 |
| 18 namespace chromeos { | 18 namespace chromeos { |
| 19 | 19 |
| 20 // The data structure of IBusObject is represented as variant in "(sav...)" | 20 // The data structure of IBusObject is represented as variant in "(sav...)" |
| 21 // signatur. The IBusObject is constructed with two sections, header and | 21 // signatur. The IBusObject is constructed with two sections, header and |
| 22 // contents. The header section is represent as "sav" which contains type name | 22 // contents. The header section is represent as "sav" which contains type name |
| 23 // and attachement array. The contents section is corresponding to "..." in | 23 // and attachement array. The contents section is corresponding to "..." in |
| 24 // above signature, which can store arbitary type values including IBusObject. | 24 // above signature, which can store arbitary type values including IBusObject. |
| 25 // | 25 // |
| 26 // DATA STRUCTURE OVERVIEW: | 26 // DATA STRUCTURE OVERVIEW: |
| 27 // | 27 // |
| 28 // variant struct { | 28 // variant // Handle with top_variant_writer_/top_variant_reader_. |
| 29 // struct { // Handle with contents_writer_/contents_reader_. | |
| 29 // // Header section | 30 // // Header section |
| 30 // string typename // The type name of object, like "IBusText" | 31 // string typename // The type name of object, like "IBusText" |
| 31 // array [] // attachement array. | 32 // array [] // attachement array. |
| 32 // | 33 // |
| 33 // // Contents section | 34 // // Contents section |
| 34 // ... // The contents area. | 35 // ... // The contents area. |
| 35 // } | 36 // } |
| 36 // | 37 // |
| 37 // EXAMPLE: IBusText | 38 // EXAMPLE: IBusText |
| 38 // | 39 // |
| (...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. | 85 // Reads IBusOBject with |reader| and checks if the type name is valid. |
| 85 bool InitWithParentReader(dbus::MessageReader* reader); | 86 bool InitWithParentReader(dbus::MessageReader* reader); |
| 86 | 87 |
| 87 // Returns true if the IBusObject is valid. | 88 // Returns true if the IBusObject is valid. |
| 88 bool IsValid() const; | 89 bool IsValid() const; |
| 89 | 90 |
| 90 // The following functions delegate dbus::MessageReader's functions. | 91 // The following functions delegate dbus::MessageReader's functions. |
| 91 bool PopString(std::string* out); | 92 bool PopString(std::string* out); |
| 92 bool PopUint32(uint32* out); | 93 bool PopUint32(uint32* out); |
| 93 bool PopArray(dbus::MessageReader* reader); | 94 bool PopArray(dbus::MessageReader* reader); |
| 95 bool PopBool(bool* out); | |
| 96 bool PopInt32(int32* out); | |
| 97 bool HasMoreData(); | |
| 98 | |
| 99 // Sets up |reader| for reading an IBusObject entry. | |
| 94 bool PopIBusObject(IBusObjectReader* reader); | 100 bool PopIBusObject(IBusObjectReader* reader); |
| 95 bool HasMoreData(); | 101 |
| 102 // Returns main reader if the specified IBusObject is valid, otherwise returns | |
| 103 // NULL. This reader corresponds to second depth struct field(see above | |
|
satorux1
2012/05/18 01:23:36
please add a space before (
Seigo Nonaka
2012/05/18 01:41:52
Done.
| |
| 104 // description). This function is useful in the case of adding other | |
| 105 // IBusObjects. | |
| 106 dbus::MessageReader* GetContentsReader(); | |
|
satorux1
2012/05/18 01:23:36
I'm confused. Why do we need to expose this? Canno
Seigo Nonaka
2012/05/18 01:41:52
If I want to add IBusText into some IBusObject, Ap
satorux1
2012/05/18 04:54:46
Where is the IBusObject class? Is there such a cla
Seigo Nonaka
2012/05/18 17:01:47
Sorry not IBusObject, IBusObjectWriter is correct.
| |
| 96 | 107 |
| 97 private: | 108 private: |
| 98 enum CheckResult { | 109 enum CheckResult { |
| 99 IBUS_OBJECT_VALID, // Already checked and valid type. | 110 IBUS_OBJECT_VALID, // Already checked and valid type. |
| 100 IBUS_OBJECT_INVALID, // Already checked but invalid type. | 111 IBUS_OBJECT_INVALID, // Already checked but invalid type. |
| 101 IBUS_OBJECT_NOT_CHECKED, // Not checked yet. | 112 IBUS_OBJECT_NOT_CHECKED, // Not checked yet. |
| 102 }; | 113 }; |
| 103 | 114 |
| 104 std::string type_name_; | 115 std::string type_name_; |
| 105 dbus::MessageReader* original_reader_; | 116 dbus::MessageReader* original_reader_; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 134 const std::string& signature, | 145 const std::string& signature, |
| 135 dbus::MessageWriter* writer); | 146 dbus::MessageWriter* writer); |
| 136 virtual ~IBusObjectWriter(); | 147 virtual ~IBusObjectWriter(); |
| 137 | 148 |
| 138 // Appends IBusObject headers with |writer|, should be called once. | 149 // Appends IBusObject headers with |writer|, should be called once. |
| 139 void InitWithParentWriter(dbus::MessageWriter* writer); | 150 void InitWithParentWriter(dbus::MessageWriter* writer); |
| 140 | 151 |
| 141 // The following functions delegate dbus::MessageReader's functions. | 152 // The following functions delegate dbus::MessageReader's functions. |
| 142 void AppendString(const std::string& input); | 153 void AppendString(const std::string& input); |
| 143 void AppendUint32(uint32 value); | 154 void AppendUint32(uint32 value); |
| 155 void AppendInt32(int32 value); | |
| 156 void AppendBool(bool value); | |
| 144 void OpenArray(const std::string& signature, | 157 void OpenArray(const std::string& signature, |
| 145 dbus::MessageWriter* writer); | 158 dbus::MessageWriter* writer); |
| 146 void CloseContainer(dbus::MessageWriter* writer); | 159 void CloseContainer(dbus::MessageWriter* writer); |
| 147 | 160 |
| 148 // Sets up |writer| for writing new IBusObject entry. | 161 // Sets up |writer| for writing new IBusObject entry. |
| 149 void AppendIBusObject(IBusObjectWriter* writer); | 162 void AppendIBusObject(IBusObjectWriter* writer); |
| 150 | 163 |
| 151 // Closes all opened containers. | 164 // Closes all opened containers. |
| 152 void CloseAll(); | 165 void CloseAll(); |
| 153 | 166 |
| 154 // Returns true if writer is initialized. | 167 // Returns true if writer is initialized. |
| 155 bool IsInitialized() const; | 168 bool IsInitialized() const; |
| 156 | 169 |
| 170 // Returns main contents writer if it is initialized, otherwise returns NULL. | |
| 171 // this writer corresponds to second depth struct(see above description). This | |
| 172 // function is useful in the case of appeding other IBusObjects. | |
| 173 dbus::MessageWriter* GetContentsWriter(); | |
| 174 | |
| 157 private: | 175 private: |
| 158 friend class TestableIBusObjectWriter; | 176 friend class TestableIBusObjectWriter; |
| 159 // Appends IBusObject headers, should be called once. | 177 // Appends IBusObject headers, should be called once. |
| 160 void Init(); | 178 void Init(); |
| 161 | 179 |
| 162 std::string type_name_; | 180 std::string type_name_; |
| 163 std::string signature_; | 181 std::string signature_; |
| 164 dbus::MessageWriter* original_writer_; | 182 dbus::MessageWriter* original_writer_; |
| 165 scoped_ptr<dbus::MessageWriter> top_variant_writer_; | 183 scoped_ptr<dbus::MessageWriter> top_variant_writer_; |
| 166 scoped_ptr<dbus::MessageWriter> contents_writer_; | 184 scoped_ptr<dbus::MessageWriter> contents_writer_; |
| 167 | 185 |
| 168 DISALLOW_COPY_AND_ASSIGN(IBusObjectWriter); | 186 DISALLOW_COPY_AND_ASSIGN(IBusObjectWriter); |
| 169 }; | 187 }; |
| 170 | 188 |
| 171 } // namespace chromeos | 189 } // namespace chromeos |
| 172 | 190 |
| 173 #endif // CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_ | 191 #endif // CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_ |
| OLD | NEW |