FPersistentConnection.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "FirebaseDatabase/Sources/Api/Private/FTypedefs_Private.h"
  17. #import "FirebaseDatabase/Sources/Core/FRepoInfo.h"
  18. #import "FirebaseDatabase/Sources/Realtime/FConnection.h"
  19. #import "FirebaseDatabase/Sources/Utilities/FTypedefs.h"
  20. #import <Foundation/Foundation.h>
  21. @protocol FPersistentConnectionDelegate;
  22. @protocol FSyncTreeHash;
  23. @class FQuerySpec;
  24. @class FIRDatabaseConfig;
  25. @interface FPersistentConnection : NSObject <FConnectionDelegate>
  26. @property(nonatomic, weak) id<FPersistentConnectionDelegate> delegate;
  27. @property(nonatomic) BOOL pauseWrites;
  28. - (id)initWithRepoInfo:(FRepoInfo *)repoInfo
  29. dispatchQueue:(dispatch_queue_t)queue
  30. config:(FIRDatabaseConfig *)config;
  31. - (void)open;
  32. - (void)putData:(id)data
  33. forPath:(NSString *)pathString
  34. withHash:(NSString *)hash
  35. withCallback:(fbt_void_nsstring_nsstring)onComplete;
  36. - (void)mergeData:(id)data
  37. forPath:(NSString *)pathString
  38. withCallback:(fbt_void_nsstring_nsstring)onComplete;
  39. - (void)listen:(FQuerySpec *)query
  40. tagId:(NSNumber *)tagId
  41. hash:(id<FSyncTreeHash>)hash
  42. onComplete:(fbt_void_nsstring)onComplete;
  43. - (void)unlisten:(FQuerySpec *)query tagId:(NSNumber *)tagId;
  44. - (void)refreshAuthToken:(NSString *)token;
  45. - (void)onDisconnectPutData:(id)data
  46. forPath:(FPath *)path
  47. withCallback:(fbt_void_nsstring_nsstring)callback;
  48. - (void)onDisconnectMergeData:(id)data
  49. forPath:(FPath *)path
  50. withCallback:(fbt_void_nsstring_nsstring)callback;
  51. - (void)onDisconnectCancelPath:(FPath *)path
  52. withCallback:(fbt_void_nsstring_nsstring)callback;
  53. - (void)ackPuts;
  54. - (void)purgeOutstandingWrites;
  55. - (void)interruptForReason:(NSString *)reason;
  56. - (void)resumeForReason:(NSString *)reason;
  57. - (BOOL)isInterruptedForReason:(NSString *)reason;
  58. // FConnection delegate methods
  59. - (void)onReady:(FConnection *)fconnection
  60. atTime:(NSNumber *)timestamp
  61. sessionID:(NSString *)sessionID;
  62. - (void)onDataMessage:(FConnection *)fconnection
  63. withMessage:(NSDictionary *)message;
  64. - (void)onDisconnect:(FConnection *)fconnection
  65. withReason:(FDisconnectReason)reason;
  66. - (void)onKill:(FConnection *)fconnection withReason:(NSString *)reason;
  67. // Testing methods
  68. - (NSDictionary *)dumpListens;
  69. @end
  70. @protocol FPersistentConnectionDelegate <NSObject>
  71. - (void)onDataUpdate:(FPersistentConnection *)fpconnection
  72. forPath:(NSString *)pathString
  73. message:(id)message
  74. isMerge:(BOOL)isMerge
  75. tagId:(NSNumber *)tagId;
  76. - (void)onRangeMerge:(NSArray *)ranges
  77. forPath:(NSString *)path
  78. tagId:(NSNumber *)tag;
  79. - (void)onConnect:(FPersistentConnection *)fpconnection;
  80. - (void)onDisconnect:(FPersistentConnection *)fpconnection;
  81. - (void)onServerInfoUpdate:(FPersistentConnection *)fpconnection
  82. updates:(NSDictionary *)updates;
  83. @end