/core/externals/update-engine/Core/KSCommandRunner.h

http://macfuse.googlecode.com/ · C Header · 71 lines · 15 code · 9 blank · 47 comment · 0 complexity · 958f39d8b06060c34d1f762b89f9810a 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 <Foundation/Foundation.h>
  15. // KSCommandRunner
  16. //
  17. // Protocol that defines the methods that must be implemented by any object that
  18. // can act as a "command runner". A command runner object is an object that can
  19. // run a command for you, and return you the results.
  20. @protocol KSCommandRunner <NSObject>
  21. // This method runs the command at |path|, with the specified |args| and |env|,
  22. // and return the commands output in |*output| and the command's return code as
  23. // the return value of this method.
  24. //
  25. // Args:
  26. // path - the full path of the command to be executed
  27. // args - an array of arguments to give to the command; may be nil
  28. // env - a dictionary of environment variables to be set; may be nil
  29. // output - returns the command's output; may not be nil. Don't even try it.
  30. // Why? Tiger gets confused sending a nil NSString **.
  31. // Passing nil on the server side leads to the client
  32. // actually getting passed a non-nil pointer to an
  33. // NSString. This **pointer gets an NSString assigned
  34. // to it, which then causes DO to crash deep in its guts
  35. // on the client side trying to return the value.
  36. // stdError - returns text emitted from standard error. Like for output,
  37. // don't pass nil.
  38. //
  39. // Returns:
  40. // The return code is the return code from the command, and |output| will be
  41. // filled in with the command's output. |stderror| will be filled in with
  42. // the command's standard error.
  43. - (int)runCommand:(NSString *)path
  44. withArgs:(NSArray *)args
  45. environment:(NSDictionary *)env
  46. output:(NSString **)output
  47. stdError:(NSString **)stderror;
  48. // Simpler version that doesn't return standard error.
  49. - (int)runCommand:(NSString *)path
  50. withArgs:(NSArray *)args
  51. environment:(NSDictionary *)env
  52. output:(NSString **)output;
  53. @end
  54. // KSTaskCommandRunner
  55. //
  56. // This class is used to run external commands (via NSTask) with given args and
  57. // environment, and will return the standard output of the command along with
  58. // the command's return code.
  59. @interface KSTaskCommandRunner : NSObject <KSCommandRunner>
  60. // Returns an autoreleased KSCommandRunner instance
  61. + (id)commandRunner;
  62. @end