ObjFW
OFApplication.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 #include <signal.h>
21 
22 #import "OFObject.h"
23 #import "OFNotification.h"
24 
25 OF_ASSUME_NONNULL_BEGIN
26 
29 @class OFArray OF_GENERIC(ObjectType);
30 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
31 @class OFMutableArray OF_GENERIC(ObjectType);
32 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
33 @class OFSandbox;
34 @class OFString;
35 
41 
46 
71 #define OF_APPLICATION_DELEGATE(class_) \
72  int \
73  main(int argc, char *argv[]) \
74  { \
75  return OFApplicationMain(&argc, &argv, \
76  (class_ *)[[class_ alloc] init]); \
77  }
78 
79 #ifdef OF_HAVE_PLEDGE
80 # define OF_HAVE_SANDBOX
81 #endif
82 
98 - (void)applicationDidFinishLaunching: (OFNotification *)notification;
99 
100 @optional
107 - (void)applicationWillTerminate: (OFNotification *)notification;
108 
117 - (void)applicationDidReceiveSIGINT;
118 
119 #ifdef SIGHUP
120 
130 - (void)applicationDidReceiveSIGHUP;
131 #endif
132 
133 #ifdef SIGUSR1
134 
144 - (void)applicationDidReceiveSIGUSR1;
145 #endif
146 
147 #ifdef SIGUSR2
148 
158 - (void)applicationDidReceiveSIGUSR2;
159 #endif
160 @end
161 
175 OF_SUBCLASSING_RESTRICTED
177 {
178  OFString *_programName;
179  OFArray OF_GENERIC(OFString *) *_arguments;
180  OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_environment;
181  int *_argc;
182  char ***_argv;
183  id <OFApplicationDelegate> _Nullable _delegate;
184  void (*_Nullable _SIGINTHandler)(id, SEL);
185 #ifndef OF_WINDOWS
186  void (*_Nullable _SIGHUPHandler)(id, SEL);
187  void (*_Nullable _SIGUSR1Handler)(id, SEL);
188  void (*_Nullable _SIGUSR2Handler)(id, SEL);
189 #endif
190 #ifdef OF_HAVE_SANDBOX
191  OFSandbox *_Nullable _activeSandbox;
192  OFSandbox *_Nullable _activeSandboxForChildProcesses;
193 #endif
194 }
195 
196 #ifdef OF_HAVE_CLASS_PROPERTIES
197 @property (class, readonly, nullable, nonatomic)
198  OFApplication *sharedApplication;
199 @property (class, readonly, nullable, nonatomic) OFString *programName;
200 @property (class, readonly, nullable, nonatomic)
201  OFArray OF_GENERIC(OFString *) *arguments;
202 @property (class, readonly, nullable, nonatomic)
203  OFDictionary OF_GENERIC(OFString *, OFString *) *environment;
204 #endif
205 
209 @property (readonly, nonatomic) OFString *programName;
210 
214 @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *arguments;
215 
219 @property (readonly, nonatomic)
221 
225 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
226  id <OFApplicationDelegate> delegate;
227 
228 #ifdef OF_HAVE_SANDBOX
229 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFSandbox *activeSandbox;
230 @property OF_NULLABLE_PROPERTY (readonly, nonatomic)
231  OFSandbox *activeSandboxForChildProcesses;
232 #endif
233 
239 + (nullable OFApplication *)sharedApplication;
240 
246 + (nullable OFString *)programName;
247 
253 + (nullable OFArray OF_GENERIC(OFString *) *)arguments;
254 
260 + (nullable OFDictionary OF_GENERIC(OFString *, OFString *) *)environment;
261 
265 + (void)terminate OF_NO_RETURN;
266 
272 + (void)terminateWithStatus: (int)status OF_NO_RETURN;
273 
274 #ifdef OF_HAVE_SANDBOX
275 + (void)of_activateSandbox: (OFSandbox *)sandbox;
276 + (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox;
277 #endif
278 
279 - (instancetype)init OF_UNAVAILABLE;
280 
287 - (void)getArgumentCount: (int *_Nonnull *_Nonnull)argc
288  andArgumentValues: (char *_Nullable *_Nonnull *_Nonnull[_Nonnull])argv;
289 
293 - (void)terminate OF_NO_RETURN;
294 
300 - (void)terminateWithStatus: (int)status OF_NO_RETURN;
301 
302 #ifdef OF_HAVE_SANDBOX
303 - (void)of_activateSandbox: (OFSandbox *)sandbox;
304 - (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox;
305 #endif
306 @end
307 
308 #ifdef __cplusplus
309 extern "C" {
310 #endif
311 extern int OFApplicationMain(int *_Nonnull, char *_Nullable *_Nonnull[_Nonnull],
312  id <OFApplicationDelegate>);
313 #ifdef __cplusplus
314 }
315 #endif
316 
317 OF_ASSUME_NONNULL_END
const struct objc_selector * SEL
A selector.
Definition: ObjFWRT.h:102
An abstract class for storing objects in an array.
Definition: OFArray.h:107
A class to represent a notification for or from OFNotificationCenter.
Definition: OFNotification.h:40
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
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:47
const OFNotificationName OFApplicationWillTerminateNotification
A notification that will be sent when the application will terminate.
Definition: OFApplication.m:96
const OFNotificationName OFApplicationDidFinishLaunchingNotification
A notification that will be sent when the application did finish launching.
Definition: OFApplication.m:94
A class for handling strings.
Definition: OFString.h:138
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:82
OFDictionary * environment
The environment of the application.
Definition: OFApplication.h:220
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:46
A protocol for delegates of OFApplication.
A class which represents the application as an object.
Definition: OFApplication.h:176
OFArray * arguments
The arguments passed to the application.
Definition: OFApplication.h:214