2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 // Created by Helge Hess on Mon Mar 11 2002.
23 #if !LIB_FOUNDATION_LIBRARY
26 #include "NSRunLoop+FileObjects.h"
27 #include "FileObjectHolder.h"
28 #import <Foundation/NSMapTable.h>
29 #import <Foundation/NSNotification.h>
32 NSString *NSFileObjectBecameActiveNotificationName =
33 @"NSFileObjectBecameActiveNotification";
35 #if GNUSTEP_BASE_LIBRARY
37 @interface NSObject(FileObjectWatcher) < RunLoopEvents >
40 @implementation NSObject(FileObjectWatcher)
42 - (NSDate *)timedOutEvent:(void *)_fdData
43 type: (RunLoopEventType)_type
44 forMode: (NSString *)_mode
46 NSLog(@"%s: timed out ...", __PRETTY_FUNCTION__);
50 - (void)receivedEvent:(void *)_fdData
51 type:(RunLoopEventType)_type
53 forMode:(NSString *)_mode
55 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
57 [nc postNotificationName:NSFileObjectBecameActiveNotificationName
61 @end /* NSObject(FileObjectWatcher) */
65 @implementation NSRunLoop(FileObjects)
67 #if GNUSTEP_BASE_LIBRARY
69 /* implement using -addEvent:type:watcher:forMode: */
71 - (void)addFileObject:(id)_fileObject
72 activities:(unsigned int)_activities
73 forMode:(NSString *)_mode
77 _fileObject = RETAIN(_fileObject);
79 [self addEvent:(void *)[_fileObject fileDescriptor]
84 - (void)removeFileObject:(id)_fileObject
85 forMode:(NSString *)_mode
89 _fileObject = AUTORELEASE(_fileObject);
90 [self removeEvent:(void *)[_fileObject fileDescriptor]
96 #else /* eg MacOSX Foundation ... */
98 static NSMutableArray *activeHandles = nil;
100 - (void)addFileObject:(id)_fileObject
101 activities:(unsigned int)_activities
102 forMode:(NSString *)_mode
104 FileObjectHolder *fo;
106 if (activeHandles == nil)
107 activeHandles = [[NSMutableArray alloc] init];
109 fo = [[FileObjectHolder alloc] initWithFileObject:_fileObject
110 activities:_activities
112 [activeHandles addObject:fo];
117 - (FileObjectHolder *)_findHolderForObject:(id)_fileObject {
119 FileObjectHolder *fo;
121 if (activeHandles == nil) return NULL;
122 e = [activeHandles objectEnumerator];
123 while ((fo = [e nextObject])) {
124 if ([fo fileObject] == _fileObject)
130 - (void)removeFileObject:(id)_fileObject
131 forMode:(NSString *)_mode
133 FileObjectHolder *fo;
135 if ((fo = [self _findHolderForObject:_fileObject]) == nil) {
136 NSLog(@"found no holder for fileobject %@ ...", _fileObject);
141 [activeHandles removeObject:fo];
146 #endif /* !GNUSTEP_BASE_LIBRARY */
148 @end /* NSRunLoop(FileObjects) */
150 #endif /* !LIB_FOUNDATION_LIBRARY */