Skip to content

Commit 317ccfb

Browse files
committed
consolidate public headers into one place
1 parent cbd135f commit 317ccfb

20 files changed

+46
-183
lines changed

Firestore/core/interfaceForSwift/api/CollectionStage.h

-39
This file was deleted.

Firestore/core/interfaceForSwift/api/FirestorePipeline.h

-37
This file was deleted.

Firestore/core/interfaceForSwift/api/PipelineSource.h

-47
This file was deleted.

Firestore/Source/Public/FirebaseFirestore/FIRCallbackWrapper.h renamed to Firestore/core/src/api/FIRCallbackWrapper.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616

1717
#import <Foundation/Foundation.h>
18-
19-
#if defined(__cplusplus)
2018
#include <memory>
2119
#include <vector>
2220

@@ -40,11 +38,11 @@ namespace core = firebase::firestore::core;
4038

4139
NS_ASSUME_NONNULL_BEGIN
4240

43-
typedef api::PipelineResult CppPipelineResult;
44-
45-
typedef void (^PipelineBlock)(CppPipelineResult *_Nullable result, NSError *_Nullable error)
41+
typedef void (^PipelineBlock)(std::vector<api::PipelineResult> result, NSError *_Nullable error)
4642
NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");
4743

44+
typedef std::vector<api::PipelineResult> PipelineResultVector;
45+
4846
NS_SWIFT_SENDABLE
4947
NS_SWIFT_NAME(CallbackWrapper)
5048
@interface FIRCallbackWrapper : NSObject
@@ -53,13 +51,12 @@ NS_SWIFT_NAME(CallbackWrapper)
5351
// are invoked on a different thread than the one they were originally defined in. If this callback
5452
// is expected to be called on a different thread, it should be marked as `Sendable` to ensure
5553
// thread safety.
56-
+ (std::shared_ptr<core::EventListener<api::PipelineResult>>)
54+
+ (std::shared_ptr<core::EventListener<std::vector<api::PipelineResult>>>)
5755
wrapPipelineCallback:(std::shared_ptr<api::Firestore>)firestore
58-
completion:(void (^NS_SWIFT_SENDABLE)(CppPipelineResult *_Nullable result,
56+
completion:(void (^NS_SWIFT_SENDABLE)(PipelineResultVector result,
5957
NSError *_Nullable error))completion
6058
NS_SWIFT_NAME(wrapPipelineCallback(firestore:completion:));
6159

6260
@end
6361

6462
NS_ASSUME_NONNULL_END
65-
#endif

Firestore/Source/API/FIRCallbackWrapper.mm renamed to Firestore/core/src/api/FIRCallbackWrapper.mm

+10-14
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include <utility>
2121
#include <vector>
2222

23-
#include "Firestore/core/interfaceForSwift/api/Pipeline.h"
24-
#include "Firestore/core/interfaceForSwift/api/PipelineResult.h"
23+
#include "Firestore/core/src/api/pipeline.h"
24+
#include "Firestore/core/src/api/pipeline_result.h"
2525
#include "Firestore/core/src/core/event_listener.h"
2626
#include "Firestore/core/src/util/error_apple.h"
2727
#include "Firestore/core/src/util/statusor.h"
@@ -34,26 +34,22 @@
3434

3535
@implementation FIRCallbackWrapper
3636

37-
// In public Swift documentation for integrating Swift and C++, using raw pointers in C++ is
38-
// generally considered unsafe. However, during an experiment where the result was passed as a value
39-
// instead of a pointer, a double free error occurred. This issue could not be traced effectively
40-
// because the implementation resides within the Swift-C++ transition layer. In this specific use
41-
// case, the C++ OnEvent() scope is destroyed after the Swift callback has been destroyed. Due to
42-
// this ordering, using a raw pointer is a safe workaround for now.
4337
+ (PipelineSnapshotListener)wrapPipelineCallback:(std::shared_ptr<api::Firestore>)firestore
44-
completion:(void (^)(CppPipelineResult *_Nullable result,
38+
completion:(void (^)(PipelineResultVector result,
4539
NSError *_Nullable error))completion {
46-
class Converter : public EventListener<CppPipelineResult> {
40+
class Converter : public EventListener<std::vector<PipelineResult>> {
4741
public:
4842
explicit Converter(std::shared_ptr<api::Firestore> firestore, PipelineBlock completion)
4943
: firestore_(firestore), completion_(completion) {
5044
}
5145

52-
void OnEvent(StatusOr<CppPipelineResult> maybe_snapshot) override {
46+
void OnEvent(StatusOr<std::vector<PipelineResult>> maybe_snapshot) override {
5347
if (maybe_snapshot.ok()) {
54-
completion_(&maybe_snapshot.ValueOrDie(), nullptr);
48+
completion_(
49+
std::initializer_list<PipelineResult>{PipelineResult::GetTestResult(firestore_)},
50+
nullptr);
5551
} else {
56-
completion_(nullptr, MakeNSError(maybe_snapshot.status()));
52+
completion_(std::initializer_list<PipelineResult>{}, MakeNSError(maybe_snapshot.status()));
5753
}
5854
}
5955

@@ -62,7 +58,7 @@ void OnEvent(StatusOr<CppPipelineResult> maybe_snapshot) override {
6258
PipelineBlock completion_;
6359
};
6460

65-
return std::make_shared<Converter>(firestore, completion);
61+
return absl::make_unique<Converter>(firestore, completion);
6662
}
6763

6864
@end

Firestore/core/interfaceForSwift/api/FirebaseFirestoreCpp.h renamed to Firestore/core/src/api/FirebaseFirestoreCpp.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
#ifndef FIRESTORE_CORE_INTERFACEFORSWIFT_API_FIREBASEFIRESTORECPP_H_
1818
#define FIRESTORE_CORE_INTERFACEFORSWIFT_API_FIREBASEFIRESTORECPP_H_
1919

20-
#import "Firestore/core/interfaceForSwift/api/collection_stage.h"
21-
#import "Firestore/core/interfaceForSwift/api/firestore_pipeline.h"
22-
#import "Firestore/core/interfaceForSwift/api/pipeline.h"
23-
#import "Firestore/core/interfaceForSwift/api/pipeline_result.h"
24-
#import "Firestore/core/interfaceForSwift/api/pipeline_source.h"
25-
#import "Firestore/core/interfaceForSwift/api/stage.h"
20+
#import "Firestore/core/src/api/FIRCallbackWrapper.h"
21+
#import "Firestore/core/src/api/collection_stage.h"
22+
#import "Firestore/core/src/api/firestore_pipeline.h"
23+
#import "Firestore/core/src/api/pipeline.h"
24+
#import "Firestore/core/src/api/pipeline_result.h"
25+
#import "Firestore/core/src/api/pipeline_source.h"
26+
#import "Firestore/core/src/api/stage.h"
2627

2728
#endif // FIRESTORE_CORE_INTERFACEFORSWIFT_API_FIREBASEFIRESTORECPP_H_

Firestore/core/interfaceForSwift/api/CollectionStage.cc renamed to Firestore/core/src/api/collection_stage.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "Firestore/core/interfaceForSwift/api/CollectionStage.h"
15+
#include "Firestore/core/src/api/collection_stage.h"
1616
#include <iostream>
1717

1818
namespace firebase {

Firestore/core/interfaceForSwift/api/collection_stage.h renamed to Firestore/core/src/api/collection_stage.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define FIRESTORE_CORE_INTERFACEFORSWIFT_API_COLLECTION_STAGE_H_
1717

1818
#include <string>
19-
#include "Firestore/core/interfaceForSwift/api/stage.h"
19+
#include "Firestore/core/src/api/stage.h"
2020

2121
namespace firebase {
2222
namespace firestore {

Firestore/core/src/api/firestore.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include <mutex>
2222
#include <string>
2323

24-
#include "Firestore/core/interfaceForSwift/api/PipelineSource.h"
2524
#include "Firestore/core/src/api/api_fwd.h"
2625
#include "Firestore/core/src/api/load_bundle_task.h"
26+
#include "Firestore/core/src/api/pipeline_source.h"
2727
#include "Firestore/core/src/api/settings.h"
2828
#include "Firestore/core/src/core/core_fwd.h"
2929
#include "Firestore/core/src/credentials/credentials_fwd.h"

Firestore/core/interfaceForSwift/api/FirestorePipeline.cc renamed to Firestore/core/src/api/firestore_pipeline.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "Firestore/core/interfaceForSwift/api/FirestorePipeline.h"
15+
#include "Firestore/core/src/api/firestore_pipeline.h"
1616

1717
#include <memory>
1818

Firestore/core/interfaceForSwift/api/firestore_pipeline.h renamed to Firestore/core/src/api/firestore_pipeline.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <memory>
1919

20-
#include "Firestore/core/interfaceForSwift/api/pipeline_source.h"
20+
#include "Firestore/core/src/api/pipeline_source.h"
2121

2222
namespace firebase {
2323
namespace firestore {

Firestore/core/interfaceForSwift/api/Pipeline.cc renamed to Firestore/core/src/api/pipeline.cc

+5-7
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "Firestore/core/interfaceForSwift/api/Pipeline.h"
15+
#include "Firestore/core/src/api/pipeline.h"
1616

17-
#include <future>
17+
#include <future> // NOLINT(build/c++11)
1818
#include <memory>
1919

2020
#include "Firestore/core/include/firebase/firestore/timestamp.h"
21-
#include "Firestore/core/interfaceForSwift/api/PipelineResult.h"
2221
#include "Firestore/core/src/api/firestore.h"
2322
#include "Firestore/core/src/api/listener_registration.h"
23+
#include "Firestore/core/src/api/pipeline_result.h"
2424
#include "Firestore/core/src/api/source.h"
2525
#include "Firestore/core/src/core/event_listener.h"
2626
#include "Firestore/core/src/core/listen_options.h"
@@ -45,10 +45,8 @@ void Pipeline::GetPipelineResult(PipelineSnapshotListener callback) const {
4545
/*include_document_metadata_changes=*/true,
4646
/*wait_for_sync_when_online=*/true);
4747

48-
PipelineResult sample = PipelineResult::GetTestResult(firestore_);
49-
50-
StatusOr<PipelineResult> res(sample);
51-
callback->OnEvent(res);
48+
callback->OnEvent(StatusOr<std::vector<PipelineResult>>(
49+
{(PipelineResult::GetTestResult(firestore_))}));
5250

5351
// class ListenOnce : public EventListener<std::vector<PipelineResult>> {
5452
// public:

Firestore/core/interfaceForSwift/api/Pipeline.h renamed to Firestore/core/src/api/pipeline.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include <functional>
1919
#include <memory>
2020
#include <vector>
21-
#include "PipelineResult.h"
22-
#include "Stage.h"
21+
#include "Firestore/core/src/api/pipeline_result.h"
22+
#include "Firestore/core/src/api/stage.h"
2323

2424
namespace firebase {
2525
namespace firestore {
@@ -35,7 +35,7 @@ class Firestore;
3535
class PipelineResult;
3636

3737
using PipelineSnapshotListener =
38-
std::shared_ptr<core::EventListener<PipelineResult>>;
38+
std::shared_ptr<core::EventListener<std::vector<PipelineResult>>>;
3939

4040
class Pipeline {
4141
public:

Firestore/core/interfaceForSwift/api/PipelineResult.cc renamed to Firestore/core/src/api/pipeline_result.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <iostream>
16-
15+
#include "Firestore/core/src/api/pipeline_result.h"
1716
#include "Firestore/core/include/firebase/firestore/timestamp.h"
18-
#include "Firestore/core/interfaceForSwift/api/PipelineResult.h"
1917

2018
namespace firebase {
2119
namespace firestore {

Firestore/core/interfaceForSwift/api/PipelineResult.h renamed to Firestore/core/src/api/pipeline_result.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef FIRESTORE_CORE_INTERFACEFORSWIFT_API_PIPELINERESULT_H_
16-
#define FIRESTORE_CORE_INTERFACEFORSWIFT_API_PIPELINERESULT_H_
15+
#ifndef FIRESTORE_CORE_INTERFACEFORSWIFT_API_PIPELINE_RESULT_H_
16+
#define FIRESTORE_CORE_INTERFACEFORSWIFT_API_PIPELINE_RESULT_H_
1717

1818
#include <memory>
1919

@@ -48,4 +48,4 @@ class PipelineResult {
4848

4949
} // namespace firestore
5050
} // namespace firebase
51-
#endif // FIRESTORE_CORE_INTERFACEFORSWIFT_API_PIPELINERESULT_H_
51+
#endif // FIRESTORE_CORE_INTERFACEFORSWIFT_API_PIPELINE_RESULT_H_

Firestore/core/interfaceForSwift/api/PipelineSource.cc renamed to Firestore/core/src/api/pipeline_source.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "Firestore/core/interfaceForSwift/api/PipelineSource.h"
15+
#include "Firestore/core/src/api/pipeline_source.h"
1616

1717
#include <string>
1818

19-
#include "Firestore/core/interfaceForSwift/api/CollectionStage.h"
19+
#include "Firestore/core/src/api/collection_stage.h"
2020
#include "Firestore/core/src/api/document_reference.h"
2121
#include "Firestore/core/src/api/firestore.h"
2222

Firestore/core/interfaceForSwift/api/pipeline_source.h renamed to Firestore/core/src/api/pipeline_source.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <string>
2020
#include <vector>
2121

22-
#include "Firestore/core/interfaceForSwift/api/pipeline.h"
22+
#include "Firestore/core/src/api/pipeline.h"
2323

2424
namespace firebase {
2525
namespace firestore {

Firestore/core/interfaceForSwift/api/Stage.cc renamed to Firestore/core/src/api/stage.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "Firestore/core/interfaceForSwift/api/Stage.h"
15+
#include "Firestore/core/src/api/stage.h"
1616

1717
namespace firebase {
1818
namespace firestore {

0 commit comments

Comments
 (0)