Skip to content

Commit

Permalink
consolidate public headers into one place
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-hui committed Jan 30, 2025
1 parent 9adb9c7 commit 5b61b67
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#import "FIRAggregateQuery.h"
#import "FIRAggregateQuerySnapshot.h"
#import "FIRAggregateSource.h"
#import "FIRCallbackWrapper.h"
#import "FIRCollectionReference.h"
#import "FIRDocumentChange.h"
#import "FIRDocumentReference.h"
Expand Down
39 changes: 0 additions & 39 deletions Firestore/core/interfaceForSwift/api/CollectionStage.h

This file was deleted.

37 changes: 0 additions & 37 deletions Firestore/core/interfaceForSwift/api/FirestorePipeline.h

This file was deleted.

47 changes: 0 additions & 47 deletions Firestore/core/interfaceForSwift/api/PipelineSource.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

#ifndef FIRESTORE_CORE_SRC_API_FIRCALLBACKWRAPPER_H_
#define FIRESTORE_CORE_SRC_API_FIRCALLBACKWRAPPER_H_

#import <Foundation/Foundation.h>

#if defined(__cplusplus)
Expand All @@ -26,40 +29,43 @@ namespace api {
class Firestore;
class PipelineResult;
} // namespace api

namespace core {
template <typename T>
class EventListener;
} // namespace core

} // namespace firestore
} // namespace firebase

namespace api = firebase::firestore::api;
namespace core = firebase::firestore::core;

NS_ASSUME_NONNULL_BEGIN

typedef api::PipelineResult CppPipelineResult;

typedef void (^PipelineBlock)(CppPipelineResult *_Nullable result, NSError *_Nullable error)
typedef void (^PipelineBlock)(CppPipelineResult* _Nullable result,
NSError* _Nullable error)
NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");

NS_SWIFT_SENDABLE
NS_SWIFT_NAME(CallbackWrapper)
@interface FIRCallbackWrapper : NSObject

// Note: Marking callbacks in callback-based APIs as `Sendable` can help prevent crashes when they
// are invoked on a different thread than the one they were originally defined in. If this callback
// is expected to be called on a different thread, it should be marked as `Sendable` to ensure
// thread safety.
// Note: Marking callbacks in callback-based APIs as `Sendable` can help prevent
// crashes when they are invoked on a different thread than the one they were
// originally defined in. If this callback is expected to be called on a
// different thread, it should be marked as `Sendable` to ensure thread safety.
+ (std::shared_ptr<core::EventListener<api::PipelineResult>>)
// NOLINTNEXTLINE(whitespace/parens)
wrapPipelineCallback:(std::shared_ptr<api::Firestore>)firestore
completion:(void (^NS_SWIFT_SENDABLE)(CppPipelineResult *_Nullable result,
NSError *_Nullable error))completion
// NOLINTNEXTLINE(whitespace/parens)
completion:(void (^NS_SWIFT_SENDABLE)(
CppPipelineResult* _Nullable result,
NSError* _Nullable error))completion
NS_SWIFT_NAME(wrapPipelineCallback(firestore:completion:));

@end

NS_ASSUME_NONNULL_END
#endif
#endif // defined(__cplusplus)

#endif // FIRESTORE_CORE_SRC_API_FIRCALLBACKWRAPPER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <utility>
#include <vector>

#include "Firestore/core/interfaceForSwift/api/Pipeline.h"
#include "Firestore/core/interfaceForSwift/api/PipelineResult.h"
#include "Firestore/core/src/api/pipeline.h"
#include "Firestore/core/src/api/pipeline_result.h"
#include "Firestore/core/src/core/event_listener.h"
#include "Firestore/core/src/util/error_apple.h"
#include "Firestore/core/src/util/statusor.h"
Expand All @@ -34,18 +34,22 @@

@implementation FIRCallbackWrapper

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

#ifndef FIRESTORE_CORE_INTERFACEFORSWIFT_API_FIREBASEFIRESTORECPP_H_
#define FIRESTORE_CORE_INTERFACEFORSWIFT_API_FIREBASEFIRESTORECPP_H_
#ifndef FIRESTORE_CORE_SRC_API_FIREBASEFIRESTORECPP_H_
#define FIRESTORE_CORE_SRC_API_FIREBASEFIRESTORECPP_H_

#import "Firestore/core/interfaceForSwift/api/collection_stage.h"
#import "Firestore/core/interfaceForSwift/api/firestore_pipeline.h"
#import "Firestore/core/interfaceForSwift/api/pipeline.h"
#import "Firestore/core/interfaceForSwift/api/pipeline_result.h"
#import "Firestore/core/interfaceForSwift/api/pipeline_source.h"
#import "Firestore/core/interfaceForSwift/api/stage.h"
#import "Firestore/core/src/api/FIRCallbackWrapper.h"

Check failure on line 20 in Firestore/core/src/api/FirebaseFirestoreCpp.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'Firestore/core/src/api/FIRCallbackWrapper.h' file not found

Check failure on line 20 in Firestore/core/src/api/FirebaseFirestoreCpp.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'Firestore/core/src/api/FIRCallbackWrapper.h' file not found

Check failure on line 20 in Firestore/core/src/api/FirebaseFirestoreCpp.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'Firestore/core/src/api/FIRCallbackWrapper.h' file not found
#import "Firestore/core/src/api/collection_stage.h"
#import "Firestore/core/src/api/firestore_pipeline.h"
#import "Firestore/core/src/api/pipeline.h"
#import "Firestore/core/src/api/pipeline_result.h"
#import "Firestore/core/src/api/pipeline_source.h"
#import "Firestore/core/src/api/stage.h"

#endif // FIRESTORE_CORE_INTERFACEFORSWIFT_API_FIREBASEFIRESTORECPP_H_
#endif // FIRESTORE_CORE_SRC_API_FIREBASEFIRESTORECPP_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "Firestore/core/interfaceForSwift/api/CollectionStage.h"
#include "Firestore/core/src/api/collection_stage.h"
#include <iostream>

namespace firebase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef FIRESTORE_CORE_INTERFACEFORSWIFT_API_COLLECTION_STAGE_H_
#define FIRESTORE_CORE_INTERFACEFORSWIFT_API_COLLECTION_STAGE_H_
#ifndef FIRESTORE_CORE_SRC_API_COLLECTION_STAGE_H_
#define FIRESTORE_CORE_SRC_API_COLLECTION_STAGE_H_

#include <string>
#include "Firestore/core/interfaceForSwift/api/stage.h"
#include "Firestore/core/src/api/stage.h"

namespace firebase {
namespace firestore {
Expand All @@ -36,4 +36,4 @@ class Collection : public Stage {
} // namespace firestore
} // namespace firebase

#endif // FIRESTORE_CORE_INTERFACEFORSWIFT_API_COLLECTION_STAGE_H_
#endif // FIRESTORE_CORE_SRC_API_COLLECTION_STAGE_H_
2 changes: 1 addition & 1 deletion Firestore/core/src/api/firestore.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include <mutex>
#include <string>

#include "Firestore/core/interfaceForSwift/api/PipelineSource.h"
#include "Firestore/core/src/api/api_fwd.h"
#include "Firestore/core/src/api/load_bundle_task.h"
#include "Firestore/core/src/api/pipeline_source.h"
#include "Firestore/core/src/api/settings.h"
#include "Firestore/core/src/core/core_fwd.h"
#include "Firestore/core/src/credentials/credentials_fwd.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "Firestore/core/interfaceForSwift/api/FirestorePipeline.h"
#include "Firestore/core/src/api/firestore_pipeline.h"

#include <memory>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef FIRESTORE_CORE_INTERFACEFORSWIFT_API_FIRESTORE_PIPELINE_H_
#define FIRESTORE_CORE_INTERFACEFORSWIFT_API_FIRESTORE_PIPELINE_H_
#ifndef FIRESTORE_CORE_SRC_API_FIRESTORE_PIPELINE_H_
#define FIRESTORE_CORE_SRC_API_FIRESTORE_PIPELINE_H_

#include <memory>

#include "Firestore/core/interfaceForSwift/api/pipeline_source.h"
#include "Firestore/core/src/api/pipeline_source.h"

namespace firebase {
namespace firestore {
Expand All @@ -34,4 +34,4 @@ class FirestorePipeline {
} // namespace firestore
} // namespace firebase

#endif // FIRESTORE_CORE_INTERFACEFORSWIFT_API_FIRESTORE_PIPELINE_H_
#endif // FIRESTORE_CORE_SRC_API_FIRESTORE_PIPELINE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "Firestore/core/interfaceForSwift/api/Pipeline.h"

#include <future>
#include <memory>
#include "Firestore/core/src/api/pipeline.h"

#include "Firestore/core/include/firebase/firestore/timestamp.h"
#include "Firestore/core/interfaceForSwift/api/PipelineResult.h"
#include "Firestore/core/src/api/firestore.h"
#include "Firestore/core/src/api/listener_registration.h"
#include "Firestore/core/src/api/pipeline_result.h"
#include "Firestore/core/src/api/source.h"
#include "Firestore/core/src/core/event_listener.h"
#include "Firestore/core/src/core/listen_options.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef FIRESTORE_CORE_INTERFACEFORSWIFT_API_PIPELINE_H_
#define FIRESTORE_CORE_INTERFACEFORSWIFT_API_PIPELINE_H_
#ifndef FIRESTORE_CORE_SRC_API_PIPELINE_H_
#define FIRESTORE_CORE_SRC_API_PIPELINE_H_

#include <functional>
#include <memory>
#include <vector>
#include "PipelineResult.h"
#include "Stage.h"
#include "Firestore/core/src/api/pipeline_result.h"
#include "Firestore/core/src/api/stage.h"

namespace firebase {
namespace firestore {
Expand Down Expand Up @@ -57,4 +57,4 @@ class Pipeline {
} // namespace firestore
} // namespace firebase

#endif // FIRESTORE_CORE_INTERFACEFORSWIFT_API_PIPELINE_H_
#endif // FIRESTORE_CORE_SRC_API_PIPELINE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>

#include "Firestore/core/src/api/pipeline_result.h"
#include "Firestore/core/include/firebase/firestore/timestamp.h"
#include "Firestore/core/interfaceForSwift/api/PipelineResult.h"

namespace firebase {
namespace firestore {
Expand Down
Loading

0 comments on commit 5b61b67

Please sign in to comment.