• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef ANDROID_VINTF_PARSE_XML_H
18 #define ANDROID_VINTF_PARSE_XML_H
19 
20 #include "CompatibilityMatrix.h"
21 #include "HalManifest.h"
22 #include "SerializeFlags.h"
23 
24 namespace android {
25 namespace vintf {
26 
27 template<typename Object>
28 struct XmlConverter {
XmlConverterXmlConverter29     XmlConverter() {}
~XmlConverterXmlConverter30     virtual ~XmlConverter() {}
31 
32     virtual const std::string &lastError() const = 0;
33 
34     // deprecated. Use operator() instead.
35     virtual std::string serialize(
36         const Object& o, SerializeFlags::Type flags = SerializeFlags::EVERYTHING) const = 0;
37 
38     // Serialize an object to XML.
39     virtual std::string operator()(
40         const Object& o, SerializeFlags::Type flags = SerializeFlags::EVERYTHING) const = 0;
41 
42     // deprecated. Use operator() instead. These APIs sets lastError(). Kept for testing.
43     virtual bool deserialize(Object* o, const std::string& xml) = 0;
44     virtual bool operator()(Object* o, const std::string& xml) = 0;
45 
46     // Deserialize an XML to object. Return whether it is successful. This API
47     // does not touch lastError(), but instead sets error message
48     // to optional "error" out parameter (which can be null).
49     virtual bool operator()(Object* o, const std::string& xml, std::string* error) const = 0;
50 };
51 
52 extern XmlConverter<HalManifest>& gHalManifestConverter;
53 
54 extern XmlConverter<CompatibilityMatrix>& gCompatibilityMatrixConverter;
55 
56 } // namespace vintf
57 } // namespace android
58 
59 #endif // ANDROID_VINTF_PARSE_XML_H
60