2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 // Created by Helge Hess on Mon Mar 11 2002.
24 #if !LIB_FOUNDATION_LIBRARY
27 #include "NSRunLoop+FileObjects.h"
28 #include "FileObjectHolder.h"
29 #import <Foundation/NSMapTable.h>
30 #import <Foundation/NSNotification.h>
33 NSString *NSFileObjectBecameActiveNotificationName =
34 @"NSFileObjectBecameActiveNotification";
36 #if GNUSTEP_BASE_LIBRARY
38 @interface NSObject(FileObjectWatcher) < RunLoopEvents >
41 @implementation NSObject(FileObjectWatcher)
43 - (NSDate *)timedOutEvent:(void *)_fdData
44 type: (RunLoopEventType)_type
45 forMode: (NSString *)_mode
47 NSLog(@"%s: timed out ...", __PRETTY_FUNCTION__);
51 - (void)receivedEvent:(void *)_fdData
52 type:(RunLoopEventType)_type
54 forMode:(NSString *)_mode
56 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
58 [nc postNotificationName:NSFileObjectBecameActiveNotificationName
62 @end /* NSObject(FileObjectWatcher) */
66 @implementation NSRunLoop(FileObjects)
68 #if GNUSTEP_BASE_LIBRARY
70 /* implement using -addEvent:type:watcher:forMode: */
72 - (void)addFileObject:(id)_fileObject
73 activities:(unsigned int)_activities
74 forMode:(NSString *)_mode
78 _fileObject = RETAIN(_fileObject);
80 [self addEvent:(void *)[_fileObject fileDescriptor]
85 - (void)removeFileObject:(id)_fileObject
86 forMode:(NSString *)_mode
90 _fileObject = AUTORELEASE(_fileObject);
91 [self removeEvent:(void *)[_fileObject fileDescriptor]
97 #else /* eg MacOSX Foundation ... */
99 static NSMutableArray *activeHandles = nil;
101 - (void)addFileObject:(id)_fileObject
102 activities:(unsigned int)_activities
103 forMode:(NSString *)_mode
105 FileObjectHolder *fo;
107 if (activeHandles == nil)
108 activeHandles = [[NSMutableArray alloc] init];
110 fo = [[FileObjectHolder alloc] initWithFileObject:_fileObject
111 activities:_activities
113 [activeHandles addObject:fo];
118 - (FileObjectHolder *)_findHolderForObject:(id)_fileObject {
120 FileObjectHolder *fo;
122 if (activeHandles == nil) return NULL;
123 e = [activeHandles objectEnumerator];
124 while ((fo = [e nextObject])) {
125 if ([fo fileObject] == _fileObject)
131 - (void)removeFileObject:(id)_fileObject
132 forMode:(NSString *)_mode
134 FileObjectHolder *fo;
136 if ((fo = [self _findHolderForObject:_fileObject]) == nil) {
137 NSLog(@"found no holder for fileobject %@ ...", _fileObject);
142 [activeHandles removeObject:fo];
147 #endif /* !GNUSTEP_BASE_LIBRARY */
149 @end /* NSRunLoop(FileObjects) */
151 #endif /* !LIB_FOUNDATION_LIBRARY */