1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "core/strategy.h"
16
17 namespace location {
18 namespace nearby {
19 namespace connections {
20
21 const Strategy Strategy::kNone = {Strategy::ConnectionType::kNone,
22 Strategy::TopologyType::kUnknown};
23 const Strategy Strategy::kP2pCluster{Strategy::ConnectionType::kPointToPoint,
24 Strategy::TopologyType::kManyToMany};
25 const Strategy Strategy::kP2pStar{Strategy::ConnectionType::kPointToPoint,
26 Strategy::TopologyType::kOneToMany};
27 const Strategy Strategy::kP2pPointToPoint{
28 Strategy::ConnectionType::kPointToPoint, Strategy::TopologyType::kOneToOne};
29
IsNone() const30 bool Strategy::IsNone() const {
31 return *this == kNone;
32 }
33
IsValid() const34 bool Strategy::IsValid() const {
35 return *this == kP2pStar || *this == kP2pCluster || *this ==kP2pPointToPoint;
36 }
37
GetName() const38 std::string Strategy::GetName() const {
39 if (*this == Strategy::kP2pCluster) {
40 return "P2P_CLUSTER";
41 } else if (*this == Strategy::kP2pStar) {
42 return "P2P_STAR";
43 } else if (*this == Strategy::kP2pPointToPoint) {
44 return "P2P_POINT_TO_POINT";
45 } else {
46 return "UNKNOWN";
47 }
48 }
49
operator ==(const Strategy & lhs,const Strategy & rhs)50 bool operator==(const Strategy& lhs, const Strategy& rhs) {
51 return lhs.connection_type_ == rhs.connection_type_ &&
52 lhs.topology_type_ == rhs.topology_type_;
53 }
54
operator !=(const Strategy & lhs,const Strategy & rhs)55 bool operator!=(const Strategy& lhs, const Strategy& rhs) {
56 return !(lhs == rhs);
57 }
58
59 } // namespace connections
60 } // namespace nearby
61 } // namespace location
62