ObjFW
OFRunLoop.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #import "OFString.h"
18 
19 #ifdef OF_AMIGAOS
20 # include <exec/types.h>
21 #endif
22 
23 OF_ASSUME_NONNULL_BEGIN
24 
27 @class OFSortedList OF_GENERIC(ObjectType);
28 #ifdef OF_HAVE_THREADS
29 @class OFMutex;
30 @class OFCondition;
31 #endif
32 #ifdef OF_HAVE_SOCKETS
34 #endif
35 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
36 @class OFTimer;
37 @class OFDate;
38 
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
51 #ifdef __cplusplus
52 }
53 #endif
54 
60 OF_SUBCLASSING_RESTRICTED
61 @interface OFRunLoop: OFObject
62 {
63  OFMutableDictionary *_states;
64 #ifdef OF_HAVE_THREADS
65  OFMutex *_statesMutex;
66 #endif
67  OFRunLoopMode _Nullable _currentMode;
68  volatile bool _stop;
69 }
70 
71 #ifdef OF_HAVE_CLASS_PROPERTIES
72 @property (class, readonly, nullable, nonatomic) OFRunLoop *mainRunLoop;
73 @property (class, readonly, nullable, nonatomic) OFRunLoop *currentRunLoop;
74 #endif
75 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFRunLoopMode currentMode;
76 
82 + (nullable OFRunLoop *)mainRunLoop;
83 
89 + (nullable OFRunLoop *)currentRunLoop;
90 
96 - (void)addTimer: (OFTimer *)timer;
97 
104 - (void)addTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode;
105 
106 #if defined(OF_AMIGAOS) || defined(DOXYGEN)
107 
121 - (void)addExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector;
122 
138 - (void)addExecSignal: (ULONG)signal
139  forMode: (OFRunLoopMode)mode
140  target: (id)target
141  selector: (SEL)selector;
142 
151 - (void)removeExecSignal: (ULONG)signal
152  target: (id)target
153  selector: (SEL)selector;
154 
164 - (void)removeExecSignal: (ULONG)signal
165  forMode: (OFRunLoopMode)mode
166  target: (id)target
167  selector: (SEL)selector;
168 #endif
169 
173 - (void)run;
174 
180 - (void)runUntilDate: (nullable OFDate *)deadline;
181 
189 - (void)runMode: (OFRunLoopMode)mode beforeDate: (nullable OFDate *)deadline;
190 
195 - (void)stop;
196 @end
197 
198 OF_ASSUME_NONNULL_END
A class for creating mutual exclusions.
Definition: OFMutex.h:32
A class for storing, accessing and comparing dates.
Definition: OFDate.h:29
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:37
The root class for all other classes inside ObjFW.
Definition: OFObject.h:686
A class which provides easy to use sorted double-linked lists.
Definition: OFSortedList.h:28
OFConstantString * OFRunLoopMode
A mode for an OFRunLoop.
Definition: OFRunLoop.h:37
A class for creating and firing timers.
Definition: OFTimer.h:44
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:42
A class that can observe multiple kernel events (e.g. streams being ready to read) at once...
Definition: OFKernelEventObserver.h:117
A class providing a run loop for the application and its processes.
Definition: OFRunLoop.h:61
A class implementing a condition variable for thread synchronization.
Definition: OFCondition.h:29
const OFRunLoopMode OFDefaultRunLoopMode
The default mode for an OFRunLoop.