FKeepSyncedEventRegistration.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "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 raise:NSInternalInconsistencyException format:@"Should never create event for FKeepSyncedEventRegistration"];
  33. return nil;
  34. }
  35. - (void) fireEvent:(id<FEvent>)event queue:(dispatch_queue_t)queue {
  36. [NSException raise:NSInternalInconsistencyException format:@"Should never raise event for FKeepSyncedEventRegistration"];
  37. }
  38. - (FCancelEvent *) createCancelEventFromError:(NSError *)error path:(FPath *)path {
  39. // Don't create cancel events....
  40. return nil;
  41. }
  42. - (FIRDatabaseHandle) handle {
  43. // TODO[offline]: returning arbitray, can't return NSNotFound since that is used to match other event registrations
  44. // We should really redo this to match on different kind of events (single observer, all observers, cancelled)
  45. // rather than on a NSNotFound handle...
  46. return NSNotFound - 1;
  47. }
  48. - (BOOL) matches:(id<FEventRegistration>)other {
  49. // Only matches singleton instance
  50. return self == other;
  51. }
  52. @end