-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d9b7c2
commit 5462e69
Showing
12 changed files
with
134 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2024 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
#import "FIRCallbackWrapper.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "Firestore/core/interfaceForSwift/api/pipeline.h" | ||
#include "Firestore/core/interfaceForSwift/api/pipeline_result.h" | ||
#include "Firestore/core/src/core/event_listener.h" | ||
#include "Firestore/core/src/util/error_apple.h" | ||
#include "Firestore/core/src/util/statusor.h" | ||
|
||
using firebase::firestore::api::PipelineResult; | ||
using firebase::firestore::api::PipelineSnapshotListener; | ||
using firebase::firestore::core::EventListener; | ||
using firebase::firestore::util::MakeNSError; | ||
using firebase::firestore::util::StatusOr; | ||
|
||
@implementation FIRCallbackWrapper | ||
|
||
+ (PipelineSnapshotListener) | ||
wrapPipelineCallback:(std::shared_ptr<api::Firestore>)firestore | ||
completion:(void (^)(std::shared_ptr<std::vector<PipelineResult>> result, | ||
NSError *_Nullable error))completion { | ||
class Converter : public EventListener<std::vector<PipelineResult>> { | ||
public: | ||
explicit Converter(std::shared_ptr<api::Firestore> firestore, PipelineBlock completion) | ||
: firestore_(firestore), completion_(completion) { | ||
} | ||
|
||
void OnEvent(StatusOr<std::vector<PipelineResult>> maybe_snapshot) override { | ||
if (maybe_snapshot.ok()) { | ||
completion_( | ||
std::make_shared<std::vector<PipelineResult>>( | ||
std::initializer_list<PipelineResult>{PipelineResult::GetTestResult(firestore_)}), | ||
nullptr); | ||
} else { | ||
completion_(nullptr, MakeNSError(maybe_snapshot.status())); | ||
} | ||
} | ||
|
||
private: | ||
std::shared_ptr<api::Firestore> firestore_; | ||
PipelineBlock completion_; | ||
}; | ||
|
||
return absl::make_unique<Converter>(firestore, completion); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Firestore/Source/Public/FirebaseFirestore/FIRCallbackWrapper.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2024 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <memory> | ||
|
||
namespace firebase { | ||
namespace firestore { | ||
namespace api { | ||
class Firestore; | ||
class PipelineResult; | ||
} // namespace api | ||
|
||
namespace core { | ||
template <typename T> | ||
class EventListener; | ||
} // namespace core | ||
|
||
} // namespace firestore | ||
} // namespace firebase | ||
|
||
namespace api = firebase::firestore::api; | ||
namespace core = firebase::firestore::core; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
typedef void (^PipelineBlock)(std::shared_ptr<std::vector<api::PipelineResult>> result, | ||
NSError *_Nullable error) | ||
NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead."); | ||
|
||
typedef std::shared_ptr<std::vector<api::PipelineResult>> PipelineResultVectorPtr; | ||
|
||
NS_SWIFT_SENDABLE | ||
NS_SWIFT_NAME(CallbackWrapper) | ||
@interface FIRCallbackWrapper : NSObject | ||
|
||
+ (std::unique_ptr<core::EventListener<std::vector<api::PipelineResult>>>) | ||
wrapPipelineCallback:(std::shared_ptr<api::Firestore>)firestore | ||
completion:(void (^)(std::shared_ptr<std::vector<api::PipelineResult>> result, | ||
NSError *_Nullable error))completion | ||
NS_SWIFT_NAME(wrapPipelineCallback(firestore:completion:)); | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters