-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathpipeline.cc
102 lines (88 loc) · 3.33 KB
/
pipeline.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2025 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.
#include "Firestore/core/interfaceForSwift/api/pipeline.h"
#include <future> // NOLINT(build/c++11)
#include <memory>
#include "Firestore/core/include/firebase/firestore/timestamp.h"
#include "Firestore/core/interfaceForSwift/api/pipeline_result.h"
#include "Firestore/core/src/api/firestore.h"
#include "Firestore/core/src/api/listener_registration.h"
#include "Firestore/core/src/api/source.h"
#include "Firestore/core/src/core/event_listener.h"
#include "Firestore/core/src/core/listen_options.h"
#include "Firestore/core/src/core/view_snapshot.h"
namespace firebase {
namespace firestore {
namespace api {
using core::EventListener;
using core::ListenOptions;
using core::ViewSnapshot;
Pipeline::Pipeline(std::shared_ptr<Firestore> firestore, Stage stage)
: firestore_(firestore), stage_(stage) {
}
void Pipeline::GetPipelineResult(PipelineSnapshotListener callback) const {
ListenOptions options(
/*include_query_metadata_changes=*/true,
/*include_document_metadata_changes=*/true,
/*wait_for_sync_when_online=*/true);
PipelineResult sample = PipelineResult::GetTestResult(firestore_);
StatusOr<PipelineResult> res(sample);
callback->OnEvent(res);
// class ListenOnce : public EventListener<std::vector<PipelineResult>> {
// public:
// ListenOnce(PipelineSnapshotListener listener)
// : listener_(std::move(listener)) {
// }
//
// void OnEvent(
// StatusOr<std::vector<PipelineResult>> maybe_snapshot) override {
// if (!maybe_snapshot.ok()) {
// listener_->OnEvent(std::move(maybe_snapshot));
// return;
// }
//
// std::vector<PipelineResult> snapshot =
// std::move(maybe_snapshot).ValueOrDie();
//
// // Remove query first before passing event to user to avoid user
// actions
// // affecting the now stale query.
// std::unique_ptr<ListenerRegistration> registration =
// registration_promise_.get_future().get();
// registration->Remove();
//
// listener_->OnEvent(std::move(snapshot));
// };
//
// void Resolve(std::unique_ptr<ListenerRegistration> registration) {
// registration_promise_.set_value(std::move(registration));
// }
//
// private:
// PipelineSnapshotListener listener_;
//
// std::promise<std::unique_ptr<ListenerRegistration>>
// registration_promise_;
// };
//
// auto listener = absl::make_unique<ListenOnce>(std::move(callback));
// auto* listener_unowned = listener.get();
// std::unique_ptr<ListenerRegistration> registration =
// AddSnapshotListener(std::move(options), std::move(listener));
//
// listener_unowned->Resolve(std::move(registration));
}
} // namespace api
} // namespace firestore
} // namespace firebase