Revision: 29697
http://sourceforge.net/p/bibdesk/svn/29697
Author: hofman
Date: 2025-10-10 16:50:04 +0000 (Fri, 10 Oct 2025)
Log Message:
-----------
separate callback methods for failure and success
Modified Paths:
--------------
trunk/bibdesk/BDSKSharingServer.m
Modified: trunk/bibdesk/BDSKSharingServer.m
===================================================================
--- trunk/bibdesk/BDSKSharingServer.m 2025-10-10 16:05:17 UTC (rev 29696)
+++ trunk/bibdesk/BDSKSharingServer.m 2025-10-10 16:50:04 UTC (rev 29697)
@@ -409,98 +409,88 @@
}
}
-- (void)server:(BDSKAsyncSharingServer *)aServer didSetup:(BOOL)success
withPort:(int)port {
+- (void)server:(BDSKAsyncSharingServer *)aServer didSetupWithPort:(int)port {
BDSKASSERT(aServer == asyncServer || asyncServer == nil);
- if (success) {
- // the service was able to register the port
+ // the service was able to register the port
+
+ BDSKPRECONDITION(netService == nil);
+
+ // lazily instantiate the NSNetService object that will advertise on our
behalf
+ netService = [self newNetServiceWithSharingName:[self sharingName]
port:port];
+
+ BDSKPOSTCONDITION(netService != nil);
+
+ if (netService) {
+ // our DO server will also use Bonjour, but this gives us a browseable
name
+ [netService publishWithOptions:NSNetServiceNoAutoRename];
- BDSKPRECONDITION(netService == nil);
+ // register for notifications
+ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
- // lazily instantiate the NSNetService object that will advertise on
our behalf
- netService = [self newNetServiceWithSharingName:[self sharingName]
port:port];
+ BDSKASSERT(BDSKComputerNameChangedNotification);
- BDSKPOSTCONDITION(netService != nil);
+ [nc addObserver:self
+ selector:@selector(handleComputerNameChangedNotification:)
+ name:BDSKComputerNameChangedNotification
+ object:nil];
- if (netService) {
- // our DO server will also use Bonjour, but this gives us a
browseable name
- [netService publishWithOptions:NSNetServiceNoAutoRename];
-
- // register for notifications
- NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
-
- BDSKASSERT(BDSKComputerNameChangedNotification);
-
- [nc addObserver:self
- selector:@selector(handleComputerNameChangedNotification:)
- name:BDSKComputerNameChangedNotification
- object:nil];
-
- [nc addObserver:self
-
selector:@selector(handleSharingPasswordChangedNotification:)
- name:BDSKSharingPasswordChangedNotification
- object:nil];
-
- [nc addObserver:self
- selector:@selector(queueDataChangedNotification:)
- name:BDSKDocumentControllerAddDocumentNotification
- object:nil];
+ [nc addObserver:self
+ selector:@selector(handleSharingPasswordChangedNotification:)
+ name:BDSKSharingPasswordChangedNotification
+ object:nil];
+
+ [nc addObserver:self
+ selector:@selector(queueDataChangedNotification:)
+ name:BDSKDocumentControllerAddDocumentNotification
+ object:nil];
- [nc addObserver:self
- selector:@selector(queueDataChangedNotification:)
- name:BDSKDocumentControllerRemoveDocumentNotification
- object:nil];
-
- [nc addObserver:self
- selector:@selector(queueDataChangedNotification:)
- name:BDSKDocumentDidAddItemNotification
- object:nil];
+ [nc addObserver:self
+ selector:@selector(queueDataChangedNotification:)
+ name:BDSKDocumentControllerRemoveDocumentNotification
+ object:nil];
+
+ [nc addObserver:self
+ selector:@selector(queueDataChangedNotification:)
+ name:BDSKDocumentDidAddItemNotification
+ object:nil];
- [nc addObserver:self
- selector:@selector(queueDataChangedNotification:)
- name:BDSKDocumentDidRemoveItemNotification
- object:nil];
-
- [nc addObserver:self
- selector:@selector(handleApplicationWillTerminate:)
- name:NSApplicationWillTerminateNotification
- object:nil];
-
- NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
- [sud addObserver:self forKeyPath:BDSKSharingNameKey options:0
context:&BDSKSharingServerDefaultsObservationContext];
-
- [sud addObserver:self forKeyPath:BDSKSharingRequiresPasswordKey
options:0 context:&BDSKSharingServerDefaultsObservationContext];
-
- } else {
- [self disableSharing];
- }
+ [nc addObserver:self
+ selector:@selector(queueDataChangedNotification:)
+ name:BDSKDocumentDidRemoveItemNotification
+ object:nil];
- } else {
- // the service was not able to register the port
+ [nc addObserver:self
+ selector:@selector(handleApplicationWillTerminate:)
+ name:NSApplicationWillTerminateNotification
+ object:nil];
- // shouldn't happen
- if (asyncServer != aServer)
- [aServer stop];
+ NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
+ [sud addObserver:self forKeyPath:BDSKSharingNameKey options:0
context:&BDSKSharingServerDefaultsObservationContext];
- [asyncServer stop];
- asyncServer = nil;
+ [sud addObserver:self forKeyPath:BDSKSharingRequiresPasswordKey
options:0 context:&BDSKSharingServerDefaultsObservationContext];
- [self setStatus:BDSKSharingStatusOff];
-
- // try again with a different name
- [self _enableSharing];
+ } else {
+ [self disableSharing];
}
}
-- (void)netServiceWillPublish:(NSNetService *)sender
-{
- [self setStatus:BDSKSharingStatusPublishing];
+- (void)serverDidFailToSetup:(BDSKAsyncSharingServer *)aServer {
+ BDSKASSERT(aServer == asyncServer || asyncServer == nil);
+ // the service was not able to register the port
+
+ // shouldn't happen
+ if (asyncServer != aServer)
+ [aServer stop];
+
+ [asyncServer stop];
+ asyncServer = nil;
+
+ [self setStatus:BDSKSharingStatusOff];
+
+ // try again with a different name
+ [self _enableSharing];
}
-- (void)netServiceDidPublish:(NSNetService *)sender
-{
- [self setStatus:BDSKSharingStatusSharing];
-}
-
- (void)netService:(NSNetService *)sender didNotPublish:(NSDictionary
*)errorDict
{
NSInteger err = [[errorDict objectForKey:NSNetServicesErrorCode]
integerValue];
@@ -665,15 +655,20 @@
// so we get connection:shouldMakeNewConnection: messages
[connection setDelegate:self];
#pragma clang diagnostic pop
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [sharingServer server:self didSetupWithPort:port];
+ // this is no longer needed
+ sharingServer = nil;
+ });
}
@catch(id exception) {
NSLog(@"%@", exception);
success = NO;
- // the callback from the delegate should stop the DO server, and may
try again with a different name
- }
- @finally {
+ // the callback from the delegate should stop the async server, and
may try again with a different name
dispatch_async(dispatch_get_main_queue(), ^{
- [sharingServer server:self didSetup:success withPort:port];
+ [sharingServer serverDidFailToSetup:self];
+ // this is no longer needed
+ sharingServer = nil;
});
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit