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#include <iostream>
18#include <vintf/parse_xml.h>
19#include <vintf/parse_string.h>
20#include <vintf/VintfObject.h>
21
22// A convenience binary to dump information available through libvintf.
23int main(int, char **) {
24    using namespace ::android::vintf;
25
26    std::cout << "======== Device HAL Manifest =========" << std::endl;
27
28    const HalManifest *vm = VintfObject::GetDeviceHalManifest();
29    if (vm != nullptr)
30        std::cout << gHalManifestConverter(*vm);
31
32    std::cout << "======== Framework HAL Manifest =========" << std::endl;
33
34    const HalManifest *fm = VintfObject::GetFrameworkHalManifest();
35    if (fm != nullptr)
36        std::cout << gHalManifestConverter(*fm);
37
38    std::cout << "======== Device Compatibility Matrix =========" << std::endl;
39
40    const CompatibilityMatrix *vcm = VintfObject::GetDeviceCompatibilityMatrix();
41    if (vcm != nullptr)
42        std::cout << gCompatibilityMatrixConverter(*vcm);
43
44    std::cout << "======== Framework Compatibility Matrix =========" << std::endl;
45
46    const CompatibilityMatrix *fcm = VintfObject::GetFrameworkCompatibilityMatrix();
47    if (fcm != nullptr)
48        std::cout << gCompatibilityMatrixConverter(*fcm);
49
50    std::cout << "======== Runtime Info =========" << std::endl;
51
52    const RuntimeInfo* ki = VintfObject::GetRuntimeInfo();
53    if (ki != nullptr) std::cout << dump(*ki);
54    std::cout << std::endl;
55
56    std::cout << "======== Compatibility check =========" << std::endl;
57    std::cout << "Device HAL Manifest? " << (vm != nullptr) << std::endl
58              << "Device Compatibility Matrix? " << (vcm != nullptr) << std::endl
59              << "Framework HAL Manifest? " << (fm != nullptr) << std::endl
60              << "Framework Compatibility Matrix? " << (fcm != nullptr) << std::endl;
61    std::string error;
62    if (vm && fcm) {
63        bool compatible = vm->checkCompatibility(*fcm, &error);
64        std::cout << "Device HAL Manifest <==> Framework Compatibility Matrix? "
65                  << compatible;
66        if (!compatible)
67            std::cout << ", " << error;
68        std::cout << std::endl;
69    }
70    if (fm && vcm) {
71        bool compatible = fm->checkCompatibility(*vcm, &error);
72        std::cout << "Framework HAL Manifest <==> Device Compatibility Matrix? "
73                  << compatible;
74        if (!compatible)
75            std::cout << ", " << error;
76        std::cout << std::endl;
77    }
78    if (ki && fcm) {
79        bool compatible = ki->checkCompatibility(*fcm, &error);
80        std::cout << "Runtime info <==> Framework Compatibility Matrix? " << compatible;
81        if (!compatible) std::cout << ", " << error;
82        std::cout << std::endl;
83    }
84
85    {
86        auto compatible = VintfObject::CheckCompatibility({}, &error);
87        std::cout << "VintfObject::CheckCompatibility (0 == compatible)? " << compatible;
88        if (compatible != COMPATIBLE) std::cout << ", " << error;
89        std::cout << std::endl;
90    }
91}
92