FKeepSyncedEventRegistration.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/Core/View/FKeepSyncedEventRegistration.h"
  17. @interface FKeepSyncedEventRegistration ()
  18. @end
  19. @implementation FKeepSyncedEventRegistration
  20. + (FKeepSyncedEventRegistration *)instance {
  21. static dispatch_once_t onceToken;
  22. static FKeepSyncedEventRegistration *keepSynced;
  23. dispatch_once(&onceToken, ^{
  24. keepSynced = [[FKeepSyncedEventRegistration alloc] init];
  25. });
  26. return keepSynced;
  27. }
  28. - (BOOL)responseTo:(FIRDataEventType)eventType {
  29. return NO;
  30. }
  31. - (FDataEvent *)createEventFrom:(FChange *)change query:(FQuerySpec *)query {
  32. [NSException
  33. raise:NSInternalInconsistencyException
  34. format:@"Should never create event for FKeepSyncedEventRegistration"];
  35. return nil;
  36. }
  37. - (void)fireEvent:(id<FEvent>)event queue:(dispatch_queue_t)queue {
  38. [NSException
  39. raise:NSInternalInconsistencyException
  40. format:@"Should never raise event for FKeepSyncedEventRegistration"];
  41. }
  42. - (FCancelEvent *)createCancelEventFromError:(NSError *)error
  43. path:(FPath *)path {
  44. // Don't create cancel events....
  45. return nil;
  46. }
  47. - (FIRDatabaseHandle)handle {
  48. // TODO[offline]: returning arbitrary, can't return NSNotFound since that is
  49. // used to match other event registrations We should really redo this to
  50. // match on different kind of events (single observer, all observers,
  51. // cancelled) rather than on a NSNotFound handle...
  52. return NSNotFound - 1;
  53. }
  54. - (BOOL)matches:(id<FEventRegistration>)other {
  55. // Only matches singleton instance
  56. return self == other;
  57. }
  58. @end