FPersistentConnection.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #import "FConnection.h"
  18. #import "FRepoInfo.h"
  19. #import "FTypedefs.h"
  20. #import "FTypedefs_Private.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 forPath:(NSString *)pathString withHash:(NSString *)hash withCallback:(fbt_void_nsstring_nsstring)onComplete;
  33. - (void) mergeData:(id)data forPath:(NSString *)pathString withCallback:(fbt_void_nsstring_nsstring)onComplete;
  34. - (void) listen:(FQuerySpec *)query
  35. tagId:(NSNumber *)tagId
  36. hash:(id<FSyncTreeHash>)hash
  37. onComplete:(fbt_void_nsstring)onComplete;
  38. - (void) unlisten:(FQuerySpec *)query tagId:(NSNumber *)tagId;
  39. - (void) refreshAuthToken:(NSString *)token;
  40. - (void) onDisconnectPutData:(id)data forPath:(FPath *)path withCallback:(fbt_void_nsstring_nsstring)callback;
  41. - (void) onDisconnectMergeData:(id)data forPath:(FPath *)path withCallback:(fbt_void_nsstring_nsstring)callback;
  42. - (void) onDisconnectCancelPath:(FPath *)path withCallback:(fbt_void_nsstring_nsstring)callback;
  43. - (void) ackPuts;
  44. - (void) purgeOutstandingWrites;
  45. - (void) interruptForReason:(NSString *)reason;
  46. - (void) resumeForReason:(NSString *)reason;
  47. - (BOOL) isInterruptedForReason:(NSString *)reason;
  48. // FConnection delegate methods
  49. - (void)onReady:(FConnection *)fconnection atTime:(NSNumber *)timestamp sessionID:(NSString *)sessionID;
  50. - (void)onDataMessage:(FConnection *)fconnection withMessage:(NSDictionary *)message;
  51. - (void)onDisconnect:(FConnection *)fconnection withReason:(FDisconnectReason)reason;
  52. - (void)onKill:(FConnection *)fconnection withReason:(NSString *)reason;
  53. // Testing methods
  54. - (NSDictionary *) dumpListens;
  55. @end
  56. @protocol FPersistentConnectionDelegate <NSObject>
  57. - (void)onDataUpdate:(FPersistentConnection *)fpconnection forPath:(NSString *)pathString message:(id)message isMerge:(BOOL)isMerge tagId:(NSNumber *)tagId;
  58. - (void)onRangeMerge:(NSArray *)ranges forPath:(NSString *)path tagId:(NSNumber *)tag;
  59. - (void)onConnect:(FPersistentConnection *)fpconnection;
  60. - (void)onDisconnect:(FPersistentConnection *)fpconnection;
  61. - (void)onServerInfoUpdate:(FPersistentConnection *)fpconnection updates:(NSDictionary *)updates;
  62. @end