/Foundation/CPInvocationOperation.j

http://github.com/cacaodev/cappuccino · Unknown · 104 lines · 91 code · 13 blank · 0 comment · 0 complexity · cc0ccbf8de589e14acb2e8965cd10b4a MD5 · raw file

  1. /*
  2. * CPInvocationOperation.j
  3. *
  4. * Created by Johannes Fahrenkrug.
  5. * Copyright 2009, Springenwerk.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. @import "CPInvocation.j"
  22. @import "CPObject.j"
  23. @import "CPOperation.j"
  24. /*!
  25. @class CPInvocationOperation
  26. @brief Represents an operation using an invocation that can be run in an CPOperationQueue
  27. */
  28. @implementation CPInvocationOperation : CPOperation
  29. {
  30. CPInvocation _invocation;
  31. }
  32. - (void)main
  33. {
  34. if (_invocation)
  35. {
  36. [_invocation invoke];
  37. }
  38. }
  39. - (id)init
  40. {
  41. if (self = [super init])
  42. {
  43. _invocation = nil;
  44. }
  45. return self;
  46. }
  47. /*!
  48. Returns a CPInvocationOperation object initialized with the specified invocation object.
  49. @param inv the invocation
  50. */
  51. - (id)initWithInvocation:(CPInvocation)inv
  52. {
  53. if (self = [self init])
  54. {
  55. _invocation = inv;
  56. }
  57. return self;
  58. }
  59. /*!
  60. Returns a CPInvocationOperation object initialized with the specified target and selector.
  61. @param target the target
  62. @param sel the selector that should be called on the target
  63. @param arg the arguments
  64. */
  65. - (id)initWithTarget:(id)target selector:(SEL)sel object:(id)arg
  66. {
  67. var inv = [[CPInvocation alloc] initWithMethodSignature:nil];
  68. [inv setTarget:target];
  69. [inv setSelector:sel];
  70. [inv setArgument:arg atIndex:2];
  71. return [self initWithInvocation:inv];
  72. }
  73. /*!
  74. Returns the receiver’s invocation object.
  75. */
  76. - (CPInvocation)invocation
  77. {
  78. return _invocation;
  79. }
  80. /*!
  81. Returns the result of the invocation or method.
  82. */
  83. - (id)result
  84. {
  85. if ([self isFinished] && _invocation)
  86. {
  87. return [_invocation returnValue];
  88. }
  89. return nil;
  90. }
  91. @end