FOperationSource.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 fromServer:(BOOL)isFromServer queryParams:(FQueryParams *)params tagged:(BOOL)tagged {
  30. self = [super init];
  31. if (self) {
  32. self.fromUser = isFromUser;
  33. self.fromServer = isFromServer;
  34. self.queryParams = params;
  35. self.isTagged = tagged;
  36. }
  37. return self;
  38. }
  39. + (FOperationSource *) userInstance {
  40. static FOperationSource *user = nil;
  41. static dispatch_once_t userToken;
  42. dispatch_once(&userToken, ^{
  43. user = [[FOperationSource alloc] initWithFromUser:YES fromServer:NO queryParams:nil tagged:NO];
  44. });
  45. return user;
  46. }
  47. + (FOperationSource *) serverInstance {
  48. static FOperationSource *server = nil;
  49. static dispatch_once_t serverToken;
  50. dispatch_once(&serverToken, ^{
  51. server = [[FOperationSource alloc] initWithFromUser:NO fromServer:YES queryParams:nil tagged:NO];
  52. });
  53. return server;
  54. }
  55. + (FOperationSource *) forServerTaggedQuery:(FQueryParams *)params {
  56. return [[FOperationSource alloc] initWithFromUser:NO fromServer:YES queryParams:params tagged:YES];
  57. }
  58. - (NSString *) description {
  59. return [NSString stringWithFormat:@"FOperationSource { fromUser=%d, fromServer=%d, queryId=%@, tagged=%d }",
  60. self.fromUser, self.fromServer, self.queryParams, self.isTagged];
  61. }
  62. @end