diff --git a/Firestore/Source/API/FIRInterface.mm b/Firestore/Source/API/FIRInterface.mm new file mode 100644 index 00000000000..5dc0e5bac1c --- /dev/null +++ b/Firestore/Source/API/FIRInterface.mm @@ -0,0 +1,36 @@ +/* + * Copyright 2024 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. + */ + +#import + +#import "Firestore/Source/Public/FirebaseFirestore/FIRInterface.h" + +#import "Firestore/core/src/api/used_by_objective_c.h" +#include "Firestore/core/src/util/string_apple.h" + +using firebase::firestore::util::MakeString; + +NS_ASSUME_NONNULL_BEGIN + +@implementation FIRInterface + ++ (void)print:(NSString *)content { + CppInterfaceCalledByObjectiveC::print(MakeString(content)); +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Public/FirebaseFirestore/FIRInterface.h b/Firestore/Source/Public/FirebaseFirestore/FIRInterface.h new file mode 100644 index 00000000000..222b7024e91 --- /dev/null +++ b/Firestore/Source/Public/FirebaseFirestore/FIRInterface.h @@ -0,0 +1,29 @@ +/* + * Copyright 2024 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. + */ + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface FIRInterface : NSObject + +#pragma mark - Create Filter + ++ (void)print:(NSString *)content; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift b/Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift index aaafb30ef3d..fafeec43e98 100644 --- a/Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift +++ b/Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift @@ -18,8 +18,8 @@ @_exported import FirebaseFirestoreCpp #endif // SWIFT_PACKAGE -public class SwiftCppWrapper { +public class SwiftCallingCpp { public init(_ value: String) { - _ = UsedBySwift(std.string(value)) + CppInterfaceCalledBySwift.print(std.string(value)) } } diff --git a/Firestore/core/src/api/used_by_objective_c.cc b/Firestore/core/src/api/used_by_objective_c.cc new file mode 100644 index 00000000000..1333cecfe1f --- /dev/null +++ b/Firestore/core/src/api/used_by_objective_c.cc @@ -0,0 +1,22 @@ +/* + * Copyright 2024 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 "used_by_objective_c.h" +#include + +void CppInterfaceCalledByObjectiveC::print(std::string content) { + std::cout << "C++ function runs with value: " << content << std::endl; +} diff --git a/Firestore/core/src/api/used_by_objective_c.h b/Firestore/core/src/api/used_by_objective_c.h new file mode 100644 index 00000000000..06360f441ba --- /dev/null +++ b/Firestore/core/src/api/used_by_objective_c.h @@ -0,0 +1,27 @@ +/* + * Copyright 2024 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. + */ + +#ifndef FIREBASE_USED_BY_SWIFT_H +#define FIREBASE_USED_BY_SWIFT_H + +#include + +class CppInterfaceCalledByObjectiveC { + public: + static void print(std::string content); +}; + +#endif // FIREBASE_USED_BY_SWIFT_H diff --git a/Firestore/core/swift/include/used_by_swift.h b/Firestore/core/swift/include/used_by_swift.h index c5d5c516fc4..e4016b3c6a7 100644 --- a/Firestore/core/swift/include/used_by_swift.h +++ b/Firestore/core/swift/include/used_by_swift.h @@ -19,9 +19,9 @@ #include -class UsedBySwift { +class CppInterfaceCalledBySwift { public: - explicit UsedBySwift(std::string content); + static void print(std::string content); }; #endif // FIREBASE_USED_BY_SWIFT_H diff --git a/Firestore/core/swift/src/used_by_swift.cc b/Firestore/core/swift/src/used_by_swift.cc index 87981e2c4c7..d5261294e62 100644 --- a/Firestore/core/swift/src/used_by_swift.cc +++ b/Firestore/core/swift/src/used_by_swift.cc @@ -17,6 +17,6 @@ #include "../include/used_by_swift.h" #include -UsedBySwift::UsedBySwift(std::string content) { - std::cout << "ctor runs with value: " << content << std::endl; +void CppInterfaceCalledBySwift::print(std::string content) { + std::cout << "C++ function runs with value: " << content << std::endl; }