/core/externals/update-engine/Common/KSAction.m

http://macfuse.googlecode.com/ · Objective C · 93 lines · 54 code · 17 blank · 22 comment · 6 complexity · e6216b88c384578eabf94e12c5fd049f MD5 · raw file

  1. // Copyright 2008 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "KSAction.h"
  15. #import "KSActionProcessor.h"
  16. #import "KSActionPipe.h"
  17. #import "GTMDefines.h"
  18. #import "GTMLogger.h"
  19. @implementation KSAction
  20. - (id)init {
  21. if ((self = [super init])) {
  22. [self setInPipe:nil];
  23. [self setOutPipe:nil];
  24. }
  25. return self;
  26. }
  27. - (void)dealloc {
  28. [processor_ release];
  29. [inpipe_ release];
  30. [outpipe_ release];
  31. [super dealloc];
  32. }
  33. - (KSActionProcessor *)processor {
  34. return [[processor_ retain] autorelease];
  35. }
  36. - (void)setProcessor:(KSActionProcessor *)processor {
  37. [processor_ autorelease];
  38. processor_ = [processor retain];
  39. }
  40. - (KSActionPipe *)inPipe {
  41. return [[inpipe_ retain] autorelease];
  42. }
  43. - (void)setInPipe:(KSActionPipe *)inpipe {
  44. [inpipe_ autorelease];
  45. inpipe_ = [inpipe retain];
  46. if (inpipe_ == nil) // Never let inpipe be nil
  47. inpipe_ = [[KSActionPipe alloc] init];
  48. }
  49. - (KSActionPipe *)outPipe {
  50. return [[outpipe_ retain] autorelease];
  51. }
  52. - (void)setOutPipe:(KSActionPipe *)outpipe {
  53. [outpipe_ autorelease];
  54. outpipe_ = [outpipe retain];
  55. if (outpipe_ == nil) // Never let outpipe be nil
  56. outpipe_ = [[KSActionPipe alloc] init];
  57. }
  58. - (BOOL)isRunning {
  59. return [[self processor] currentAction] == self;
  60. }
  61. // COV_NF_START
  62. - (void)performAction {
  63. // Subclasses must override this method, otherwise their actions will be
  64. // useless.
  65. // If this method is not overridden, we'll _GTMDevAssert so that debug builds
  66. // break, but in Release builds we'll just log and tell the processor that
  67. // we're done so it doesn't hang.
  68. _GTMDevAssert(NO, @"-performAction: method not overridden");
  69. [processor_ finishedProcessing:self successfully:NO];
  70. }
  71. // COV_NF_END
  72. - (void)terminateAction {
  73. // Do nothing. Subclasses may optionally override this method if they need to
  74. // do special cleanup when their action is being terminated.
  75. }
  76. @end