Flattening of Input/OutputFile.

PiperOrigin-RevId: 469595318
This commit is contained in:
John Carroll
2022-08-23 17:19:08 -07:00
committed by Copybara-Service
parent 337c1547c8
commit 3e78cef57f
9 changed files with 149 additions and 23 deletions
+4
View File
@@ -78,6 +78,7 @@ lexan.cc_windows_dll(
"connection_options_w.cc",
"core_adapter.cc",
"discovery_options_w.cc",
"file_w.cc",
"listeners_w.cc",
"payload_w.cc",
"strategy_w.cc",
@@ -88,6 +89,7 @@ lexan.cc_windows_dll(
"core_adapter.h",
"discovery_options_w.h",
"dll_config.h",
"file_w.h",
"listeners_w.h",
"medium_selector_w.h",
"options_base_w.h",
@@ -123,6 +125,7 @@ lexan.cc_windows_dll(
"core_adapter.cc",
"dart/core_adapter_dart.cc",
"discovery_options_w.cc",
"file_w.cc",
"listeners_w.cc",
"payload_w.cc",
"strategy_w.cc",
@@ -134,6 +137,7 @@ lexan.cc_windows_dll(
"dart/core_adapter_dart.h",
"discovery_options_w.h",
"dll_config.h",
"file_w.h",
"listeners_w.h",
"medium_selector_w.h",
"options_base_w.h",
@@ -22,7 +22,6 @@
#include "connections/core.h"
#include "connections/payload.h"
#include "internal/platform/count_down_latch.h"
#include "internal/platform/file.h"
#include "internal/platform/logging.h"
namespace location::nearby::windows {
@@ -609,7 +608,7 @@ void SendPayloadDart(Core *pCore, const char *endpoint_id,
NEARBY_LOG(INFO, "File name: %s, size %d", payload_dart.data,
payload_dart.size);
std::string file_name_str(payload_dart.data);
InputFile input_file(file_name_str, payload_dart.size);
InputFileW input_file(file_name_str, payload_dart.size);
PayloadW payload(input_file);
std::vector<const char *> c_string_array;
+58
View File
@@ -0,0 +1,58 @@
// Copyright 2022 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 "connections/clients/windows/file_w.h"
#include "internal/platform/file.h"
namespace location::nearby {
namespace windows {
InputFileW::InputFileW(InputFile* input_file)
: impl_(std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>(
new nearby::InputFile(std::move(*input_file)))) {}
InputFileW::InputFileW(PayloadId payload_id, size_t size)
: impl_(std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>(
new nearby::InputFile(payload_id, size))) {}
InputFileW::InputFileW(std::string file_path, size_t size)
: impl_(std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>(
new nearby::InputFile(file_path, size))) {}
InputFileW::InputFileW(InputFileW&& other) noexcept
: impl_(std::move(other.impl_)) {}
// Returns a string that uniquely identifies this file.
std::string InputFileW::GetFilePath() const { return impl_->GetFilePath(); }
// Returns total size of this file in bytes.
size_t InputFileW::GetTotalSize() const { return impl_->GetTotalSize(); }
std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter>
InputFileW::GetImpl() {
return std::move(impl_);
}
OutputFileW::OutputFileW(PayloadId payload_id) {}
OutputFileW::OutputFileW(std::string file_path) {}
OutputFileW::OutputFileW(OutputFileW&&) noexcept {}
OutputFileW& OutputFileW::operator=(OutputFileW&& other) noexcept {
impl_ = std::move(other.impl_);
return *this;
}
std::unique_ptr<nearby::OutputFile, nearby::OutputFileDeleter>
OutputFileW::GetImpl() {
return std::move(impl_);
}
} // namespace windows
} // namespace location::nearby
+60
View File
@@ -0,0 +1,60 @@
// Copyright 2022 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_CONNECTIONS_CLIENTS_WINDOWS_FILE_W_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_FILE_W_H_
#include <memory>
#include <string>
#include "connections/clients/windows/dll_config.h"
#include "internal/platform/file.h"
#include "internal/platform/payload_id.h"
namespace location::nearby::windows {
class DLL_API InputFileW {
public:
InputFileW(InputFile* input_file);
InputFileW(PayloadId payload_id, size_t size);
InputFileW(std::string file_path, size_t size);
InputFileW(InputFileW&&) noexcept;
// Returns a string that uniquely identifies this file.
std::string GetFilePath() const;
// Returns total size of this file in bytes.
size_t GetTotalSize() const;
std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter> GetImpl();
private:
std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter> impl_;
};
class DLL_API OutputFileW {
public:
explicit OutputFileW(PayloadId payload_id);
explicit OutputFileW(std::string file_path);
OutputFileW(OutputFileW&&) noexcept;
OutputFileW& operator=(OutputFileW&&) noexcept;
std::unique_ptr<nearby::OutputFile, nearby::OutputFileDeleter> GetImpl();
private:
std::unique_ptr<nearby::OutputFile, nearby::OutputFileDeleter> impl_;
};
} // namespace location::nearby::windows
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_FILE_W_H_
+2 -2
View File
@@ -204,7 +204,7 @@ PayloadListenerW::PayloadListenerW(PayloadCB payloadCB,
break;
}
case connections::PayloadType::kFile: {
InputFile file(std::move(*payload.AsFile()));
InputFileW file(std::move(payload.AsFile()));
payloadW = PayloadW(payload.GetId(), std::move(file));
} break;
@@ -213,7 +213,7 @@ PayloadListenerW::PayloadListenerW(PayloadCB payloadCB,
// payloadW = PayloadW(payload.AsStream());
//}
case connections::PayloadType::kStream: {
InputFile file(std::move(*payload.AsFile()));
InputFileW file(std::move(payload.AsFile()));
payloadW = PayloadW(payload.GetId(), std::move(file));
} break;
case connections::PayloadType::kUnknown: {
+8 -7
View File
@@ -13,6 +13,7 @@
// limitations under the License.
#include "connections/clients/windows/payload_w.h"
#include "connections/clients/windows/file_w.h"
#include "connections/payload.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/payload_id.h"
@@ -44,9 +45,9 @@ PayloadW::PayloadW(const char *bytes, const size_t bytes_size)
: impl_(std::unique_ptr<connections::Payload, connections::PayloadDeleter>(
new connections::Payload(ByteArray(bytes, bytes_size)))) {}
PayloadW::PayloadW(InputFile &file)
PayloadW::PayloadW(InputFileW &file)
: impl_(std::unique_ptr<connections::Payload, connections::PayloadDeleter>(
new connections::Payload(std::move(file)))) {}
new connections::Payload(InputFile(std::move(*file.GetImpl()))))) {}
// TODO(jfcarroll): Convert std::function to function pointer
PayloadW::PayloadW(std::function<InputStream &()> stream)
@@ -58,15 +59,15 @@ PayloadW::PayloadW(PayloadId id, const char *bytes, const size_t bytes_size)
: impl_(std::unique_ptr<connections::Payload, connections::PayloadDeleter>(
new connections::Payload(id, ByteArray(bytes, bytes_size)))) {}
PayloadW::PayloadW(PayloadId id, InputFile file)
PayloadW::PayloadW(PayloadId id, InputFileW file)
: impl_(std::unique_ptr<connections::Payload, connections::PayloadDeleter>(
new connections::Payload(id, std::move(file)))) {}
new connections::Payload(id, std::move(*file.GetImpl())))) {}
PayloadW::PayloadW(const char *parent_folder, const char *file_name,
InputFile file)
InputFileW file)
: impl_(std::unique_ptr<connections::Payload, connections::PayloadDeleter>(
new connections::Payload(parent_folder, file_name,
std::move(file)))) {}
std::move(*file.GetImpl())))) {}
PayloadW::PayloadW(PayloadId id, std::function<InputStream &()> stream)
: impl_(std::unique_ptr<connections::Payload, connections::PayloadDeleter>(
@@ -100,7 +101,7 @@ bool PayloadW::AsBytes(const char *bytes, size_t &bytes_size) && {
// Returns InputStream* payload, if it has been defined, or nullptr.
InputStream *PayloadW::AsStream() { return impl_->AsStream(); }
// Returns InputFile* payload, if it has been defined, or nullptr.
const InputFile *PayloadW::AsFile() const { return impl_->AsFile(); }
InputFile *PayloadW::AsFile() const { return impl_->AsFile(); }
// Returns Payload unique ID.
int64_t PayloadW::GetId() const { return impl_->GetId(); }
+5 -4
View File
@@ -21,6 +21,7 @@
#include <utility>
#include "connections/clients/windows/dll_config.h"
#include "connections/clients/windows/file_w.h"
#include "connections/payload_type.h"
#include "internal/platform/payload_id.h"
@@ -53,14 +54,14 @@ class DLL_API PayloadW {
// Constructors for outgoing payloads.
explicit PayloadW(const char* bytes, const size_t size);
explicit PayloadW(InputFile& file);
explicit PayloadW(InputFileW& file);
explicit PayloadW(std::function<InputStream&()> stream);
// Constructors for incoming payloads.
PayloadW(PayloadId id, const char* bytes, const size_t size);
PayloadW(PayloadId id, InputFile file);
PayloadW(PayloadId id, InputFileW file);
explicit PayloadW(const char* parent_folder, const char* file_name,
InputFile file);
InputFileW file);
// TODO(jfcarroll): Convert std::function to function pointer
PayloadW(PayloadId id, std::function<InputStream&()> stream);
@@ -71,7 +72,7 @@ class DLL_API PayloadW {
// Returns InputStream* payload, if it has been defined, or nullptr.
InputStream* AsStream();
// Returns InputFile* payload, if it has been defined, or nullptr.
const InputFile* AsFile() const;
InputFile* AsFile() const;
// Returns Payload unique ID.
int64_t GetId() const;
+2
View File
@@ -16,6 +16,8 @@
namespace location {
namespace nearby {
void InputFileDeleter::operator()(nearby::InputFile* p) { delete p; }
void OutputFileDeleter::operator()(nearby::OutputFile* p) { delete p; }
InputFile::InputFile(PayloadId id, std::int64_t size)
: impl_(Platform::CreateInputFile(id, size)) {}
+9 -8
View File
@@ -29,11 +29,16 @@
namespace location {
namespace nearby {
class InputFile;
struct InputFileDeleter {
void operator()(InputFile* p);
};
class OutputFile;
struct OutputFileDeleter {
void operator()(nearby::OutputFile* p);
};
// TODO(b/227677097) This will cause the dll to fail. Currently this class
// must be exported. There are future plans to wrap this
// and export it from connections/clients/windows
// class DLL_API InputFile final {
class InputFile final {
public:
using Platform = api::ImplementationPlatform;
@@ -73,10 +78,6 @@ class InputFile final {
std::unique_ptr<api::InputFile> impl_;
};
// TODO(b/227677097) This will cause the dll to fail. Currently this class
// must be exported. There are future plans to wrap this
// and export it from connections/clients/windows
// class DLL_API OutputFile final {
class OutputFile final {
public:
using Platform = api::ImplementationPlatform;