forked from google/nearby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_presence_service.cc
107 lines (88 loc) · 3.53 KB
/
fake_presence_service.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// 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 "presence/fake_presence_service.h"
#include <memory>
#include <utility>
#include <vector>
#include "internal/interop/device_provider.h"
#include "internal/platform/borrowable.h"
#include "presence/fake_presence_client.h"
namespace nearby {
namespace presence {
FakePresenceService::FakePresenceService() = default;
std::unique_ptr<PresenceClient> FakePresenceService::CreatePresenceClient() {
auto fake = std::make_unique<FakePresenceClient>();
most_recent_fake_presence_client_ = fake.get();
return std::move(fake);
}
// Not implemented.
absl::StatusOr<ScanSessionId> FakePresenceService::StartScan(
ScanRequest scan_request, ScanCallback callback) {
return absl::Status(absl::StatusCode::kCancelled,
"StartScan not implemented yet");
}
// Not implemented.
void FakePresenceService::StopScan(ScanSessionId session_id) {}
// Not implemented.
absl::StatusOr<BroadcastSessionId> FakePresenceService::StartBroadcast(
BroadcastRequest broadcast_request, BroadcastCallback callback) {
return absl::Status(absl::StatusCode::kCancelled,
"StartBroadcast not implemented yet");
}
// Not implemented.
void FakePresenceService::StopBroadcast(BroadcastSessionId session_id) {}
void FakePresenceService::UpdateDeviceIdentityMetaData(
const ::nearby::internal::DeviceIdentityMetaData& metadata,
bool regen_credentials,
absl::string_view manager_app_id,
const std::vector<nearby::internal::IdentityType>& identity_types,
int credential_life_cycle_days, int contiguous_copy_of_credentials,
GenerateCredentialsResultCallback credentials_generated_cb) {
metadata_ = metadata;
if (!regen_credentials) {
// No need to call back on credentials_generated_cb.
return;
}
if (gen_credentials_status_.ok()) {
std::move(credentials_generated_cb.credentials_generated_cb)(
shared_credentials_);
} else {
std::move(credentials_generated_cb.credentials_generated_cb)(
gen_credentials_status_);
}
}
NearbyDeviceProvider* FakePresenceService::GetLocalDeviceProvider() {
return provider_;
}
void FakePresenceService::GetLocalPublicCredentials(
const CredentialSelector& credential_selector,
GetPublicCredentialsResultCallback callback) {
if (get_public_credentials_status_.ok()) {
std::move(callback.credentials_fetched_cb)(shared_credentials_);
return;
}
std::move(callback.credentials_fetched_cb)(get_public_credentials_status_);
}
void FakePresenceService::UpdateRemotePublicCredentials(
absl::string_view manager_app_id, absl::string_view account_name,
const std::vector<nearby::internal::SharedCredential>& remote_public_creds,
UpdateRemotePublicCredentialsCallback credentials_updated_cb) {
if (update_remote_public_credentials_status_.ok()) {
remote_shared_credentials_ = remote_public_creds;
}
std::move(credentials_updated_cb.credentials_updated_cb)(
update_remote_public_credentials_status_);
}
} // namespace presence
} // namespace nearby