FPRNetworkInstrumentHelpers.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/Network/FPRNetworkInstrumentHelpers.h"
  15. #import "FirebasePerformance/Sources/Instrumentation/FPRClassInstrumentor.h"
  16. #import "FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.h"
  17. FOUNDATION_EXTERN_INLINE
  18. void ThrowExceptionBecauseSelectorNotFoundOnClass(SEL selector, Class aClass) {
  19. [NSException raise:NSInternalInconsistencyException
  20. format:@"Selector %@ not found on class %@", NSStringFromSelector(selector),
  21. NSStringFromClass(aClass)];
  22. }
  23. FOUNDATION_EXTERN_INLINE
  24. void ThrowExceptionBecauseSelectorInstrumentorHasBeenDeallocated(SEL selector, Class aClass) {
  25. [NSException raise:NSInternalInconsistencyException
  26. format:@"Selector instrumentor has been deallocated: %@|%@",
  27. NSStringFromSelector(selector), NSStringFromClass(aClass)];
  28. }
  29. FOUNDATION_EXTERN_INLINE
  30. void ThrowExceptionBecauseInstrumentHasBeenDeallocated(SEL selector, Class aClass) {
  31. [NSException raise:NSInternalInconsistencyException
  32. format:@"The instrument has been deallocated: %@|%@", NSStringFromSelector(selector),
  33. NSStringFromClass(aClass)];
  34. }
  35. /** Returns an FPRSelectorInstrumentor given a SEL and FPRClassInstrumentor. This is a convenience
  36. * function.
  37. *
  38. * @param selector The selector to instrument.
  39. * @param instrumentor The class instrumentor to generate the selector instrumentor from.
  40. * @param isClassSelector YES if the selector is a class selector, NO otherwise.
  41. * @return An FPRSelectorInstrumentor instance if the selector is on the class.
  42. * @throws An exception if the selector is NOT found on the class.
  43. */
  44. FOUNDATION_EXTERN_INLINE
  45. FPRSelectorInstrumentor *SelectorInstrumentor(SEL selector,
  46. FPRClassInstrumentor *instrumentor,
  47. BOOL isClassSelector) {
  48. FPRSelectorInstrumentor *selectorInstrumentor =
  49. isClassSelector ? [instrumentor instrumentorForClassSelector:selector]
  50. : [instrumentor instrumentorForInstanceSelector:selector];
  51. if (!selectorInstrumentor) {
  52. ThrowExceptionBecauseSelectorNotFoundOnClass(selector, instrumentor.instrumentedClass);
  53. }
  54. return selectorInstrumentor;
  55. }