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