ObjFW
OFApplication.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2023 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 #include <signal.h>
17 
18 #import "OFObject.h"
19 #import "OFNotification.h"
20 
21 OF_ASSUME_NONNULL_BEGIN
22 
25 @class OFArray OF_GENERIC(ObjectType);
26 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
27 @class OFMutableArray OF_GENERIC(ObjectType);
28 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
29 @class OFSandbox;
30 @class OFString;
31 
37 
42 
67 #define OF_APPLICATION_DELEGATE(class_) \
68  int \
69  main(int argc, char *argv[]) \
70  { \
71  return OFApplicationMain(&argc, &argv, \
72  (class_ *)[[class_ alloc] init]); \
73  }
74 
75 #ifdef OF_HAVE_PLEDGE
76 # define OF_HAVE_SANDBOX
77 #endif
78 
94 - (void)applicationDidFinishLaunching: (OFNotification *)notification;
95 
96 @optional
103 - (void)applicationWillTerminate: (OFNotification *)notification;
104 
113 - (void)applicationDidReceiveSIGINT;
114 
115 #ifdef SIGHUP
116 
126 - (void)applicationDidReceiveSIGHUP;
127 #endif
128 
129 #ifdef SIGUSR1
130 
140 - (void)applicationDidReceiveSIGUSR1;
141 #endif
142 
143 #ifdef SIGUSR2
144 
154 - (void)applicationDidReceiveSIGUSR2;
155 #endif
156 @end
157 
171 OF_SUBCLASSING_RESTRICTED
173 {
174  OFString *_programName;
175  OFArray OF_GENERIC(OFString *) *_arguments;
176  OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_environment;
177  int *_argc;
178  char ***_argv;
179  id <OFApplicationDelegate> _Nullable _delegate;
180  void (*_Nullable _SIGINTHandler)(id, SEL);
181 #ifndef OF_WINDOWS
182  void (*_Nullable _SIGHUPHandler)(id, SEL);
183  void (*_Nullable _SIGUSR1Handler)(id, SEL);
184  void (*_Nullable _SIGUSR2Handler)(id, SEL);
185 #endif
186 #ifdef OF_HAVE_SANDBOX
187  OFSandbox *_Nullable _activeSandbox;
188  OFSandbox *_Nullable _activeSandboxForChildProcesses;
189 #endif
190 }
191 
192 #ifdef OF_HAVE_CLASS_PROPERTIES
193 @property (class, readonly, nullable, nonatomic)
194  OFApplication *sharedApplication;
195 @property (class, readonly, nullable, nonatomic) OFString *programName;
196 @property (class, readonly, nullable, nonatomic)
197  OFArray OF_GENERIC(OFString *) *arguments;
198 @property (class, readonly, nullable, nonatomic)
199  OFDictionary OF_GENERIC(OFString *, OFString *) *environment;
200 #endif
201 
205 @property (readonly, nonatomic) OFString *programName;
206 
210 @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *arguments;
211 
215 @property (readonly, nonatomic)
217 
221 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
222  id <OFApplicationDelegate> delegate;
223 
224 #ifdef OF_HAVE_SANDBOX
225 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFSandbox *activeSandbox;
226 @property OF_NULLABLE_PROPERTY (readonly, nonatomic)
227  OFSandbox *activeSandboxForChildProcesses;
228 #endif
229 
235 + (nullable OFApplication *)sharedApplication;
236 
242 + (nullable OFString *)programName;
243 
249 + (nullable OFArray OF_GENERIC(OFString *) *)arguments;
250 
256 + (nullable OFDictionary OF_GENERIC(OFString *, OFString *) *)environment;
257 
261 + (void)terminate OF_NO_RETURN;
262 
268 + (void)terminateWithStatus: (int)status OF_NO_RETURN;
269 
270 #ifdef OF_HAVE_SANDBOX
271 + (void)of_activateSandbox: (OFSandbox *)sandbox;
272 + (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox;
273 #endif
274 
275 - (instancetype)init OF_UNAVAILABLE;
276 
283 - (void)getArgumentCount: (int *_Nonnull *_Nonnull)argc
284  andArgumentValues: (char *_Nullable *_Nonnull *_Nonnull[_Nonnull])argv;
285 
289 - (void)terminate OF_NO_RETURN;
290 
296 - (void)terminateWithStatus: (int)status OF_NO_RETURN;
297 
298 #ifdef OF_HAVE_SANDBOX
299 - (void)of_activateSandbox: (OFSandbox *)sandbox;
300 - (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox;
301 #endif
302 @end
303 
304 #ifdef __cplusplus
305 extern "C" {
306 #endif
307 extern int OFApplicationMain(int *_Nonnull, char *_Nullable *_Nonnull[_Nonnull],
308  id <OFApplicationDelegate>);
309 #ifdef __cplusplus
310 }
311 #endif
312 
313 OF_ASSUME_NONNULL_END
const struct objc_selector * SEL
A selector.
Definition: ObjFWRT.h:98
An abstract class for storing objects in an array.
Definition: OFArray.h:103
A class to represent a notification for or from OFNotificationCenter.
Definition: OFNotification.h:36
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
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:43
const OFNotificationName OFApplicationWillTerminateNotification
A notification that will be sent when the application will terminate.
Definition: OFApplication.m:92
const OFNotificationName OFApplicationDidFinishLaunchingNotification
A notification that will be sent when the application did finish launching.
Definition: OFApplication.m:90
A class for handling strings.
Definition: OFString.h:134
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:78
OFDictionary * environment
The environment of the application.
Definition: OFApplication.h:216
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:42
A protocol for delegates of OFApplication.
A class which represents the application as an object.
Definition: OFApplication.h:172
OFArray * arguments
The arguments passed to the application.
Definition: OFApplication.h:210