mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Roll forward to cl/338482889
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: Ic2bdb234e89f3c5860d1b483dd4bce689f13d057
This commit is contained in:
@@ -13,20 +13,18 @@
|
||||
# limitations under the License.
|
||||
|
||||
cc_library(
|
||||
name = "posix_lock",
|
||||
name = "posix_mutex",
|
||||
srcs = [
|
||||
"posix_lock.cc",
|
||||
"posix_mutex.cc",
|
||||
],
|
||||
hdrs = [
|
||||
"posix_lock.h",
|
||||
"posix_mutex.h",
|
||||
],
|
||||
visibility = [
|
||||
"//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__",
|
||||
"//platform/impl:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//platform/api",
|
||||
],
|
||||
deps = ["//platform/api:types"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
@@ -39,49 +37,35 @@ cc_library(
|
||||
],
|
||||
visibility = [
|
||||
"//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__",
|
||||
"//platform/impl:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
":posix_lock",
|
||||
"//platform:types",
|
||||
"//platform/api:condition_variable",
|
||||
":posix_mutex",
|
||||
"//platform/api:types",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "atomic_boolean",
|
||||
hdrs = ["atomic_boolean_impl.h"],
|
||||
visibility = [
|
||||
"//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__",
|
||||
"//platform/impl:__subpackages__",
|
||||
],
|
||||
deps = ["//platform/api"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "file",
|
||||
srcs = ["file_impl.cc"],
|
||||
hdrs = ["file_impl.h"],
|
||||
srcs = ["file.cc"],
|
||||
hdrs = ["file.h"],
|
||||
visibility = [
|
||||
"//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__",
|
||||
"//core:__subpackages__",
|
||||
"//platform/impl:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//platform:types",
|
||||
"//platform/api",
|
||||
"//platform/api:types",
|
||||
"//platform/base",
|
||||
"//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "file_test",
|
||||
timeout = "short",
|
||||
srcs = [
|
||||
"file_impl_test.cc",
|
||||
],
|
||||
srcs = ["file_test.cc"],
|
||||
deps = [
|
||||
":file",
|
||||
"//file/util:temp_path",
|
||||
"//platform/base",
|
||||
"//testing/base/public:gunit_main",
|
||||
"//absl/strings",
|
||||
],
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
# 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_file STATIC)
|
||||
|
||||
target_sources(platform_impl_shared_file
|
||||
PRIVATE
|
||||
"file_impl.cc"
|
||||
PUBLIC
|
||||
"file_impl.h"
|
||||
)
|
||||
|
||||
target_include_directories(platform_impl_shared_file
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(platform_impl_shared_file
|
||||
PUBLIC
|
||||
platform_api
|
||||
platform_types
|
||||
)
|
||||
|
||||
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)
|
||||
@@ -1,47 +0,0 @@
|
||||
// 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_
|
||||
@@ -12,78 +12,84 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "platform/impl/shared/file_impl.h"
|
||||
#include "platform/impl/shared/file.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
#include "platform/base/exception.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace shared {
|
||||
|
||||
// InputFile
|
||||
|
||||
InputFileImpl::InputFileImpl(const std::string& path, std::int64_t size)
|
||||
InputFile::InputFile(const std::string& path, std::int64_t size)
|
||||
: file_(path), path_(path), total_size_(size) {}
|
||||
|
||||
ExceptionOr<ConstPtr<ByteArray>> InputFileImpl::read(int64_t size) {
|
||||
ExceptionOr<ByteArray> InputFile::Read(std::int64_t size) {
|
||||
if (!file_.is_open()) {
|
||||
return ExceptionOr<ConstPtr<ByteArray>>(Exception::IO);
|
||||
return ExceptionOr<ByteArray>{Exception::kIo};
|
||||
}
|
||||
|
||||
if (file_.peek() == EOF) {
|
||||
return ExceptionOr<ConstPtr<ByteArray>>(ConstPtr<ByteArray>());
|
||||
return ExceptionOr<ByteArray>{ByteArray{}};
|
||||
}
|
||||
|
||||
if (!file_.good()) {
|
||||
return ExceptionOr<ConstPtr<ByteArray>>(Exception::IO);
|
||||
return ExceptionOr<ByteArray>{Exception::kIo};
|
||||
}
|
||||
|
||||
std::unique_ptr<char[]> read_bytes {new char [size]};
|
||||
ByteArray bytes(size);
|
||||
std::unique_ptr<char[]> read_bytes{new char[size]};
|
||||
file_.read(read_bytes.get(), static_cast<ptrdiff_t>(size));
|
||||
auto num_bytes_read = file_.gcount();
|
||||
if (num_bytes_read == 0) {
|
||||
return ExceptionOr<ConstPtr<ByteArray>>(Exception::IO);
|
||||
return ExceptionOr<ByteArray>{Exception::kIo};
|
||||
}
|
||||
|
||||
return ExceptionOr<ConstPtr<ByteArray>>(
|
||||
MakeConstPtr(new ByteArray(read_bytes.get(), num_bytes_read)));
|
||||
return ExceptionOr<ByteArray>(ByteArray(read_bytes.get(), num_bytes_read));
|
||||
}
|
||||
|
||||
std::string InputFileImpl::getFilePath() const { return path_; }
|
||||
|
||||
std::int64_t InputFileImpl::getTotalSize() const { return total_size_; }
|
||||
|
||||
void InputFileImpl::close() {
|
||||
Exception InputFile::Close() {
|
||||
if (file_.is_open()) {
|
||||
file_.close();
|
||||
}
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
// OutputFile
|
||||
|
||||
OutputFileImpl::OutputFileImpl(const std::string& path) : file_(path) {}
|
||||
|
||||
Exception::Value OutputFileImpl::write(ConstPtr<ByteArray> data) {
|
||||
ScopedPtr<ConstPtr<ByteArray>> scoped_data(data);
|
||||
OutputFile::OutputFile(absl::string_view path) : file_(std::string(path)) {}
|
||||
|
||||
Exception OutputFile::Write(const ByteArray& data) {
|
||||
if (!file_.is_open()) {
|
||||
return Exception::IO;
|
||||
return {Exception::kIo};
|
||||
}
|
||||
|
||||
if (!file_.good()) {
|
||||
return Exception::IO;
|
||||
return {Exception::kIo};
|
||||
}
|
||||
|
||||
file_.write(data->getData(), data->size());
|
||||
file_.write(data.data(), data.size());
|
||||
file_.flush();
|
||||
return file_.good() ? Exception::NONE : Exception::IO;
|
||||
return {file_.good() ? Exception::kSuccess : Exception::kIo};
|
||||
}
|
||||
|
||||
void OutputFileImpl::close() {
|
||||
Exception OutputFile::Flush() {
|
||||
file_.flush();
|
||||
return {file_.good() ? Exception::kSuccess : Exception::kIo};
|
||||
}
|
||||
|
||||
Exception OutputFile::Close() {
|
||||
if (file_.is_open()) {
|
||||
file_.close();
|
||||
}
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
} // namespace shared
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
@@ -0,0 +1,67 @@
|
||||
// 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_FILE_H_
|
||||
#define PLATFORM_IMPL_SHARED_FILE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
|
||||
#include "platform/api/input_file.h"
|
||||
#include "platform/api/output_file.h"
|
||||
#include "platform/base/exception.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace shared {
|
||||
|
||||
class InputFile final : public api::InputFile {
|
||||
public:
|
||||
explicit InputFile(const std::string& path, std::int64_t size);
|
||||
~InputFile() override = default;
|
||||
InputFile(InputFile&&) = default;
|
||||
InputFile& operator=(InputFile&&) = default;
|
||||
|
||||
ExceptionOr<ByteArray> Read(std::int64_t size) override;
|
||||
std::string GetFilePath() const override { return path_; }
|
||||
std::int64_t GetTotalSize() const override { return total_size_; }
|
||||
Exception Close() override;
|
||||
|
||||
private:
|
||||
std::ifstream file_;
|
||||
std::string path_;
|
||||
std::int64_t total_size_;
|
||||
};
|
||||
|
||||
class OutputFile final : public api::OutputFile {
|
||||
public:
|
||||
explicit OutputFile(absl::string_view path);
|
||||
~OutputFile() override = default;
|
||||
OutputFile(OutputFile&&) = default;
|
||||
OutputFile& operator=(OutputFile&&) = default;
|
||||
|
||||
Exception Write(const ByteArray& data) override;
|
||||
Exception Flush() override;
|
||||
Exception Close() override;
|
||||
|
||||
private:
|
||||
std::ofstream file_;
|
||||
};
|
||||
|
||||
} // namespace shared
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // PLATFORM_IMPL_SHARED_FILE_H_
|
||||
@@ -1,60 +0,0 @@
|
||||
// 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_FILE_IMPL_H_
|
||||
#define PLATFORM_IMPL_SHARED_FILE_IMPL_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
|
||||
#include "platform/api/input_file.h"
|
||||
#include "platform/api/output_file.h"
|
||||
#include "platform/exception.h"
|
||||
#include "platform/ptr.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
class InputFileImpl final : public InputFile {
|
||||
public:
|
||||
InputFileImpl(const std::string& path, std::int64_t size);
|
||||
~InputFileImpl() override {}
|
||||
|
||||
ExceptionOr<ConstPtr<ByteArray>> read(std::int64_t size) override;
|
||||
std::string getFilePath() const override;
|
||||
std::int64_t getTotalSize() const override;
|
||||
void close() override;
|
||||
|
||||
private:
|
||||
std::ifstream file_;
|
||||
const std::string path_;
|
||||
const std::int64_t total_size_;
|
||||
};
|
||||
|
||||
class OutputFileImpl final : public OutputFile {
|
||||
public:
|
||||
explicit OutputFileImpl(const std::string& path);
|
||||
~OutputFileImpl() override {}
|
||||
|
||||
Exception::Value write(ConstPtr<ByteArray> data) override;
|
||||
void close() override;
|
||||
|
||||
private:
|
||||
std::ofstream file_;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // PLATFORM_IMPL_SHARED_FILE_IMPL_H_
|
||||
@@ -1,148 +0,0 @@
|
||||
// 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/file_impl.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
|
||||
class FileImplTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
path_ = std::tmpnam(nullptr);;
|
||||
std::ofstream output_file(path_);
|
||||
file_ = std::fstream(path_, std::fstream::in | std::fstream::out);
|
||||
}
|
||||
|
||||
void WriteToFile(absl::string_view text) {
|
||||
file_ << text;
|
||||
file_.flush();
|
||||
size_ += text.size();
|
||||
}
|
||||
|
||||
size_t GetSize() const { return size_; }
|
||||
|
||||
void AssertEquals(const ExceptionOr<ConstPtr<ByteArray>>& bytes,
|
||||
const std::string& expected) {
|
||||
ASSERT_TRUE(bytes.ok());
|
||||
ScopedPtr<ConstPtr<ByteArray>> byte_array(bytes.result());
|
||||
ASSERT_STREQ(byte_array->getData(), expected.c_str());
|
||||
ASSERT_EQ(byte_array->size(), expected.length());
|
||||
}
|
||||
|
||||
void AssertNull(const ExceptionOr<ConstPtr<ByteArray>>& bytes) {
|
||||
ASSERT_TRUE(bytes.ok());
|
||||
ASSERT_TRUE(bytes.result().isNull());
|
||||
}
|
||||
|
||||
static constexpr int64_t kMaxSize = 3;
|
||||
|
||||
std::string path_;
|
||||
std::fstream file_;
|
||||
size_t size_ = 0;
|
||||
};
|
||||
|
||||
TEST_F(FileImplTest, InputFile_NonExistentPath) {
|
||||
InputFileImpl input_file("/not/a/valid/path.txt", GetSize());
|
||||
ExceptionOr<ConstPtr<ByteArray>> read_result = input_file.read(kMaxSize);
|
||||
ASSERT_FALSE(read_result.ok());
|
||||
ASSERT_EQ(read_result.exception(), Exception::IO);
|
||||
}
|
||||
|
||||
TEST_F(FileImplTest, InputFile_GetFilePath) {
|
||||
InputFileImpl input_file(path_, GetSize());
|
||||
ASSERT_EQ(input_file.getFilePath(), path_);
|
||||
}
|
||||
|
||||
TEST_F(FileImplTest, InputFile_EmptyFileEOF) {
|
||||
InputFileImpl input_file(path_, GetSize());
|
||||
AssertNull(input_file.read(kMaxSize));
|
||||
}
|
||||
|
||||
TEST_F(FileImplTest, InputFile_ReadWorks) {
|
||||
WriteToFile("abc");
|
||||
InputFileImpl input_file(path_, GetSize());
|
||||
auto read_data = input_file.read(kMaxSize);
|
||||
read_data.result().destroy();
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST_F(FileImplTest, InputFile_ReadUntilEOF) {
|
||||
WriteToFile("abc");
|
||||
InputFileImpl input_file(path_, GetSize());
|
||||
AssertEquals(input_file.read(kMaxSize), "abc");
|
||||
AssertNull(input_file.read(kMaxSize));
|
||||
}
|
||||
|
||||
TEST_F(FileImplTest, InputFile_ReadWithSize) {
|
||||
WriteToFile("abc");
|
||||
InputFileImpl input_file(path_, GetSize());
|
||||
AssertEquals(input_file.read(2), "ab");
|
||||
AssertEquals(input_file.read(1), "c");
|
||||
AssertNull(input_file.read(kMaxSize));
|
||||
}
|
||||
|
||||
TEST_F(FileImplTest, InputFile_GetTotalSize) {
|
||||
WriteToFile("abc");
|
||||
InputFileImpl input_file(path_, GetSize());
|
||||
EXPECT_EQ(input_file.getTotalSize(), 3);
|
||||
AssertEquals(input_file.read(1), "a");
|
||||
EXPECT_EQ(input_file.getTotalSize(), 3);
|
||||
}
|
||||
|
||||
TEST_F(FileImplTest, InputFile_Close) {
|
||||
WriteToFile("abc");
|
||||
InputFileImpl input_file(path_, GetSize());
|
||||
input_file.close();
|
||||
ExceptionOr<ConstPtr<ByteArray>> read_result = input_file.read(kMaxSize);
|
||||
ASSERT_FALSE(read_result.ok());
|
||||
ASSERT_EQ(read_result.exception(), Exception::IO);
|
||||
}
|
||||
|
||||
TEST_F(FileImplTest, OutputFile_NonExistentPath) {
|
||||
OutputFileImpl output_file("/not/a/valid/path.txt");
|
||||
ConstPtr<ByteArray> bytes = MakeConstPtr(new ByteArray("a", 1));
|
||||
Exception::Value write_result = output_file.write(bytes);
|
||||
ASSERT_EQ(write_result, Exception::IO);
|
||||
}
|
||||
|
||||
TEST_F(FileImplTest, OutputFile_Write) {
|
||||
OutputFileImpl output_file(path_);
|
||||
ConstPtr<ByteArray> bytes1 = MakeConstPtr(new ByteArray("a", 1));
|
||||
ConstPtr<ByteArray> bytes2 = MakeConstPtr(new ByteArray("bc", 2));
|
||||
ASSERT_EQ(output_file.write(bytes1), Exception::NONE);
|
||||
ASSERT_EQ(output_file.write(bytes2), Exception::NONE);
|
||||
InputFileImpl input_file(path_, GetSize());
|
||||
AssertEquals(input_file.read(kMaxSize), "abc");
|
||||
}
|
||||
|
||||
TEST_F(FileImplTest, OutputFile_Close) {
|
||||
OutputFileImpl output_file(path_);
|
||||
output_file.close();
|
||||
ConstPtr<ByteArray> bytes = MakeConstPtr(new ByteArray("a", 1));
|
||||
ASSERT_EQ(output_file.write(bytes), Exception::IO);
|
||||
}
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
@@ -0,0 +1,148 @@
|
||||
// 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/file.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
#include "file/util/temp_path.h"
|
||||
#include "platform/base/byte_array.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace shared {
|
||||
|
||||
class FileTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
temp_path_ = std::make_unique<TempPath>(TempPath::Local);
|
||||
path_ = temp_path_->path() + "/file.txt";
|
||||
std::ofstream output_file(path_);
|
||||
file_ = std::fstream(path_, std::fstream::in | std::fstream::out);
|
||||
}
|
||||
|
||||
void WriteToFile(absl::string_view text) {
|
||||
file_ << text;
|
||||
file_.flush();
|
||||
size_ += text.size();
|
||||
}
|
||||
|
||||
size_t GetSize() const { return size_; }
|
||||
|
||||
void AssertEquals(const ExceptionOr<ByteArray>& bytes,
|
||||
const std::string& expected) {
|
||||
EXPECT_TRUE(bytes.ok());
|
||||
EXPECT_EQ(std::string(bytes.result()), expected);
|
||||
}
|
||||
|
||||
void AssertEmpty(const ExceptionOr<ByteArray>& bytes) {
|
||||
EXPECT_TRUE(bytes.ok());
|
||||
EXPECT_TRUE(bytes.result().Empty());
|
||||
}
|
||||
|
||||
static constexpr int64_t kMaxSize = 3;
|
||||
|
||||
std::unique_ptr<TempPath> temp_path_;
|
||||
std::string path_;
|
||||
std::fstream file_;
|
||||
size_t size_ = 0;
|
||||
};
|
||||
|
||||
TEST_F(FileTest, InputFile_NonExistentPath) {
|
||||
InputFile input_file("/not/a/valid/path.txt", GetSize());
|
||||
ExceptionOr<ByteArray> read_result = input_file.Read(kMaxSize);
|
||||
EXPECT_FALSE(read_result.ok());
|
||||
EXPECT_TRUE(read_result.GetException().Raised(Exception::kIo));
|
||||
}
|
||||
|
||||
TEST_F(FileTest, InputFile_GetFilePath) {
|
||||
InputFile input_file(path_, GetSize());
|
||||
EXPECT_EQ(input_file.GetFilePath(), path_);
|
||||
}
|
||||
|
||||
TEST_F(FileTest, InputFile_EmptyFileEOF) {
|
||||
InputFile input_file(path_, GetSize());
|
||||
AssertEmpty(input_file.Read(kMaxSize));
|
||||
}
|
||||
|
||||
TEST_F(FileTest, InputFile_ReadWorks) {
|
||||
WriteToFile("abc");
|
||||
InputFile input_file(path_, GetSize());
|
||||
input_file.Read(kMaxSize);
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST_F(FileTest, InputFile_ReadUntilEOF) {
|
||||
WriteToFile("abc");
|
||||
InputFile input_file(path_, GetSize());
|
||||
AssertEquals(input_file.Read(kMaxSize), "abc");
|
||||
AssertEmpty(input_file.Read(kMaxSize));
|
||||
}
|
||||
|
||||
TEST_F(FileTest, InputFile_ReadWithSize) {
|
||||
WriteToFile("abc");
|
||||
InputFile input_file(path_, GetSize());
|
||||
AssertEquals(input_file.Read(2), "ab");
|
||||
AssertEquals(input_file.Read(1), "c");
|
||||
AssertEmpty(input_file.Read(kMaxSize));
|
||||
}
|
||||
|
||||
TEST_F(FileTest, InputFile_GetTotalSize) {
|
||||
WriteToFile("abc");
|
||||
InputFile input_file(path_, GetSize());
|
||||
EXPECT_EQ(input_file.GetTotalSize(), 3);
|
||||
AssertEquals(input_file.Read(1), "a");
|
||||
EXPECT_EQ(input_file.GetTotalSize(), 3);
|
||||
}
|
||||
|
||||
TEST_F(FileTest, InputFile_Close) {
|
||||
WriteToFile("abc");
|
||||
InputFile input_file(path_, GetSize());
|
||||
input_file.Close();
|
||||
ExceptionOr<ByteArray> read_result = input_file.Read(kMaxSize);
|
||||
EXPECT_FALSE(read_result.ok());
|
||||
EXPECT_TRUE(read_result.GetException().Raised(Exception::kIo));
|
||||
}
|
||||
|
||||
TEST_F(FileTest, OutputFile_NonExistentPath) {
|
||||
OutputFile output_file("/not/a/valid/path.txt");
|
||||
ByteArray bytes("a", 1);
|
||||
EXPECT_TRUE(output_file.Write(bytes).Raised(Exception::kIo));
|
||||
}
|
||||
|
||||
TEST_F(FileTest, OutputFile_Write) {
|
||||
OutputFile output_file(path_);
|
||||
ByteArray bytes1("a");
|
||||
ByteArray bytes2("bc");
|
||||
EXPECT_EQ(output_file.Write(bytes1), Exception{Exception::kSuccess});
|
||||
EXPECT_EQ(output_file.Write(bytes2), Exception{Exception::kSuccess});
|
||||
InputFile input_file(path_, GetSize());
|
||||
AssertEquals(input_file.Read(kMaxSize), "abc");
|
||||
}
|
||||
|
||||
TEST_F(FileTest, OutputFile_Close) {
|
||||
OutputFile output_file(path_);
|
||||
output_file.Close();
|
||||
ByteArray bytes("a");
|
||||
EXPECT_EQ(output_file.Write(bytes), Exception{Exception::kIo});
|
||||
}
|
||||
|
||||
} // namespace shared
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
@@ -16,27 +16,29 @@
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace posix {
|
||||
|
||||
PosixConditionVariable::PosixConditionVariable(Ptr<PosixLock> lock)
|
||||
: lock_(lock), attr_(), cond_() {
|
||||
ConditionVariable::ConditionVariable(Mutex* mutex)
|
||||
: mutex_(mutex), attr_(), cond_() {
|
||||
pthread_condattr_init(&attr_);
|
||||
|
||||
pthread_cond_init(&cond_, &attr_);
|
||||
}
|
||||
|
||||
PosixConditionVariable::~PosixConditionVariable() {
|
||||
ConditionVariable::~ConditionVariable() {
|
||||
pthread_cond_destroy(&cond_);
|
||||
|
||||
pthread_condattr_destroy(&attr_);
|
||||
}
|
||||
|
||||
void PosixConditionVariable::notify() { pthread_cond_broadcast(&cond_); }
|
||||
void ConditionVariable::Notify() { pthread_cond_broadcast(&cond_); }
|
||||
|
||||
Exception::Value PosixConditionVariable::wait() {
|
||||
pthread_cond_wait(&cond_, &(lock_->mutex_));
|
||||
Exception ConditionVariable::Wait() {
|
||||
pthread_cond_wait(&cond_, &(mutex_->mutex_));
|
||||
|
||||
return Exception::kSuccess;
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
} // namespace posix
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
@@ -18,26 +18,27 @@
|
||||
#include <pthread.h>
|
||||
|
||||
#include "platform/api/condition_variable.h"
|
||||
#include "platform/impl/shared/posix_lock.h"
|
||||
#include "platform/ptr.h"
|
||||
#include "platform/impl/shared/posix_mutex.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace posix {
|
||||
|
||||
class PosixConditionVariable : public ConditionVariable {
|
||||
class ConditionVariable : public api::ConditionVariable {
|
||||
public:
|
||||
explicit PosixConditionVariable(Ptr<PosixLock> lock);
|
||||
~PosixConditionVariable() override;
|
||||
explicit ConditionVariable(Mutex* mutex);
|
||||
~ConditionVariable() override;
|
||||
|
||||
void notify() override;
|
||||
Exception::Value wait() override;
|
||||
void Notify() override;
|
||||
Exception Wait() override;
|
||||
|
||||
private:
|
||||
Ptr<PosixLock> lock_;
|
||||
Mutex* mutex_;
|
||||
pthread_condattr_t attr_;
|
||||
pthread_cond_t cond_;
|
||||
};
|
||||
|
||||
} // namespace posix
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
|
||||
@@ -12,27 +12,29 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "platform/impl/shared/posix_lock.h"
|
||||
#include "platform/impl/shared/posix_mutex.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace posix {
|
||||
|
||||
PosixLock::PosixLock() : attr_(), mutex_() {
|
||||
Mutex::Mutex() : attr_(), mutex_() {
|
||||
pthread_mutexattr_init(&attr_);
|
||||
pthread_mutexattr_settype(&attr_, PTHREAD_MUTEX_RECURSIVE);
|
||||
|
||||
pthread_mutex_init(&mutex_, &attr_);
|
||||
}
|
||||
|
||||
PosixLock::~PosixLock() {
|
||||
Mutex::~Mutex() {
|
||||
pthread_mutex_destroy(&mutex_);
|
||||
|
||||
pthread_mutexattr_destroy(&attr_);
|
||||
}
|
||||
|
||||
void PosixLock::lock() { pthread_mutex_lock(&mutex_); }
|
||||
void Mutex::Lock() { pthread_mutex_lock(&mutex_); }
|
||||
|
||||
void PosixLock::unlock() { pthread_mutex_unlock(&mutex_); }
|
||||
void Mutex::Unlock() { pthread_mutex_unlock(&mutex_); }
|
||||
|
||||
} // namespace posix
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
@@ -12,32 +12,34 @@
|
||||
// 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_
|
||||
#ifndef PLATFORM_IMPL_SHARED_POSIX_MUTEX_H_
|
||||
#define PLATFORM_IMPL_SHARED_POSIX_MUTEX_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "platform/api/lock.h"
|
||||
#include "platform/api/mutex.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace posix {
|
||||
|
||||
class PosixLock : public Lock {
|
||||
class ABSL_LOCKABLE Mutex : public api::Mutex {
|
||||
public:
|
||||
PosixLock();
|
||||
~PosixLock() override;
|
||||
Mutex();
|
||||
~Mutex() override;
|
||||
|
||||
void lock() override;
|
||||
void unlock() override;
|
||||
void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION() override;
|
||||
void Unlock() ABSL_UNLOCK_FUNCTION() override;
|
||||
|
||||
private:
|
||||
friend class PosixConditionVariable;
|
||||
friend class ConditionVariable;
|
||||
|
||||
pthread_mutexattr_t attr_;
|
||||
pthread_mutex_t mutex_;
|
||||
};
|
||||
|
||||
} // namespace posix
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // PLATFORM_IMPL_SHARED_POSIX_LOCK_H_
|
||||
#endif // PLATFORM_IMPL_SHARED_POSIX_MUTEX_H_
|
||||
@@ -1,35 +0,0 @@
|
||||
# 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__",
|
||||
],
|
||||
deps = [
|
||||
"//platform:types",
|
||||
"//platform:utils",
|
||||
"//platform/api",
|
||||
"//platform/port:string",
|
||||
"//absl/time",
|
||||
],
|
||||
)
|
||||
@@ -1,31 +0,0 @@
|
||||
# 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
|
||||
)
|
||||
@@ -1,124 +0,0 @@
|
||||
// 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
|
||||
@@ -1,73 +0,0 @@
|
||||
// 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