Skip to content

Commit 7f73d46

Browse files
jonsimantova-maurice
authored andcommitted
Refactor platform selection to use platform.h macros,
FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS, FIREBASE_PLATFORM_WINDOWS, etc. PiperOrigin-RevId: 264702710
1 parent 797e3b9 commit 7f73d46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+348
-374
lines changed

admob/src/common/banner_view_internal.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@
1515
*/
1616

1717
#include "admob/src/common/banner_view_internal.h"
18+
1819
#include "admob/src/include/firebase/admob/banner_view.h"
1920
#include "app/src/include/firebase/future.h"
21+
#include "app/src/include/firebase/internal/platform.h"
2022
#include "app/src/mutex.h"
2123
#include "app/src/reference_counted_future_impl.h"
2224

23-
#if defined(__APPLE__)
24-
#include "TargetConditionals.h"
25-
#endif // __APPLE__
26-
27-
#if defined(__ANDROID__)
25+
#if FIREBASE_PLATFORM_ANDROID
2826
#include "admob/src/android/banner_view_internal_android.h"
29-
#elif TARGET_OS_IPHONE
27+
#elif FIREBASE_PLATFORM_IOS
3028
#include "admob/src/ios/banner_view_internal_ios.h"
3129
#else
3230
#include "admob/src/stub/banner_view_internal_stub.h"
33-
#endif // __ANDROID__, TARGET_OS_IPHONE
31+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS
3432

3533
namespace firebase {
3634
namespace admob {
@@ -40,13 +38,13 @@ BannerViewInternal::BannerViewInternal(BannerView* base)
4038
: base_(base), future_data_(kBannerViewFnCount), listener_(nullptr) {}
4139

4240
BannerViewInternal* BannerViewInternal::CreateInstance(BannerView* base) {
43-
#if defined(__ANDROID__)
41+
#if FIREBASE_PLATFORM_ANDROID
4442
return new BannerViewInternalAndroid(base);
45-
#elif TARGET_OS_IPHONE
43+
#elif FIREBASE_PLATFORM_IOS
4644
return new BannerViewInternalIOS(base);
4745
#else
4846
return new BannerViewInternalStub(base);
49-
#endif // __ANDROID__, TARGET_OS_IPHONE
47+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS
5048
}
5149

5250
void BannerViewInternal::SetListener(BannerView::Listener* listener) {

admob/src/common/interstitial_ad_internal.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@
1515
*/
1616

1717
#include "admob/src/common/interstitial_ad_internal.h"
18+
1819
#include "admob/src/include/firebase/admob/interstitial_ad.h"
1920
#include "app/src/include/firebase/future.h"
21+
#include "app/src/include/firebase/internal/platform.h"
2022
#include "app/src/mutex.h"
2123
#include "app/src/reference_counted_future_impl.h"
2224

23-
#if defined(__APPLE__)
24-
#include "TargetConditionals.h"
25-
#endif // __APPLE__
26-
27-
#if defined(__ANDROID__)
25+
#if FIREBASE_PLATFORM_ANDROID
2826
#include "admob/src/android/interstitial_ad_internal_android.h"
29-
#elif TARGET_OS_IPHONE
27+
#elif FIREBASE_PLATFORM_IOS
3028
#include "admob/src/ios/interstitial_ad_internal_ios.h"
3129
#else
3230
#include "admob/src/stub/interstitial_ad_internal_stub.h"
33-
#endif // __ANDROID__, TARGET_OS_IPHONE
31+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS
3432

3533
namespace firebase {
3634
namespace admob {
@@ -41,13 +39,13 @@ InterstitialAdInternal::InterstitialAdInternal(InterstitialAd* base)
4139

4240
InterstitialAdInternal* InterstitialAdInternal::CreateInstance(
4341
InterstitialAd* base) {
44-
#if defined(__ANDROID__)
42+
#if FIREBASE_PLATFORM_ANDROID
4543
return new InterstitialAdInternalAndroid(base);
46-
#elif TARGET_OS_IPHONE
44+
#elif FIREBASE_PLATFORM_IOS
4745
return new InterstitialAdInternalIOS(base);
4846
#else
4947
return new InterstitialAdInternalStub(base);
50-
#endif // __ANDROID__, TARGET_OS_IPHONE
48+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS
5149
}
5250

5351
void InterstitialAdInternal::SetListener(InterstitialAd::Listener* listener) {

admob/src/common/native_express_ad_view_internal.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@
1515
*/
1616

1717
#include "admob/src/common/native_express_ad_view_internal.h"
18+
1819
#include "admob/src/include/firebase/admob/native_express_ad_view.h"
1920
#include "app/src/include/firebase/future.h"
21+
#include "app/src/include/firebase/internal/platform.h"
2022
#include "app/src/mutex.h"
2123
#include "app/src/reference_counted_future_impl.h"
2224

23-
#if defined(__APPLE__)
24-
#include "TargetConditionals.h"
25-
#endif // __APPLE__
26-
27-
#if defined(__ANDROID__)
25+
#if FIREBASE_PLATFORM_ANDROID
2826
#include "admob/src/android/native_express_ad_view_internal_android.h"
29-
#elif TARGET_OS_IPHONE
27+
#elif FIREBASE_PLATFORM_IOS
3028
#include "admob/src/ios/native_express_ad_view_internal_ios.h"
3129
#else
3230
#include "admob/src/stub/native_express_ad_view_internal_stub.h"
33-
#endif // __ANDROID__, TARGET_OS_IPHONE
31+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS
3432

3533
namespace firebase {
3634
namespace admob {
@@ -44,13 +42,13 @@ NativeExpressAdViewInternal::NativeExpressAdViewInternal(
4442

4543
NativeExpressAdViewInternal* NativeExpressAdViewInternal::CreateInstance(
4644
NativeExpressAdView* base) {
47-
#if defined(__ANDROID__)
45+
#if FIREBASE_PLATFORM_ANDROID
4846
return new NativeExpressAdViewInternalAndroid(base);
49-
#elif TARGET_OS_IPHONE
47+
#elif FIREBASE_PLATFORM_IOS
5048
return new NativeExpressAdViewInternalIOS(base);
5149
#else
5250
return new NativeExpressAdViewInternalStub(base);
53-
#endif // __ANDROID__, TARGET_OS_IPHONE
51+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS
5452
}
5553

5654
void NativeExpressAdViewInternal::SetListener(

admob/src/common/rewarded_video_internal.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@
1515
*/
1616

1717
#include "admob/src/common/rewarded_video_internal.h"
18+
1819
#include "admob/src/include/firebase/admob/rewarded_video.h"
1920
#include "app/src/include/firebase/future.h"
21+
#include "app/src/include/firebase/internal/platform.h"
2022
#include "app/src/mutex.h"
2123
#include "app/src/reference_counted_future_impl.h"
2224

23-
#if defined(__APPLE__)
24-
#include "TargetConditionals.h"
25-
#endif // __APPLE__
26-
27-
#if defined(__ANDROID__)
25+
#if FIREBASE_PLATFORM_ANDROID
2826
#include "admob/src/android/rewarded_video_internal_android.h"
29-
#elif TARGET_OS_IPHONE
27+
#elif FIREBASE_PLATFORM_IOS
3028
#include "admob/src/ios/rewarded_video_internal_ios.h"
3129
#else
3230
#include "admob/src/stub/rewarded_video_internal_stub.h"
33-
#endif // __ANDROID__, TARGET_OS_IPHONE
31+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS
3432

3533
namespace firebase {
3634
namespace admob {
@@ -41,13 +39,13 @@ RewardedVideoInternal::RewardedVideoInternal()
4139
: future_data_(kRewardedVideoFnCount), listener_(nullptr) {}
4240

4341
RewardedVideoInternal* RewardedVideoInternal::CreateInstance() {
44-
#if defined(__ANDROID__)
42+
#if FIREBASE_PLATFORM_ANDROID
4543
return new RewardedVideoInternalAndroid();
46-
#elif TARGET_OS_IPHONE
44+
#elif FIREBASE_PLATFORM_IOS
4745
return new RewardedVideoInternalIOS();
4846
#else
4947
return new RewardedVideoInternalStub();
50-
#endif // __ANDROID__, TARGET_OS_IPHONE
48+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS
5149
}
5250

5351
void RewardedVideoInternal::SetListener(Listener* listener) {

admob/src/include/firebase/admob.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef FIREBASE_ADMOB_CLIENT_CPP_INCLUDE_FIREBASE_ADMOB_H_
18-
#define FIREBASE_ADMOB_CLIENT_CPP_INCLUDE_FIREBASE_ADMOB_H_
17+
#ifndef FIREBASE_ADMOB_CLIENT_CPP_SRC_INCLUDE_FIREBASE_ADMOB_H_
18+
#define FIREBASE_ADMOB_CLIENT_CPP_SRC_INCLUDE_FIREBASE_ADMOB_H_
1919

20-
#ifdef __ANDROID__
20+
#include "firebase/internal/platform.h"
21+
22+
#if FIREBASE_PLATFORM_ANDROID
2123
#include <jni.h>
22-
#endif // __ANDROID__
24+
#endif // FIREBASE_PLATFORM_ANDROID
2325

2426
#include "firebase/admob/banner_view.h"
2527
#include "firebase/admob/interstitial_ad.h"
@@ -69,7 +71,7 @@ InitResult Initialize(const ::firebase::App& app);
6971
/// Google Play services (for example, when using 'play-services-ads-lite').
7072
InitResult Initialize(const ::firebase::App& app, const char* admob_app_id);
7173

72-
#if defined(__ANDROID__) || defined(DOXYGEN)
74+
#if FIREBASE_PLATFORM_ANDROID || defined(DOXYGEN)
7375
/// Initializes AdMob without Firebase for Android.
7476
///
7577
/// The arguments to @ref Initialize are platform-specific so the caller must do
@@ -122,7 +124,7 @@ InitResult Initialize(JNIEnv* jni_env, jobject activity);
122124
InitResult Initialize(JNIEnv* jni_env, jobject activity,
123125
const char* admob_app_id);
124126
#endif // defined(__ANDROID__) || defined(DOXYGEN)
125-
#if !defined(__ANDROID__) || defined(DOXYGEN)
127+
#if !FIREBASE_PLATFORM_ANDROID || defined(DOXYGEN)
126128
/// Initializes AdMob without Firebase for iOS.
127129
InitResult Initialize();
128130

@@ -152,4 +154,4 @@ void Terminate();
152154
} // namespace admob
153155
} // namespace firebase
154156

155-
#endif // FIREBASE_ADMOB_CLIENT_CPP_INCLUDE_FIREBASE_ADMOB_H_
157+
#endif // FIREBASE_ADMOB_CLIENT_CPP_SRC_INCLUDE_FIREBASE_ADMOB_H_

admob/src/include/firebase/admob/types.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef FIREBASE_ADMOB_CLIENT_CPP_INCLUDE_FIREBASE_ADMOB_TYPES_H_
18-
#define FIREBASE_ADMOB_CLIENT_CPP_INCLUDE_FIREBASE_ADMOB_TYPES_H_
17+
#ifndef FIREBASE_ADMOB_CLIENT_CPP_SRC_INCLUDE_FIREBASE_ADMOB_TYPES_H_
18+
#define FIREBASE_ADMOB_CLIENT_CPP_SRC_INCLUDE_FIREBASE_ADMOB_TYPES_H_
1919

20-
#if defined(__APPLE__)
21-
#include "TargetConditionals.h"
22-
#endif // __APPLE__
20+
#include "firebase/internal/platform.h"
2321

24-
#if defined(__ANDROID__)
22+
#if FIREBASE_PLATFORM_ANDROID
2523
#include <jni.h>
26-
#elif defined(TARGET_OS_IPHONE)
24+
#elif FIREBASE_PLATFORM_IOS
2725
extern "C" {
2826
#include <objc/objc.h>
2927
} // extern "C"
30-
#endif // __ANDROID__, TARGET_OS_IPHONE
28+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS
3129

3230
namespace firebase {
3331
namespace admob {
@@ -39,16 +37,16 @@ namespace admob {
3937
/// <li>Android: A `jobject` which references an Android Activity.</li>
4038
/// <li>iOS: An `id` which references an iOS UIView.</li>
4139
/// </ul>
42-
#if defined(__ANDROID__)
40+
#if FIREBASE_PLATFORM_ANDROID
4341
/// An Android Activity from Java.
4442
typedef jobject AdParent;
45-
#elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
43+
#elif FIREBASE_PLATFORM_IOS
4644
/// A pointer to an iOS UIView.
4745
typedef id AdParent;
4846
#else
4947
/// A void pointer for stub classes.
5048
typedef void *AdParent;
51-
#endif // __ANDROID__, TARGET_OS_IPHONE
49+
#endif // FIREBASE_PLATFORM_ANDROID, FIREBASE_PLATFORM_IOS
5250

5351
#ifdef INTERNAL_EXPERIMENTAL
5452
// LINT.IfChange
@@ -175,4 +173,4 @@ struct BoundingBox {
175173
} // namespace admob
176174
} // namespace firebase
177175

178-
#endif // FIREBASE_ADMOB_CLIENT_CPP_INCLUDE_FIREBASE_ADMOB_TYPES_H_
176+
#endif // FIREBASE_ADMOB_CLIENT_CPP_SRC_INCLUDE_FIREBASE_ADMOB_TYPES_H_

app/rest/request_file.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@
1616

1717
#include "app/rest/request_file.h"
1818

19+
#include "app/src/include/firebase/internal/platform.h"
20+
1921
#ifndef _FILE_OFFSET_BITS
2022
#define _FILE_OFFSET_BITS 64
2123
#endif // _FILE_OFFSET_BITS
2224
#include <stdio.h>
25+
2326
#include <cassert>
2427
#include <cstddef>
2528

2629
// Map to POSIX compliant fseek on Windows.
27-
#ifdef _WIN32
30+
#if FIREBASE_PLATFORM_WINDOWS
2831
#define fseeko _fseeki64
2932
#define ftello _ftelli64
30-
#endif // _WIN32
33+
#endif // FIREBASE_PLATFORM_WINDOWS
3134

3235
namespace firebase {
3336
namespace rest {

app/rest/transport_curl.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@
2323
#include "app/rest/controller_curl.h"
2424
#include "app/rest/util.h"
2525
#include "app/src/assert.h"
26+
#include "app/src/include/firebase/internal/platform.h"
2627
#include "app/src/mutex.h"
2728
#include "app/src/semaphore.h"
2829
#include "app/src/thread.h"
2930
#include "app/src/util.h"
3031
#include "curl/curl.h"
3132

32-
#ifdef _WIN32
33+
#if FIREBASE_PLATFORM_WINDOWS
3334
#include "Winsock2.h"
3435
#else
3536
#include <sys/select.h>
36-
#endif // _WIN32
37+
#endif // FIREBASE_PLATFORM_WINDOWS
3738

3839
namespace firebase {
3940
namespace rest {
@@ -560,8 +561,8 @@ bool BackgroundTransportCurl::PerformBackground(Request* request) {
560561
options.post_fields.c_str()),
561562
"set http post fields");
562563
if (controller_) {
563-
controller_->set_transfer_size(static_cast<int64_t>(
564-
options.post_fields.size()));
564+
controller_->set_transfer_size(
565+
static_cast<int64_t>(options.post_fields.size()));
565566
}
566567
}
567568

app/src/app_common.cc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,20 @@
2424
#include <utility> // Used to detect STL variant.
2525
#include <vector>
2626

27-
#ifdef __APPLE__
28-
#include "TargetConditionals.h"
29-
#endif // __APPLE__
30-
3127
#include "app/memory/unique_ptr.h"
3228
#include "app/src/assert.h"
3329
#include "app/src/callback.h"
3430
#include "app/src/cleanup_notifier.h"
3531
#include "app/src/include/firebase/app.h"
32+
#include "app/src/include/firebase/internal/platform.h"
3633
#include "app/src/include/firebase/version.h"
3734
#include "app/src/mutex.h"
3835
#include "app/src/util.h"
3936

4037
// strtok_r is strtok_s on Windows.
41-
#if defined(_WIN32)
38+
#if FIREBASE_PLATFORM_WINDOWS
4239
#define strtok_r strtok_s
43-
#endif // defined(_WIN32)
40+
#endif // FIREBASE_PLATFORM_WINDOWS
4441

4542
#if !defined(FIREBASE_NAMESPACE)
4643
#define FIREBASE_NAMESPACE firebase
@@ -55,7 +52,7 @@ namespace app_common {
5552

5653
// clang-format=off
5754
// Detect operating system and architecture.
58-
#if defined(_MSVC_VER) || defined(_WIN32)
55+
#if FIREBASE_PLATFORM_WINDOWS
5956

6057
const char* kOperatingSystem = "windows";
6158
#if defined(_DLL) && _DLL == 1
@@ -79,9 +76,9 @@ const char* kCpuArchitecture = "arm32";
7976

8077
#elif defined(__APPLE__)
8178
const char* kCppRuntimeOrStl = "libcpp";
82-
#if TARGET_OS_IOS
79+
#if FIREBASE_PLATFORM_IOS
8380
const char* kOperatingSystem = "ios";
84-
#elif TARGET_OS_OSX
81+
#elif FIREBASE_PLATFORM_OSX
8582
const char* kOperatingSystem = "darwin";
8683
#else
8784
#error Unknown Apple operating system.
@@ -99,7 +96,7 @@ const char* kCpuArchitecture = "arm32";
9996
#error Unknown Apple architecture.
10097
#endif // Architecture
10198

102-
#elif __ANDROID__
99+
#elif FIREBASE_PLATFORM_ANDROID
103100
const char* kOperatingSystem = "android";
104101

105102
#if __i386__
@@ -132,7 +129,7 @@ const char* kCppRuntimeOrStl = "libcpp";
132129
#error Unknown Android STL.
133130
#endif // STL
134131

135-
#elif __linux__
132+
#elif FIREBASE_PLATFORM_LINUX
136133
const char* kOperatingSystem = "linux";
137134
const char* kCppRuntimeOrStl = "gnustl";
138135

0 commit comments

Comments
 (0)