FIRFirestoreSettings.mm 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "FIRFirestoreSettings.h"
  17. #import "Firestore/Source/Util/FSTUsageValidation.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. static NSString *const kDefaultHost = @"firestore.googleapis.com";
  20. static const BOOL kDefaultSSLEnabled = YES;
  21. static const BOOL kDefaultPersistenceEnabled = YES;
  22. // TODO(b/73820332): flip the default.
  23. static const BOOL kDefaultTimestampsInSnapshotsEnabled = NO;
  24. @implementation FIRFirestoreSettings
  25. - (instancetype)init {
  26. if (self = [super init]) {
  27. _host = kDefaultHost;
  28. _sslEnabled = kDefaultSSLEnabled;
  29. _dispatchQueue = dispatch_get_main_queue();
  30. _persistenceEnabled = kDefaultPersistenceEnabled;
  31. _timestampsInSnapshotsEnabled = kDefaultTimestampsInSnapshotsEnabled;
  32. }
  33. return self;
  34. }
  35. - (BOOL)isEqual:(id)other {
  36. if (self == other) {
  37. return YES;
  38. } else if (![other isKindOfClass:[FIRFirestoreSettings class]]) {
  39. return NO;
  40. }
  41. FIRFirestoreSettings *otherSettings = (FIRFirestoreSettings *)other;
  42. return [self.host isEqual:otherSettings.host] &&
  43. self.isSSLEnabled == otherSettings.isSSLEnabled &&
  44. self.dispatchQueue == otherSettings.dispatchQueue &&
  45. self.isPersistenceEnabled == otherSettings.isPersistenceEnabled &&
  46. self.timestampsInSnapshotsEnabled == otherSettings.timestampsInSnapshotsEnabled;
  47. }
  48. - (NSUInteger)hash {
  49. NSUInteger result = [self.host hash];
  50. result = 31 * result + (self.isSSLEnabled ? 1231 : 1237);
  51. // Ignore the dispatchQueue to avoid having to deal with sizeof(dispatch_queue_t).
  52. result = 31 * result + (self.isPersistenceEnabled ? 1231 : 1237);
  53. result = 31 * result + (self.timestampsInSnapshotsEnabled ? 1231 : 1237);
  54. return result;
  55. }
  56. - (id)copyWithZone:(nullable NSZone *)zone {
  57. FIRFirestoreSettings *copy = [[FIRFirestoreSettings alloc] init];
  58. copy.host = _host;
  59. copy.sslEnabled = _sslEnabled;
  60. copy.dispatchQueue = _dispatchQueue;
  61. copy.persistenceEnabled = _persistenceEnabled;
  62. copy.timestampsInSnapshotsEnabled = _timestampsInSnapshotsEnabled;
  63. return copy;
  64. }
  65. - (void)setHost:(NSString *)host {
  66. if (!host) {
  67. FSTThrowInvalidArgument(
  68. @"host setting may not be nil. You should generally just use the default value "
  69. "(which is %@)",
  70. kDefaultHost);
  71. }
  72. _host = [host mutableCopy];
  73. }
  74. - (void)setDispatchQueue:(dispatch_queue_t)dispatchQueue {
  75. if (!dispatchQueue) {
  76. FSTThrowInvalidArgument(
  77. @"dispatch queue setting may not be nil. Create a new dispatch queue with "
  78. "dispatch_queue_create(\"com.example.MyQueue\", NULL) or just use the default "
  79. "(which is the main queue, returned from dispatch_get_main_queue())");
  80. }
  81. _dispatchQueue = dispatchQueue;
  82. }
  83. @end
  84. NS_ASSUME_NONNULL_END