FIRHeartbeatLogger.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #import <Foundation/Foundation.h>
  15. NS_ASSUME_NONNULL_BEGIN
  16. #ifndef FIREBASE_BUILD_CMAKE
  17. @class FIRHeartbeatsPayload;
  18. #endif // FIREBASE_BUILD_CMAKE
  19. /// Enum representing different daily heartbeat codes.
  20. /// This enum is only used by clients using platform logging V1. This is because
  21. /// the V1 payload only supports a single daily heartbeat.
  22. typedef NS_ENUM(NSInteger, FIRDailyHeartbeatCode) {
  23. /// Represents the absence of a daily heartbeat.
  24. FIRDailyHeartbeatCodeNone = 0,
  25. /// Represents the presence of a daily heartbeat.
  26. FIRDailyHeartbeatCodeSome = 2,
  27. };
  28. @protocol FIRHeartbeatLoggerProtocol <NSObject>
  29. /// Asynchronously logs a heartbeat.
  30. - (void)log;
  31. #ifndef FIREBASE_BUILD_CMAKE
  32. /// Flushes heartbeats from storage into a structured payload of heartbeats.
  33. - (FIRHeartbeatsPayload *)flushHeartbeatsIntoPayload;
  34. #endif // FIREBASE_BUILD_CMAKE
  35. /// Gets the heartbeat code for today.
  36. - (FIRDailyHeartbeatCode)heartbeatCodeForToday;
  37. @end
  38. #ifndef FIREBASE_BUILD_CMAKE
  39. /// Returns a nullable string header value from a given heartbeats payload.
  40. ///
  41. /// This API returns `nil` when the given heartbeats payload is considered empty.
  42. ///
  43. /// @param heartbeatsPayload The heartbeats payload.
  44. NSString *_Nullable FIRHeaderValueFromHeartbeatsPayload(FIRHeartbeatsPayload *heartbeatsPayload);
  45. #endif // FIREBASE_BUILD_CMAKE
  46. /// A thread safe, synchronized object that logs and flushes platform logging info.
  47. @interface FIRHeartbeatLogger : NSObject <FIRHeartbeatLoggerProtocol>
  48. /// Designated initializer.
  49. ///
  50. /// @param appID The app ID that this heartbeat logger corresponds to.
  51. - (instancetype)initWithAppID:(NSString *)appID;
  52. /// Asynchronously logs a new heartbeat corresponding to the Firebase User Agent, if needed.
  53. ///
  54. /// @note This API is thread-safe.
  55. - (void)log;
  56. #ifndef FIREBASE_BUILD_CMAKE
  57. /// Flushes heartbeats from storage into a structured payload of heartbeats.
  58. ///
  59. /// This API is for clients using platform logging V2.
  60. ///
  61. /// @note This API is thread-safe.
  62. /// @return A payload of heartbeats.
  63. - (FIRHeartbeatsPayload *)flushHeartbeatsIntoPayload;
  64. #endif // FIREBASE_BUILD_CMAKE
  65. /// Gets today's corresponding heartbeat code.
  66. ///
  67. /// This API is for clients using platform logging V1.
  68. ///
  69. /// @note This API is thread-safe.
  70. /// @return Heartbeat code indicating whether or not there is an unsent global heartbeat.
  71. - (FIRDailyHeartbeatCode)heartbeatCodeForToday;
  72. @end
  73. NS_ASSUME_NONNULL_END