FIRComponent.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef FIREBASECORE_SOURCES_PRIVATE_FIRCOMPONENT_H_
  17. #define FIREBASECORE_SOURCES_PRIVATE_FIRCOMPONENT_H_
  18. #import <Foundation/Foundation.h>
  19. @class FIRApp;
  20. @class FIRComponentContainer;
  21. NS_ASSUME_NONNULL_BEGIN
  22. /// Provides a system to clean up cached instances returned from the component system.
  23. NS_SWIFT_NAME(ComponentLifecycleMaintainer)
  24. @protocol FIRComponentLifecycleMaintainer
  25. /// The associated app will be deleted, clean up any resources as they are about to be deallocated.
  26. - (void)appWillBeDeleted:(FIRApp *)app;
  27. @end
  28. typedef _Nullable id (^FIRComponentCreationBlock)(FIRComponentContainer *container,
  29. BOOL *isCacheable)
  30. NS_SWIFT_NAME(ComponentCreationBlock);
  31. @class FIRDependency;
  32. /// Describes the timing of instantiation. Note: new components should default to lazy unless there
  33. /// is a strong reason to be eager.
  34. typedef NS_ENUM(NSInteger, FIRInstantiationTiming) {
  35. FIRInstantiationTimingLazy,
  36. FIRInstantiationTimingAlwaysEager,
  37. FIRInstantiationTimingEagerInDefaultApp
  38. } NS_SWIFT_NAME(InstantiationTiming);
  39. /// A component that can be used from other Firebase SDKs.
  40. NS_SWIFT_NAME(Component)
  41. @interface FIRComponent : NSObject
  42. /// The protocol describing functionality provided from the Component.
  43. @property(nonatomic, strong, readonly) Protocol *protocol;
  44. /// The timing of instantiation.
  45. @property(nonatomic, readonly) FIRInstantiationTiming instantiationTiming;
  46. /// An array of dependencies for the component.
  47. @property(nonatomic, copy, readonly) NSArray<FIRDependency *> *dependencies;
  48. /// A block to instantiate an instance of the component with the appropriate dependencies.
  49. @property(nonatomic, copy, readonly) FIRComponentCreationBlock creationBlock;
  50. // There's an issue with long NS_SWIFT_NAMES that causes compilation to fail, disable clang-format
  51. // for the next two methods.
  52. // clang-format off
  53. /// Creates a component with no dependencies that will be lazily initialized.
  54. + (instancetype)componentWithProtocol:(Protocol *)protocol
  55. creationBlock:(FIRComponentCreationBlock)creationBlock
  56. NS_SWIFT_NAME(init(_:creationBlock:));
  57. /// Creates a component to be registered with the component container.
  58. ///
  59. /// @param protocol - The protocol describing functionality provided by the component.
  60. /// @param instantiationTiming - When the component should be initialized. Use .lazy unless there's
  61. /// a good reason to be instantiated earlier.
  62. /// @param dependencies - Any dependencies the `implementingClass` has, optional or required.
  63. /// @param creationBlock - A block to instantiate the component with a container, and if
  64. /// @return A component that can be registered with the component container.
  65. + (instancetype)componentWithProtocol:(Protocol *)protocol
  66. instantiationTiming:(FIRInstantiationTiming)instantiationTiming
  67. dependencies:(NSArray<FIRDependency *> *)dependencies
  68. creationBlock:(FIRComponentCreationBlock)creationBlock
  69. NS_SWIFT_NAME(init(_:instantiationTiming:dependencies:creationBlock:));
  70. // clang-format on
  71. /// Unavailable.
  72. - (instancetype)init NS_UNAVAILABLE;
  73. @end
  74. NS_ASSUME_NONNULL_END
  75. #endif // FIREBASECORE_SOURCES_PRIVATE_FIRCOMPONENT_H_