Export more symbols, refactor how this is laid out for dll compliance

PiperOrigin-RevId: 402286243
This commit is contained in:
jfcarroll
2021-10-11 07:05:49 -07:00
committed by Copybara-Service
parent 51a19d24c1
commit 99b77bda8e
11 changed files with 185 additions and 60 deletions
+2
View File
@@ -29,6 +29,7 @@ cc_library(
"cancelable_alarm.h",
"cancellable_task.h",
"condition_variable.h",
"core_config.h",
"count_down_latch.h",
"crypto.h",
"file.h",
@@ -75,6 +76,7 @@ cc_library(
srcs = [
"ble.cc",
"bluetooth_classic.cc",
"file.cc",
"wifi_lan.cc",
],
hdrs = [
+38
View File
@@ -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.
#ifndef CORE_CONFIG_H_
#define CORE_CONFIG_H_
namespace location {
namespace nearby {
namespace connections {
#ifdef _WIN32 // These storage class specifiers only matter to win32 dll
// builds.
#ifdef CORE_ADAPTER_DLL
#define DLL_API \
__declspec(dllexport) // If we're building the core, we're exporting.
#else // !CORE_ADAPTER_DLL
#define DLL_API \
__declspec(dllimport) // If we're not building the core, we're importing.
#endif // CORE_ADAPTER_DLL
#else // !_WIN32
#define DLL_API // We're not building a win32 dll, leave the source unchanged.
#endif // _WIN32
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_CONFIG_H_
+92
View File
@@ -0,0 +1,92 @@
// 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/public/file.h"
namespace location {
namespace nearby {
InputFile::InputFile(PayloadId payload_id, std::int64_t size)
: impl_(Platform::CreateInputFile(payload_id, size)), id_(payload_id) {}
InputFile::~InputFile() = default;
InputFile::InputFile(InputFile&&) noexcept = default;
InputFile& InputFile::operator=(InputFile&&) noexcept = default;
// Reads up to size bytes and returns as a ByteArray object wrapped by
// ExceptionOr.
// Returns Exception::kIo on error, or end of file.
ExceptionOr<ByteArray> InputFile::Read(std::int64_t size) {
return impl_->Read(size);
}
// Returns a string that uniqely identifies this file.
std::string InputFile::GetFilePath() const { return impl_->GetFilePath(); }
// Returns total size of this file in bytes.
std::int64_t InputFile::GetTotalSize() const { return impl_->GetTotalSize(); }
ExceptionOr<size_t> InputFile::Skip(size_t offset) {
return impl_->Skip(offset);
}
// Disallows further reads from the file and frees system resources,
// associated with it.
Exception InputFile::Close() { return impl_->Close(); }
// Returns a handle to the underlying input stream.
//
// Returned handle will remain valid even if InputFile is moved, for as long
// as original InputFile lifetime continues.
// Side effects of any non-const operation invoked for InputFile (such as
// Read, or Close will be observable through InputStream& handle, and vice
// versa.
InputStream& InputFile::GetInputStream() { return *impl_; }
// Returns payload id of this file. The closest "file" equivalent is inode.
PayloadId InputFile::GetPayloadId() const { return id_; }
OutputFile::OutputFile(PayloadId payload_id)
: impl_(Platform::CreateOutputFile(payload_id)), id_(payload_id) {}
OutputFile::~OutputFile() = default;
OutputFile::OutputFile(OutputFile&&) noexcept = default;
OutputFile& OutputFile::operator=(OutputFile&&) noexcept = default;
// Writes all data from ByteArray object to the underlying stream.
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
Exception OutputFile::Write(const ByteArray& data) {
return impl_->Write(data);
}
// Ensures that all data written by previous calls to Write() is passed
// down to the applicable transport layer.
Exception OutputFile::Flush() { return impl_->Flush(); }
// Disallows further writes to the file and frees system resources,
// associated with it.
Exception OutputFile::Close() { return impl_->Close(); }
// Returns a handle to the underlying output stream.
//
// Returned handle will remain valid even if OutputFile is moved, for as long
// as original OutputFile lifetime continues.
// Side effects of any non-const operation invoked for OutputFile (such as
// Write, or Close will be observable through OutputStream& handle, and vice
// versa.
OutputStream& OutputFile::GetOutputStream() { return *impl_; }
// Returns payload id of this file. The closest "file" equivalent is inode.
PayloadId OutputFile::GetPayloadId() const { return id_; }
} // namespace nearby
} // namespace location
+23 -24
View File
@@ -26,35 +26,35 @@
#include "platform/base/exception.h"
#include "platform/base/input_stream.h"
#include "platform/base/output_stream.h"
#include "platform/public/core_config.h"
namespace location {
namespace nearby {
class InputFile final {
class DLL_API InputFile final {
public:
using Platform = api::ImplementationPlatform;
InputFile(PayloadId payload_id, std::int64_t size)
: impl_(Platform::CreateInputFile(payload_id, size)), id_(payload_id) {}
~InputFile() = default;
InputFile(InputFile&&) = default;
InputFile& operator=(InputFile&&) = default;
InputFile(PayloadId payload_id, std::int64_t size);
~InputFile();
InputFile(InputFile&&) noexcept;
InputFile& operator=(InputFile&&) noexcept;
// Reads up to size bytes and returns as a ByteArray object wrapped by
// ExceptionOr.
// Returns Exception::kIo on error, or end of file.
ExceptionOr<ByteArray> Read(std::int64_t size) { return impl_->Read(size); }
ExceptionOr<ByteArray> Read(std::int64_t size);
// Returns a string that uniqely identifies this file.
std::string GetFilePath() const { return impl_->GetFilePath(); }
std::string GetFilePath() const;
// Returns total size of this file in bytes.
std::int64_t GetTotalSize() const { return impl_->GetTotalSize(); }
std::int64_t GetTotalSize() const;
ExceptionOr<size_t> Skip(size_t offset) { return impl_->Skip(offset); }
ExceptionOr<size_t> Skip(size_t offset);
// Disallows further reads from the file and frees system resources,
// associated with it.
Exception Close() { return impl_->Close(); }
Exception Close();
// Returns a handle to the underlying input stream.
//
@@ -63,36 +63,35 @@ class InputFile final {
// Side effects of any non-const operation invoked for InputFile (such as
// Read, or Close will be observable through InputStream& handle, and vice
// versa.
InputStream& GetInputStream() { return *impl_; }
InputStream& GetInputStream();
// Returns payload id of this file. The closest "file" equivalent is inode.
PayloadId GetPayloadId() const { return id_; }
PayloadId GetPayloadId() const;
private:
std::unique_ptr<api::InputFile> impl_;
PayloadId id_;
};
class OutputFile final {
class DLL_API OutputFile final {
public:
using Platform = api::ImplementationPlatform;
explicit OutputFile(PayloadId payload_id)
: impl_(Platform::CreateOutputFile(payload_id)), id_(payload_id) {}
~OutputFile() = default;
OutputFile(OutputFile&&) = default;
OutputFile& operator=(OutputFile&&) = default;
explicit OutputFile(PayloadId payload_id);
~OutputFile();
OutputFile(OutputFile&&) noexcept;
OutputFile& operator=(OutputFile&&) noexcept;
// Writes all data from ByteArray object to the underlying stream.
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
Exception Write(const ByteArray& data) { return impl_->Write(data); }
Exception Write(const ByteArray& data);
// Ensures that all data written by previous calls to Write() is passed
// down to the applicable transport layer.
Exception Flush() { return impl_->Flush(); }
Exception Flush();
// Disallows further writes to the file and frees system resources,
// associated with it.
Exception Close() { return impl_->Close(); }
Exception Close();
// Returns a handle to the underlying output stream.
//
@@ -101,10 +100,10 @@ class OutputFile final {
// Side effects of any non-const operation invoked for OutputFile (such as
// Write, or Close will be observable through OutputStream& handle, and vice
// versa.
OutputStream& GetOutputStream() { return *impl_; }
OutputStream& GetOutputStream();
// Returns payload id of this file. The closest "file" equivalent is inode.
PayloadId GetPayloadId() const { return id_; }
PayloadId GetPayloadId() const;
private:
std::unique_ptr<api::OutputFile> impl_;