ObjFW  Check-in [83ad0894c0]

Overview
Comment:Make it possible to handle common signals in OFApplicationDelegate.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 83ad0894c02a804916d7ac6342fb9097d3b85c47b5c1e27422062679f902fa39
User & Date: js on 2012-02-17 17:13:22
Other Links: manifest | tags
Context
2012-02-20
22:40
Set version to 0.7-dev in default branch. check-in: 584a8dccec user: js tags: trunk
22:38
Create branch for 0.6. check-in: 01ca5677b9 user: js tags: 0.6
2012-02-17
21:15
Create a branch for a bridge to Foundation, integrated into ObjFW. check-in: 7746f5f864 user: js tags: bridge
17:13
Make it possible to handle common signals in OFApplicationDelegate. check-in: 83ad0894c0 user: js tags: trunk
16:25
Fix a very bad typo in OFStreamObserver_poll. check-in: e9b0575094 user: js tags: trunk
Changes

Modified src/OFApplication.h from [3eec16fb74] to [1bcf3be869].

46
47
48
49
50
51
52








































53
54
55
56
57
58
59
60
61
62
63
64
65






66
67
68
69
70
71
72
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional
#endif
/**
 * \brief A method which is called when the application will terminate.
 */
- (void)applicationWillTerminate;








































@end

/**
 * \brief Represents the application as an object.
 */
@interface OFApplication: OFObject
{
	OFString *programName;
	OFMutableArray *arguments;
	OFMutableDictionary *environment;
	id <OFApplicationDelegate> delegate;
	int *argc;
	char ***argv;






}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, assign) OFString *programName;
@property (readonly, assign) OFArray *arguments;
@property (readonly, assign) OFDictionary *environment;
@property (assign) id <OFApplicationDelegate> delegate;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










<


>
>
>
>
>
>







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifdef OF_HAVE_OPTIONAL_PROTOCOLS
@optional
#endif
/**
 * \brief A method which is called when the application will terminate.
 */
- (void)applicationWillTerminate;

/**
 * \brief A method which is called when the application received a SIGINT.
 *
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGINT;

/**
 * \brief A method which is called when the application received a SIGHUP.
 *
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGHUP;

/**
 * \brief A method which is called when the application received a SIGUSR1.
 *
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGUSR1;

/**
 * \brief A method which is called when the application received a SIGUSR2.
 *
 * \warning You are not allowed to send any messages inside this method, as
 *	    message dispatching is not signal-safe! You are only allowed to do
 *	    signal-safe operations like setting a variable or calling a
 *	    signal-safe function!
 */
- (void)applicationDidReceiveSIGUSR2;
@end

/**
 * \brief Represents the application as an object.
 */
@interface OFApplication: OFObject
{
	OFString *programName;
	OFMutableArray *arguments;
	OFMutableDictionary *environment;

	int *argc;
	char ***argv;
@public
	id <OFApplicationDelegate> delegate;
	void (*SIGINTHandler)(id, SEL);
	void (*SIGHUPHandler)(id, SEL);
	void (*SIGUSR1Handler)(id, SEL);
	void (*SIGUSR2Handler)(id, SEL);
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, assign) OFString *programName;
@property (readonly, assign) OFArray *arguments;
@property (readonly, assign) OFDictionary *environment;
@property (assign) id <OFApplicationDelegate> delegate;

Modified src/OFApplication.m from [8f063b7bf5] to [14e0a7d129].

43
44
45
46
47
48
49













50
51
52
53
54
55
56
	id <OFApplicationDelegate> delegate = [app delegate];

	[delegate applicationWillTerminate];

	[(id)delegate release];
}














int
of_application_main(int *argc, char **argv[], Class cls)
{
	OFApplication *app = [OFApplication sharedApplication];
	id <OFApplicationDelegate> delegate = [[cls alloc] init];

	[app setArgumentCount: argc







>
>
>
>
>
>
>
>
>
>
>
>
>







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
	id <OFApplicationDelegate> delegate = [app delegate];

	[delegate applicationWillTerminate];

	[(id)delegate release];
}

#define SIGNAL_HANDLER(sig)					\
	static void						\
	handle##sig(int signal)					\
	{							\
		app->sig##Handler(app->delegate,		\
		    @selector(applicationDidReceive##sig));	\
	}
SIGNAL_HANDLER(SIGINT)
SIGNAL_HANDLER(SIGHUP)
SIGNAL_HANDLER(SIGUSR1)
SIGNAL_HANDLER(SIGUSR2)
#undef SIGNAL_HANDLER

int
of_application_main(int *argc, char **argv[], Class cls)
{
	OFApplication *app = [OFApplication sharedApplication];
	id <OFApplicationDelegate> delegate = [[cls alloc] init];

	[app setArgumentCount: argc
232
233
234
235
236
237
238















239
240
241
242
243
244
245
{
	return delegate;
}

- (void)setDelegate: (id <OFApplicationDelegate>)delegate_
{
	delegate = delegate_;















}

- (void)run
{
	[delegate applicationDidFinishLaunching];
}








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
{
	return delegate;
}

- (void)setDelegate: (id <OFApplicationDelegate>)delegate_
{
	delegate = delegate_;

#define REGISTER_SIGNAL(sig)						  \
	sig##Handler = (void(*)(id, SEL))[(id)delegate methodForSelector: \
	    @selector(applicationDidReceive##sig)];			  \
	if (sig##Handler != (void(*)(id, SEL))[OFObject			  \
	    instanceMethodForSelector:					  \
	    @selector(applicationDidReceive##sig)])			  \
		signal(sig, handle##sig);				  \
	else								  \
		signal(sig, SIG_DFL);
	REGISTER_SIGNAL(SIGINT)
	REGISTER_SIGNAL(SIGHUP)
	REGISTER_SIGNAL(SIGUSR1)
	REGISTER_SIGNAL(SIGUSR2)
#undef REGISTER_SIGNAL
}

- (void)run
{
	[delegate applicationDidFinishLaunching];
}

268
269
270
271
272
273
274
















275
	@throw [OFNotImplementedException exceptionWithClass: isa
						    selector: _cmd];
}

- (void)applicationWillTerminate
{
}
















@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
	@throw [OFNotImplementedException exceptionWithClass: isa
						    selector: _cmd];
}

- (void)applicationWillTerminate
{
}

- (void)applicationDidReceiveSIGINT
{
}

- (void)applicationDidReceiveSIGHUP
{
}

- (void)applicationDidReceiveSIGUSR1
{
}

- (void)applicationDidReceiveSIGUSR2
{
}
@end