GDTCORTransformer.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #import <Foundation/Foundation.h>
  17. #import <GoogleDataTransport/GDTCORLifecycle.h>
  18. @class GDTCOREvent;
  19. @protocol GDTCOREventTransformer;
  20. NS_ASSUME_NONNULL_BEGIN
  21. /** Manages the transforming of events. It's desirable for this to be its own class
  22. * because running all events through a single instance ensures that transformers are thread-safe.
  23. * Having a per-transport queue to run on isn't sufficient because transformer objects could
  24. * maintain state (or at least, there's nothing to stop them from doing that) and the same instances
  25. * may be used across multiple instances.
  26. */
  27. @interface GDTCORTransformer : NSObject <GDTCORLifecycleProtocol>
  28. /** Instantiates or returns the event transformer singleton.
  29. *
  30. * @return The singleton instance of the event transformer.
  31. */
  32. + (instancetype)sharedInstance;
  33. /** Writes the result of applying the given transformers' -transform method on the given event.
  34. *
  35. * @note If the app is suspended, a background task will be created to complete work in-progress,
  36. * but this method will not send any further events until the app is resumed.
  37. *
  38. * @param event The event to apply transformers on.
  39. * @param transformers The list of transformers to apply.
  40. * @param completion A block to run when an event was written to disk or dropped.
  41. */
  42. - (void)transformEvent:(GDTCOREvent *)event
  43. withTransformers:(nullable NSArray<id<GDTCOREventTransformer>> *)transformers
  44. onComplete:(void (^_Nullable)(BOOL wasWritten, NSError *_Nullable error))completion;
  45. @end
  46. NS_ASSUME_NONNULL_END