ObjFW
Loading...
Searching...
No Matches
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
25OF_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
90@protocol OFApplicationDelegate <OFObject>
98- (void)applicationDidFinishLaunching: (OFNotification *)notification;
99
100@optional
107- (void)applicationWillTerminate: (OFNotification *)notification;
108
117- (void)applicationDidReceiveSIGINT;
118
119#ifdef SIGHUP
130- (void)applicationDidReceiveSIGHUP;
131#endif
132
133#ifdef SIGUSR1
144- (void)applicationDidReceiveSIGUSR1;
145#endif
146
147#ifdef SIGUSR2
158- (void)applicationDidReceiveSIGUSR2;
159#endif
160@end
161
175OF_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
309extern "C" {
310#endif
311extern int OFApplicationMain(int *_Nonnull, char *_Nullable *_Nonnull[_Nonnull],
312 id <OFApplicationDelegate>);
313#ifdef __cplusplus
314}
315#endif
316
317OF_ASSUME_NONNULL_END
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
const struct objc_selector * SEL
A selector.
Definition ObjFWRT.h:102
A class which represents the application as an object.
Definition OFApplication.h:177
OFDictionary * environment
The environment of the application.
Definition OFApplication.h:220
OFArray * arguments
The arguments passed to the application.
Definition OFApplication.h:214
An abstract class for storing objects in an array.
Definition OFArray.h:109
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, adding and removing objects in an array.
Definition OFMutableArray.h:48
An abstract class for storing and changing objects in a dictionary.
Definition OFMutableDictionary.h:48
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
A class for handling strings.
Definition OFString.h:139