• 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 
23 namespace android {
24 namespace vintf {
25 
26 enum SerializeFlag : uint32_t {
27     NO_HALS = 1 << 0,
28     NO_AVB = 1 << 1,
29     NO_SEPOLICY = 1 << 2,
30     NO_VNDK = 1 << 3,
31     NO_KERNEL = 1 << 4,
32     NO_XMLFILES = 1 << 5,
33     NO_SSDK = 1 << 6,
34     NO_FQNAME = 1 << 7,
35 
36     EVERYTHING = 0,
37     HALS_ONLY = ~(NO_HALS | NO_FQNAME),  // <hal> with <fqname>
38     XMLFILES_ONLY = ~NO_XMLFILES,
39     SEPOLICY_ONLY = ~NO_SEPOLICY,
40     VNDK_ONLY = ~NO_VNDK,
41     HALS_NO_FQNAME = ~NO_HALS,  // <hal> without <fqname>
42 };
43 using SerializeFlags = uint32_t;
44 
45 template<typename Object>
46 struct XmlConverter {
XmlConverterXmlConverter47     XmlConverter() {}
~XmlConverterXmlConverter48     virtual ~XmlConverter() {}
49 
50     virtual const std::string &lastError() const = 0;
51 
52     // deprecated. Use operator() instead.
53     virtual std::string serialize(const Object& o, SerializeFlags flags = EVERYTHING) const = 0;
54 
55     // Serialize an object to XML.
56     virtual std::string operator()(const Object& o, SerializeFlags flags = EVERYTHING) const = 0;
57 
58     // deprecated. Use operator() instead. These APIs sets lastError(). Kept for testing.
59     virtual bool deserialize(Object* o, const std::string& xml) = 0;
60     virtual bool operator()(Object* o, const std::string& xml) = 0;
61 
62     // Deserialize an XML to object. Return whether it is successful. This API
63     // does not touch lastError(), but instead sets error message
64     // to optional "error" out parameter (which can be null).
65     virtual bool operator()(Object* o, const std::string& xml, std::string* error) const = 0;
66 };
67 
68 extern XmlConverter<HalManifest>& gHalManifestConverter;
69 
70 extern XmlConverter<CompatibilityMatrix>& gCompatibilityMatrixConverter;
71 
72 } // namespace vintf
73 } // namespace android
74 
75 #endif // ANDROID_VINTF_PARSE_XML_H
76