ObjFW
OFApplication.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 #include <signal.h>
17 
18 #import "OFObject.h"
19 
20 OF_ASSUME_NONNULL_BEGIN
21 
24 @class OFArray OF_GENERIC(ObjectType);
25 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
26 @class OFMutableArray OF_GENERIC(ObjectType);
27 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
28 @class OFSandbox;
29 @class OFString;
30 
55 #define OF_APPLICATION_DELEGATE(class_) \
56  int \
57  main(int argc, char *argv[]) \
58  { \
59  return of_application_main(&argc, &argv, \
60  (class_ *)[[class_ alloc] init]); \
61  }
62 
63 #ifdef OF_HAVE_PLEDGE
64 # define OF_HAVE_SANDBOX
65 #endif
66 
80 
81 @optional
86 
96 
97 #ifdef SIGHUP
109 #endif
110 
111 #ifdef SIGUSR1
123 #endif
124 
125 #ifdef SIGUSR2
137 #endif
138 @end
139 
149 OF_SUBCLASSING_RESTRICTED
151 {
152  OFString *_programName;
153  OFArray OF_GENERIC(OFString *) *_arguments;
154  OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_environment;
155  int *_argc;
156  char ***_argv;
157  id <OFApplicationDelegate> _Nullable _delegate;
158  void (*_Nullable _SIGINTHandler)(id, SEL);
159 #ifndef OF_WINDOWS
160  void (*_Nullable _SIGHUPHandler)(id, SEL);
161  void (*_Nullable _SIGUSR1Handler)(id, SEL);
162  void (*_Nullable _SIGUSR2Handler)(id, SEL);
163 #endif
164 #ifdef OF_HAVE_SANDBOX
165  OFSandbox *_Nullable _activeSandbox;
166  OFSandbox *_Nullable _activeSandboxForChildProcesses;
167 #endif
168 }
169 
170 #ifdef OF_HAVE_CLASS_PROPERTIES
171 @property (class, readonly, nullable, nonatomic)
172  OFApplication *sharedApplication;
173 @property (class, readonly, nullable, nonatomic) OFString *programName;
174 @property (class, readonly, nullable, nonatomic)
175  OFArray OF_GENERIC(OFString *) *arguments;
176 @property (class, readonly, nullable, nonatomic)
177  OFDictionary OF_GENERIC(OFString *, OFString *) *environment;
178 #endif
179 
183 @property (readonly, nonatomic) OFString *programName;
184 
188 @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *arguments;
189 
193 @property (readonly, nonatomic)
195 
199 @property OF_NULLABLE_PROPERTY (assign, nonatomic)
201 
202 #ifdef OF_HAVE_SANDBOX
206 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFSandbox *activeSandbox;
207 
211 @property OF_NULLABLE_PROPERTY (readonly, nonatomic)
212  OFSandbox *activeSandboxForChildProcesses;
213 #endif
214 
220 + (nullable OFApplication *)sharedApplication;
221 
227 + (nullable OFString *)programName;
228 
234 + (nullable OFArray OF_GENERIC(OFString *) *)arguments;
235 
241 + (nullable OFDictionary OF_GENERIC(OFString *, OFString *) *)environment;
242 
246 + (void)terminate OF_NO_RETURN;
247 
253 + (void)terminateWithStatus: (int)status OF_NO_RETURN;
254 
255 #ifdef OF_HAVE_SANDBOX
270 + (void)activateSandbox: (OFSandbox *)sandbox;
271 
286 + (void)activateSandboxForChildProcesses: (OFSandbox *)sandbox;
287 #endif
288 
289 - (instancetype)init OF_UNAVAILABLE;
290 
297 - (void)getArgumentCount: (int *_Nonnull *_Nonnull)argc
298  andArgumentValues: (char *_Nullable *_Nonnull *_Nonnull[_Nonnull])argv;
299 
303 - (void)terminate OF_NO_RETURN;
304 
310 - (void)terminateWithStatus: (int)status OF_NO_RETURN;
311 
312 #ifdef OF_HAVE_SANDBOX
327 - (void)activateSandbox: (OFSandbox *)sandbox;
328 
343 - (void)activateSandboxForChildProcesses: (OFSandbox *)sandbox;
344 #endif
345 @end
346 
347 #ifdef __cplusplus
348 extern "C" {
349 #endif
350 extern int of_application_main(int *_Nonnull,
351  char *_Nullable *_Nonnull[_Nonnull], id <OFApplicationDelegate>);
352 #ifdef __cplusplus
353 }
354 #endif
355 
356 OF_ASSUME_NONNULL_END
struct objc_object * id
A pointer to any object.
Definition: ObjFWRT.h:90
const struct objc_selector * SEL
A selector.
Definition: ObjFWRT.h:98
A class which represents the application as an object.
Definition: OFApplication.h:151
OFSandbox * activeSandbox
The sandbox currently active for this application.
Definition: OFApplication.h:206
OFDictionary * environment
The environment of the application.
Definition: OFApplication.h:194
OFArray * arguments
The arguments passed to the application.
Definition: OFApplication.h:188
An abstract class for storing objects in an array.
Definition: OFArray.h:92
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:58
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:44
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:44
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A class which describes a sandbox for the application.
Definition: OFSandbox.h:39
A class for handling strings.
Definition: OFString.h:132
A protocol for delegates of OFApplication.
Definition: OFApplication.h:74
void applicationWillTerminate()
A method which is called when the application will terminate.
void applicationDidFinishLaunching()
A method which is called when the application was initialized and is running now.
void applicationDidReceiveSIGINT()
A method which is called when the application received a SIGINT.
void applicationDidReceiveSIGUSR1()
A method which is called when the application received a SIGUSR1.
void applicationDidReceiveSIGUSR2()
A method which is called when the application received a SIGUSR2.
void applicationDidReceiveSIGHUP()
A method which is called when the application received a SIGHUP.