xref: /aosp_15_r20/system/libvintf/include/vintf/TransportArch.h (revision 70a7ec852fcefd15a4fb57f8f183a8b1c3aacb08)
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 
18 #ifndef ANDROID_VINTF_TRANSPORT_ARCH_H
19 #define ANDROID_VINTF_TRANSPORT_ARCH_H
20 
21 #include <optional>
22 
23 #include "Arch.h"
24 #include "Transport.h"
25 
26 namespace android {
27 namespace vintf {
28 
29 struct TransportArch {
30     Transport transport = Transport::EMPTY;
31     Arch arch = Arch::ARCH_EMPTY;
32     std::optional<std::string> ip;
33     std::optional<uint64_t> port;
34 
35     TransportArch() = default;
TransportArchTransportArch36     TransportArch(Transport t, Arch a) : transport(t), arch(a) {}
37 
38     inline bool operator==(const TransportArch& other) const {
39         return transport == other.transport && arch == other.arch;
40     }
41     inline bool operator<(const TransportArch& other) const {
42         if (transport < other.transport) return true;
43         if (transport > other.transport) return false;
44         return arch < other.arch;
45     }
46 
47    private:
48     friend struct TransportArchConverter;
49     friend struct ManifestHalConverter;
50     friend struct ManifestHal;
51     friend bool parse(const std::string &s, TransportArch *ta);
52     bool empty() const;
53     // Valid combinations:
54     // <transport arch="32">passthrough</transport>
55     // <transport arch="64">passthrough</transport>
56     // <transport arch="32+64">passthrough</transport>
57     // <transport>hwbinder</transport>
58     // "ip" and "port" can be any string and uint64_t value respectively
59     // <transport ip="1.2.3.4" port="1234">inet</transport>
60     // Element doesn't exist
61     bool isValid(std::string* error = nullptr) const;
62 };
63 
64 
65 } // namespace vintf
66 } // namespace android
67 
68 #endif // ANDROID_VINTF_TRANSPORT_ARCH_H
69