Permalink
Browse files

Omni's acumulated changes from LinkBack 1.0.3 to the current date:

- Replaced the old .xcode project with a .xcodeproj and based the framework off Omni's Xcode configurations.
- Modified FindLinkBackServer() to accept an additional parameter, in which an alternate server can be returned.
- Fix up directory resolution order to make sure we get valid paths.
- Use NSSearchPathForDirectoriesInDomains() to identify the Application folders where we will search for the LinkBack server, rather than hard-coding those paths.
- Add optional bundleIdentifier parameter to server methods, so you can specify an identifier to use other than the main bundles id. (part of bug #25588)
- Various fixes to DO invalidation.
- Make this build with -Wshadow (though it exposes a strange cast).
- Use non-deprecated NSFileManager API so this will build on 10.6.
- Fix clang warnings/leaks
- Fix 64->32 implicit cast warnings
  • Loading branch information...
1 parent 30285de commit 0f158b4cfaeabbc136c72d72a505b166fa36347e @tjw tjw committed May 18, 2010
Binary file not shown.
View
@@ -139,9 +139,11 @@ BOOL LinkBackDataBelongsToActiveApplication(id data) ;
// ...........................................................................
// Server-side methods
//
-+ (BOOL)publishServerWithName:(NSString*)name delegate:(id<LinkBackServerDelegate>)del ;
++ (BOOL)publishServerWithName:(NSString*)name delegate:(id<LinkBackServerDelegate>)del;
++ (BOOL)publishServerWithName:(NSString*)name bundleIdentifier:(NSString *)anIdentifier delegate:(id<LinkBackServerDelegate>)del;
-+ (void)retractServerWithName:(NSString*)name ;
++ (void)retractServerWithName:(NSString*)name;
++ (void)retractServerWithName:(NSString*)name bundleIdentifier:(NSString *)anIdentifier;
- (void)sendEdit ;
View
@@ -70,8 +70,8 @@ id LinkBackGetAppData(id LinkBackData)
static int counter = 0 ;
NSString* base = [[NSBundle mainBundle] bundleIdentifier] ;
- unsigned long time = [NSDate timeIntervalSinceReferenceDate] ;
- return [NSString stringWithFormat: @"%@%.8x.%.4x",base,time,counter++] ;
+ uint64_t secondsSinceReferenceDate = [NSDate timeIntervalSinceReferenceDate];
+ return [NSString stringWithFormat: @"%@%qu.%.4x", base, secondsSinceReferenceDate, counter++] ;
}
BOOL LinkBackDataBelongsToActiveApplication(id data)
@@ -133,7 +133,7 @@ + (NSDictionary*)linkBackDataWithServerName:(NSString*)serverName appData:(id)ap
if (action) [ret setObject: action forKey: LinkBackServerActionKey] ;
if (appData) [ret setObject: appData forKey: LinkBackApplicationDataKey] ;
if (url) [ret setObject: url forKey: LinkBackApplicationURLKey] ;
- [ret setObject: [NSNumber numberWithFloat: rate] forKey: LinkBackSuggestedRefreshKey] ;
+ [ret setObject: [NSNumber numberWithDouble: rate] forKey: LinkBackSuggestedRefreshKey] ;
return [ret autorelease] ;
}
@@ -223,35 +223,43 @@ + (LinkBack*)activeLinkBackForItemKey:(id)aKey
- (id)initServerWithClient: (LinkBack*)aLinkBack delegate: (id<LinkBackServerDelegate>)aDel
{
- if (self = [super init]) {
- peer = [aLinkBack retain] ;
- sourceName = [[peer sourceName] copy] ;
- sourceApplicationName = [[peer sourceApplicationName] copy] ;
- key = [[peer itemKey] copy] ;
- isServer = YES ;
- delegate = aDel ;
- [keyedLinkBacks setObject: self forKey: key] ;
- }
+ if (![super init])
+ return nil;
+
+ peer = [aLinkBack retain] ;
+ sourceName = [[peer sourceName] copy] ;
+ sourceApplicationName = [[peer sourceApplicationName] copy] ;
+ key = [[peer itemKey] copy] ;
+ isServer = YES ;
+ delegate = aDel ;
+ [keyedLinkBacks setObject: self forKey: key] ;
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(connectionDidDie:)
+ name:NSConnectionDidDieNotification
+ object:[(NSDistantObject *)peer connectionForProxy]];
return self ;
}
- (id)initClientWithSourceName:(NSString*)aName delegate:(id<LinkBackClientDelegate>)aDel itemKey:(NSString*)aKey ;
{
- if (self = [super init]) {
- isServer = NO ;
- delegate = aDel ;
- sourceName = [aName copy] ;
- sourceApplicationName = [[NSProcessInfo processInfo] processName] ;
- pboard = [[NSPasteboard pasteboardWithUniqueName] retain] ;
- key = [aKey copy] ;
- }
+ if (![super init])
+ return nil;
+
+ isServer = NO ;
+ delegate = aDel ;
+ sourceName = [aName copy] ;
+ sourceApplicationName = [[NSProcessInfo processInfo] processName] ;
+ pboard = [[NSPasteboard pasteboardWithUniqueName] retain] ;
+ key = [aKey copy] ;
return self ;
}
- (void)dealloc
{
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:NSConnectionDidDieNotification object:nil];
+
[repobj release] ;
[sourceName release] ;
@@ -304,11 +312,14 @@ - (void)closeLink
{
// inform peer of closure
if (peer) {
- [peer remoteCloseLink] ;
- [peer release] ;
+ LinkBack *closingPeer = peer;
+ // note we can get an incoming -remoteCloseLink while we're calling the other side's closeLink
peer = nil ;
+ delegate = nil ;
[self release] ;
[keyedLinkBacks removeObjectForKey: [self itemKey]];
+ [closingPeer remoteCloseLink] ;
+ [closingPeer release] ;
}
}
@@ -333,12 +344,22 @@ + (BOOL)publishServerWithName:(NSString*)name delegate:(id<LinkBackServerDelegat
return [LinkBackServer publishServerWithName: name delegate: del] ;
}
++ (BOOL)publishServerWithName:(NSString*)name bundleIdentifier:(NSString *)anIdentifier delegate:(id<LinkBackServerDelegate>)del;
+{
+ return [LinkBackServer publishServerWithName:name bundleIdentifier:anIdentifier delegate:del] ;
+}
+
+ (void)retractServerWithName:(NSString*)name
{
LinkBackServer* server = [LinkBackServer LinkBackServerWithName: name] ;
if (server) [server retract] ;
}
++ (void)retractServerWithName:(NSString*)name bundleIdentifier:(NSString *)anIdentifier;
+{
+ LinkBackServer *server = [LinkBackServer LinkBackServerWithName:name bundleIdentifier:anIdentifier] ;
+ [server retract];
+}
- (void)sendEdit
{
if (!peer) [NSException raise: NSGenericException format: @"tried to request edit from a live link not connect to a server."] ;
@@ -365,10 +386,10 @@ + (LinkBack*)editLinkBackData:(id)data sourceName:(NSString*)aName delegate:(id<
if(nil==ret) {
BOOL ok ;
- NSString* serverName ;
- NSString* serverId ;
- NSString* appName ;
- NSURL* url ;
+ NSString* serverName = nil ;
+ NSString* serverId = nil ;
+ NSString* appName = nil ;
+ NSURL* url = nil ;
// collect server contact information from data.
ok = [data isKindOfClass: [NSDictionary class]] ;
@@ -382,12 +403,14 @@ + (LinkBack*)editLinkBackData:(id)data sourceName:(NSString*)aName delegate:(id<
if (!ok || !serverName || !serverId) [NSException raise: NSInvalidArgumentException format: @"LinkBackData is not of the correct format: %@", data] ;
// create the live link object and try to connect to the server.
- ret = [[LinkBack alloc] initClientWithSourceName: aName delegate: del itemKey: aKey] ;
+ ret = [[LinkBack alloc] initClientWithSourceName: aName delegate: del itemKey: aKey];
if (![ret connectToServerWithName: serverName inApplication: serverId fallbackURL: url appName: appName]) {
+ // if connection to server failed, return nil.
[ret release] ;
ret = nil ;
- }
+ } else
+ [ret autorelease];
}
// now with a live link in hand, request an edit
@@ -398,14 +421,9 @@ + (LinkBack*)editLinkBackData:(id)data sourceName:(NSString*)aName delegate:(id<
[my_pboard setPropertyList: data forType: LinkBackPboardType] ;
[ret requestEdit] ;
-
- // if connection to server failed, return nil.
- } else {
- [ret release] ;
- ret = nil ;
}
- return ret ;
+ return ret;
}
- (BOOL)connectToServerWithName:(NSString*)aName inApplication:(NSString*)bundleIdentifier fallbackURL:(NSURL*)url appName:(NSString*)appName
@@ -442,4 +460,10 @@ - (void)refreshEditWithPasteboardName:(bycopy NSString*)pboardName
[delegate performSelectorOnMainThread: @selector(linkBackServerDidSendEdit:) withObject: self waitUntilDone: NO] ;
}
+- (void)connectionDidDie:(NSNotification *)notification;
+{
+ [self remoteCloseLink];
+}
+
+
@end
Oops, something went wrong. Retry.

0 comments on commit 0f158b4

Please sign in to comment.