FOperationSource.m 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "FOperationSource.h"
  17. #import "FPath.h"
  18. #import "FQueryParams.h"
  19. @interface FOperationSource ()
  20. @property(nonatomic, readwrite) BOOL fromUser;
  21. @property(nonatomic, readwrite) BOOL fromServer;
  22. @property(nonatomic, readwrite) BOOL isTagged;
  23. @property(nonatomic, strong, readwrite) FQueryParams *queryParams;
  24. @end
  25. @implementation FOperationSource
  26. @synthesize fromUser;
  27. @synthesize fromServer;
  28. @synthesize queryParams;
  29. - (id)initWithFromUser:(BOOL)isFromUser
  30. fromServer:(BOOL)isFromServer
  31. queryParams:(FQueryParams *)params
  32. tagged:(BOOL)tagged {
  33. self = [super init];
  34. if (self) {
  35. self.fromUser = isFromUser;
  36. self.fromServer = isFromServer;
  37. self.queryParams = params;
  38. self.isTagged = tagged;
  39. }
  40. return self;
  41. }
  42. + (FOperationSource *)userInstance {
  43. static FOperationSource *user = nil;
  44. static dispatch_once_t userToken;
  45. dispatch_once(&userToken, ^{
  46. user = [[FOperationSource alloc] initWithFromUser:YES
  47. fromServer:NO
  48. queryParams:nil
  49. tagged:NO];
  50. });
  51. return user;
  52. }
  53. + (FOperationSource *)serverInstance {
  54. static FOperationSource *server = nil;
  55. static dispatch_once_t serverToken;
  56. dispatch_once(&serverToken, ^{
  57. server = [[FOperationSource alloc] initWithFromUser:NO
  58. fromServer:YES
  59. queryParams:nil
  60. tagged:NO];
  61. });
  62. return server;
  63. }
  64. + (FOperationSource *)forServerTaggedQuery:(FQueryParams *)params {
  65. return [[FOperationSource alloc] initWithFromUser:NO
  66. fromServer:YES
  67. queryParams:params
  68. tagged:YES];
  69. }
  70. - (NSString *)description {
  71. return [NSString stringWithFormat:@"FOperationSource { fromUser=%d, "
  72. @"fromServer=%d, queryId=%@, tagged=%d }",
  73. self.fromUser, self.fromServer,
  74. self.queryParams, self.isTagged];
  75. }
  76. @end