1996-03-19 02:02:52 +00:00
|
|
|
|
/* Interface for NSRunLoop for GNUStep
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1996-03-19 02:02:52 +00:00
|
|
|
|
Created: March 1996
|
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1996-03-19 02:02:52 +00:00
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1996-03-19 02:02:52 +00:00
|
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
1996-03-19 02:02:52 +00:00
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1996-03-19 02:02:52 +00:00
|
|
|
|
License along with this library; if not, write to the Free
|
2006-03-07 09:14:37 +00:00
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
Boston, MA 02111 USA.
|
1996-03-19 02:02:52 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
|
#ifndef __NSRunLoop_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
|
#define __NSRunLoop_h_GNUSTEP_BASE_INCLUDE
|
2006-10-31 07:05:46 +00:00
|
|
|
|
#import <GNUstepBase/GSVersionMacros.h>
|
1996-03-19 02:02:52 +00:00
|
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
|
#import <Foundation/NSMapTable.h>
|
1996-03-19 02:02:52 +00:00
|
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
@class NSTimer, NSDate, NSPort;
|
1996-03-19 02:02:52 +00:00
|
|
|
|
|
2004-07-29 15:30:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* Run loop mode used to deal with input sources other than NSConnections or
|
|
|
|
|
* dialog windows. Most commonly used. Defined in
|
|
|
|
|
* <code>Foundation/NSRunLoop.h</code>.
|
|
|
|
|
*/
|
2002-06-06 14:02:59 +00:00
|
|
|
|
GS_EXPORT NSString * const NSDefaultRunLoopMode;
|
1996-03-19 02:02:52 +00:00
|
|
|
|
|
2009-01-12 18:36:37 +00:00
|
|
|
|
@interface NSRunLoop : NSObject
|
1997-09-01 21:59:51 +00:00
|
|
|
|
{
|
2010-02-14 10:48:10 +00:00
|
|
|
|
#if GS_EXPOSE(NSRunLoop)
|
1999-04-19 14:29:52 +00:00
|
|
|
|
@private
|
2002-01-30 15:28:50 +00:00
|
|
|
|
NSString *_currentMode;
|
|
|
|
|
NSMapTable *_contextMap;
|
|
|
|
|
NSMutableArray *_contextStack;
|
|
|
|
|
NSMutableArray *_timedPerformers;
|
|
|
|
|
void *_extra;
|
2010-02-14 10:48:10 +00:00
|
|
|
|
#endif
|
1997-09-01 21:59:51 +00:00
|
|
|
|
}
|
1996-03-19 02:02:52 +00:00
|
|
|
|
|
2013-12-20 10:18:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the run loop instance for the current thread.
|
|
|
|
|
*/
|
1996-03-19 02:02:52 +00:00
|
|
|
|
+ (NSRunLoop*) currentRunLoop;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2013-12-20 10:18:12 +00:00
|
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5,GS_API_LATEST)
|
|
|
|
|
/**
|
|
|
|
|
* Returns the run loop instance of the main thread.
|
|
|
|
|
*/
|
|
|
|
|
+ (NSRunLoop*) mainRunLoop;
|
|
|
|
|
#endif
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void) acceptInputForMode: (NSString*)mode
|
2001-12-17 14:31:42 +00:00
|
|
|
|
beforeDate: (NSDate*)limit_date;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
- (void) addTimer: (NSTimer*)timer
|
|
|
|
|
forMode: (NSString*)mode;
|
|
|
|
|
|
1996-03-19 02:02:52 +00:00
|
|
|
|
- (NSString*) currentMode;
|
|
|
|
|
|
2002-01-30 15:28:50 +00:00
|
|
|
|
- (NSDate*) limitDateForMode: (NSString*)mode;
|
1996-03-19 02:02:52 +00:00
|
|
|
|
|
|
|
|
|
- (void) run;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
2013-12-20 13:32:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* Calls -limitDateForMode: to determine if a timeout occurs before the
|
|
|
|
|
* specified date, then calls -acceptInputForMode:beforeDate: to run the
|
|
|
|
|
* loop once.<br />
|
|
|
|
|
* The specified date may be nil ... in which case the loop runs
|
|
|
|
|
* until the limit date of the first input or timeout.<br />
|
|
|
|
|
* If the specified date is in the past, this runs the loop once only,
|
|
|
|
|
* to handle any events already available.<br />
|
|
|
|
|
* If there are no input sources or timers in mode, this method
|
|
|
|
|
* returns NO without running the loop (irrespective of the supplied
|
|
|
|
|
* date argument), otherwise returns YES.
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (BOOL) runMode: (NSString*)mode
|
|
|
|
|
beforeDate: (NSDate*)date;
|
|
|
|
|
|
2001-12-17 14:31:42 +00:00
|
|
|
|
- (void) runUntilDate: (NSDate*)date;
|
1996-03-19 02:02:52 +00:00
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
@interface NSRunLoop(OPENSTEP)
|
|
|
|
|
|
|
|
|
|
- (void) addPort: (NSPort*)port
|
|
|
|
|
forMode: (NSString*)mode;
|
|
|
|
|
|
2002-08-27 14:24:54 +00:00
|
|
|
|
- (void) cancelPerformSelectorsWithTarget: (id)target;
|
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void) cancelPerformSelector: (SEL)aSelector
|
2002-01-30 15:28:50 +00:00
|
|
|
|
target: (id)target
|
|
|
|
|
argument: (id)argument;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
|
|
|
|
|
- (void) configureAsServer;
|
|
|
|
|
|
|
|
|
|
- (void) performSelector: (SEL)aSelector
|
2002-01-30 15:28:50 +00:00
|
|
|
|
target: (id)target
|
|
|
|
|
argument: (id)argument
|
2009-02-23 20:42:32 +00:00
|
|
|
|
order: (NSUInteger)order
|
1997-09-01 21:59:51 +00:00
|
|
|
|
modes: (NSArray*)modes;
|
|
|
|
|
|
|
|
|
|
- (void) removePort: (NSPort*)port
|
|
|
|
|
forMode: (NSString*)mode;
|
|
|
|
|
|
|
|
|
|
@end
|
1996-04-10 18:21:12 +00:00
|
|
|
|
|
2012-07-10 06:58:54 +00:00
|
|
|
|
/** This type specifies the kinds of event which may be 'watched' in a
|
|
|
|
|
* run loop.
|
2004-07-29 15:30:47 +00:00
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
typedef enum {
|
2010-03-19 12:10:11 +00:00
|
|
|
|
#ifdef __MINGW__
|
2005-10-30 10:42:42 +00:00
|
|
|
|
ET_HANDLE, /* Watch for an I/O event on a handle. */
|
|
|
|
|
ET_RPORT, /* Watch for message arriving on port. */
|
|
|
|
|
ET_WINMSG, /* Watch for a message on a window handle. */
|
2006-03-21 15:33:05 +00:00
|
|
|
|
ET_TRIGGER /* Trigger immediately when the loop runs. */
|
2005-02-23 16:05:09 +00:00
|
|
|
|
#else
|
2002-01-30 15:28:50 +00:00
|
|
|
|
ET_RDESC, /* Watch for descriptor becoming readable. */
|
|
|
|
|
ET_WDESC, /* Watch for descriptor becoming writeable. */
|
2005-03-07 01:11:38 +00:00
|
|
|
|
ET_RPORT, /* Watch for message arriving on port. */
|
2006-03-07 09:14:37 +00:00
|
|
|
|
ET_EDESC, /* Watch for descriptor with out-of-band data. */
|
2006-03-21 15:33:05 +00:00
|
|
|
|
ET_TRIGGER /* Trigger immediately when the loop runs. */
|
2005-03-07 01:11:38 +00:00
|
|
|
|
#endif
|
1997-09-01 21:59:51 +00:00
|
|
|
|
} RunLoopEventType;
|
2012-07-10 06:58:54 +00:00
|
|
|
|
|
|
|
|
|
/** This protocol defines the mandatory interface a run loop watcher must
|
|
|
|
|
* provide in order for it to be notified of events occurring in the loop
|
|
|
|
|
* it is watching.<br />
|
|
|
|
|
* Optional methods are documented in the NSObject(RunLoopEvents)
|
|
|
|
|
* category.
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
@protocol RunLoopEvents
|
2012-07-10 06:58:54 +00:00
|
|
|
|
/** This is the message sent back to a watcher when an event is observed
|
|
|
|
|
* by the run loop.<br />
|
2009-06-19 20:19:55 +00:00
|
|
|
|
* The 'data', 'type' and 'mode' arguments are the same as the arguments
|
2012-07-10 06:58:54 +00:00
|
|
|
|
* passed to the -addEvent:type:watcher:forMode: method.<br />
|
2009-06-19 20:19:55 +00:00
|
|
|
|
* The 'extra' argument varies. For an ET_TRIGGER event, it is the same
|
|
|
|
|
* as the 'data' argument. For other events on unix it is the file
|
|
|
|
|
* descriptor associated with the event (which may be the same as the
|
2012-07-10 06:58:54 +00:00
|
|
|
|
* 'data' argument, but is not in the case of ET_RPORT).<br />
|
2009-06-19 20:19:55 +00:00
|
|
|
|
* For windows it will be the handle or the windows message assciated
|
|
|
|
|
* with the event.
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void) receivedEvent: (void*)data
|
|
|
|
|
type: (RunLoopEventType)type
|
|
|
|
|
extra: (void*)extra
|
|
|
|
|
forMode: (NSString*)mode;
|
|
|
|
|
@end
|
2012-07-10 06:58:54 +00:00
|
|
|
|
|
|
|
|
|
/** This informal protocol defiens optional methods of the run loop watcher.
|
|
|
|
|
*/
|
2008-04-17 07:53:46 +00:00
|
|
|
|
@interface NSObject (RunLoopEvents)
|
2012-07-10 06:58:54 +00:00
|
|
|
|
/** Called by the run loop to find out whether it needs to block to wait
|
|
|
|
|
* for events for this watcher. The shouldTrigger flag is used to inform
|
|
|
|
|
* the run loop if tit should immediately trigger a received event for the
|
|
|
|
|
* watcher.
|
|
|
|
|
*/
|
2008-04-17 07:53:46 +00:00
|
|
|
|
- (BOOL) runLoopShouldBlock: (BOOL*)shouldTrigger;
|
|
|
|
|
@end
|
2012-07-10 06:58:54 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The run loop watcher API was originally intended to perform two
|
|
|
|
|
* tasks ...
|
|
|
|
|
* 1. provide the most efficient API reasonably possible to integrate
|
|
|
|
|
* unix networking code into the runloop.
|
|
|
|
|
* 2. provide a standard mechanism to allow people to contribute
|
|
|
|
|
* code to add new I/O mechanisms to GNUstep (OpenStep didn't allow this).
|
|
|
|
|
* It succeeded in 1, and partially succeeded in 2 (adding support
|
|
|
|
|
* for the win32 API).
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
@interface NSRunLoop(GNUstepExtensions)
|
2012-07-10 06:58:54 +00:00
|
|
|
|
/** Adds a watcher to the receiver ... the watcher is used to monitor events
|
|
|
|
|
* of the specified type which are associted with the event handle data and
|
|
|
|
|
* it operates in the specified run loop modes.<br />
|
|
|
|
|
* The watcher remains in place until a corresponding call to
|
|
|
|
|
* -removeEvent:type:forMode:all: is made.
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void) addEvent: (void*)data
|
|
|
|
|
type: (RunLoopEventType)type
|
|
|
|
|
watcher: (id<RunLoopEvents>)watcher
|
|
|
|
|
forMode: (NSString*)mode;
|
2012-07-10 06:58:54 +00:00
|
|
|
|
/** Removes a watcher from the receiver ... the watcher must have been
|
|
|
|
|
* previously added using -addEvent:type:watcher:forMode:<br />
|
|
|
|
|
* This method mirrors exactly one addition of a watcher unless removeAll
|
|
|
|
|
* is YES, in which case it removes all additions of watchers matching the
|
|
|
|
|
* other paramters.
|
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
- (void) removeEvent: (void*)data
|
|
|
|
|
type: (RunLoopEventType)type
|
1997-09-09 15:30:24 +00:00
|
|
|
|
forMode: (NSString*)mode
|
|
|
|
|
all: (BOOL)removeAll;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
@end
|
|
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
|
#endif /*__NSRunLoop_h_GNUSTEP_BASE_INCLUDE */
|