FPRDiagnostics.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2020 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. #import "FirebasePerformance/Sources/FPRConsoleLogger.h"
  16. /** Logs assert information. This shouldn't be called by anything except FPRAssert.
  17. *
  18. * @param object The object (or class) that is asserting.
  19. * @param condition The condition that is being asserted to be true.
  20. * @param func The value of the __func__ variable.
  21. */
  22. FOUNDATION_EXTERN void __FPRAssert(id object, BOOL condition, const char *func);
  23. /** This protocol defines the selectors that are invoked when a diagnostics event occurs. */
  24. @protocol FPRDiagnosticsProtocol
  25. @optional
  26. /** Emits class-level diagnostic information. */
  27. + (void)emitDiagnostics;
  28. /** Emits object-level diagnostic information. */
  29. - (void)emitDiagnostics;
  30. @end
  31. // Use this define in implementations of +/-emitDiagnostics.
  32. #define EMIT_DIAGNOSTIC(...) FPRLogNotice(kFPRDiagnosticLog, __VA_ARGS__)
  33. // This assert adds additional functionality to the normal NSAssert, including printing out
  34. // information when NSAsserts are stripped. A __builtin_expect is utilized to keep running speed
  35. // as fast as possible.
  36. #define FPRAssert(condition, ...) \
  37. { \
  38. do { \
  39. __FPRAssert(self, !!(condition), __func__); \
  40. NSAssert(condition, __VA_ARGS__); \
  41. } while (0); \
  42. }
  43. /** This class handles the control of diagnostics in the SDK. */
  44. @interface FPRDiagnostics : NSObject
  45. /** YES if diagnostics are enabled, NO otherwise. */
  46. @property(class, nonatomic, readonly, getter=isEnabled) BOOL enabled;
  47. @end