FPRObjectInstrumentor.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. @end
  29. /** This class allows the instrumentation of specific objects by isa swizzling specific instances
  30. * with a dynamically generated subclass of the object's original class and installing methods
  31. * onto this new class.
  32. */
  33. NS_EXTENSION_UNAVAILABLE("Firebase Performance is not supported for extensions.")
  34. @interface FPRObjectInstrumentor : FPRInstrument
  35. /** The instrumented object. */
  36. @property(nonatomic, weak) id instrumentedObject;
  37. /** YES if there is reason to swizzle, NO if swizzling is not needed. */
  38. @property(nonatomic) BOOL hasModifications;
  39. /** Please use the designated initializer. */
  40. - (instancetype)init NS_UNAVAILABLE;
  41. /** Instantiates an instance of this class. The designated initializer.
  42. *
  43. * @param object The object to be instrumented.
  44. * @return An instance of this class.
  45. */
  46. - (instancetype)initWithObject:(id)object NS_DESIGNATED_INITIALIZER;
  47. /** Attempts to copy a selector from a donor class onto the dynamically generated subclass that the
  48. * object will adopt when -swizzle is called.
  49. *
  50. * @param selector The selector to use.
  51. * @param aClass The class to copy the selector from.
  52. * @param isClassSelector YES if the selector is a class selector, NO otherwise.
  53. */
  54. - (void)copySelector:(SEL)selector fromClass:(Class)aClass isClassSelector:(BOOL)isClassSelector;
  55. /** Swizzles the isa of the object and sets its class to the dynamically created subclass. */
  56. - (void)swizzle;
  57. @end
  58. NS_ASSUME_NONNULL_END