ObjFW  Check-in [f034850a98]

Overview
Comment:Add OFApplication.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f034850a98c65abf7e03b55e767ef20a96d50ec64f0fb1c90a5261537cc30c84
User & Date: js on 2010-04-07 19:55:32
Other Links: manifest | tags
Context
2010-04-07
20:56
Make tests an OFApplicationDelegate. check-in: 666d38f8be user: js tags: trunk
19:55
Add OFApplication. check-in: f034850a98 user: js tags: trunk
18:43
Add -[writeFormat:] to OFStream. check-in: fe3b6e5457 user: js tags: trunk
Changes

Modified ObjFW.xcodeproj/project.pbxproj from [c5af7d315e] to [25cf49574b].

67
68
69
70
71
72
73


74
75
76
77
78
79
80
			remoteInfo = configure;
		};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
		4B0108C910EB8C9300631877 /* OFEnumerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFEnumerator.h; path = src/OFEnumerator.h; sourceTree = SOURCE_ROOT; };
		4B0108CA10EB8C9300631877 /* OFEnumerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFEnumerator.m; path = src/OFEnumerator.m; sourceTree = SOURCE_ROOT; };


		4B4986DF1101F64500A2CFDA /* objc_properties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = objc_properties.m; path = src/objc_properties.m; sourceTree = SOURCE_ROOT; };
		4B6799561099E7C50041064A /* asprintf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = asprintf.h; path = src/asprintf.h; sourceTree = "<group>"; };
		4B6799581099E7C50041064A /* objc_sync.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = objc_sync.m; path = src/objc_sync.m; sourceTree = "<group>"; };
		4B67995A1099E7C50041064A /* OFArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFArray.h; path = src/OFArray.h; sourceTree = "<group>"; };
		4B67995B1099E7C50041064A /* OFArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFArray.m; path = src/OFArray.m; sourceTree = "<group>"; };
		4B67995C1099E7C50041064A /* OFAutoreleasePool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFAutoreleasePool.h; path = src/OFAutoreleasePool.h; sourceTree = "<group>"; };
		4B67995D1099E7C50041064A /* OFAutoreleasePool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFAutoreleasePool.m; path = src/OFAutoreleasePool.m; sourceTree = "<group>"; };







>
>







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
			remoteInfo = configure;
		};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
		4B0108C910EB8C9300631877 /* OFEnumerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFEnumerator.h; path = src/OFEnumerator.h; sourceTree = SOURCE_ROOT; };
		4B0108CA10EB8C9300631877 /* OFEnumerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFEnumerator.m; path = src/OFEnumerator.m; sourceTree = SOURCE_ROOT; };
		4B175C1D116D130B003C99CB /* OFApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFApplication.h; path = src/OFApplication.h; sourceTree = SOURCE_ROOT; };
		4B175C1E116D130B003C99CB /* OFApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFApplication.m; path = src/OFApplication.m; sourceTree = SOURCE_ROOT; };
		4B4986DF1101F64500A2CFDA /* objc_properties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = objc_properties.m; path = src/objc_properties.m; sourceTree = SOURCE_ROOT; };
		4B6799561099E7C50041064A /* asprintf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = asprintf.h; path = src/asprintf.h; sourceTree = "<group>"; };
		4B6799581099E7C50041064A /* objc_sync.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = objc_sync.m; path = src/objc_sync.m; sourceTree = "<group>"; };
		4B67995A1099E7C50041064A /* OFArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFArray.h; path = src/OFArray.h; sourceTree = "<group>"; };
		4B67995B1099E7C50041064A /* OFArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFArray.m; path = src/OFArray.m; sourceTree = "<group>"; };
		4B67995C1099E7C50041064A /* OFAutoreleasePool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFAutoreleasePool.h; path = src/OFAutoreleasePool.h; sourceTree = "<group>"; };
		4B67995D1099E7C50041064A /* OFAutoreleasePool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFAutoreleasePool.m; path = src/OFAutoreleasePool.m; sourceTree = "<group>"; };
131
132
133
134
135
136
137


138
139
140
141
142
143
144
		4BFBDD1610A0724800051AFB /* unicode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = unicode.m; path = src/unicode.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXGroup section */
		08FB7794FE84155DC02AAC07 /* ObjFW */ = {
			isa = PBXGroup;
			children = (


				4B67995A1099E7C50041064A /* OFArray.h */,
				4B67995B1099E7C50041064A /* OFArray.m */,
				4B67995C1099E7C50041064A /* OFAutoreleasePool.h */,
				4B67995D1099E7C50041064A /* OFAutoreleasePool.m */,
				4B67995E1099E7C50041064A /* OFConstString.h */,
				4B67995F1099E7C50041064A /* OFConstString.m */,
				4B6799601099E7C50041064A /* OFDataArray.h */,







>
>







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
		4BFBDD1610A0724800051AFB /* unicode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = unicode.m; path = src/unicode.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXGroup section */
		08FB7794FE84155DC02AAC07 /* ObjFW */ = {
			isa = PBXGroup;
			children = (
				4B175C1D116D130B003C99CB /* OFApplication.h */,
				4B175C1E116D130B003C99CB /* OFApplication.m */,
				4B67995A1099E7C50041064A /* OFArray.h */,
				4B67995B1099E7C50041064A /* OFArray.m */,
				4B67995C1099E7C50041064A /* OFAutoreleasePool.h */,
				4B67995D1099E7C50041064A /* OFAutoreleasePool.m */,
				4B67995E1099E7C50041064A /* OFConstString.h */,
				4B67995F1099E7C50041064A /* OFConstString.m */,
				4B6799601099E7C50041064A /* OFDataArray.h */,

Modified src/Makefile from [e3b387ddcd] to [ec470858d6].

1
2
3
4
5
6

7
8
9
10
11
12
13
14
include ../extra.mk

LIB = ${LIB_PREFIX}objfw${LIB_SUFFIX}
LIB_MAJOR = ${OBJFW_LIB_MAJOR}
LIB_MINOR = ${OBJFW_LIB_MINOR}


SRCS = OFArray.m		\
       OFAutoreleasePool.m	\
       OFConstString.m		\
       OFDataArray.m		\
       OFDictionary.m		\
       OFExceptions.m		\
       OFFile.m			\
       OFHashes.m		\






>
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
include ../extra.mk

LIB = ${LIB_PREFIX}objfw${LIB_SUFFIX}
LIB_MAJOR = ${OBJFW_LIB_MAJOR}
LIB_MINOR = ${OBJFW_LIB_MINOR}

SRCS = OFApplication.m		\
       OFArray.m		\
       OFAutoreleasePool.m	\
       OFConstString.m		\
       OFDataArray.m		\
       OFDictionary.m		\
       OFExceptions.m		\
       OFFile.m			\
       OFHashes.m		\

Added src/OFApplication.h version [7806bade69].







































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
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
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import "OFObject.h"

@class OFArray;
@class OFMutableArray;

/**
 * \brief A protocol for delegates of OFApplication,
 */
@protocol OFApplicationDelegate
/**
 * This method is called when the application was initialized and is running
 * now.
 */
- (void)applicationDidFinishLaunching;

/**
 * This method is called when the application is going to get terminated.
 */
- (void)applicationWillTerminate;
@end

/**
 * \brief Represents the application as an object.
 */
@interface OFApplication: OFObject
{
	OFMutableArray *arguments;
	id delegate;
}

/**
 * \return The only OFApplication instance in the application
 */
+ sharedApplication;

/**
 * \return The arguments passed to the application
 */
+ (OFArray*)arguments;

/**
 * Terminates the application.
 */
+ (void)terminate;

/**
 * Sets argc and argv.
 *
 * You should not call this directly! Use of_application_main instead!
 *
 * \param argc The number of arguments
 * \param argv The argument values
 */
-  setArgumentCount: (int)argc
  andArgumentValues: (char**)argv;

/**
 * \return The arguments passed to the application
 */
- (OFArray*)arguments;

/**
 * \return The delegate of the application
 */
- (id)delegate;

/**
 * Sets the delegate of the application.
 *
 * \param delegate The delegate for the application
 */
- setDelegate: (id)delegate;

/**
 * Starts the application after everything has been initialized.
 */
- run;

/**
 * Terminates the application.
 */
- (void)terminate;
@end

@interface OFObject (OFApplicationDelegate) <OFApplicationDelegate>
@end

extern int of_application_main(int, char*[], Class);

Added src/OFApplication.m version [cd773f7bc7].









































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <stdlib.h>

#import "OFApplication.h"
#import "OFArray.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"

OFApplication *app = nil;

static void
atexit_handler()
{
	id delegate = [app delegate];

	[delegate applicationWillTerminate];
}

int
of_application_main(int argc, char *argv[], Class cls)
{
	OFApplication *app;
	id delegate = nil;

	if (cls != Nil)
		delegate = [[cls alloc] init];

	app = [OFApplication sharedApplication];

	[app setArgumentCount: argc
	    andArgumentValues: argv];

	[app setDelegate: delegate];
	[delegate release];

	[app run];

	return 0;
}

@implementation OFApplication
+ sharedApplication
{
	if (app == nil)
		app = [[self alloc] init];

	return app;
}

+ (OFArray*)arguments
{
	return [app arguments];
}

+ (void)terminate
{
	exit(0);
}

- init
{
	self = [super init];

	atexit(atexit_handler);

	return self;
}

-  setArgumentCount: (int)argc
  andArgumentValues: (char**)argv
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	int i;

	if (arguments != nil)
		[arguments release];

	arguments = [[OFMutableArray alloc] init];

	for (i = 0; i < argc; i++)
		[arguments addObject: [OFString stringWithCString: argv[i]]];

	[pool release];

	return self;
}

- (OFArray*)arguments
{
	return [[arguments retain] autorelease];
}

- (id)delegate
{
	return [[delegate retain] autorelease];
}

- setDelegate: (id)delegate_
{
	id old = delegate;
	delegate = [delegate_ retain];
	[old release];

	return self;
}

- run
{
	[delegate applicationDidFinishLaunching];

	return self;
}

- (void)terminate
{
	exit(0);
}

- (void)dealloc
{
	[arguments release];
	[delegate release];

	[super dealloc];
}
@end

@implementation OFObject (OFApplicationDelegate)
- (void)applicationDidFinishLaunching
{
}

- (void)applicationWillTerminate
{
}
@end

Modified src/ObjFW.h from [2a47813884] to [7f2109937b].

32
33
34
35
36
37
38


39
40
41
42
43
44
45
#import "OFFile.h"

#import "OFSocket.h"
#import "OFTCPSocket.h"

#import "OFHashes.h"
#import "OFXMLElement.h"



#import "macros.h"

#ifdef OF_PLUGINS
# import "OFPlugin.h"
#endif








>
>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#import "OFFile.h"

#import "OFSocket.h"
#import "OFTCPSocket.h"

#import "OFHashes.h"
#import "OFXMLElement.h"

#import "OFApplication.h"

#import "macros.h"

#ifdef OF_PLUGINS
# import "OFPlugin.h"
#endif