00001 /* 00002 File: TaskWrapper.h 00003 00004 Description: This class is a generalized process handling class that makes asynchronous interaction with an NSTask easier. There is also a protocol designed to work in conjunction with the TaskWrapper class; your process controller should conform to this protocol. TaskWrapper objects are one-shot (since NSTask is one-shot); if you need to run a task more than once, destroy/create new TaskWrapper objects. 00005 00006 Author: EP & MCF 00007 00008 Copyright: © Copyright 2002 Apple Computer, Inc. All rights reserved. 00009 00010 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. 00011 ("Apple") in consideration of your agreement to the following terms, and your 00012 use, installation, modification or redistribution of this Apple software 00013 constitutes acceptance of these terms. If you do not agree with these terms, 00014 please do not use, install, modify or redistribute this Apple software. 00015 00016 In consideration of your agreement to abide by the following terms, and subject 00017 to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs 00018 copyrights in this original Apple software (the "Apple Software"), to use, 00019 reproduce, modify and redistribute the Apple Software, with or without 00020 modifications, in source and/or binary forms; provided that if you redistribute 00021 the Apple Software in its entirety and without modifications, you must retain 00022 this notice and the following text and disclaimers in all such redistributions of 00023 the Apple Software. Neither the name, trademarks, service marks or logos of 00024 Apple Computer, Inc. may be used to endorse or promote products derived from the 00025 Apple Software without specific prior written permission from Apple. Except as 00026 expressly stated in this notice, no other rights or licenses, express or implied, 00027 are granted by Apple herein, including but not limited to any patent rights that 00028 may be infringed by your derivative works or by other works in which the Apple 00029 Software may be incorporated. 00030 00031 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO 00032 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 00033 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00034 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 00035 COMBINATION WITH YOUR PRODUCTS. 00036 00037 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 00038 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00039 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00040 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION 00041 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT 00042 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN 00043 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00044 00045 */ 00046 00047 00048 #import <Foundation/Foundation.h> 00049 00050 @protocol TaskWrapperController 00051 00052 // Your controller's implementation of this method will be called when output arrives from the NSTask. 00053 // Output will come from both stdout and stderr, per the TaskWrapper implementation. 00054 - (void)appendOutput:(NSString *)output fromTask:(id) task; 00055 00056 // This method is a callback which your controller can use to do other initialization when a process 00057 // is launched. 00058 - (void)processStarted:(id)task; 00059 00060 // This method is a callback which your controller can use to do other cleanup when a process 00061 // is halted. 00062 - (void)processFinished:(id)task; 00063 00064 @end 00065 00066 @interface TaskWrapper : NSObject { 00067 NSTask *task; 00068 id <TaskWrapperController>controller; 00069 NSArray *arguments; 00070 } 00071 00072 // This is the designated initializer - pass in your controller and any task arguments. 00073 // The first argument should be the path to the executable to launch with the NSTask. 00074 - (id)initWithController:(id <TaskWrapperController>)controller arguments:(NSArray *)args; 00075 00076 // This method launches the process, setting up asynchronous feedback notifications. 00077 - (void) startProcess; 00078 00079 // This method stops the process, stoping asynchronous feedback notifications. 00080 - (void) stopProcess; 00081 00082 @end 00083