• 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_STRING_H
18 #define ANDROID_VINTF_PARSE_STRING_H
19 
20 #include <iostream>
21 #include <sstream>
22 #include <string>
23 #include <string_view>
24 
25 #include "CompatibilityMatrix.h"
26 #include "RuntimeInfo.h"
27 #include "HalManifest.h"
28 
29 namespace android {
30 namespace vintf {
31 
32 std::ostream &operator<<(std::ostream &os, HalFormat hf);
33 std::ostream &operator<<(std::ostream &os, Transport tr);
34 std::ostream &operator<<(std::ostream &os, Arch ar);
35 std::ostream &operator<<(std::ostream &os, KernelConfigType il);
36 std::ostream &operator<<(std::ostream &os, Tristate tr);
37 std::ostream &operator<<(std::ostream &os, SchemaType ksv);
38 std::ostream& operator<<(std::ostream& os, XmlSchemaFormat f);
39 std::ostream& operator<<(std::ostream& os, Level l);
40 std::ostream& operator<<(std::ostream& os, KernelSepolicyVersion v);
41 std::ostream &operator<<(std::ostream &os, const Version &ver);
42 std::ostream &operator<<(std::ostream &os, const VersionRange &vr);
43 
44 #pragma clang diagnostic push
45 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
46 std::ostream &operator<<(std::ostream &os, const VndkVersionRange &vr);
47 #pragma clang diagnostic pop
48 
49 std::ostream &operator<<(std::ostream &os, const KernelVersion &ver);
50 std::ostream &operator<<(std::ostream &os, const TransportArch &ta);
51 std::ostream &operator<<(std::ostream &os, const ManifestHal &hal);
52 std::ostream &operator<<(std::ostream &os, const KernelConfigTypedValue &kcv);
53 std::ostream& operator<<(std::ostream& os, const FqInstance& fqInstance);
54 
55 template <typename T>
to_string(const T & obj)56 std::string to_string(const T &obj) {
57     std::ostringstream oss;
58     oss << obj;
59     return oss.str();
60 }
61 
62 bool parse(const std::string &s, HalFormat *hf);
63 bool parse(const std::string &s, Transport *tr);
64 bool parse(const std::string &s, Arch *ar);
65 bool parse(const std::string &s, KernelConfigType *il);
66 bool parse(const std::string &s, KernelConfigKey *key);
67 bool parse(const std::string &s, Tristate *tr);
68 bool parse(const std::string &s, SchemaType *ver);
69 bool parse(const std::string& s, XmlSchemaFormat* ver);
70 bool parse(const std::string& s, Level* l);
71 bool parse(const std::string &s, KernelSepolicyVersion *ksv);
72 bool parse(const std::string &s, Version *ver);
73 bool parse(const std::string &s, VersionRange *vr);
74 
75 #pragma clang diagnostic push
76 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
77 bool parse(const std::string &s, VndkVersionRange *vr);
78 #pragma clang diagnostic pop
79 
80 bool parse(const std::string &s, KernelVersion *ver);
81 bool parse(const std::string& s, FqInstance* fqInstance);
82 
83 bool parseKernelConfigInt(const std::string &s, int64_t *i);
84 bool parseKernelConfigInt(const std::string &s, uint64_t *i);
85 bool parseRange(const std::string &s, KernelConfigRangeValue *range);
86 
87 // Parse the KernelConfigValue in s, assuming type kctv->type, and store it in
88 // kctv->value.
89 bool parseKernelConfigValue(const std::string &s, KernelConfigTypedValue *kctv);
90 
91 // Parse the KernelConfigTypedValue in s (type is guessed) and store it in kctv.
92 // Do not expect quotes in strings.
93 bool parseKernelConfigTypedValue(const std::string& s, KernelConfigTypedValue* kctv);
94 
95 // "100" <=> Version{kFakeAidlMajorVersion, 100}
96 std::string aidlVersionToString(const Version& v);
97 bool parseAidlVersion(const std::string& s, Version* version);
98 
99 // "100" <=> VersionRange{kFakeAidlMajorVersion, 100}
100 // "100-105" <=> VersionRange{kFakeAidlMajorVersion, 100, 105}
101 std::string aidlVersionRangeToString(const VersionRange& vr);
102 bool parseAidlVersionRange(const std::string& s, VersionRange* vr);
103 
104 // A string that describes the whole object, with versions of all
105 // its components. For debugging and testing purposes only. This is not
106 // the XML string.
107 std::string dump(const HalManifest &vm);
108 
109 std::string dump(const RuntimeInfo& ki, bool verbose = true);
110 
111 std::vector<std::string> expandInstances(const MatrixHal& req);
112 
113 std::string toFQNameString(const std::string& package, const Version& version,
114                            const std::string& intf = "", const std::string& instance = "");
115 
116 std::string toFQNameString(const Version& version, const std::string& intf,
117                            const std::string& instance);
118 
119 // android.hardware.foo@1.0-1::IFoo/default.
120 // Note that the format is extended to support a range of versions.
121 std::string toFQNameString(const std::string& package, const VersionRange& range,
122                            const std::string& interface, const std::string& instance);
123 
124 std::string toFQNameString(const VersionRange& range, const std::string& interface,
125                            const std::string& instance);
126 
127 std::string toFQNameString(const std::string& interface, const std::string& instance);
128 
129 std::string toAidlFqnameString(const std::string& package, const std::string& interface,
130                                const std::string& instance = "");
131 
132 std::string_view parseApexName(std::string_view path);
133 
134 } // namespace vintf
135 } // namespace android
136 
137 #endif // ANDROID_VINTF_PARSE_STRING_H
138