FIRCallbackWrapper.mm 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "FIRCallbackWrapper.h"
  17. #include <iostream>
  18. #include <memory>
  19. #include <utility>
  20. #include <vector>
  21. #include "Firestore/core/interfaceForSwift/api/pipeline.h"
  22. #include "Firestore/core/interfaceForSwift/api/pipeline_result.h"
  23. #include "Firestore/core/src/core/event_listener.h"
  24. #include "Firestore/core/src/util/error_apple.h"
  25. #include "Firestore/core/src/util/statusor.h"
  26. using firebase::firestore::api::PipelineResult;
  27. using firebase::firestore::api::PipelineSnapshotListener;
  28. using firebase::firestore::core::EventListener;
  29. using firebase::firestore::util::MakeNSError;
  30. using firebase::firestore::util::StatusOr;
  31. @implementation FIRCallbackWrapper
  32. + (PipelineSnapshotListener)wrapPipelineCallback:(std::shared_ptr<api::Firestore>)firestore
  33. completion:(void (^)(CppPipelineResult *result,
  34. NSError *_Nullable error))completion {
  35. class Converter : public EventListener<CppPipelineResult> {
  36. public:
  37. explicit Converter(std::shared_ptr<api::Firestore> firestore, PipelineBlock completion)
  38. : firestore_(firestore), completion_(completion) {
  39. }
  40. void OnEvent(StatusOr<CppPipelineResult> maybe_snapshot) override {
  41. if (maybe_snapshot.ok()) {
  42. std::cout << "zzyzx OnEvent 1" << std::endl;
  43. CppPipelineResult result = maybe_snapshot.ValueOrDie();
  44. std::cout << "zzyzx OnEvent 2 result.id=" << result.id_ << std::endl;
  45. completion_(&result, nullptr);
  46. std::cout << "zzyzx OnEvent 3 result.id=" << result.id_ << std::endl;
  47. } else {
  48. // completion_(PipelineResult::GetTestResult(firestore_),
  49. // MakeNSError(maybe_snapshot.status()));
  50. }
  51. }
  52. private:
  53. std::shared_ptr<api::Firestore> firestore_;
  54. PipelineBlock completion_;
  55. };
  56. return std::make_shared<Converter>(firestore, completion);
  57. }
  58. @end