FPRObjectInstrumentor.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "FirebasePerformance/Sources/Instrumentation/FPRInstrument.h"
  15. #import "FirebasePerformance/Sources/ISASwizzler/FPRSwizzledObject.h"
  16. @class FPRSelectorInstrumentor;
  17. NS_ASSUME_NONNULL_BEGIN
  18. /** Defines the interface that an instrumentor should implement if they are going to instrument
  19. * objects.
  20. */
  21. @protocol FPRObjectInstrumentorProtocol <NSObject>
  22. @required
  23. /** Registers an instance of the delegate class to be instrumented.
  24. *
  25. * @param object The instance to instrument.
  26. */
  27. - (void)registerObject:(id)object;
  28. /** Registers an instance of the delegate class to be instrumented.
  29. *
  30. * @param proxy The instance to instrument.
  31. */
  32. - (void)registerProxy:(id)proxy;
  33. @end
  34. /** This class allows the instrumentation of specific objects by isa swizzling specific instances
  35. * with a dynamically generated subclass of the object's original class and installing methods
  36. * onto this new class.
  37. */
  38. NS_EXTENSION_UNAVAILABLE("Firebase Performance is not supported for extensions.")
  39. @interface FPRObjectInstrumentor : FPRInstrument
  40. /** The instrumented object. */
  41. @property(nonatomic, weak) id instrumentedObject;
  42. /** YES if there is reason to swizzle, NO if swizzling is not needed. */
  43. @property(nonatomic) BOOL hasModifications;
  44. /** Please use the designated initializer. */
  45. - (instancetype)init NS_UNAVAILABLE;
  46. /** Instantiates an instance of this class. The designated initializer.
  47. *
  48. * @param object The object to be instrumented.
  49. * @return An instance of this class.
  50. */
  51. - (instancetype)initWithObject:(id)object NS_DESIGNATED_INITIALIZER;
  52. /** Attempts to copy a selector from a donor class onto the dynamically generated subclass that the
  53. * object will adopt when -swizzle is called.
  54. *
  55. * @param selector The selector to use.
  56. * @param aClass The class to copy the selector from.
  57. * @param isClassSelector YES if the selector is a class selector, NO otherwise.
  58. */
  59. - (void)copySelector:(SEL)selector fromClass:(Class)aClass isClassSelector:(BOOL)isClassSelector;
  60. /** Swizzles the isa of the object and sets its class to the dynamically created subclass. */
  61. - (void)swizzle;
  62. @end
  63. NS_ASSUME_NONNULL_END