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 program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 #import "OFString.h"
22 
23 #ifdef OF_AMIGAOS
24 # include <exec/types.h>
25 #endif
26 
27 OF_ASSUME_NONNULL_BEGIN
28 
31 @class OFSortedList OF_GENERIC(ObjectType);
32 #ifdef OF_HAVE_THREADS
33 @class OFMutex;
34 @class OFCondition;
35 #endif
36 #ifdef OF_HAVE_SOCKETS
38 #endif
39 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
40 @class OFTimer;
41 @class OFDate;
42 
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
55 #ifdef __cplusplus
56 }
57 #endif
58 
64 OF_SUBCLASSING_RESTRICTED
65 @interface OFRunLoop: OFObject
66 {
67  OFMutableDictionary *_states;
68 #ifdef OF_HAVE_THREADS
69  OFMutex *_statesMutex;
70 #endif
71  OFRunLoopMode _Nullable _currentMode;
72  volatile bool _stop;
73 }
74 
75 #ifdef OF_HAVE_CLASS_PROPERTIES
76 @property (class, readonly, nullable, nonatomic) OFRunLoop *mainRunLoop;
77 @property (class, readonly, nullable, nonatomic) OFRunLoop *currentRunLoop;
78 #endif
79 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFRunLoopMode currentMode;
80 
86 + (nullable OFRunLoop *)mainRunLoop;
87 
93 + (nullable OFRunLoop *)currentRunLoop;
94 
100 - (void)addTimer: (OFTimer *)timer;
101 
108 - (void)addTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode;
109 
110 #if defined(OF_AMIGAOS) || defined(DOXYGEN)
111 
125 - (void)addExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector;
126 
142 - (void)addExecSignal: (ULONG)signal
143  forMode: (OFRunLoopMode)mode
144  target: (id)target
145  selector: (SEL)selector;
146 
155 - (void)removeExecSignal: (ULONG)signal
156  target: (id)target
157  selector: (SEL)selector;
158 
168 - (void)removeExecSignal: (ULONG)signal
169  forMode: (OFRunLoopMode)mode
170  target: (id)target
171  selector: (SEL)selector;
172 #endif
173 
177 - (void)run;
178 
184 - (void)runUntilDate: (nullable OFDate *)deadline;
185 
193 - (void)runMode: (OFRunLoopMode)mode beforeDate: (nullable OFDate *)deadline;
194 
199 - (void)stop;
200 @end
201 
202 OF_ASSUME_NONNULL_END
A class for creating mutual exclusions.
Definition: OFMutex.h:36
A class for storing, accessing and comparing dates.
Definition: OFDate.h:33
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:41
The root class for all other classes inside ObjFW.
Definition: OFObject.h:690
A class which provides easy to use sorted double-linked lists.
Definition: OFSortedList.h:32
OFConstantString * OFRunLoopMode
A mode for an OFRunLoop.
Definition: OFRunLoop.h:41
A class for creating and firing timers.
Definition: OFTimer.h:48
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:46
A class that can observe multiple kernel events (e.g. streams being ready to read) at once...
Definition: OFKernelEventObserver.h:114
A class providing a run loop for the application and its processes.
Definition: OFRunLoop.h:65
A class implementing a condition variable for thread synchronization.
Definition: OFCondition.h:33
const OFRunLoopMode OFDefaultRunLoopMode
The default mode for an OFRunLoop.