mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Initial impl for Nearby Presence in Nearby SDk.
discovery associated data types. PiperOrigin-RevId: 436615656
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
# Copyright 2020 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
licenses(["notice"])
|
||||
|
||||
cc_library(
|
||||
name = "types",
|
||||
srcs = [
|
||||
"device_motion.cc",
|
||||
"presence_action.cc",
|
||||
"presence_identity.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"device_motion.h",
|
||||
"presence_action.h",
|
||||
"presence_identity.h",
|
||||
],
|
||||
visibility = [
|
||||
"//third_party/nearby/presence:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/types:variant",
|
||||
"@com_google_glog//:glog",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "types_test",
|
||||
size = "small",
|
||||
srcs = [
|
||||
"device_motion_test.cc",
|
||||
"presence_action_test.cc",
|
||||
"presence_identity_test.cc",
|
||||
],
|
||||
shard_count = 6,
|
||||
deps = [
|
||||
":types",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "third_party/nearby/presence/device_motion.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
DeviceMotion::DeviceMotion(MotionType motion_type, float confidence) noexcept
|
||||
: motion_type_(motion_type), confidence_(confidence) {}
|
||||
DeviceMotion::MotionType DeviceMotion::GetMotionType() const {
|
||||
return motion_type_;
|
||||
}
|
||||
float DeviceMotion::GetConfidence() const { return confidence_; }
|
||||
|
||||
} // namespace presence
|
||||
} // namespace nearby
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_PRESENCE_DEVICE_MOTION_H_
|
||||
#define THIRD_PARTY_NEARBY_PRESENCE_DEVICE_MOTION_H_
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
class DeviceMotion {
|
||||
public:
|
||||
enum class MotionType {
|
||||
kPointAndHold = 0,
|
||||
};
|
||||
DeviceMotion(MotionType motion_type = MotionType::kPointAndHold,
|
||||
float confidence = 0) noexcept;
|
||||
~DeviceMotion() noexcept = default;
|
||||
MotionType GetMotionType() const;
|
||||
float GetConfidence() const;
|
||||
|
||||
private:
|
||||
const MotionType motion_type_;
|
||||
const float confidence_;
|
||||
};
|
||||
|
||||
inline bool operator==(const DeviceMotion& m1, const DeviceMotion& m2) {
|
||||
return m1.GetMotionType() == m2.GetMotionType() &&
|
||||
m1.GetConfidence() == m2.GetConfidence();
|
||||
}
|
||||
inline bool operator!=(const DeviceMotion& m1, const DeviceMotion& m2) {
|
||||
return !(m1 == m2);
|
||||
}
|
||||
|
||||
} // namespace presence
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_PRESENCE_DEVICE_MOTION_H_
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "third_party/nearby/presence/device_motion.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
static constexpr DeviceMotion::MotionType kDefaultMotionType =
|
||||
DeviceMotion::MotionType::kPointAndHold;
|
||||
static constexpr float kDefaultConfidence = 0;
|
||||
static constexpr float kConfidenceForTest = 0.1;
|
||||
TEST(DeviceMotionTest, DefaultConstructorWorks) {
|
||||
DeviceMotion motion;
|
||||
EXPECT_EQ(motion.GetMotionType(), kDefaultMotionType);
|
||||
EXPECT_EQ(motion.GetConfidence(), kDefaultConfidence);
|
||||
}
|
||||
|
||||
TEST(DeviceMotionTest, DefaultEquals) {
|
||||
DeviceMotion motion1;
|
||||
DeviceMotion motion2;
|
||||
EXPECT_EQ(motion1, motion2);
|
||||
}
|
||||
|
||||
TEST(DeviceMotionTest, ExplicitInitEquals) {
|
||||
DeviceMotion motion1 = {kDefaultMotionType, kConfidenceForTest};
|
||||
DeviceMotion motion2 = {kDefaultMotionType, kConfidenceForTest};
|
||||
EXPECT_EQ(motion1, motion2);
|
||||
EXPECT_EQ(motion1.GetConfidence(), kConfidenceForTest);
|
||||
}
|
||||
|
||||
TEST(DeviceMotionTest, ExplicitInitNotEquals) {
|
||||
DeviceMotion motion1 = {kDefaultMotionType, kConfidenceForTest};
|
||||
DeviceMotion motion2 = {kDefaultMotionType};
|
||||
EXPECT_NE(motion1, motion2);
|
||||
}
|
||||
|
||||
TEST(DeviceMotionTest, CopyInitEquals) {
|
||||
DeviceMotion motion1;
|
||||
DeviceMotion motion2 = {motion1};
|
||||
EXPECT_EQ(motion1, motion2);
|
||||
}
|
||||
|
||||
} // namespace presence
|
||||
} // namespace nearby
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "third_party/nearby/presence/presence_action.h"
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
PresenceAction::PresenceAction(int action_identifier)
|
||||
: action_identifier_(action_identifier) {
|
||||
CHECK(kMinActionIdentifierValue <= action_identifier_ &&
|
||||
action_identifier_ <= kMaxActionIdentifierValue);
|
||||
}
|
||||
|
||||
int PresenceAction::GetActionIdentifier() const { return action_identifier_; }
|
||||
|
||||
} // namespace presence
|
||||
} // namespace nearby
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_PRESENCE_PRESENCE_ACTION_H_
|
||||
#define THIRD_PARTY_NEARBY_PRESENCE_PRESENCE_ACTION_H_
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
class PresenceAction {
|
||||
public:
|
||||
PresenceAction(int action_identifier = 1);
|
||||
~PresenceAction() noexcept = default;
|
||||
int GetActionIdentifier() const;
|
||||
|
||||
private:
|
||||
static constexpr int kMinActionIdentifierValue = 1;
|
||||
static constexpr int kMaxActionIdentifierValue = 255;
|
||||
const int action_identifier_;
|
||||
};
|
||||
|
||||
inline bool operator==(const PresenceAction& a1, const PresenceAction& a2) {
|
||||
return a1.GetActionIdentifier() == a2.GetActionIdentifier();
|
||||
}
|
||||
|
||||
inline bool operator!=(const PresenceAction& a1, const PresenceAction& a2) {
|
||||
return !(a1 == a2);
|
||||
}
|
||||
} // namespace presence
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_PRESENCE_PRESENCE_ACTION_H_
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "third_party/nearby/presence/presence_action.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
static constexpr int kDefaultActionIdentifier = 1;
|
||||
static constexpr int kTestActionIdentifier = 2;
|
||||
TEST(PresenceActionTest, DefaultConstructorWorks) {
|
||||
PresenceAction action;
|
||||
EXPECT_EQ(action.GetActionIdentifier(), kDefaultActionIdentifier);
|
||||
}
|
||||
|
||||
TEST(PresenceActionTest, DefaultEquals) {
|
||||
PresenceAction action1;
|
||||
PresenceAction action2;
|
||||
EXPECT_EQ(action1, action2);
|
||||
}
|
||||
|
||||
TEST(PresenceActionTest, ExplicitInitEquals) {
|
||||
PresenceAction action1 = {kTestActionIdentifier};
|
||||
PresenceAction action2 = {kTestActionIdentifier};
|
||||
EXPECT_EQ(action1, action2);
|
||||
EXPECT_EQ(action1.GetActionIdentifier(), kTestActionIdentifier);
|
||||
}
|
||||
|
||||
TEST(PresenceActionTest, ExplicitInitNotEquals) {
|
||||
PresenceAction action1 = {kDefaultActionIdentifier};
|
||||
PresenceAction action2 = {kTestActionIdentifier};
|
||||
EXPECT_NE(action1, action2);
|
||||
}
|
||||
|
||||
TEST(PresenceActionTest, CopyInitEquals) {
|
||||
PresenceAction action1 = {kTestActionIdentifier};
|
||||
PresenceAction action2 = {action1};
|
||||
|
||||
EXPECT_EQ(action1, action2);
|
||||
}
|
||||
|
||||
} // namespace presence
|
||||
} // namespace nearby
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "third_party/nearby/presence/presence_identity.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
PresenceIdentity::PresenceIdentity(IdentityType identity_type) noexcept
|
||||
: identity_type_(identity_type) {}
|
||||
|
||||
PresenceIdentity::IdentityType PresenceIdentity::GetIdentityType() const {
|
||||
return identity_type_;
|
||||
}
|
||||
|
||||
} // namespace presence
|
||||
} // namespace nearby
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_PRESENCE_PRESENCE_IDENTITY_H_
|
||||
#define THIRD_PARTY_NEARBY_PRESENCE_PRESENCE_IDENTITY_H_
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
class PresenceIdentity {
|
||||
public:
|
||||
enum class IdentityType {
|
||||
kPrivate = 0,
|
||||
kTrusted,
|
||||
};
|
||||
PresenceIdentity(IdentityType type = IdentityType::kPrivate) noexcept;
|
||||
~PresenceIdentity() noexcept = default;
|
||||
IdentityType GetIdentityType() const;
|
||||
|
||||
private:
|
||||
const IdentityType identity_type_;
|
||||
};
|
||||
|
||||
inline bool operator==(const PresenceIdentity& i1, const PresenceIdentity& i2) {
|
||||
return i1.GetIdentityType() == i2.GetIdentityType();
|
||||
}
|
||||
|
||||
inline bool operator!=(const PresenceIdentity& i1, const PresenceIdentity& i2) {
|
||||
return !(i1 == i2);
|
||||
}
|
||||
} // namespace presence
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_PRESENCE_PRESENCE_IDENTITY_H_
|
||||
@@ -0,0 +1,59 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "third_party/nearby/presence/presence_identity.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
static constexpr PresenceIdentity::IdentityType kDefaultIdentityType =
|
||||
PresenceIdentity::IdentityType::kPrivate;
|
||||
static constexpr PresenceIdentity::IdentityType kTestIdentityType =
|
||||
PresenceIdentity::IdentityType::kTrusted;
|
||||
|
||||
TEST(PresenceIdentityTest, DefaultIsError) {
|
||||
PresenceIdentity identity;
|
||||
EXPECT_EQ(identity.GetIdentityType(), kDefaultIdentityType);
|
||||
}
|
||||
|
||||
TEST(PresenceIdentityTest, DefaultEquals) {
|
||||
PresenceIdentity identity1;
|
||||
PresenceIdentity identity2;
|
||||
EXPECT_EQ(identity1, identity2);
|
||||
}
|
||||
|
||||
TEST(PresenceIdentityTest, ExplicitInitEquals) {
|
||||
PresenceIdentity identity1 = {kTestIdentityType};
|
||||
PresenceIdentity identity2 = {kTestIdentityType};
|
||||
EXPECT_EQ(identity1, identity2);
|
||||
EXPECT_EQ(identity1.GetIdentityType(), kTestIdentityType);
|
||||
}
|
||||
|
||||
TEST(PresenceIdentityTest, ExplicitInitNotEquals) {
|
||||
PresenceIdentity identity1 = {kTestIdentityType};
|
||||
PresenceIdentity identity2;
|
||||
EXPECT_NE(identity1, identity2);
|
||||
}
|
||||
|
||||
TEST(PresenceIdentityTest, CopyInitEquals) {
|
||||
PresenceIdentity identity1 = {kTestIdentityType};
|
||||
PresenceIdentity identity2 = {identity1};
|
||||
EXPECT_EQ(identity1, identity2);
|
||||
}
|
||||
|
||||
} // namespace presence
|
||||
} // namespace nearby
|
||||
Reference in New Issue
Block a user