OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_XML_PARSE_HELPERS_H_ |
| 6 #define CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_XML_PARSE_HELPERS_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "talk/base/basictypes.h" |
| 11 #include "talk/base/scoped_ptr.h" |
| 12 #include "talk/base/stream.h" |
| 13 |
| 14 namespace buzz { |
| 15 class XmlBuilder; |
| 16 class XmlElement; |
| 17 class XmlParser; |
| 18 class QName; |
| 19 } |
| 20 |
| 21 namespace notifier { |
| 22 buzz::XmlElement* ReadXmlFromStream(talk_base::StreamInterface* stream); |
| 23 bool ParseInt64Attr(const buzz::XmlElement* element, |
| 24 const buzz::QName& attribute, int64* result); |
| 25 bool ParseIntAttr(const buzz::XmlElement* element, |
| 26 const buzz::QName& attribute, int* result); |
| 27 bool ParseBoolAttr(const buzz::XmlElement* element, |
| 28 const buzz::QName& attribute, bool* result); |
| 29 bool ParseStringAttr(const buzz::XmlElement* element, |
| 30 const buzz::QName& attribute, std::string* result); |
| 31 |
| 32 void WriteXmlToStream(talk_base::StreamInterface* stream, |
| 33 const buzz::XmlElement* xml); |
| 34 bool SetInt64Attr(buzz::XmlElement* element, const buzz::QName& attribute, |
| 35 int64 result); |
| 36 bool SetIntAttr(buzz::XmlElement* element, const buzz::QName& attribute, |
| 37 int result); |
| 38 bool SetBoolAttr(buzz::XmlElement* element, const buzz::QName& attribute, |
| 39 bool result); |
| 40 bool SetStringAttr(buzz::XmlElement* element, const buzz::QName& attribute, |
| 41 const std::string& result); |
| 42 |
| 43 template<class T> |
| 44 void SetAttr(buzz::XmlElement* xml, const buzz::QName& name, const T& data); |
| 45 |
| 46 /////////////////////////////////////////////////////////////////////////////// |
| 47 // XmlStream |
| 48 /////////////////////////////////////////////////////////////////////////////// |
| 49 |
| 50 class XmlStream : public talk_base::StreamInterface { |
| 51 public: |
| 52 XmlStream(); |
| 53 virtual ~XmlStream(); |
| 54 |
| 55 buzz::XmlElement* CreateElement(); |
| 56 |
| 57 virtual talk_base::StreamState GetState() const { return state_; } |
| 58 |
| 59 virtual talk_base::StreamResult Read(void* buffer, size_t buffer_len, |
| 60 size_t* read, int* error); |
| 61 virtual talk_base::StreamResult Write(const void* data, size_t data_len, |
| 62 size_t* written, int* error); |
| 63 virtual void Close(); |
| 64 |
| 65 private: |
| 66 talk_base::StreamState state_; |
| 67 scoped_ptr<buzz::XmlBuilder> builder_; |
| 68 scoped_ptr<buzz::XmlParser> parser_; |
| 69 }; |
| 70 |
| 71 /////////////////////////////////////////////////////////////////////////////// |
| 72 |
| 73 } // namespace buzz |
| 74 |
| 75 #endif // CHROME_BROWSER_SYNC_NOTIFIER_COMMUNICATOR_XML_PARSE_HELPERS_H_ |
OLD | NEW |