FIRHeartbeatLogger.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef FIREBASECORE_FIRHEARTBEATLOGGER_H
  15. #define FIREBASECORE_FIRHEARTBEATLOGGER_H
  16. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. #ifndef FIREBASE_BUILD_CMAKE
  19. @class FIRHeartbeatsPayload;
  20. #endif // FIREBASE_BUILD_CMAKE
  21. /// Enum representing different daily heartbeat codes.
  22. /// This enum is only used by clients using platform logging V1. This is because
  23. /// the V1 payload only supports a single daily heartbeat.
  24. typedef NS_ENUM(NSInteger, FIRDailyHeartbeatCode) {
  25. /// Represents the absence of a daily heartbeat.
  26. FIRDailyHeartbeatCodeNone = 0,
  27. /// Represents the presence of a daily heartbeat.
  28. FIRDailyHeartbeatCodeSome = 2,
  29. };
  30. NS_SWIFT_SENDABLE
  31. @protocol FIRHeartbeatLoggerProtocol <NSObject>
  32. /// Asynchronously logs a heartbeat.
  33. - (void)log;
  34. /// Gets the heartbeat code for today.
  35. - (FIRDailyHeartbeatCode)heartbeatCodeForToday;
  36. #ifndef FIREBASE_BUILD_CMAKE
  37. /// Returns the header value for the heartbeat logger via the given completion handler..
  38. - (void)asyncHeaderValueWithCompletionHandler:(void (^)(NSString *_Nullable))completionHandler
  39. API_AVAILABLE(ios(13.0), macosx(10.15), macCatalyst(13.0), tvos(13.0), watchos(6.0));
  40. /// Return the header value for the heartbeat logger.
  41. - (NSString *_Nullable)headerValue;
  42. #endif // FIREBASE_BUILD_CMAKE
  43. @end
  44. #ifndef FIREBASE_BUILD_CMAKE
  45. /// Returns a nullable string header value from a given heartbeats payload.
  46. ///
  47. /// This API returns `nil` when the given heartbeats payload is considered empty.
  48. ///
  49. /// @param heartbeatsPayload The heartbeats payload.
  50. NSString *_Nullable FIRHeaderValueFromHeartbeatsPayload(FIRHeartbeatsPayload *heartbeatsPayload);
  51. #endif // FIREBASE_BUILD_CMAKE
  52. /// A thread safe, synchronized object that logs and flushes platform logging info.
  53. @interface FIRHeartbeatLogger : NSObject <FIRHeartbeatLoggerProtocol>
  54. /// Designated initializer.
  55. ///
  56. /// @param appID The app ID that this heartbeat logger corresponds to.
  57. - (instancetype)initWithAppID:(NSString *)appID;
  58. /// Asynchronously logs a new heartbeat corresponding to the Firebase User Agent, if needed.
  59. ///
  60. /// @note This API is thread-safe.
  61. - (void)log;
  62. #ifndef FIREBASE_BUILD_CMAKE
  63. /// Synchronously flushes heartbeats from storage into a structured payload of heartbeats.
  64. ///
  65. /// This API is for clients using platform logging V2.
  66. ///
  67. /// @note This API is thread-safe.
  68. /// @return A payload of heartbeats.
  69. - (FIRHeartbeatsPayload *)flushHeartbeatsIntoPayload;
  70. /// Asynchronously flushes heartbeats from storage into a structured payload of heartbeats.
  71. ///
  72. /// This API is for clients using platform logging V2.
  73. ///
  74. /// @note This API is thread-safe.
  75. /// @param completionHandler A completion handler to process the flushed payload of heartbeats.
  76. - (void)flushHeartbeatsIntoPayloadWithCompletionHandler:
  77. (void (^)(FIRHeartbeatsPayload *))completionHandler
  78. API_AVAILABLE(ios(13.0), macosx(10.15), macCatalyst(13.0), tvos(13.0), watchos(6.0));
  79. #endif // FIREBASE_BUILD_CMAKE
  80. /// Gets today's corresponding heartbeat code.
  81. ///
  82. /// This API is for clients using platform logging V1.
  83. ///
  84. /// @note This API is thread-safe.
  85. /// @return Heartbeat code indicating whether or not there is an unsent global heartbeat.
  86. - (FIRDailyHeartbeatCode)heartbeatCodeForToday;
  87. @end
  88. NS_ASSUME_NONNULL_END
  89. #endif // FIREBASECORE_FIRHEARTBEATLOGGER_H