Revision: 27879
http://sourceforge.net/p/bibdesk/svn/27879
Author: hofman
Date: 2022-09-09 14:07:03 +0000 (Fri, 09 Sep 2022)
Log Message:
-----------
include flags as direct ivars
Modified Paths:
--------------
trunk/bibdesk/BDSKAsyncObject.h
trunk/bibdesk/BDSKAsyncObject.m
trunk/bibdesk/BDSKSharingClient.m
Modified: trunk/bibdesk/BDSKAsyncObject.h
===================================================================
--- trunk/bibdesk/BDSKAsyncObject.h 2022-09-09 09:38:16 UTC (rev 27878)
+++ trunk/bibdesk/BDSKAsyncObject.h 2022-09-09 14:07:03 UTC (rev 27879)
@@ -39,18 +39,14 @@
#import <Cocoa/Cocoa.h>
#import <stdatomic.h>
-typedef struct _BDSKAsyncObjectFlags {
+@interface BDSKAsyncObject : NSObject {
+ @private
+ NSThread *localThread;
+ BOOL stopRunning;
_Atomic(BOOL) shouldKeepRunning;
#ifdef DEBUG
_Atomic(BOOL) didStart;
#endif
-} BDSKAsyncObjectFlags;
-
-@interface BDSKAsyncObject : NSObject {
- @private
- NSThread *localThread; // mainly for debugging
- BOOL stopRunning; // set to signal to stop running
the run loop for the local server thread
- BDSKAsyncObjectFlags aoFlags; // state variables
}
/*
Modified: trunk/bibdesk/BDSKAsyncObject.m
===================================================================
--- trunk/bibdesk/BDSKAsyncObject.m 2022-09-09 09:38:16 UTC (rev 27878)
+++ trunk/bibdesk/BDSKAsyncObject.m 2022-09-09 14:07:03 UTC (rev 27879)
@@ -37,7 +37,6 @@
*/
#import "BDSKAsyncObject.h"
-#import <objc/runtime.h>
@interface BDSKAsyncObject (Private)
- (void)runLocalThread;
@@ -51,7 +50,7 @@
#ifdef DEBUG
- (void)checkStartup:(NSTimer *)ignored
{
- if (NO == atomic_load(&aoFlags.didStart))
+ if (NO == atomic_load(&didStart))
NSLog(@"*** Warning *** %@ has not been started after 1 second", self);
}
#endif
@@ -61,9 +60,9 @@
self = [super init];
if (self) {
// set up flags
- aoFlags.shouldKeepRunning = YES;
+ shouldKeepRunning = YES;
#ifdef DEBUG
- aoFlags.didStart = NO;
+ didStart = NO;
// check for absentminded developers; there's no actual requirement
that start be called immediately
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self
selector:@selector(checkStartup:) userInfo:nil repeats:NO];
@@ -79,7 +78,7 @@
- (void)start;
{
#ifdef DEBUG
- atomic_store(&aoFlags.didStart, YES);
+ atomic_store(&didStart, YES);
#endif
// run a background thread
localThread = [[NSThread alloc] initWithTarget:self
selector:@selector(runLocalThread) object:nil];
@@ -152,7 +151,7 @@
{
BDSKASSERT([NSThread isMainThread]);
// set the stop flag, so any long process (possibly with loops) knows it
can return
- atomic_store(&aoFlags.shouldKeepRunning, NO);
+ atomic_store(&shouldKeepRunning, NO);
// this is mainly to tickle the runloop on the local thread so it will
finish
[self performSelectorOnLocalThread:@selector(stopRunning) withObject:nil
waitUntilDone:NO];
BDSKDESTROY(localThread);
@@ -161,7 +160,7 @@
#pragma mark Thread Safe
- (BOOL)shouldKeepRunning {
- return atomic_load(&aoFlags.shouldKeepRunning) == YES;
+ return atomic_load(&shouldKeepRunning) == YES;
}
@end
Modified: trunk/bibdesk/BDSKSharingClient.m
===================================================================
--- trunk/bibdesk/BDSKSharingClient.m 2022-09-09 09:38:16 UTC (rev 27878)
+++ trunk/bibdesk/BDSKSharingClient.m 2022-09-09 14:07:03 UTC (rev 27879)
@@ -45,20 +45,16 @@
static NSString *BDSKClientServiceNameForKeychain = @"BibDesk Sharing Access";
-typedef struct _BDSKSharingClientFlags {
+// private class for async object. We have it as a separate object so we don't
get a retain loop, we remove it from the thread runloop in the client's dealloc
+@interface BDSKAsyncSharingClient : BDSKAsyncObject <NSConnectionDelegate> {
+ NSNetService *service; // service with information about the
remote server (BDSKSharingServer)
+ BDSKSharingClient *client; // the owner of the async client
(BDSKSharingClient)
+ id remoteServer; // proxy for the remote sharing server to
which we connect
BOOL needsAuthentication;
BOOL legacyServer;
_Atomic(BOOL) authenticationFailed;
_Atomic(BOOL) canceledAuthentication;
_Atomic(BOOL) failedDownload;
-} BDSKSharingClientFlags;
-
-// private class for async object. We have it as a separate object so we don't
get a retain loop, we remove it from the thread runloop in the client's dealloc
-@interface BDSKAsyncSharingClient : BDSKAsyncObject <NSConnectionDelegate> {
- NSNetService *service; // service with information about the
remote server (BDSKSharingServer)
- BDSKSharingClient *client; // the owner of the async client
(BDSKSharingClient)
- id remoteServer; // proxy for the remote sharing server to
which we connect
- BDSKSharingClientFlags flags; // state variables
NSString *uniqueIdentifier; // used by the remote server
NSString *errorMessage;
}
@@ -182,14 +178,19 @@
service = [aService retain];
// set up flags
- memset(&flags, 0, sizeof(flags));
-
+ authenticationFailed = NO;
+ canceledAuthentication = NO;
+ failedDownload = NO;
+
// set up the authentication flag
NSData *TXTData = [service TXTRecordData];
if(TXTData){
NSDictionary *dict = [NSNetService
dictionaryFromTXTRecordData:TXTData];
- flags.needsAuthentication = [[[[NSString alloc] initWithData:[dict
objectForKey:BDSKTXTAuthenticateKey] encoding:NSUTF8StringEncoding]
autorelease] boolValue];
- flags.legacyServer = [[dict objectForKey:BDSKTXTVersionKey]
isEqual:[@"0" dataUsingEncoding:NSUTF8StringEncoding]];
+ needsAuthentication = [[[[NSString alloc] initWithData:[dict
objectForKey:BDSKTXTAuthenticateKey] encoding:NSUTF8StringEncoding]
autorelease] boolValue];
+ legacyServer = [[dict objectForKey:BDSKTXTVersionKey]
isEqual:[@"0" dataUsingEncoding:NSUTF8StringEncoding]];
+ }else{
+ needsAuthentication = NO;
+ legacyServer = NO;
}
// test this to see if we've registered with the remote host
@@ -220,15 +221,15 @@
}
- (BOOL)needsAuthentication {
- return flags.needsAuthentication;
+ return needsAuthentication;
}
- (BOOL)authenticationFailed {
- return atomic_load(&flags.authenticationFailed) == YES ||
atomic_load(&flags.canceledAuthentication) == YES;
+ return atomic_load(&authenticationFailed) == YES ||
atomic_load(&canceledAuthentication) == YES;
}
- (BOOL)failedDownload {
- return atomic_load(&flags.failedDownload) == YES;
+ return atomic_load(&failedDownload) == YES;
}
#pragma mark Authentication
@@ -271,7 +272,7 @@
- (BOOL)authenticateIfNeeded:(BOOL)isNew {
// authenticate to a server of version 1+
- if (flags.needsAuthentication == NO || flags.legacyServer == YES || (isNew
== NO && atomic_load(&flags.canceledAuthentication) == NO &&
atomic_load(&flags.authenticationFailed) == NO)) {
+ if (needsAuthentication == NO || legacyServer == YES || (isNew == NO &&
atomic_load(&canceledAuthentication) == NO &&
atomic_load(&authenticationFailed) == NO)) {
// no need to authenticate, or legacy server, or we already
authenticated
return YES;
}
@@ -279,9 +280,9 @@
NSString *password = nil;
BOOL fromPanel = NO;
- atomic_store(&flags.canceledAuthentication, NO);
+ atomic_store(&canceledAuthentication, NO);
- if(atomic_load(&flags.authenticationFailed) == NO)
+ if(atomic_load(&authenticationFailed) == NO)
password = [self passwordFromKeychain];
if ([self shouldKeepRunning] == NO)
@@ -293,7 +294,7 @@
if (password == nil) {
// canceled by user
- atomic_store(&flags.canceledAuthentication, YES);
+ atomic_store(&canceledAuthentication, YES);
return NO;
} else {
fromPanel = YES;
@@ -309,7 +310,7 @@
}
@catch (id exception) {
NSLog(@"%@: unable to authenticate with remote server %@", [self
class], [service hostName]);
- atomic_store(&flags.authenticationFailed, YES);
+ atomic_store(&authenticationFailed, YES);
// don't show the alert when we couldn't authenticate when
cleaning up
if ([self shouldKeepRunning])
[self runAuthenticationFailedAlert];
@@ -323,7 +324,7 @@
return YES;
} else {
// set the flag and try again, until we succeed or user cancels
- atomic_store(&flags.authenticationFailed, YES);
+ atomic_store(&authenticationFailed, YES);
}
}
return NO;
@@ -332,14 +333,14 @@
// this can be called from any thread
- (NSData *)authenticationDataForComponents:(NSArray *)components;
{
- if (flags.needsAuthentication && flags.legacyServer) {
+ if (needsAuthentication && legacyServer) {
// legacy server of version 0 expect authentication through this method
NSString *password = nil;
- atomic_store(&flags.canceledAuthentication, NO);
+ atomic_store(&canceledAuthentication, NO);
- if(atomic_load(&flags.authenticationFailed) == NO)
+ if(atomic_load(&authenticationFailed) == NO)
password = [self passwordFromKeychain];
if(password == nil && [self shouldKeepRunning]){
@@ -350,11 +351,11 @@
// retry from the keychain
if (password){
// assume we succeeded; the exception handler for the
connection will change it back if we fail again
- atomic_store(&flags.authenticationFailed, NO);
+ atomic_store(&authenticationFailed, NO);
[self setPasswordFromKeychain:password];
}else{
// nil return, will throw NSGenericException
- atomic_store(&flags.canceledAuthentication, YES);
+ atomic_store(&canceledAuthentication, YES);
}
}
return [password sha1Signature];
@@ -408,8 +409,8 @@
if([exception respondsToSelector:@selector(name)] && [[exception
name] isEqual:NSFailedAuthenticationException]){
// if the user didn't cancel, set an auth failure flag and
show an alert
- if(atomic_load(&flags.canceledAuthentication) == NO){
- atomic_store(&flags.authenticationFailed, YES);
+ if(atomic_load(&canceledAuthentication) == NO){
+ atomic_store(&authenticationFailed, YES);
// don't show the alert when we couldn't authenticate when
cleaning up
if([self shouldKeepRunning])
[self runAuthenticationFailedAlert];
@@ -418,7 +419,7 @@
} else if([exception respondsToSelector:@selector(name)] &&
[[exception name] isEqual:NSGenericException]){
// this is thrown when authentication is canceled
- if(atomic_load(&flags.canceledAuthentication) == NO){
+ if(atomic_load(&canceledAuthentication) == NO){
@throw [NSString stringWithFormat:@"%@: exception \"%@\"
while connecting to remote server %@", NSStringFromSelector(_cmd), exception,
[service hostName]];
}
@@ -461,7 +462,7 @@
- (oneway void)retrievePublications;
{
// set so we don't try calling this multiple times
- atomic_store(&flags.failedDownload, NO);
+ atomic_store(&failedDownload, NO);
NSAutoreleasePool *pool = [NSAutoreleasePool new];
@@ -487,7 +488,7 @@
}
@catch(id exception){
NSLog(@"%@: discarding exception \"%@\" while retrieving
publications", [self class], exception);
- atomic_store(&flags.failedDownload, YES);
+ atomic_store(&failedDownload, YES);
[self setErrorMessage:NSLocalizedString(@"Failed to retrieve
publications", @"")];
// this posts a notification that the publications of the client
changed, forcing a redisplay of the table cell
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