mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 07:36:10 -04:00
Export InputStream class.
PiperOrigin-RevId: 476215485
This commit is contained in:
committed by
Copybara-Service
parent
fd59e9aede
commit
43da74bb7c
@@ -627,7 +627,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);
|
||||
InputFileW input_file(file_name_str, payload_dart.size);
|
||||
InputFileW input_file(file_name_str.c_str(), payload_dart.size);
|
||||
PayloadW payload(input_file);
|
||||
|
||||
std::vector<const char *> c_string_array;
|
||||
|
||||
@@ -13,9 +13,13 @@
|
||||
// limitations under the License.
|
||||
#include "connections/clients/windows/file_w.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "internal/platform/file.h"
|
||||
|
||||
namespace location::nearby {
|
||||
void InputFileDeleter::operator()(nearby::InputFile* p) { delete p; }
|
||||
void OutputFileDeleter::operator()(nearby::OutputFile* p) { delete p; }
|
||||
|
||||
namespace windows {
|
||||
InputFileW::InputFileW(InputFile* input_file)
|
||||
@@ -24,14 +28,19 @@ InputFileW::InputFileW(InputFile* 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)
|
||||
InputFileW::InputFileW(const char* 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(); }
|
||||
// Caller allocates buffer[MAX_PATH] and is responsible
|
||||
// for freeing.
|
||||
void InputFileW::GetFilePath(char* file_path) const {
|
||||
std::string fp = impl_->GetFilePath();
|
||||
strncpy(file_path, fp.c_str(), fp.length());
|
||||
}
|
||||
|
||||
// Returns total size of this file in bytes.
|
||||
size_t InputFileW::GetTotalSize() const { return impl_->GetTotalSize(); }
|
||||
@@ -42,7 +51,7 @@ InputFileW::GetImpl() {
|
||||
}
|
||||
|
||||
OutputFileW::OutputFileW(PayloadId payload_id) {}
|
||||
OutputFileW::OutputFileW(std::string file_path) {}
|
||||
OutputFileW::OutputFileW(const char* file_path) {}
|
||||
OutputFileW::OutputFileW(OutputFileW&&) noexcept {}
|
||||
OutputFileW& OutputFileW::operator=(OutputFileW&& other) noexcept {
|
||||
impl_ = std::move(other.impl_);
|
||||
|
||||
@@ -18,43 +18,69 @@
|
||||
#include <string>
|
||||
|
||||
#include "connections/clients/windows/dll_config.h"
|
||||
#include "internal/platform/file.h"
|
||||
#include "internal/platform/payload_id.h"
|
||||
|
||||
namespace location::nearby::windows {
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
class InputFile;
|
||||
struct InputFileDeleter {
|
||||
void operator()(InputFile* p);
|
||||
};
|
||||
|
||||
class OutputFile;
|
||||
struct OutputFileDeleter {
|
||||
void operator()(OutputFile* p);
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace 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);
|
||||
explicit InputFileW(location::nearby::InputFile* input_file);
|
||||
InputFileW(location::nearby::PayloadId payload_id, size_t size);
|
||||
InputFileW(const char* file_path, size_t size);
|
||||
InputFileW(InputFileW&&) noexcept;
|
||||
|
||||
// Returns a string that uniquely identifies this file.
|
||||
std::string GetFilePath() const;
|
||||
void GetFilePath(char* file_path) const;
|
||||
|
||||
// Returns total size of this file in bytes.
|
||||
size_t GetTotalSize() const;
|
||||
|
||||
std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter> GetImpl();
|
||||
std::unique_ptr<location::nearby::InputFile,
|
||||
location::nearby::InputFileDeleter>
|
||||
GetImpl();
|
||||
|
||||
private:
|
||||
std::unique_ptr<nearby::InputFile, nearby::InputFileDeleter> impl_;
|
||||
std::unique_ptr<location::nearby::InputFile,
|
||||
location::nearby::InputFileDeleter>
|
||||
impl_;
|
||||
};
|
||||
|
||||
class DLL_API OutputFileW {
|
||||
public:
|
||||
explicit OutputFileW(PayloadId payload_id);
|
||||
explicit OutputFileW(std::string file_path);
|
||||
explicit OutputFileW(location::nearby::PayloadId payload_id);
|
||||
explicit OutputFileW(const char* file_path);
|
||||
OutputFileW(OutputFileW&&) noexcept;
|
||||
OutputFileW& operator=(OutputFileW&&) noexcept;
|
||||
|
||||
std::unique_ptr<nearby::OutputFile, nearby::OutputFileDeleter> GetImpl();
|
||||
std::unique_ptr<location::nearby::OutputFile,
|
||||
location::nearby::OutputFileDeleter>
|
||||
GetImpl();
|
||||
|
||||
private:
|
||||
std::unique_ptr<nearby::OutputFile, nearby::OutputFileDeleter> impl_;
|
||||
std::unique_ptr<location::nearby::OutputFile,
|
||||
location::nearby::OutputFileDeleter>
|
||||
impl_;
|
||||
};
|
||||
|
||||
} // namespace location::nearby::windows
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_FILE_W_H_
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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/input_stream_w.h"
|
||||
|
||||
#include "internal/platform/input_stream.h"
|
||||
|
||||
namespace location::nearby {
|
||||
void InputStreamDeleter::operator()(nearby::InputStream* p) { delete p; }
|
||||
} // namespace location::nearby
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
char* InputStreamW::Read(size_t size) {
|
||||
auto result = impl_->Read(size);
|
||||
if (result.ok()) {
|
||||
return result.GetResult().data();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int64_t InputStreamW::Skip(size_t offset) {
|
||||
auto result = impl_->Skip(offset);
|
||||
if (result.ok()) {
|
||||
return result.GetResult();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64_t InputStreamW::Close() {
|
||||
auto result = impl_->Close();
|
||||
if (result.Ok()) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
@@ -0,0 +1,51 @@
|
||||
// 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_INPUT_STREAM_W_H_
|
||||
#define THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_INPUT_STREAM_W_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
class InputStream;
|
||||
struct InputStreamDeleter {
|
||||
void operator()(InputStream* p);
|
||||
};
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
class InputStreamW {
|
||||
public:
|
||||
char* Read(size_t size);
|
||||
|
||||
// throws Exception::kIo
|
||||
int64_t Skip(size_t offset);
|
||||
|
||||
// throws Exception::kIo
|
||||
int64_t Close();
|
||||
|
||||
private:
|
||||
std::unique_ptr<nearby::InputStream, nearby::InputStreamDeleter> impl_;
|
||||
};
|
||||
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_INPUT_STREAM_W_H_
|
||||
@@ -25,16 +25,29 @@
|
||||
#include "connections/payload_type.h"
|
||||
#include "internal/platform/payload_id.h"
|
||||
|
||||
namespace location::nearby {
|
||||
// Forward declarations
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
class Payload;
|
||||
struct PayloadDeleter {
|
||||
void operator()(Payload* p);
|
||||
};
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
class InputFile;
|
||||
class InputStream;
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
extern "C" {
|
||||
@@ -78,7 +91,7 @@ class DLL_API PayloadW {
|
||||
int64_t GetId() const;
|
||||
|
||||
// Returns Payload type.
|
||||
const connections::PayloadType GetType() const;
|
||||
const location::nearby::connections::PayloadType GetType() const;
|
||||
|
||||
// Sets the payload offset in bytes
|
||||
void SetOffset(size_t offset);
|
||||
@@ -98,7 +111,9 @@ class DLL_API PayloadW {
|
||||
};
|
||||
|
||||
} // extern "C"
|
||||
|
||||
} // namespace windows
|
||||
} // namespace location::nearby
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_CLIENTS_WINDOWS_PAYLOAD_W_H_
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
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)) {}
|
||||
|
||||
@@ -29,15 +29,6 @@
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
class InputFile;
|
||||
struct InputFileDeleter {
|
||||
void operator()(InputFile* p);
|
||||
};
|
||||
|
||||
class OutputFile;
|
||||
struct OutputFileDeleter {
|
||||
void operator()(nearby::OutputFile* p);
|
||||
};
|
||||
|
||||
class InputFile final {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user