Merged in changes.

CQTexperiment
vspader 2009-06-28 10:52:58 -07:00
commit b795030bde
4 changed files with 48 additions and 56 deletions

View File

@ -59,7 +59,7 @@ escapeForLastFM(NSString *string)
- (semaphore_t) semaphore; - (semaphore_t) semaphore;
- (void) processAudioScrobblerCommands:(AudioScrobbler *)myself; - (void) processAudioScrobblerCommands:(id)unused;
@end @end
@ -85,7 +85,7 @@ escapeForLastFM(NSString *string)
return nil; return nil;
} }
[NSThread detachNewThreadSelector:@selector(processAudioScrobblerCommands:) toTarget:self withObject:self]; [NSThread detachNewThreadSelector:@selector(processAudioScrobblerCommands:) toTarget:self withObject:nil];
} }
return self; return self;
} }
@ -190,7 +190,7 @@ escapeForLastFM(NSString *string)
return _semaphore; return _semaphore;
} }
- (void) processAudioScrobblerCommands:(AudioScrobbler *)myself - (void) processAudioScrobblerCommands:(id)unused
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
AudioScrobblerClient *client = [[AudioScrobblerClient alloc] init]; AudioScrobblerClient *client = [[AudioScrobblerClient alloc] init];
@ -200,15 +200,15 @@ escapeForLastFM(NSString *string)
NSString *response = nil; NSString *response = nil;
in_port_t port = 33367; in_port_t port = 33367;
while([myself keepProcessingAudioScrobblerCommands]) { while([self keepProcessingAudioScrobblerCommands]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Get the first command to be sent // Get the first command to be sent
@synchronized([myself queue]) { @synchronized([self queue]) {
enumerator = [[myself queue] objectEnumerator]; enumerator = [[self queue] objectEnumerator];
command = [[enumerator nextObject] retain]; command = [[enumerator nextObject] retain];
[[myself queue] removeObjectIdenticalTo:command]; [[self queue] removeObjectIdenticalTo:command];
} }
if(nil != command) { if(nil != command) {
@ -234,14 +234,14 @@ escapeForLastFM(NSString *string)
} }
} }
semaphore_timedwait([myself semaphore], timeout); semaphore_timedwait([self semaphore], timeout);
[pool release]; [pool release];
} }
// Send a final stop command to cleanup // Send a final stop command to cleanup
@try { @try {
if([client connectToHost:@"localhost" port:port]) { if([client connectToHost:@"localhost" port:port]) {
[client send:[NSString stringWithFormat:@"STOP c=%@\n", [myself pluginID]]]; [client send:[NSString stringWithFormat:@"STOP c=%@\n", [self pluginID]]];
response = [client receive]; response = [client receive];
if(2 > [response length] || NSOrderedSame != [response compare:@"OK" options:NSLiteralSearch range:NSMakeRange(0,2)]) if(2 > [response length] || NSOrderedSame != [response compare:@"OK" options:NSLiteralSearch range:NSMakeRange(0,2)])
@ -256,7 +256,7 @@ escapeForLastFM(NSString *string)
} }
[client release]; [client release];
[myself setAudioScrobblerThreadCompleted:YES]; [self setAudioScrobblerThreadCompleted:YES];
[pool release]; [pool release];
} }

View File

@ -188,8 +188,11 @@ addressForHost(NSString *hostname)
{ {
NSParameterAssert(INADDR_NONE != remoteAddress); NSParameterAssert(INADDR_NONE != remoteAddress);
struct sockaddr_in socketAddress; _port = port;
int result; int result;
do {
struct sockaddr_in socketAddress;
_socket = socket(AF_INET, SOCK_STREAM, 0); _socket = socket(AF_INET, SOCK_STREAM, 0);
if(-1 == _socket) { if(-1 == _socket) {
@ -197,33 +200,20 @@ addressForHost(NSString *hostname)
return NO; return NO;
} }
_port = port;
socketAddress.sin_family = AF_INET; socketAddress.sin_family = AF_INET;
socketAddress.sin_addr.s_addr = remoteAddress; socketAddress.sin_addr.s_addr = remoteAddress;
socketAddress.sin_port = htons(_port); socketAddress.sin_port = htons(_port);
result = connect(_socket, (const struct sockaddr *)&socketAddress, sizeof(struct sockaddr_in)); result = connect(_socket, (const struct sockaddr *)&socketAddress, sizeof(struct sockaddr_in));
// Don't check result yet
if(_doPortStepping) {
while(-1 == result && _port <= (port + kPortsToStep)) {
socketAddress.sin_port = htons(++_port);
result = connect(_socket, (const struct sockaddr *)&socketAddress, sizeof(struct sockaddr_in));
}
}
// Don't log failures, because the client may not be running
if(-1 == result) { if(-1 == result) {
close(_socket); close(_socket);
_socket = -1; _socket = -1;
_port = 0;
_doPortStepping = NO;
return NO; _port++;
} }
} while (YES == _doPortStepping && -1 == result && _port < (port + kPortsToStep));
return YES; return (-1 != result);
} }
@end @end

View File

@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>LSMinimumSystemVersion</key>
<string>10.5.0</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>English</string> <string>English</string>
<key>CFBundleDocumentTypes</key> <key>CFBundleDocumentTypes</key>
@ -89,7 +91,7 @@
<key>CFBundleTypeIconFile</key> <key>CFBundleTypeIconFile</key>
<string>ape.icns</string> <string>ape.icns</string>
<key>CFBundleTypeName</key> <key>CFBundleTypeName</key>
<string>Monkey's Audio File</string> <string>Monkey&apos;s Audio File</string>
<key>CFBundleTypeRole</key> <key>CFBundleTypeRole</key>
<string>Viewer</string> <string>Viewer</string>
<key>LSTypeIsPackage</key> <key>LSTypeIsPackage</key>

View File

@ -157,7 +157,7 @@
- (void)tableView:(NSTableView *)tableView - (void)tableView:(NSTableView *)tableView
didClickTableColumn:(NSTableColumn *)tableColumn didClickTableColumn:(NSTableColumn *)tableColumn
{ {
if ([self shuffle] == YES) if ([self shuffle] != ShuffleOff)
[self resetShuffleList]; [self resetShuffleList];
} }
@ -278,7 +278,7 @@
[acceptedURLs release]; [acceptedURLs release];
if ([self shuffle] == YES) if ([self shuffle] != ShuffleOff)
[self resetShuffleList]; [self resetShuffleList];
return YES; return YES;
@ -293,7 +293,7 @@
{ {
[super insertObjects:objects atArrangedObjectIndexes:indexes]; [super insertObjects:objects atArrangedObjectIndexes:indexes];
if ([self shuffle] == YES) if ([self shuffle] != ShuffleOff)
[self resetShuffleList]; [self resetShuffleList];
} }
@ -326,7 +326,7 @@
[super removeObjectsAtArrangedObjectIndexes:indexes]; [super removeObjectsAtArrangedObjectIndexes:indexes];
if ([self shuffle] == YES) if ([self shuffle] != ShuffleOff)
[self resetShuffleList]; [self resetShuffleList];
[playbackController playlistDidChange:self]; [playbackController playlistDidChange:self];
@ -360,7 +360,7 @@
[s release]; [s release];
if ([self shuffle] == YES) if ([self shuffle] != ShuffleOff)
[self resetShuffleList]; [self resetShuffleList];
} }
@ -369,7 +369,7 @@
[self setSortDescriptors:nil]; [self setSortDescriptors:nil];
[self setContent:[Shuffle shuffleList:[self content]]]; [self setContent:[Shuffle shuffleList:[self content]]];
if ([self shuffle] == YES) if ([self shuffle] != ShuffleOff)
[self resetShuffleList]; [self resetShuffleList];
} }
@ -484,7 +484,7 @@
return pe; return pe;
} }
if ([self shuffle] == YES) if ([self shuffle] != ShuffleOff)
{ {
return [self shuffledEntryAtIndex:(pe.shuffleIndex + 1)]; return [self shuffledEntryAtIndex:(pe.shuffleIndex + 1)];
} }
@ -532,7 +532,7 @@
return pe; return pe;
} }
if ([self shuffle] == YES) if ([self shuffle] != ShuffleOff)
{ {
return [self shuffledEntryAtIndex:(pe.shuffleIndex - 1)]; return [self shuffledEntryAtIndex:(pe.shuffleIndex - 1)];
} }