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, const ManifestHal &hal);
38 std::ostream &operator<<(std::ostream &os, const Version &ver);
39 std::ostream &operator<<(std::ostream &os, const VersionRange &vr);
40 std::ostream &operator<<(std::ostream &os, const VndkVersionRange &vr);
41 std::ostream &operator<<(std::ostream &os, const KernelVersion &ver);
42 std::ostream &operator<<(std::ostream &os, const TransportArch &ta);
43 std::ostream &operator<<(std::ostream &os, const ManifestHal &hal);
44 std::ostream &operator<<(std::ostream &os, const MatrixHal &req);
45 std::ostream &operator<<(std::ostream &os, const KernelConfigTypedValue &kcv);
46 
47 template <typename T>
to_string(const T & obj)48 std::string to_string(const T &obj) {
49     std::ostringstream oss;
50     oss << obj;
51     return oss.str();
52 }
53 
54 bool parse(const std::string &s, HalFormat *hf);
55 bool parse(const std::string &s, Transport *tr);
56 bool parse(const std::string &s, Arch *ar);
57 bool parse(const std::string &s, KernelConfigType *il);
58 bool parse(const std::string &s, KernelConfigKey *key);
59 bool parse(const std::string &s, Tristate *tr);
60 bool parse(const std::string &s, SchemaType *ver);
61 bool parse(const std::string &s, KernelSepolicyVersion *ksv);
62 bool parse(const std::string &s, Version *ver);
63 bool parse(const std::string &s, VersionRange *vr);
64 bool parse(const std::string &s, VndkVersionRange *vr);
65 bool parse(const std::string &s, KernelVersion *ver);
66 // if return true, ta->isValid() must be true.
67 bool parse(const std::string &s, TransportArch *ta);
68 // if return true, hal->isValid() must be true.
69 bool parse(const std::string &s, ManifestHal *hal);
70 bool parse(const std::string &s, MatrixHal *req);
71 
72 bool parseKernelConfigInt(const std::string &s, int64_t *i);
73 bool parseKernelConfigInt(const std::string &s, uint64_t *i);
74 bool parseRange(const std::string &s, KernelConfigRangeValue *range);
75 
76 // Parse the KernelConfigValue in s, assuming type kctv->type, and store it in
77 // kctv->value.
78 bool parseKernelConfigValue(const std::string &s, KernelConfigTypedValue *kctv);
79 
80 // A string that describes the whole object, with versions of all
81 // its components. For debugging and testing purposes only. This is not
82 // the XML string.
83 std::string dump(const HalManifest &vm);
84 
85 std::string dump(const RuntimeInfo &ki);
86 
87 } // namespace vintf
88 } // namespace android
89 
90 #endif // ANDROID_VINTF_PARSE_STRING_H
91