ObjFW
OFNotificationCenter.h
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 "OFNotification.h"
22 
23 OF_ASSUME_NONNULL_BEGIN
24 
25 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
26 #ifdef OF_HAVE_THREADS
27 @class OFMutex;
28 #endif
29 
30 #ifdef OF_HAVE_BLOCKS
36 typedef void (^OFNotificationCenterBlock)(OFNotification *notification);
37 #endif
38 
45 #ifndef OF_NOTIFICATION_CENTER_M
46 OF_SUBCLASSING_RESTRICTED
47 #endif
49 {
50 #ifdef OF_HAVE_THREADS
51  OFMutex *_mutex;
52 #endif
54 }
55 
56 #ifdef OF_HAVE_CLASS_PROPERTIES
57 @property (class, readonly, nonatomic) OFNotificationCenter *defaultCenter;
58 #endif
59 
63 + (OFNotificationCenter *)defaultCenter;
64 
77 - (void)addObserver: (id)observer
78  selector: (SEL)selector
79  name: (OFNotificationName)name
80  object: (nullable id)object;
81 
91 - (void)removeObserver: (id)observer
92  selector: (SEL)selector
93  name: (OFNotificationName)name
94  object: (nullable id)object;
95 
96 #ifdef OF_HAVE_BLOCKS
109 - (id)addObserverForName: (OFNotificationName)name
110  object: (nullable id)object
111  usingBlock: (OFNotificationCenterBlock)block;
112 
119 - (void)removeObserver: (id)observer;
120 #endif
121 
127 - (void)postNotification: (OFNotification *)notification;
128 
135 - (void)postNotificationName: (OFNotificationName)name
136  object: (nullable id)object;
137 
146 - (void)postNotificationName: (OFNotificationName)name
147  object: (nullable id)object
148  userInfo: (nullable OFDictionary *)userInfo;
149 @end
150 
151 OF_ASSUME_NONNULL_END
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:84
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:48
A class for creating mutual exclusions.
Definition: OFMutex.h:38
A class to send and register for notifications.
Definition: OFNotificationCenter.h:49
A class to represent a notification for or from OFNotificationCenter.
Definition: OFNotification.h:42
The root class for all other classes inside ObjFW.
Definition: OFObject.h:692