You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. /*
  2. * Copyright 2017 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. @class GtalkDataMessageStanza;
  18. @class GPBMessage;
  19. @class FIRMessagingPersistentSyncMessage;
  20. /**
  21. * Called on each raw message.
  22. */
  23. typedef void(^FIRMessagingRmqMessageHandler)(NSDictionary<NSString *, GPBMessage *> *messages);
  24. /**
  25. * Used to scan through the rmq and perform actions on messages as required.
  26. */
  27. @protocol FIRMessagingRmqScanner <NSObject>
  28. /**
  29. * Scan the RMQ for outgoing messages and process them as required.
  30. */
  31. - (void)scanWithRmqMessageHandler:(FIRMessagingRmqMessageHandler)rmqMessageHandler;
  32. @end
  33. /**
  34. * This manages the RMQ persistent store.
  35. *
  36. * The store is used to store all the S2D id's that were received by the client and were ACK'ed
  37. * by us but the server hasn't confirmed the ACK. We don't delete these id's until the server
  38. * ACK's us that they have received them.
  39. *
  40. * We also store the upstream messages(d2s) that were sent by the client.
  41. *
  42. * Also store the lastRMQId that was sent by us so that for a new connection being setup we don't
  43. * duplicate RMQ Id's for the new messages.
  44. */
  45. @interface FIRMessagingRmqManager : NSObject <FIRMessagingRmqScanner>
  46. // designated initializer
  47. - (instancetype)initWithDatabaseName:(NSString *)databaseName;
  48. - (void)loadRmqId;
  49. /**
  50. * Save an upstream message to RMQ. If the message send fails for some reason we would not
  51. * lose the message since it would be saved in the RMQ.
  52. *
  53. * @param message The upstream message to be saved.
  54. * @param handler The handler to invoke when the database operation completes with response.
  55. *
  56. */
  57. - (void)saveRmqMessage:(GPBMessage *)message withCompletionHandler:(void(^)(BOOL success))handler;
  58. /**
  59. * Save Server to device message with the given RMQ-ID.
  60. *
  61. * @param rmqID The rmqID of the s2d message to save.
  62. *
  63. */
  64. - (void)saveS2dMessageWithRmqId:(NSString *)rmqID;
  65. /**
  66. * A list of all unacked Server to device RMQ IDs.
  67. *
  68. * @return A list of unacked Server to Device RMQ ID's. All values are Strings.
  69. */
  70. - (NSArray *)unackedS2dRmqIds;
  71. /**
  72. * Removes the messages with the given rmqIDs from RMQ store.
  73. *
  74. * @param rmqIds The lsit of rmqID's to remove from the store.
  75. *
  76. */
  77. - (void)removeRmqMessagesWithRmqIds:(NSArray *)rmqIds;
  78. /**
  79. * Removes a list of downstream messages from the RMQ.
  80. *
  81. * @param s2dIds The list of messages ACK'ed by the server that we should remove
  82. * from the RMQ store.
  83. */
  84. - (void)removeS2dIds:(NSArray *)s2dIds;
  85. #pragma mark - Sync Messages
  86. /**
  87. * Get persisted sync message with rmqID.
  88. *
  89. * @param rmqID The rmqID of the persisted sync message.
  90. *
  91. * @return A valid persistent sync message with the given rmqID if found in the RMQ else nil.
  92. */
  93. - (FIRMessagingPersistentSyncMessage *)querySyncMessageWithRmqID:(NSString *)rmqID;
  94. /**
  95. * Delete sync message with rmqID.
  96. *
  97. * @param rmqID The rmqID of the persisted sync message.
  98. *
  99. */
  100. - (void)deleteSyncMessageWithRmqID:(NSString *)rmqID;
  101. /**
  102. * Delete the expired sync messages from persisten store. Also deletes messages that have been
  103. * delivered both via APNS and MCS.
  104. *
  105. */
  106. - (void)deleteExpiredOrFinishedSyncMessages;
  107. /**
  108. * Save sync message received by the device.
  109. *
  110. * @param rmqID The rmqID of the message received.
  111. * @param expirationTime The expiration time of the sync message received.
  112. * @param apnsReceived YES if the message was received via APNS else NO.
  113. * @param mcsReceived YES if the message was received via MCS else NO.
  114. *
  115. */
  116. - (void)saveSyncMessageWithRmqID:(NSString *)rmqID
  117. expirationTime:(int64_t)expirationTime
  118. apnsReceived:(BOOL)apnsReceived
  119. mcsReceived:(BOOL)mcsReceived;
  120. /**
  121. * Update sync message received via APNS.
  122. *
  123. * @param rmqID The rmqID of the received message.
  124. *
  125. */
  126. - (void)updateSyncMessageViaAPNSWithRmqID:(NSString *)rmqID;
  127. /**
  128. * Update sync message received via MCS.
  129. *
  130. * @param rmqID The rmqID of the received message.
  131. *
  132. */
  133. - (void)updateSyncMessageViaMCSWithRmqID:(NSString *)rmqID;
  134. @end