mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Update iOS InputFile.
PiperOrigin-RevId: 416188311
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/internal/service_controller_router.h"
|
||||
#include "platform/base/payload_id.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@@ -29,24 +28,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
std::unique_ptr<::location::nearby::connections::ServiceControllerRouter>
|
||||
_service_controller_router;
|
||||
}
|
||||
|
||||
/**
|
||||
* These functions are the utilities to manipulate the InputFile in ImplementationPlatform for
|
||||
* sending File payload.
|
||||
*
|
||||
* Inserts the URL to the map, keyed by payloadID. The element will not be inserted if there
|
||||
* already is an element with the key in the map.
|
||||
*/
|
||||
- (void)insertURLToMapWithPayloadID:(::location::nearby::PayloadId)payloadId urlToSend:(NSURL *)url;
|
||||
|
||||
/**
|
||||
* Returns the URL with the payloadID and removes the entry from the map. Returns nil if
|
||||
* payloadID is not found.
|
||||
*/
|
||||
- (nullable NSURL *)extractURLWithPayloadID:(::location::nearby::PayloadId)payloadId;
|
||||
|
||||
- (void)clearSendingURLMaps;
|
||||
|
||||
@end
|
||||
|
||||
/** This function returns the Core singleton, wrapped in an Obj-C object for lifetime management. */
|
||||
|
||||
@@ -16,22 +16,15 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "third_party/absl/container/flat_hash_map.h"
|
||||
#include "third_party/absl/container/internal/common.h"
|
||||
#include "third_party/nearby/cpp/core/core.h"
|
||||
#include "third_party/nearby/cpp/core/internal/service_controller_router.h"
|
||||
#include "third_party/nearby/cpp/platform/base/payload_id.h"
|
||||
#import "third_party/objective_c/google_toolbox_for_mac/Foundation/GTMLogger.h"
|
||||
|
||||
using ::location::nearby::connections::Core;
|
||||
using ::location::nearby::PayloadId;
|
||||
using ::location::nearby::connections::ServiceControllerRouter;
|
||||
|
||||
@implementation GNCCore {
|
||||
// A map to store the NSURL object with PayloadId for sendFilePayload in GNCConnection.
|
||||
// This is the place to store the NSURL for InputFile creation in ImplementationPlatform.
|
||||
absl::flat_hash_map<PayloadId, NSURL *> _sending_urls;
|
||||
}
|
||||
@implementation GNCCore
|
||||
|
||||
- (instancetype)init {
|
||||
GTMLoggerInfo(@"GNCCore created");
|
||||
@@ -49,24 +42,6 @@ using ::location::nearby::connections::ServiceControllerRouter;
|
||||
GTMLoggerInfo(@"GNCCore deallocated");
|
||||
}
|
||||
|
||||
- (void)insertURLToMapWithPayloadID:(PayloadId)payloadId urlToSend:(NSURL *)url {
|
||||
_sending_urls.emplace(payloadId, url);
|
||||
}
|
||||
|
||||
- (nullable NSURL *)extractURLWithPayloadID:(PayloadId)payloadId {
|
||||
NSURL *url;
|
||||
auto it = _sending_urls.find(payloadId);
|
||||
if (it != _sending_urls.end()) {
|
||||
auto pair = _sending_urls.extract(it);
|
||||
url = pair.mapped();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
- (void)clearSendingURLMaps {
|
||||
_sending_urls.clear();
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
GNCCore *GNCGetCore() {
|
||||
|
||||
@@ -159,11 +159,7 @@ class GNCInputStreamFromNSStream : public InputStream {
|
||||
fileSize = fileSizeValue.longValue;
|
||||
}
|
||||
PayloadId payloadId = Payload::GenerateId();
|
||||
// Add the pair of payloadId and fileURL to the map in the GNCCore.
|
||||
[_core insertURLToMapWithPayloadID:payloadId urlToSend:fileURL];
|
||||
|
||||
// TODO(edwinwu): Need someone familiar with iOS to fix this
|
||||
std::string path("FIXME, WE NEED A PATH HERE");
|
||||
std::string path = CppStringFromObjCString([fileURL absoluteString]);
|
||||
Payload corePayload(payloadId, InputFile(path.c_str()));
|
||||
progress.totalUnitCount = fileSize;
|
||||
return [self sendPayload:std::move(corePayload)
|
||||
|
||||
@@ -1,147 +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 "third_party/nearby/cpp/platform/api/platform.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "third_party/nearby/cpp/platform/api/mutex.h"
|
||||
#include "third_party/nearby/cpp/platform/base/payload_id.h"
|
||||
#import "third_party/nearby/cpp/platform/impl/ios/Source/Internal/GNCCore.h"
|
||||
#include "third_party/nearby/cpp/platform/impl/ios/Source/Platform/atomic_boolean.h"
|
||||
#include "third_party/nearby/cpp/platform/impl/ios/Source/Platform/atomic_uint32.h"
|
||||
#include "third_party/nearby/cpp/platform/impl/ios/Source/Platform/condition_variable.h"
|
||||
#include "third_party/nearby/cpp/platform/impl/ios/Source/Platform/count_down_latch.h"
|
||||
#include "third_party/nearby/cpp/platform/impl/ios/Source/Platform/input_file.h"
|
||||
#import "third_party/nearby/cpp/platform/impl/ios/Source/Platform/log_message.h"
|
||||
#import "third_party/nearby/cpp/platform/impl/ios/Source/Platform/multi_thread_executor.h"
|
||||
#include "third_party/nearby/cpp/platform/impl/ios/Source/Platform/mutex.h"
|
||||
#import "third_party/nearby/cpp/platform/impl/ios/Source/Platform/scheduled_executor.h"
|
||||
#import "third_party/nearby/cpp/platform/impl/ios/Source/Platform/single_thread_executor.h"
|
||||
#import "third_party/nearby/cpp/platform/impl/ios/Source/Platform/utils.h"
|
||||
#include "third_party/nearby/cpp/platform/impl/ios/Source/Platform/wifi_lan.h"
|
||||
#include "third_party/nearby/cpp/platform/impl/shared/file.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
std::unique_ptr<std::string> ImplementationPlatform::GetDownloadPath(
|
||||
std::unique_ptr<std::string> path) {
|
||||
// TODO(jfcarroll): Fixme, we need to modulate the path the the system download path
|
||||
return path;
|
||||
}
|
||||
|
||||
// Atomics:
|
||||
std::unique_ptr<AtomicBoolean> ImplementationPlatform::CreateAtomicBoolean(bool initial_value) {
|
||||
return std::make_unique<ios::AtomicBoolean>(initial_value);
|
||||
}
|
||||
|
||||
std::unique_ptr<AtomicUint32> ImplementationPlatform::CreateAtomicUint32(
|
||||
std::uint32_t initial_value) {
|
||||
return std::make_unique<ios::AtomicUint32>(initial_value);
|
||||
}
|
||||
|
||||
std::unique_ptr<CountDownLatch> ImplementationPlatform::CreateCountDownLatch(std::int32_t count) {
|
||||
return std::make_unique<ios::CountDownLatch>(count);
|
||||
}
|
||||
|
||||
std::unique_ptr<Mutex> ImplementationPlatform::CreateMutex(Mutex::Mode mode) {
|
||||
// iOS does not support unchecked Mutex in debug mode, therefore
|
||||
// ios::Mutex is used for both kRegular and kRegularNoCheck.
|
||||
if (mode == Mutex::Mode::kRecursive) {
|
||||
return absl::make_unique<ios::RecursiveMutex>();
|
||||
} else {
|
||||
return absl::make_unique<ios::Mutex>();
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<ConditionVariable> ImplementationPlatform::CreateConditionVariable(Mutex* mutex) {
|
||||
return std::make_unique<ios::ConditionVariable>(static_cast<ios::Mutex*>(mutex));
|
||||
}
|
||||
|
||||
std::unique_ptr<InputFile> ImplementationPlatform::CreateInputFile(const char* file_path) {
|
||||
// Extract the NSURL object with payload_id from |GNCCore| which stores the maps. If the retrieved
|
||||
// NSURL object is not nil, we create InputFile by ios::InputFile. The difference is
|
||||
// that ios::InputFile implements to read bytes from local real file for sending.
|
||||
// TODO(jfcarroll): Need someone familiar with iOS to fix this
|
||||
#if 0
|
||||
GNCCore* core = GNCGetCore();
|
||||
NSURL* url = [core extractURLWithPayloadID:payload_id];
|
||||
if (url != nil) {
|
||||
return absl::make_unique<ios::InputFile>(url);
|
||||
} else {
|
||||
return absl::make_unique<shared::InputFile>(GetDownloadPath(payload_id), total_size);
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<OutputFile> ImplementationPlatform::CreateOutputFile(const char* file_path) {
|
||||
return absl::make_unique<shared::OutputFile>(file_path);
|
||||
}
|
||||
|
||||
std::unique_ptr<LogMessage> ImplementationPlatform::CreateLogMessage(
|
||||
const char* file, int line, LogMessage::Severity severity) {
|
||||
return absl::make_unique<ios::LogMessage>(file, line, severity);
|
||||
}
|
||||
|
||||
// Java-like Executors
|
||||
std::unique_ptr<SubmittableExecutor> ImplementationPlatform::CreateSingleThreadExecutor() {
|
||||
return std::make_unique<ios::SingleThreadExecutor>();
|
||||
}
|
||||
|
||||
std::unique_ptr<SubmittableExecutor> ImplementationPlatform::CreateMultiThreadExecutor(
|
||||
int max_concurrency) {
|
||||
return std::make_unique<ios::MultiThreadExecutor>(max_concurrency);
|
||||
}
|
||||
|
||||
std::unique_ptr<ScheduledExecutor> ImplementationPlatform::CreateScheduledExecutor() {
|
||||
return std::make_unique<ios::ScheduledExecutor>();
|
||||
}
|
||||
|
||||
// Mediums
|
||||
std::unique_ptr<BluetoothAdapter> ImplementationPlatform::CreateBluetoothAdapter() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<BluetoothClassicMedium> ImplementationPlatform::CreateBluetoothClassicMedium(
|
||||
api::BluetoothAdapter& adapter) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<BleMedium> ImplementationPlatform::CreateBleMedium(api::BluetoothAdapter& adapter) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<ble_v2::BleMedium> ImplementationPlatform::CreateBleV2Medium(
|
||||
api::BluetoothAdapter& adapter) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<ServerSyncMedium> ImplementationPlatform::CreateServerSyncMedium() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<WifiMedium> ImplementationPlatform::CreateWifiMedium() { return nullptr; }
|
||||
|
||||
std::unique_ptr<WifiLanMedium> ImplementationPlatform::CreateWifiLanMedium() {
|
||||
return std::make_unique<ios::WifiLanMedium>();
|
||||
}
|
||||
|
||||
std::unique_ptr<WebRtcMedium> ImplementationPlatform::CreateWebRtcMedium() { return nullptr; }
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
Reference in New Issue
Block a user