FPersistentConnection.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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)refreshAppCheckToken:(NSString *)token;
  46. - (void)onDisconnectPutData:(id)data
  47. forPath:(FPath *)path
  48. withCallback:(fbt_void_nsstring_nsstring)callback;
  49. - (void)onDisconnectMergeData:(id)data
  50. forPath:(FPath *)path
  51. withCallback:(fbt_void_nsstring_nsstring)callback;
  52. - (void)onDisconnectCancelPath:(FPath *)path
  53. withCallback:(fbt_void_nsstring_nsstring)callback;
  54. - (void)ackPuts;
  55. - (void)getDataAtPath:(NSString *)pathString
  56. withParams:(NSDictionary *)queryWireProtocolParams
  57. withCallback:(fbt_void_nsstring_id_nsstring)onComplete;
  58. - (void)purgeOutstandingWrites;
  59. - (void)interruptForReason:(NSString *)reason;
  60. - (void)resumeForReason:(NSString *)reason;
  61. - (BOOL)isInterruptedForReason:(NSString *)reason;
  62. // FConnection delegate methods
  63. - (void)onReady:(FConnection *)fconnection
  64. atTime:(NSNumber *)timestamp
  65. sessionID:(NSString *)sessionID;
  66. - (void)onDataMessage:(FConnection *)fconnection
  67. withMessage:(NSDictionary *)message;
  68. - (void)onDisconnect:(FConnection *)fconnection
  69. withReason:(FDisconnectReason)reason;
  70. - (void)onKill:(FConnection *)fconnection withReason:(NSString *)reason;
  71. // Testing methods
  72. - (NSDictionary *)dumpListens;
  73. @end
  74. @protocol FPersistentConnectionDelegate <NSObject>
  75. - (void)onDataUpdate:(FPersistentConnection *)fpconnection
  76. forPath:(NSString *)pathString
  77. message:(id)message
  78. isMerge:(BOOL)isMerge
  79. tagId:(NSNumber *)tagId;
  80. - (void)onRangeMerge:(NSArray *)ranges
  81. forPath:(NSString *)path
  82. tagId:(NSNumber *)tag;
  83. - (void)onConnect:(FPersistentConnection *)fpconnection;
  84. - (void)onDisconnect:(FPersistentConnection *)fpconnection;
  85. - (void)onServerInfoUpdate:(FPersistentConnection *)fpconnection
  86. updates:(NSDictionary *)updates;
  87. @end