GDTCORUploadPackage.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2019 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/GDTCORTargets.h>
  18. @class GDTCORClock;
  19. @class GDTCOREvent;
  20. @class GDTCORUploadPackage;
  21. /** A protocol that allows a handler to respond to package lifecycle events. */
  22. @protocol GDTCORUploadPackageProtocol <NSObject>
  23. @optional
  24. /** Indicates that the package has expired.
  25. *
  26. * @note Package expiration will only be checked every 5 seconds.
  27. *
  28. * @param package The package that has expired.
  29. */
  30. - (void)packageExpired:(GDTCORUploadPackage *)package;
  31. /** Indicates that the package was successfully delivered.
  32. *
  33. * @param package The package that was delivered.
  34. */
  35. - (void)packageDelivered:(GDTCORUploadPackage *)package successful:(BOOL)successful;
  36. @end
  37. /** This class is a container that's handed off to uploaders. */
  38. @interface GDTCORUploadPackage : NSObject <NSSecureCoding>
  39. /** The set of stored events in this upload package. */
  40. @property(nonatomic) NSSet<GDTCOREvent *> *events;
  41. /** The expiration time. If [[GDTCORClock snapshot] isAfter:deliverByTime] this package has expired.
  42. *
  43. * @note By default, the expiration time will be 3 minutes from creation.
  44. */
  45. @property(nonatomic) GDTCORClock *deliverByTime;
  46. /** The target of this package. */
  47. @property(nonatomic, readonly) GDTCORTarget target;
  48. /** Initializes a package instance.
  49. *
  50. * @param target The target/destination of this package.
  51. * @return An instance of this class.
  52. */
  53. - (instancetype)initWithTarget:(GDTCORTarget)target NS_DESIGNATED_INITIALIZER;
  54. // Please use the designated initializer.
  55. - (instancetype)init NS_UNAVAILABLE;
  56. /** Completes delivery of the package.
  57. *
  58. * @note This *needs* to be called by an uploader for the package to not expire.
  59. */
  60. - (void)completeDelivery;
  61. /** Sends the package back, indicating that delivery should be attempted again in the future. */
  62. - (void)retryDeliveryInTheFuture;
  63. @end