FPRObjectInstrumentor.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <GoogleUtilities/GULSwizzledObject.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. @interface FPRObjectInstrumentor : FPRInstrument
  34. /** The instrumented object. */
  35. @property(nonatomic, weak) id instrumentedObject;
  36. /** YES if there is reason to swizzle, NO if swizzling is not needed. */
  37. @property(nonatomic) BOOL hasModifications;
  38. /** Please use the designated initializer. */
  39. - (instancetype)init NS_UNAVAILABLE;
  40. /** Instantiates an instance of this class. The designated initializer.
  41. *
  42. * @param object The object to be instrumented.
  43. * @return An instance of this class.
  44. */
  45. - (instancetype)initWithObject:(id)object NS_DESIGNATED_INITIALIZER;
  46. /** Attempts to copy a selector from a donor class onto the dynamically generated subclass that the
  47. * object will adopt when -swizzle is called.
  48. *
  49. * @param selector The selector to use.
  50. * @param aClass The class to copy the selector from.
  51. * @param isClassSelector YES if the selector is a class selector, NO otherwise.
  52. */
  53. - (void)copySelector:(SEL)selector fromClass:(Class)aClass isClassSelector:(BOOL)isClassSelector;
  54. /** Swizzles the isa of the object and sets its class to the dynamically created subclass. */
  55. - (void)swizzle;
  56. @end
  57. NS_ASSUME_NONNULL_END