Skip to content

Commit 39df98b

Browse files
committed
Add Pipeline Result
1 parent 92d1380 commit 39df98b

File tree

11 files changed

+97
-20
lines changed

11 files changed

+97
-20
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Pipeline.swift
3+
// Firebase
4+
//
5+
// Created by Cheryl Lin on 2024-12-18.
6+
//
7+
8+
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
9+
public class Pipeline {
10+
var cppPtr: firebase.firestore.api.Pipeline
11+
12+
public init(_ cppSource: firebase.firestore.api.Pipeline) {
13+
cppPtr = cppSource
14+
}
15+
16+
@discardableResult
17+
public func GetPipelineResult() async throws -> PipelineResult {
18+
// return try await withCheckedThrowingContinuation { continuation in
19+
//
20+
// let callback: (
21+
// firebase.firestore.api.PipelineResult,
22+
// Bool
23+
// ) -> Void = { result, isSucceed in
24+
// if isSucceed {
25+
// continuation.resume(returning: PipelineResult(result))
26+
// } else {
27+
// continuation.resume(throwing: "ERROR!" as! Error)
28+
// }
29+
// }
30+
31+
// cppPtr.fetchDataWithCppCallback(callback)
32+
return PipelineResult(firebase.firestore.api.PipelineResult
33+
.GetTestResult(cppPtr.GetFirestore()))
34+
}
35+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// PipelineResult.swift
3+
// Firebase
4+
//
5+
// Created by Cheryl Lin on 2024-12-18.
6+
//
7+
8+
public class PipelineResult {
9+
let cppPtr: firebase.firestore.api.PipelineResult
10+
11+
public init(_ cppSource: firebase.firestore.api.PipelineResult) {
12+
cppPtr = cppSource
13+
}
14+
}

Firestore/Swift/Source/SwiftAPI/PipelineSource.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
// Created by Cheryl Lin on 2024-12-12.
66
//
77

8+
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
89
public class PipelineSource {
910
let cppPtr: firebase.firestore.api.PipelineSource
1011

1112
public init(_ cppSource: firebase.firestore.api.PipelineSource) {
1213
cppPtr = cppSource
1314
}
15+
16+
public func GetCollection(_ path: String) -> Pipeline {
17+
return Pipeline(cppPtr.GetCollection(std.string(path)))
18+
}
1419
}

Firestore/core/swift/include/FirebaseFirestoreCpp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#import "collection_stage.h"
2121
#import "firestore_pipeline.h"
2222
#import "pipeline.h"
23+
#import "pipeline_result.h"
2324
#import "pipeline_source.h"
2425
#import "stage.h"
2526
#import "used_by_swift.h"

Firestore/core/swift/include/pipeline.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#ifndef FIREBASE_PIPELINE_H
66
#define FIREBASE_PIPELINE_H
77

8+
#include <functional>
89
#include <memory>
910
#include <vector>
11+
#include "pipeline_result.h"
1012
#include "stage.h"
1113

1214
namespace firebase {
@@ -29,7 +31,12 @@ class Pipeline {
2931
public:
3032
Pipeline(std::shared_ptr<Firestore> firestore, Stage stage);
3133

32-
std::shared_ptr<PipelineSnapshotListener> GetPipelineResult();
34+
void GetPipelineResult(
35+
std::function<void(PipelineResult, bool)> callback) const;
36+
37+
std::shared_ptr<Firestore> GetFirestore() const {
38+
return firestore_;
39+
}
3340

3441
private:
3542
std::shared_ptr<Firestore> firestore_;

Firestore/core/swift/include/pipeline_result.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
#define FIREBASE_PIPELINE_RESULT_H
77

88
#include <memory>
9-
#include "Firestore/core/include/firebase/firestore/timestamp.h"
109

1110
namespace firebase {
11+
12+
class Timestamp;
13+
1214
namespace firestore {
1315

1416
namespace api {
@@ -19,17 +21,17 @@ class DocumentReference;
1921
class PipelineResult {
2022
public:
2123
PipelineResult(std::shared_ptr<Firestore> firestore,
22-
std::shared_ptr<DocumentReference> doc_ref_ptr,
23-
Timestamp execution_time,
24-
Timestamp update_time,
25-
Timestamp create_time);
24+
std::shared_ptr<Timestamp> execution_time,
25+
std::shared_ptr<Timestamp> update_time,
26+
std::shared_ptr<Timestamp> create_time);
27+
28+
static PipelineResult GetTestResult(std::shared_ptr<Firestore> firestore);
2629

2730
private:
2831
std::shared_ptr<Firestore> firestore_;
29-
std::shared_ptr<DocumentReference> doc_ref_ptr_;
30-
Timestamp execution_time_;
31-
Timestamp update_time_;
32-
Timestamp create_time_;
32+
std::shared_ptr<Timestamp> execution_time_;
33+
std::shared_ptr<Timestamp> update_time_;
34+
std::shared_ptr<Timestamp> create_time_;
3335
};
3436

3537
} // namespace api

Firestore/core/swift/include/pipeline_source.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PipelineSource {
2121
public:
2222
PipelineSource(std::shared_ptr<Firestore> firestore);
2323

24-
Pipeline GetCollection(std::string collection_path);
24+
Pipeline GetCollection(std::string collection_path) const;
2525

2626
private:
2727
std::shared_ptr<Firestore> firestore_;

Firestore/core/swift/src/pipeline.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "Firestore/core/swift/include/pipeline.h"
2+
#include "Firestore/core/include/firebase/firestore/timestamp.h"
23
#include "Firestore/core/src/api/firestore.h"
34
#include "Firestore/core/src/core/event_listener.h"
5+
#include "Firestore/core/swift/include/pipeline_result.h"
46

57
namespace firebase {
68
namespace firestore {
@@ -11,11 +13,15 @@ Pipeline::Pipeline(std::shared_ptr<Firestore> firestore, Stage stage)
1113
: firestore_(firestore), stage_(stage) {
1214
}
1315

14-
std::shared_ptr<PipelineSnapshotListener> Pipeline::GetPipelineResult() {
15-
return {};
16+
void Pipeline::GetPipelineResult(
17+
std::function<void(PipelineResult, bool)> callback) const {
18+
callback(PipelineResult(firestore_, std::make_shared<Timestamp>(0, 0),
19+
std::make_shared<Timestamp>(0, 0),
20+
std::make_shared<Timestamp>(0, 0)),
21+
true);
1622
}
1723

1824
} // namespace api
1925

2026
} // namespace firestore
21-
} // namespace firebase
27+
} // namespace firebase

Firestore/core/swift/src/pipeline_result.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11

22
#include "Firestore/core/swift/include/pipeline_result.h"
3+
#include "Firestore/core/include/firebase/firestore/timestamp.h"
34

45
namespace firebase {
56
namespace firestore {
67

78
namespace api {
89

910
PipelineResult::PipelineResult(std::shared_ptr<Firestore> firestore,
10-
std::shared_ptr<DocumentReference> doc_ref_ptr,
11-
Timestamp execution_time,
12-
Timestamp update_time,
13-
Timestamp create_time)
11+
std::shared_ptr<Timestamp> execution_time,
12+
std::shared_ptr<Timestamp> update_time,
13+
std::shared_ptr<Timestamp> create_time)
1414
: firestore_(firestore),
15-
doc_ref_ptr_(doc_ref_ptr),
1615
execution_time_(execution_time),
1716
update_time_(update_time),
1817
create_time_(create_time) {
1918
}
2019

20+
PipelineResult PipelineResult::GetTestResult(
21+
std::shared_ptr<Firestore> firestore) {
22+
return PipelineResult(firestore, std::make_shared<Timestamp>(0, 0),
23+
std::make_shared<Timestamp>(0, 0),
24+
std::make_shared<Timestamp>(0, 0));
25+
}
26+
2127
} // namespace api
2228

2329
} // namespace firestore

Firestore/core/swift/src/pipeline_source.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PipelineSource::PipelineSource(std::shared_ptr<Firestore> firestore)
1414
std::cout << "PipelineSource constructs" << std::endl;
1515
}
1616

17-
Pipeline PipelineSource::GetCollection(std::string collection_path) {
17+
Pipeline PipelineSource::GetCollection(std::string collection_path) const {
1818
return {firestore_, Collection{collection_path}};
1919
}
2020

0 commit comments

Comments
 (0)