Mercurial > sdl-ios-xcode
annotate test/testcdrom.c @ 4324:1496aa09e41e SDL-1.2
Steven Noonan to sdl
While trying to build the SDLMain.m included with SDL 1.2.14, with
#define SDL_USE_NIB_FILE 1:
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:
In function '-[SDLMain fixMenu:withAppName:]':
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:122:
warning: 'sizeToFit' is deprecated (declared at
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSMenu.h:281)
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:
In function 'main':
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:376:
warning: 'poseAsClass:' is deprecated (declared at
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:127)
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:376:
error: 'poseAsClass:' is unavailable (declared at
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:127)
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:377:
warning: passing argument 2 of 'NSApplicationMain' from incompatible
pointer type
Eric Wing to Sam
I don't have time today to look at this in detail, but the problem is definitely the poseAsClass: method.
This was deprecated in Obj-C 2.0 and not retained in 64-bit.
I've never used this method and it has always been limited to esoteric uses. I think this is why Apple wanted to dump it (among complicating some other things they do). I have read about others getting bit by this when migrating. Long story short, there really isn't a migration path for this method. The question that then must be asked is why are we using it (what does it accomplish), and then figure out the 'proper' way of accomplishing that.
Glancing at SDLMain.m, it's not obvious to me why it is there or what it is really accomplishing. My only speculation is that NSApplicationMain hardcodes something to look for NSApplication and a subclass (SDLApplication) fails for some reason (assuming that the original coder did this for good reason).
Three thoughts come to mind.
1) The Info.plist has properties to control things related to the startup class and nib.
NSPrincipalClass, NSMainNibFile
Maybe principle class needs to be SDLApplication and we can delete the poseAs
2) I was told that 10.6 introduced new APIs to make programatic NIB wrangling and avoidance easier. Unfortunately, I don't know the specifics.
3) Instead of subclassing NSApplication in SDLMain.m, maybe we can just add a category. It looks like the following is the only thing that is done (quick glance):
@interface SDLApplication : NSApplication
@end
@implementation SDLApplication
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
/* Post a SDL_QUIT event */
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
}
@end
So instead, we change this to: (warning written in mail and untested)
@interface NSApplication (SDLApplication)
- (void) terminate:(id)sender;
@end
@implementation NSApplication (SDLApplication)
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
/* Post a SDL_QUIT event */
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
}
@end
Then everywhere SDLApplication is used, we change it to NSApplication (and remove the poseAsClass line).
Perhaps you could ask the bug reporter to try this solution (#3).
And if that fails, maybe try #1.
-Eric
Steven Noonan to Sam
The suggested change (diff below) seems to work fine.
- Steven
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 12 Oct 2009 21:07:12 +0000 |
parents | b2b476a4a73c |
children | 782fd950bd46 c121d94672cb |
rev | line source |
---|---|
0 | 1 |
2 /* Test the SDL CD-ROM audio functions */ | |
3 | |
4 #include <stdlib.h> | |
1484
b2b476a4a73c
Added documentation on how to build a completely useless SDL library. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1154
diff
changeset
|
5 #include <stdio.h> |
b2b476a4a73c
Added documentation on how to build a completely useless SDL library. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1154
diff
changeset
|
6 #include <string.h> |
0 | 7 #include <ctype.h> |
8 | |
9 #include "SDL.h" | |
10 | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
11 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
12 static void quit(int rc) |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
13 { |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
14 SDL_Quit(); |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
15 exit(rc); |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
16 } |
0 | 17 |
18 static void PrintStatus(int driveindex, SDL_CD *cdrom) | |
19 { | |
20 CDstatus status; | |
21 char *status_str; | |
22 | |
23 status = SDL_CDStatus(cdrom); | |
24 switch (status) { | |
25 case CD_TRAYEMPTY: | |
26 status_str = "tray empty"; | |
27 break; | |
28 case CD_STOPPED: | |
29 status_str = "stopped"; | |
30 break; | |
31 case CD_PLAYING: | |
32 status_str = "playing"; | |
33 break; | |
34 case CD_PAUSED: | |
35 status_str = "paused"; | |
36 break; | |
37 case CD_ERROR: | |
38 status_str = "error state"; | |
39 break; | |
40 } | |
41 printf("Drive %d status: %s\n", driveindex, status_str); | |
42 if ( status >= CD_PLAYING ) { | |
43 int m, s, f; | |
44 FRAMES_TO_MSF(cdrom->cur_frame, &m, &s, &f); | |
45 printf("Currently playing track %d, %d:%2.2d\n", | |
46 cdrom->track[cdrom->cur_track].id, m, s); | |
47 } | |
48 } | |
49 | |
50 static void ListTracks(SDL_CD *cdrom) | |
51 { | |
52 int i; | |
53 int m, s, f; | |
568
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
54 char* trtype; |
0 | 55 |
56 SDL_CDStatus(cdrom); | |
57 printf("Drive tracks: %d\n", cdrom->numtracks); | |
58 for ( i=0; i<cdrom->numtracks; ++i ) { | |
59 FRAMES_TO_MSF(cdrom->track[i].length, &m, &s, &f); | |
60 if ( f > 0 ) | |
61 ++s; | |
568
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
62 switch(cdrom->track[i].type) |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
63 { |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
64 case SDL_AUDIO_TRACK: |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
65 trtype="audio"; |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
66 break; |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
67 case SDL_DATA_TRACK: |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
68 trtype="data"; |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
69 break; |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
70 default: |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
71 trtype="unknown"; |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
72 break; |
0cd6b268193b
Date: Thu, 16 Jan 2003 13:48:31 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
73 } |
613
9c6717a1c66f
Added MacOS X CD-ROM audio support (thanks Max and Darrell)
Sam Lantinga <slouken@libsdl.org>
parents:
568
diff
changeset
|
74 printf("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i, |
9c6717a1c66f
Added MacOS X CD-ROM audio support (thanks Max and Darrell)
Sam Lantinga <slouken@libsdl.org>
parents:
568
diff
changeset
|
75 cdrom->track[i].id, m, s, cdrom->track[i].length, trtype); |
0 | 76 } |
77 } | |
78 | |
79 static void PrintUsage(char *argv0) | |
80 { | |
81 fprintf(stderr, "Usage: %s [drive#] [command] [command] ...\n", argv0); | |
82 fprintf(stderr, "Where 'command' is one of:\n"); | |
83 fprintf(stderr, " -status\n"); | |
84 fprintf(stderr, " -list\n"); | |
85 fprintf(stderr, " -play [first_track] [first_frame] [num_tracks] [num_frames]\n"); | |
86 fprintf(stderr, " -pause\n"); | |
87 fprintf(stderr, " -resume\n"); | |
88 fprintf(stderr, " -stop\n"); | |
89 fprintf(stderr, " -eject\n"); | |
90 fprintf(stderr, " -sleep <milliseconds>\n"); | |
91 } | |
92 | |
93 int main(int argc, char *argv[]) | |
94 { | |
95 int drive; | |
96 int i; | |
97 SDL_CD *cdrom; | |
98 | |
99 /* Initialize SDL first */ | |
100 if ( SDL_Init(SDL_INIT_CDROM) < 0 ) { | |
101 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
102 return(1); |
0 | 103 } |
104 | |
105 /* Find out how many CD-ROM drives are connected to the system */ | |
106 if ( SDL_CDNumDrives() == 0 ) { | |
107 printf("No CD-ROM devices detected\n"); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
108 quit(0); |
0 | 109 } |
110 printf("Drives available: %d\n", SDL_CDNumDrives()); | |
111 for ( i=0; i<SDL_CDNumDrives(); ++i ) { | |
112 printf("Drive %d: \"%s\"\n", i, SDL_CDName(i)); | |
113 } | |
114 | |
115 /* Open the CD-ROM */ | |
116 drive = 0; | |
117 i=1; | |
118 if ( argv[i] && isdigit(argv[i][0]) ) { | |
119 drive = atoi(argv[i++]); | |
120 } | |
121 cdrom = SDL_CDOpen(drive); | |
122 if ( cdrom == NULL ) { | |
123 fprintf(stderr, "Couldn't open drive %d: %s\n", drive, | |
124 SDL_GetError()); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
125 quit(2); |
0 | 126 } |
127 #ifdef TEST_NULLCD | |
128 cdrom = NULL; | |
129 #endif | |
130 | |
131 /* Find out which function to perform */ | |
132 for ( ; argv[i]; ++i ) { | |
133 if ( strcmp(argv[i], "-status") == 0 ) { | |
134 /* PrintStatus(drive, cdrom); */ | |
135 } else | |
136 if ( strcmp(argv[i], "-list") == 0 ) { | |
137 ListTracks(cdrom); | |
138 } else | |
139 if ( strcmp(argv[i], "-play") == 0 ) { | |
140 int strack, sframe; | |
141 int ntrack, nframe; | |
142 | |
143 strack = 0; | |
144 if ( argv[i+1] && isdigit(argv[i+1][0]) ) { | |
145 strack = atoi(argv[++i]); | |
146 } | |
147 sframe = 0; | |
148 if ( argv[i+1] && isdigit(argv[i+1][0]) ) { | |
149 sframe = atoi(argv[++i]); | |
150 } | |
151 ntrack = 0; | |
152 if ( argv[i+1] && isdigit(argv[i+1][0]) ) { | |
153 ntrack = atoi(argv[++i]); | |
154 } | |
155 nframe = 0; | |
156 if ( argv[i+1] && isdigit(argv[i+1][0]) ) { | |
157 nframe = atoi(argv[++i]); | |
158 } | |
159 if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) { | |
160 if ( SDL_CDPlayTracks(cdrom, strack, sframe, | |
161 ntrack, nframe) < 0 ) { | |
162 fprintf(stderr, | |
163 "Couldn't play tracks %d/%d for %d/%d: %s\n", | |
164 strack, sframe, ntrack, nframe, SDL_GetError()); | |
165 } | |
166 } else { | |
167 fprintf(stderr, "No CD in drive!\n"); | |
168 } | |
169 } else | |
170 if ( strcmp(argv[i], "-pause") == 0 ) { | |
171 if ( SDL_CDPause(cdrom) < 0 ) { | |
172 fprintf(stderr, "Couldn't pause CD: %s\n", | |
173 SDL_GetError()); | |
174 } | |
175 } else | |
176 if ( strcmp(argv[i], "-resume") == 0 ) { | |
177 if ( SDL_CDResume(cdrom) < 0 ) { | |
178 fprintf(stderr, "Couldn't resume CD: %s\n", | |
179 SDL_GetError()); | |
180 } | |
181 } else | |
182 if ( strcmp(argv[i], "-stop") == 0 ) { | |
183 if ( SDL_CDStop(cdrom) < 0 ) { | |
184 fprintf(stderr, "Couldn't eject CD: %s\n", | |
185 SDL_GetError()); | |
186 } | |
187 } else | |
188 if ( strcmp(argv[i], "-eject") == 0 ) { | |
189 if ( SDL_CDEject(cdrom) < 0 ) { | |
190 fprintf(stderr, "Couldn't eject CD: %s\n", | |
191 SDL_GetError()); | |
192 } | |
193 } else | |
194 if ( (strcmp(argv[i], "-sleep") == 0) && | |
195 (argv[i+1] && isdigit(argv[i+1][0])) ) { | |
196 SDL_Delay(atoi(argv[++i])); | |
197 printf("Delayed %d milliseconds\n", atoi(argv[i])); | |
198 } else { | |
199 PrintUsage(argv[0]); | |
200 SDL_CDClose(cdrom); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
201 quit(1); |
0 | 202 } |
203 } | |
204 PrintStatus(drive, cdrom); | |
205 SDL_CDClose(cdrom); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
613
diff
changeset
|
206 SDL_Quit(); |
0 | 207 |
208 return(0); | |
209 } |