ObjFW
OFRunLoop.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2021 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
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  of_run_loop_mode_t _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)
76  of_run_loop_mode_t currentMode;
77 
83 + (nullable OFRunLoop *)mainRunLoop;
84 
90 + (nullable OFRunLoop *)currentRunLoop;
91 
97 - (void)addTimer: (OFTimer *)timer;
98 
105 - (void)addTimer: (OFTimer *)timer forMode: (of_run_loop_mode_t)mode;
106 
107 #ifdef OF_AMIGAOS
122 - (void)addExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector;
123 
139 - (void)addExecSignal: (ULONG)signal
140  forMode: (of_run_loop_mode_t)mode
141  target: (id)target
142  selector: (SEL)selector;
143 
152 - (void)removeExecSignal: (ULONG)signal
153  target: (id)target
154  selector: (SEL)selector;
155 
165 - (void)removeExecSignal: (ULONG)signal
166  forMode: (of_run_loop_mode_t)mode
167  target: (id)target
168  selector: (SEL)selector;
169 #endif
170 
174 - (void)run;
175 
181 - (void)runUntilDate: (nullable OFDate *)deadline;
182 
190 - (void)runMode: (of_run_loop_mode_t)mode
191  beforeDate: (nullable OFDate *)deadline;
192 
197 - (void)stop;
198 @end
199 
200 OF_ASSUME_NONNULL_END
const of_run_loop_mode_t of_run_loop_mode_default
The default mode for an OFRunLoop.
Definition: OFRunLoop.m:46
OFConstantString * of_run_loop_mode_t
A mode for an OFRunLoop.
Definition: OFRunLoop.h:37
A class implementing a condition variable for thread synchronization.
Definition: OFCondition.h:31
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
A class for storing, accessing and comparing dates.
Definition: OFDate.h:36
A class that can observe multiple kernel events (e.g. streams being ready to read) at once.
Definition: OFKernelEventObserver.h:119
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:44
A class for creating mutual exclusions.
Definition: OFMutex.h:30
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A class providing a run loop for the application and its processes.
Definition: OFRunLoop.h:62
A class which provides easy to use sorted double-linked lists.
Definition: OFSortedList.h:32
A class for creating and firing timers.
Definition: OFTimer.h:46