OSDN Git Service

bump ffmpeg from git-185a155 to git-0b32da9
[handbrake-jp/handbrake-jp-git.git] / macosx / HBOutputRedirect.h
1 /**
2  * @file
3  * @date 17.5.2007
4  *
5  * Interface of class HBOutputRedirect.
6  */
7
8 #import <Cocoa/Cocoa.h>
9
10 /**
11  * This class is used to redirect @c stdout and @c stderr outputs. It is never
12  * created directly; @c stdoutRedirect and @c stderrRedirect class methods
13  * should be use instead.
14  *
15  * @note Redirection is done by replacing @c _write functions for @c stdout and
16  *               @c stderr streams. Because of this messages written by NSLog(), for
17  *               example are not redirected. I consider this a good thing, but if more
18  *               universal redirecting is needed, it can be done at file descriptor
19  *               level.
20  */
21 @interface HBOutputRedirect : NSObject
22 {
23         /// Set that contains all registered listeners for this output.
24         NSMutableSet *listeners;
25         
26         /// Selector that is called on listeners to forward the output.
27         SEL forwardingSelector;
28
29         /// Output stream (@c stdout or @c stderr) redirected by this object.
30         FILE *stream;
31         
32         /// Pointer to old write function for the stream.
33         int     (*oldWriteFunc)(void *, const char *, int);
34         
35         NSLock *lock;
36 }
37
38 + (id)stdoutRedirect;
39 + (id)stderrRedirect;
40
41 - (void)addListener:(id)aListener;
42 - (void)removeListener:(id)aListener;
43
44 @end
45
46 /* Here is another technique to redirect stderr, but it is done at lower level
47    which also redirects NSLog() and other writes that are done directly to the
48    file descriptor. This method is not used by HBOutputRedirect, but should
49    be easy to implement if needed. Code is untested, but this is shows basic 
50    idea for future reference.
51
52         // Create a pipe
53         NSPipe *pipe = [[NSPipe alloc] init];
54
55         // Connect stderr to the writing end of the pipe
56         dup2([[pipe fileHandleForWriting] fileDescriptor], STDERR_FILENO);      
57         
58         // Get reading end of the pipe, we can use this to read stderr
59         NSFileHandle *fh = [pipe fileHandleForReading];
60 */