parse_xml.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2017 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef ANDROID_VINTF_PARSE_XML_H
  17. #define ANDROID_VINTF_PARSE_XML_H
  18. #include "CompatibilityMatrix.h"
  19. #include "HalManifest.h"
  20. #include "SerializeFlags.h"
  21. namespace android {
  22. namespace vintf {
  23. template<typename Object>
  24. struct XmlConverter {
  25. XmlConverter() {}
  26. virtual ~XmlConverter() {}
  27. virtual const std::string &lastError() const = 0;
  28. // deprecated. Use operator() instead.
  29. virtual std::string serialize(
  30. const Object& o, SerializeFlags::Type flags = SerializeFlags::EVERYTHING) const = 0;
  31. // Serialize an object to XML.
  32. virtual std::string operator()(
  33. const Object& o, SerializeFlags::Type flags = SerializeFlags::EVERYTHING) const = 0;
  34. // deprecated. Use operator() instead. These APIs sets lastError(). Kept for testing.
  35. virtual bool deserialize(Object* o, const std::string& xml) = 0;
  36. virtual bool operator()(Object* o, const std::string& xml) = 0;
  37. // Deserialize an XML to object. Return whether it is successful. This API
  38. // does not touch lastError(), but instead sets error message
  39. // to optional "error" out parameter (which can be null).
  40. virtual bool operator()(Object* o, const std::string& xml, std::string* error) const = 0;
  41. };
  42. extern XmlConverter<HalManifest>& gHalManifestConverter;
  43. extern XmlConverter<CompatibilityMatrix>& gCompatibilityMatrixConverter;
  44. } // namespace vintf
  45. } // namespace android
  46. #endif // ANDROID_VINTF_PARSE_XML_H