ObjFW
OFApplication.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #include <signal.h>
18 
19 #import "OFObject.h"
20 
21 OF_ASSUME_NONNULL_BEGIN
22 
23 @class OFArray OF_GENERIC(ObjectType);
24 @class OFDictionary OF_GENERIC(KeyType, ObjectType);
25 @class OFMutableArray OF_GENERIC(ObjectType);
26 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
27 @class OFSandbox;
28 @class OFString;
29 
30 #define OF_APPLICATION_DELEGATE(cls) \
31  int \
32  main(int argc, char *argv[]) \
33  { \
34  return of_application_main(&argc, &argv, [cls class]); \
35  }
36 
37 #ifdef OF_HAVE_PLEDGE
38 # define OF_HAVE_SANDBOX
39 #endif
40 
51 - (void)applicationDidFinishLaunching;
52 
53 @optional
57 - (void)applicationWillTerminate;
58 
67 - (void)applicationDidReceiveSIGINT;
68 
69 #ifdef SIGHUP
70 
80 - (void)applicationDidReceiveSIGHUP;
81 #endif
82 
83 #ifdef SIGUSR1
84 
94 - (void)applicationDidReceiveSIGUSR1;
95 #endif
96 
97 #ifdef SIGUSR2
98 
108 - (void)applicationDidReceiveSIGUSR2;
109 #endif
110 @end
111 
124 {
125  OFString *_programName;
126  OFArray OF_GENERIC(OFString *) *_arguments;
127  OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_environment;
128  int *_argc;
129  char ***_argv;
130 @public
131  id <OFApplicationDelegate> _Nullable _delegate;
132  void (*_Nullable _SIGINTHandler)(id, SEL);
133 #ifndef OF_WINDOWS
134  void (*_Nullable _SIGHUPHandler)(id, SEL);
135  void (*_Nullable _SIGUSR1Handler)(id, SEL);
136  void (*_Nullable _SIGUSR2Handler)(id, SEL);
137 #endif
138 }
139 
143 @property (readonly, nonatomic) OFString *programName;
144 
148 @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *arguments;
149 
153 @property (readonly, nonatomic)
155 
161 + (nullable OFApplication *)sharedApplication;
162 
168 + (nullable OFString *)programName;
169 
175 + (nullable OFArray OF_GENERIC(OFString *) *)arguments;
176 
182 + (nullable OFDictionary OF_GENERIC(OFString *, OFString *) *)environment;
183 
187 + (void)terminate OF_NO_RETURN;
188 
194 + (void)terminateWithStatus: (int)status OF_NO_RETURN;
195 
196 #ifdef OF_HAVE_SANDBOX
197 
204 + (void)activateSandbox: (OFSandbox *)sandbox;
205 #endif
206 
207 - init OF_UNAVAILABLE;
208 
215 - (void)getArgumentCount: (int *_Nonnull *_Nonnull)argc
216  andArgumentValues: (char *_Nonnull *_Nonnull *_Nonnull[_Nonnull])argv;
217 
223 - (nullable id <OFApplicationDelegate>)delegate;
224 
230 - (void)setDelegate: (nullable id <OFApplicationDelegate>)delegate;
231 
235 - (void)terminate OF_NO_RETURN;
236 
242 - (void)terminateWithStatus: (int)status OF_NO_RETURN;
243 
244 #ifdef OF_HAVE_SANDBOX
245 
252 - (void)activateSandbox: (OFSandbox *)sandbox;
253 #endif
254 @end
255 
256 #ifdef __cplusplus
257 extern "C" {
258 #endif
259 extern int of_application_main(int *_Nonnull,
260  char *_Nonnull *_Nonnull[_Nonnull], Class);
261 #ifdef __cplusplus
262 }
263 #endif
264 
265 OF_ASSUME_NONNULL_END
nullable id< OFApplicationDelegate > delegate()
Returns the delegate of the application.
Definition: OFApplication.m:499
OFDictionary * environment
Definition: OFApplication.h:154
nullable OFDictionary * environment()
Returns the environment of the application.
A class which describes a sandbox for the application.
Definition: OFSandbox.h:28
A protocol for delegates of OFApplication.
A class for handling strings.
Definition: OFString.h:114
void terminate()
Terminates the application with the EXIT_SUCCESS status.
Definition: OFApplication.m:183
nullable OFApplication * sharedApplication()
Returns the only OFApplication instance in the application.
Definition: OFApplication.m:163
id init()
Initializes an already allocated object.
Definition: OFObject.m:488
nullable OFArray * arguments()
Returns the arguments passed to the application.
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:39
OFArray * arguments
Definition: OFApplication.h:148
An abstract class for storing objects in a dictionary.
Definition: OFDictionary.h:54
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
An abstract class for storing objects in an array.
Definition: OFArray.h:89
nullable OFString * programName()
Returns the name of the program (argv[0]).
A class which represents the application as an object.
Definition: OFApplication.h:123
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:40