mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
Release based on cl/313536507.
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: I83ec7dee1a7ef6f4bdfd47482c94d03910525b7e
This commit is contained in:
@@ -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.
|
||||
|
||||
cc_library(
|
||||
name = "posix_lock",
|
||||
srcs = [
|
||||
"posix_lock.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"posix_lock.h",
|
||||
],
|
||||
visibility = [
|
||||
"//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__",
|
||||
"//platform/impl:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//platform/api",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "posix_condition_variable",
|
||||
srcs = [
|
||||
"posix_condition_variable.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"posix_condition_variable.h",
|
||||
],
|
||||
visibility = [
|
||||
"//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__",
|
||||
"//platform/impl:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
":posix_lock",
|
||||
"//platform:types",
|
||||
"//platform/api:condition_variable",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "atomic_boolean",
|
||||
hdrs = ["atomic_boolean_impl.h"],
|
||||
visibility = [
|
||||
"//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__",
|
||||
"//platform/impl:__subpackages__",
|
||||
],
|
||||
deps = ["//platform/api"],
|
||||
)
|
||||
@@ -0,0 +1,81 @@
|
||||
# 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.
|
||||
|
||||
add_library(platform_impl_shared_posix_lock STATIC)
|
||||
|
||||
target_sources(platform_impl_shared_posix_lock
|
||||
PRIVATE
|
||||
"posix_lock.cc"
|
||||
PUBLIC
|
||||
"posix_lock.h"
|
||||
)
|
||||
|
||||
target_include_directories(platform_impl_shared_posix_lock
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries(platform_impl_shared_posix_lock
|
||||
PUBLIC
|
||||
platform_api
|
||||
platform_types
|
||||
)
|
||||
|
||||
add_library(platform_impl_shared_posix_condition_variable STATIC)
|
||||
|
||||
target_sources(platform_impl_shared_posix_condition_variable
|
||||
PRIVATE
|
||||
"posix_condition_variable.cc"
|
||||
PUBLIC
|
||||
"posix_condition_variable.h"
|
||||
)
|
||||
|
||||
target_include_directories(platform_impl_shared_posix_condition_variable
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(platform_impl_shared_posix_condition_variable
|
||||
PUBLIC
|
||||
platform_api
|
||||
platform_impl_shared_posix_lock
|
||||
platform_types
|
||||
absl::raw_logging_internal
|
||||
)
|
||||
|
||||
add_library(platform_impl_shared_atomic_boolean STATIC)
|
||||
|
||||
target_sources(platform_impl_shared_atomic_boolean
|
||||
PUBLIC
|
||||
"atomic_boolean_impl.h"
|
||||
)
|
||||
|
||||
target_include_directories(platform_impl_shared_atomic_boolean
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(platform_impl_shared_atomic_boolean
|
||||
PUBLIC
|
||||
platform_api
|
||||
platform_types
|
||||
)
|
||||
|
||||
set_target_properties(platform_impl_shared_atomic_boolean
|
||||
PROPERTIES
|
||||
LINKER_LANGUAGE CXX
|
||||
)
|
||||
|
||||
add_subdirectory(sample)
|
||||
@@ -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 PLATFORM_IMPL_SHARED_ATOMIC_BOOLEAN_IMPL_H_
|
||||
#define PLATFORM_IMPL_SHARED_ATOMIC_BOOLEAN_IMPL_H_
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "platform/api/atomic_boolean.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
class AtomicBooleanImpl : public AtomicBoolean {
|
||||
public:
|
||||
explicit AtomicBooleanImpl(bool initial_value) : value_(initial_value) {}
|
||||
~AtomicBooleanImpl() override = default;
|
||||
|
||||
// AtomicBoolean:
|
||||
bool get() override {
|
||||
return value_.load();
|
||||
}
|
||||
|
||||
// AtomicBoolean:
|
||||
void set(bool value) override {
|
||||
value_.store(value);
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic_bool value_;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // PLATFORM_IMPL_SHARED_ATOMIC_BOOLEAN_IMPL_H_
|
||||
@@ -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.
|
||||
|
||||
#include "platform/impl/shared/posix_condition_variable.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
PosixConditionVariable::PosixConditionVariable(Ptr<PosixLock> lock)
|
||||
: lock_(lock), attr_(), cond_() {
|
||||
pthread_condattr_init(&attr_);
|
||||
|
||||
pthread_cond_init(&cond_, &attr_);
|
||||
}
|
||||
|
||||
PosixConditionVariable::~PosixConditionVariable() {
|
||||
pthread_cond_destroy(&cond_);
|
||||
|
||||
pthread_condattr_destroy(&attr_);
|
||||
}
|
||||
|
||||
void PosixConditionVariable::notify() { pthread_cond_broadcast(&cond_); }
|
||||
|
||||
Exception::Value PosixConditionVariable::wait() {
|
||||
pthread_cond_wait(&cond_, &(lock_->mutex_));
|
||||
|
||||
return Exception::kSuccess;
|
||||
}
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
@@ -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 PLATFORM_IMPL_SHARED_POSIX_CONDITION_VARIABLE_H_
|
||||
#define PLATFORM_IMPL_SHARED_POSIX_CONDITION_VARIABLE_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "platform/api/condition_variable.h"
|
||||
#include "platform/impl/shared/posix_lock.h"
|
||||
#include "platform/ptr.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
class PosixConditionVariable : public ConditionVariable {
|
||||
public:
|
||||
explicit PosixConditionVariable(Ptr<PosixLock> lock);
|
||||
~PosixConditionVariable() override;
|
||||
|
||||
void notify() override;
|
||||
Exception::Value wait() override;
|
||||
|
||||
private:
|
||||
Ptr<PosixLock> lock_;
|
||||
pthread_condattr_t attr_;
|
||||
pthread_cond_t cond_;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // PLATFORM_IMPL_SHARED_POSIX_CONDITION_VARIABLE_H_
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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 "platform/impl/shared/posix_lock.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
PosixLock::PosixLock() : attr_(), mutex_() {
|
||||
pthread_mutexattr_init(&attr_);
|
||||
pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE);
|
||||
|
||||
pthread_mutex_init(&mutex_, &attr_);
|
||||
}
|
||||
|
||||
PosixLock::~PosixLock() {
|
||||
pthread_mutex_destroy(&mutex_);
|
||||
|
||||
pthread_mutexattr_destroy(&attr_);
|
||||
}
|
||||
|
||||
void PosixLock::lock() { pthread_mutex_lock(&mutex_); }
|
||||
|
||||
void PosixLock::unlock() { pthread_mutex_unlock(&mutex_); }
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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 PLATFORM_IMPL_SHARED_POSIX_LOCK_H_
|
||||
#define PLATFORM_IMPL_SHARED_POSIX_LOCK_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "platform/api/lock.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
class PosixLock : public Lock {
|
||||
public:
|
||||
PosixLock();
|
||||
~PosixLock() override;
|
||||
|
||||
void lock() override;
|
||||
void unlock() override;
|
||||
|
||||
private:
|
||||
friend class PosixConditionVariable;
|
||||
|
||||
pthread_mutexattr_t attr_;
|
||||
pthread_mutex_t mutex_;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // PLATFORM_IMPL_SHARED_POSIX_LOCK_H_
|
||||
@@ -0,0 +1,36 @@
|
||||
# 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.
|
||||
|
||||
cc_library(
|
||||
name = "sample_wifi_medium",
|
||||
srcs = [
|
||||
"sample_wifi_medium.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"sample_wifi_medium.h",
|
||||
],
|
||||
visibility = [
|
||||
"//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__",
|
||||
"//core:__subpackages__",
|
||||
"//platform/impl:__subpackages__",
|
||||
"//location/nearby/setup/core:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//platform:types",
|
||||
"//platform:utils",
|
||||
"//platform/api",
|
||||
"//platform/port:string",
|
||||
"//absl/time",
|
||||
],
|
||||
)
|
||||
@@ -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.
|
||||
|
||||
add_library(platform_impl_shared_sample STATIC)
|
||||
|
||||
target_sources(platform_impl_shared_sample
|
||||
PRIVATE
|
||||
sample_wifi_medium.cc
|
||||
PUBLIC
|
||||
sample_wifi_medium.h
|
||||
)
|
||||
|
||||
target_link_libraries(platform_impl_shared_sample
|
||||
PUBLIC
|
||||
absl::time
|
||||
platform_api
|
||||
platform_port_string
|
||||
platform_types
|
||||
platform_utils
|
||||
)
|
||||
@@ -0,0 +1,124 @@
|
||||
// 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 "platform/impl/shared/sample/sample_wifi_medium.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "platform/prng.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace sample {
|
||||
|
||||
namespace {
|
||||
|
||||
const char* kOpenSSID = "__OPEN__";
|
||||
const char* kWpaPskSSID = "__WPA_PSK__";
|
||||
const char* kWepSSID = "__WEP__";
|
||||
const char* kNoInternetConnectivitySSID = "__NO_INTERNET_CONNECTIVITY__";
|
||||
const char* kConnectionFailureSSID = "__CONNECTION_FAILURE__";
|
||||
const char* kAuthFailureSSID = "__AUTH_FAILURE__";
|
||||
|
||||
std::uint32_t boundedUInt32(std::uint32_t upper_limit) {
|
||||
return Prng().nextUInt32() % (upper_limit + 1);
|
||||
}
|
||||
|
||||
void randomSleep(std::uint32_t upper_limit_millis) {
|
||||
absl::SleepFor(absl::Milliseconds(boundedUInt32(upper_limit_millis)));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::vector<SampleWifiScanResult> SampleWifiMedium::canned_scan_results_;
|
||||
|
||||
SampleWifiMedium::SampleWifiMedium() : current_ssid_() {
|
||||
// One-time initialization of our static canned_scan_results_.
|
||||
if (canned_scan_results_.empty()) {
|
||||
canned_scan_results_.push_back(
|
||||
SampleWifiScanResult(kOpenSSID, 1, 2401, WifiAuthType::OPEN));
|
||||
canned_scan_results_.push_back(
|
||||
SampleWifiScanResult(kWpaPskSSID, 2, 5002, WifiAuthType::WPA_PSK));
|
||||
canned_scan_results_.push_back(
|
||||
SampleWifiScanResult(kWepSSID, 3, 2403, WifiAuthType::WEP));
|
||||
canned_scan_results_.push_back(SampleWifiScanResult(
|
||||
kNoInternetConnectivitySSID, 4, 5004, WifiAuthType::OPEN));
|
||||
canned_scan_results_.push_back(SampleWifiScanResult(
|
||||
kConnectionFailureSSID, 5, 2405, WifiAuthType::OPEN));
|
||||
canned_scan_results_.push_back(
|
||||
SampleWifiScanResult(kAuthFailureSSID, 6, 5006, WifiAuthType::OPEN));
|
||||
}
|
||||
}
|
||||
|
||||
SampleWifiMedium::~SampleWifiMedium() {}
|
||||
|
||||
bool SampleWifiMedium::scan(
|
||||
Ptr<WifiMedium::ScanResultCallback> scan_result_callback) {
|
||||
// Sleep for up to 10 seconds, to simulate performing an actual Wifi scan.
|
||||
randomSleep(10 * 1000);
|
||||
|
||||
// Construct the response.
|
||||
std::vector<ConstPtr<WifiScanResult> > scan_results;
|
||||
for (std::vector<SampleWifiScanResult>::const_iterator it =
|
||||
canned_scan_results_.begin();
|
||||
it != canned_scan_results_.end(); it++) {
|
||||
scan_results.push_back(ConstPtr<WifiScanResult>(
|
||||
new SampleWifiScanResult(it->getSSID(), it->getSignalStrengthDbm(),
|
||||
it->getFrequencyMhz(), it->getAuthType())));
|
||||
}
|
||||
|
||||
// And report it back.
|
||||
scan_result_callback->onScanResults(scan_results);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
WifiConnectionStatus::Value SampleWifiMedium::connectToNetwork(
|
||||
const std::string& ssid, const std::string& password,
|
||||
WifiAuthType::Value auth_type) {
|
||||
// Sleep for up to 10 seconds, to simulate actually connecting to the SSID.
|
||||
randomSleep(10 * 1000);
|
||||
|
||||
if (kConnectionFailureSSID == ssid) {
|
||||
return WifiConnectionStatus::CONNECTION_FAILURE;
|
||||
}
|
||||
|
||||
if (kAuthFailureSSID == ssid) {
|
||||
return WifiConnectionStatus::AUTH_FAILURE;
|
||||
}
|
||||
|
||||
return WifiConnectionStatus::CONNECTED;
|
||||
}
|
||||
|
||||
bool SampleWifiMedium::verifyInternetConnectivity() {
|
||||
if (current_ssid_.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sleep for up to 5 seconds, to simulate actually verifying internet
|
||||
// connectivity.
|
||||
randomSleep(5 * 1000);
|
||||
|
||||
return current_ssid_ != kNoInternetConnectivitySSID;
|
||||
}
|
||||
|
||||
std::string SampleWifiMedium::getIPAddress() {
|
||||
return current_ssid_.empty() ? "" : "1.2.3.4";
|
||||
}
|
||||
|
||||
} // namespace sample
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
@@ -0,0 +1,73 @@
|
||||
// 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 PLATFORM_IMPL_SHARED_SAMPLE_SAMPLE_WIFI_MEDIUM_H_
|
||||
#define PLATFORM_IMPL_SHARED_SAMPLE_SAMPLE_WIFI_MEDIUM_H_
|
||||
|
||||
#include "platform/api/wifi.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace sample {
|
||||
|
||||
class SampleWifiScanResult : public WifiScanResult {
|
||||
public:
|
||||
SampleWifiScanResult(const std::string& ssid,
|
||||
std::int32_t signal_strength_dbm,
|
||||
std::int32_t frequency_mhz,
|
||||
WifiAuthType::Value auth_type)
|
||||
: ssid_(ssid),
|
||||
signal_strength_dbm_(signal_strength_dbm),
|
||||
frequency_mhz_(frequency_mhz),
|
||||
auth_type_(auth_type) {}
|
||||
~SampleWifiScanResult() override {}
|
||||
|
||||
std::string getSSID() const override { return ssid_; }
|
||||
std::int32_t getSignalStrengthDbm() const override {
|
||||
return signal_strength_dbm_;
|
||||
}
|
||||
std::int32_t getFrequencyMhz() const override { return frequency_mhz_; }
|
||||
WifiAuthType::Value getAuthType() const override { return auth_type_; }
|
||||
|
||||
private:
|
||||
const std::string ssid_;
|
||||
const std::int32_t signal_strength_dbm_;
|
||||
const std::int32_t frequency_mhz_;
|
||||
const WifiAuthType::Value auth_type_;
|
||||
};
|
||||
|
||||
class SampleWifiMedium : public WifiMedium {
|
||||
public:
|
||||
SampleWifiMedium();
|
||||
~SampleWifiMedium() override;
|
||||
|
||||
bool scan(Ptr<ScanResultCallback> scan_result_callback) override;
|
||||
WifiConnectionStatus::Value connectToNetwork(
|
||||
const std::string& ssid, const std::string& password,
|
||||
WifiAuthType::Value auth_type) override;
|
||||
bool verifyInternetConnectivity() override;
|
||||
std::string getIPAddress() override;
|
||||
|
||||
private:
|
||||
static std::vector<SampleWifiScanResult> canned_scan_results_;
|
||||
|
||||
// The SSID this Wifi stack is currently connected to; empty string if none.
|
||||
std::string current_ssid_;
|
||||
};
|
||||
|
||||
} // namespace sample
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // PLATFORM_IMPL_SHARED_SAMPLE_SAMPLE_WIFI_MEDIUM_H_
|
||||
Reference in New Issue
Block a user