FIRHeartbeatLogger.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // TODO(ncooke3): Remove in future PR when `FIRHeartbeatInfo` symbol is removed.
  16. #import "FIRHeartbeatInfo.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. #ifndef FIREBASE_BUILD_CMAKE
  19. @class FIRHeartbeatsPayload;
  20. #endif // FIREBASE_BUILD_CMAKE
  21. // TODO(ncooke3): Consider annotating protocol API as `@optional`. (#9568)
  22. @protocol FIRHeartbeatLoggerProtocol <NSObject>
  23. /// Asynchronously logs a heartbeat.
  24. - (void)log;
  25. #ifndef FIREBASE_BUILD_CMAKE
  26. /// Flushes heartbeats from storage into a structured payload of heartbeats.
  27. - (FIRHeartbeatsPayload *)flushHeartbeatsIntoPayload;
  28. #endif // FIREBASE_BUILD_CMAKE
  29. /// Gets the heartbeat code for today.
  30. - (FIRHeartbeatInfoCode)heartbeatCodeForToday;
  31. @end
  32. #ifndef FIREBASE_BUILD_CMAKE
  33. /// Returns a nullable string header value from a given heartbeats payload.
  34. ///
  35. /// This API returns `nil` when the given heartbeats payload is considered empty.
  36. ///
  37. /// @param heartbeatsPayload The heartbeats payload.
  38. NSString *_Nullable FIRHeaderValueFromHeartbeatsPayload(FIRHeartbeatsPayload *heartbeatsPayload);
  39. #endif // FIREBASE_BUILD_CMAKE
  40. /// A thread safe, synchronized object that logs and flushes platform logging info.
  41. @interface FIRHeartbeatLogger : NSObject <FIRHeartbeatLoggerProtocol>
  42. /// Designated initializer.
  43. ///
  44. /// @param appID The app ID that this heartbeat logger corresponds to.
  45. - (instancetype)initWithAppID:(NSString *)appID;
  46. /// Asynchronously logs a new heartbeat corresponding to the Firebase User Agent, if needed.
  47. ///
  48. /// @note This API is thread-safe.
  49. - (void)log;
  50. #ifndef FIREBASE_BUILD_CMAKE
  51. /// Flushes heartbeats from storage into a structured payload of heartbeats.
  52. ///
  53. /// This API is for clients using platform logging V2.
  54. ///
  55. /// @note This API is thread-safe.
  56. /// @return A payload of heartbeats.
  57. - (FIRHeartbeatsPayload *)flushHeartbeatsIntoPayload;
  58. #endif // FIREBASE_BUILD_CMAKE
  59. /// Gets today's corresponding heartbeat code.
  60. ///
  61. /// This API is for clients using platform logging V1.
  62. ///
  63. /// @note This API is thread-safe.
  64. /// @return Heartbeat code indicating whether or not there is an unsent global heartbeat.
  65. - (FIRHeartbeatInfoCode)heartbeatCodeForToday;
  66. @end
  67. NS_ASSUME_NONNULL_END