xref: /aosp_15_r20/system/libvintf/TransportArch.cpp (revision 70a7ec852fcefd15a4fb57f8f183a8b1c3aacb08)
1*70a7ec85SAndroid Build Coastguard Worker /*
2*70a7ec85SAndroid Build Coastguard Worker  * Copyright (C) 2017 The Android Open Source Project
3*70a7ec85SAndroid Build Coastguard Worker  *
4*70a7ec85SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*70a7ec85SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*70a7ec85SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*70a7ec85SAndroid Build Coastguard Worker  *
8*70a7ec85SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*70a7ec85SAndroid Build Coastguard Worker  *
10*70a7ec85SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*70a7ec85SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*70a7ec85SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*70a7ec85SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*70a7ec85SAndroid Build Coastguard Worker  * limitations under the License.
15*70a7ec85SAndroid Build Coastguard Worker  */
16*70a7ec85SAndroid Build Coastguard Worker 
17*70a7ec85SAndroid Build Coastguard Worker 
18*70a7ec85SAndroid Build Coastguard Worker #include "TransportArch.h"
19*70a7ec85SAndroid Build Coastguard Worker 
20*70a7ec85SAndroid Build Coastguard Worker #include "parse_string.h"
21*70a7ec85SAndroid Build Coastguard Worker 
22*70a7ec85SAndroid Build Coastguard Worker namespace android {
23*70a7ec85SAndroid Build Coastguard Worker namespace vintf {
24*70a7ec85SAndroid Build Coastguard Worker 
empty() const25*70a7ec85SAndroid Build Coastguard Worker bool TransportArch::empty() const {
26*70a7ec85SAndroid Build Coastguard Worker     return transport == Transport::EMPTY && arch == Arch::ARCH_EMPTY;
27*70a7ec85SAndroid Build Coastguard Worker }
28*70a7ec85SAndroid Build Coastguard Worker 
isValid(std::string * error) const29*70a7ec85SAndroid Build Coastguard Worker bool TransportArch::isValid(std::string* error) const {
30*70a7ec85SAndroid Build Coastguard Worker     if (error) {
31*70a7ec85SAndroid Build Coastguard Worker         error->clear();
32*70a7ec85SAndroid Build Coastguard Worker     }
33*70a7ec85SAndroid Build Coastguard Worker 
34*70a7ec85SAndroid Build Coastguard Worker     switch (transport) {
35*70a7ec85SAndroid Build Coastguard Worker         case Transport::EMPTY: // fallthrough
36*70a7ec85SAndroid Build Coastguard Worker         case Transport::HWBINDER:
37*70a7ec85SAndroid Build Coastguard Worker             if (arch == Arch::ARCH_EMPTY && !ip.has_value() && !port.has_value()) {
38*70a7ec85SAndroid Build Coastguard Worker                 return true;
39*70a7ec85SAndroid Build Coastguard Worker             }
40*70a7ec85SAndroid Build Coastguard Worker             if (error) {
41*70a7ec85SAndroid Build Coastguard Worker                 *error += "Transport " + to_string(transport) +
42*70a7ec85SAndroid Build Coastguard Worker                           " requires empty ip and port attributes as well as empty arch attribute";
43*70a7ec85SAndroid Build Coastguard Worker             }
44*70a7ec85SAndroid Build Coastguard Worker             return false;
45*70a7ec85SAndroid Build Coastguard Worker 
46*70a7ec85SAndroid Build Coastguard Worker         case Transport::PASSTHROUGH:
47*70a7ec85SAndroid Build Coastguard Worker             if (arch != Arch::ARCH_EMPTY && !ip.has_value() && !port.has_value()) {
48*70a7ec85SAndroid Build Coastguard Worker                 return true;
49*70a7ec85SAndroid Build Coastguard Worker             }
50*70a7ec85SAndroid Build Coastguard Worker             if (error) {
51*70a7ec85SAndroid Build Coastguard Worker                 *error += "Passthrough HALs requires arch attribute and no ip or port attributes";
52*70a7ec85SAndroid Build Coastguard Worker             }
53*70a7ec85SAndroid Build Coastguard Worker             return false;
54*70a7ec85SAndroid Build Coastguard Worker         case Transport::INET:
55*70a7ec85SAndroid Build Coastguard Worker             if (arch == Arch::ARCH_EMPTY && ip.has_value() && port.has_value()) {
56*70a7ec85SAndroid Build Coastguard Worker                 return true;
57*70a7ec85SAndroid Build Coastguard Worker             }
58*70a7ec85SAndroid Build Coastguard Worker             if (error) {
59*70a7ec85SAndroid Build Coastguard Worker                 *error += "Transport " + to_string(transport) +
60*70a7ec85SAndroid Build Coastguard Worker                           " requires ip and port attributes as well as empty arch attribute";
61*70a7ec85SAndroid Build Coastguard Worker             }
62*70a7ec85SAndroid Build Coastguard Worker             return false;
63*70a7ec85SAndroid Build Coastguard Worker     }
64*70a7ec85SAndroid Build Coastguard Worker }
65*70a7ec85SAndroid Build Coastguard Worker 
66*70a7ec85SAndroid Build Coastguard Worker } // namespace vintf
67*70a7ec85SAndroid Build Coastguard Worker } // namespace android
68