FIRCallbackWrapper.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2024 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #include <memory>
  18. #include <vector>
  19. namespace firebase {
  20. namespace firestore {
  21. namespace api {
  22. class Firestore;
  23. class PipelineResult;
  24. } // namespace api
  25. namespace core {
  26. template <typename T>
  27. class EventListener;
  28. } // namespace core
  29. } // namespace firestore
  30. } // namespace firebase
  31. namespace api = firebase::firestore::api;
  32. namespace core = firebase::firestore::core;
  33. NS_ASSUME_NONNULL_BEGIN
  34. typedef api::PipelineResult CppPipelineResult;
  35. typedef void (^PipelineBlock)(CppPipelineResult *result, NSError *_Nullable error)
  36. NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");
  37. NS_SWIFT_SENDABLE
  38. NS_SWIFT_NAME(CallbackWrapper)
  39. @interface FIRCallbackWrapper : NSObject
  40. // Note: Marking callbacks in callback-based APIs as `Sendable` can help prevent crashes when they
  41. // are invoked on a different thread than the one they were originally defined in. If this callback
  42. // is expected to be called on a different thread, it should be marked as `Sendable` to ensure
  43. // thread safety.
  44. + (std::shared_ptr<core::EventListener<api::PipelineResult>>)
  45. wrapPipelineCallback:(std::shared_ptr<api::Firestore>)firestore
  46. completion:(void (^NS_SWIFT_SENDABLE)(CppPipelineResult *result,
  47. NSError *_Nullable error))completion
  48. NS_SWIFT_NAME(wrapPipelineCallback(firestore:completion:));
  49. @end
  50. NS_ASSUME_NONNULL_END