1676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong/*
2676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * Copyright (C) 2017 The Android Open Source Project
3676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong *
4676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * Licensed under the Apache License, Version 2.0 (the "License");
5676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * you may not use this file except in compliance with the License.
6676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * You may obtain a copy of the License at
7676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong *
8676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong *      http://www.apache.org/licenses/LICENSE-2.0
9676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong *
10676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * Unless required by applicable law or agreed to in writing, software
11676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * distributed under the License is distributed on an "AS IS" BASIS,
12676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * See the License for the specific language governing permissions and
14676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong * limitations under the License.
15676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong */
16676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
17676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#ifndef ANDROID_VINTF_PARSE_STRING_H
18676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#define ANDROID_VINTF_PARSE_STRING_H
19676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
20676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#include <iostream>
21676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#include <sstream>
22676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#include <string>
23676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
24676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#include "CompatibilityMatrix.h"
25a7201e77e0c5221ada625ba5fcf89b25af45c10aYifan Hong#include "RuntimeInfo.h"
26d2b7e64894cd739da60f129ac38d0cf035238206Yifan Hong#include "HalManifest.h"
27676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
28676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongnamespace android {
29676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongnamespace vintf {
30676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
31676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongstd::ostream &operator<<(std::ostream &os, HalFormat hf);
32676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongstd::ostream &operator<<(std::ostream &os, Transport tr);
33c54d32cb0b20308a0ecea7864016a2a5dc512f71Yifan Hongstd::ostream &operator<<(std::ostream &os, Arch ar);
343f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongstd::ostream &operator<<(std::ostream &os, KernelConfigType il);
353f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongstd::ostream &operator<<(std::ostream &os, Tristate tr);
36f3a68574718c38ef9445f1cf49104a6130c5b23aYifan Hongstd::ostream &operator<<(std::ostream &os, SchemaType ksv);
37f3a68574718c38ef9445f1cf49104a6130c5b23aYifan Hongstd::ostream &operator<<(std::ostream &os, const ManifestHal &hal);
38676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongstd::ostream &operator<<(std::ostream &os, const Version &ver);
39676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongstd::ostream &operator<<(std::ostream &os, const VersionRange &vr);
4057b7f0c0360b2603e348ffa5892438754041a95dYifan Hongstd::ostream &operator<<(std::ostream &os, const VndkVersionRange &vr);
413f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongstd::ostream &operator<<(std::ostream &os, const KernelVersion &ver);
42c54d32cb0b20308a0ecea7864016a2a5dc512f71Yifan Hongstd::ostream &operator<<(std::ostream &os, const TransportArch &ta);
43676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongstd::ostream &operator<<(std::ostream &os, const ManifestHal &hal);
44676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongstd::ostream &operator<<(std::ostream &os, const MatrixHal &req);
453f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongstd::ostream &operator<<(std::ostream &os, const KernelConfigTypedValue &kcv);
46676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
47676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongtemplate <typename T>
48676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongstd::string to_string(const T &obj) {
49676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    std::ostringstream oss;
50676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    oss << obj;
51676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong    return oss.str();
52676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong}
53676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
54676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongbool parse(const std::string &s, HalFormat *hf);
55676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongbool parse(const std::string &s, Transport *tr);
56c54d32cb0b20308a0ecea7864016a2a5dc512f71Yifan Hongbool parse(const std::string &s, Arch *ar);
573f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongbool parse(const std::string &s, KernelConfigType *il);
583f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongbool parse(const std::string &s, KernelConfigKey *key);
593f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongbool parse(const std::string &s, Tristate *tr);
60f3a68574718c38ef9445f1cf49104a6130c5b23aYifan Hongbool parse(const std::string &s, SchemaType *ver);
61558380a7b95de37f6c74de683102f78e97e4fbf0Yifan Hongbool parse(const std::string &s, KernelSepolicyVersion *ksv);
62676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongbool parse(const std::string &s, Version *ver);
63676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongbool parse(const std::string &s, VersionRange *vr);
6457b7f0c0360b2603e348ffa5892438754041a95dYifan Hongbool parse(const std::string &s, VndkVersionRange *vr);
653f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongbool parse(const std::string &s, KernelVersion *ver);
66c54d32cb0b20308a0ecea7864016a2a5dc512f71Yifan Hong// if return true, ta->isValid() must be true.
67c54d32cb0b20308a0ecea7864016a2a5dc512f71Yifan Hongbool parse(const std::string &s, TransportArch *ta);
685a06ef717dbc3e417c35dc08543144386a277a6cYifan Hong// if return true, hal->isValid() must be true.
69676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongbool parse(const std::string &s, ManifestHal *hal);
70676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hongbool parse(const std::string &s, MatrixHal *req);
713f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong
723f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongbool parseKernelConfigInt(const std::string &s, int64_t *i);
733f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongbool parseKernelConfigInt(const std::string &s, uint64_t *i);
743f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongbool parseRange(const std::string &s, KernelConfigRangeValue *range);
753f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong
763f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong// Parse the KernelConfigValue in s, assuming type kctv->type, and store it in
773f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hong// kctv->value.
783f5489a519f5f1a7eb8bd7873a3170057502d93bYifan Hongbool parseKernelConfigValue(const std::string &s, KernelConfigTypedValue *kctv);
79676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
80676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong// A string that describes the whole object, with versions of all
81676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong// its components. For debugging and testing purposes only. This is not
82676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong// the XML string.
83d2b7e64894cd739da60f129ac38d0cf035238206Yifan Hongstd::string dump(const HalManifest &vm);
84676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
85a7201e77e0c5221ada625ba5fcf89b25af45c10aYifan Hongstd::string dump(const RuntimeInfo &ki);
86ccf967b6c8422975d000de558ed3f01456ea44beYifan Hong
87676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong} // namespace vintf
88676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong} // namespace android
89676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong
90676447acd00ebf93d1023f79fc02b5cbbb86dda2Yifan Hong#endif // ANDROID_VINTF_PARSE_STRING_H
91