Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TestApp/TestApp-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.mustacheware.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion TestService/TestService-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${EXECUTABLE_NAME}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
309 changes: 150 additions & 159 deletions XPCKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion XPCKit/NSArray+XPCParse.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ +(NSArray *)arrayWithContentsOfXPCObject:(xpc_object_t)object{
}
return true;
});
return [[array copy] autorelease];
return [array copy];
}

-(xpc_object_t)newXPCObject{
Expand Down
5 changes: 2 additions & 3 deletions XPCKit/NSData+XPCParse.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ +(NSData *)dataWithXPCObject:(xpc_object_t)xpcObject{

// NOTE: mmap'd files do not work right now, this returns inconsistently-sized files for some reason.
// Only remove the "NO &&" if you know what you're doing.
if(NO && type == XPC_TYPE_SHMEM){
if(/* DISABLES CODE */ (NO) && type == XPC_TYPE_SHMEM){
void *buffer = NULL;
size_t length = xpc_shmem_map(xpcObject, &buffer);
if(length > 0){
Expand All @@ -50,15 +50,14 @@ + (id)objectWithXPCObject:(xpc_object_t)xpcObject

@try {
object = [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithXPCObject:xpcObject]];
[object retain];
}
@catch (NSException *exception) {
XPCLogWarning(@"NSData object is not an object archive (this is not necessarily an error). Reason: %@", exception);
}
@finally {
}

return [object autorelease];
return object;
}


Expand Down
2 changes: 1 addition & 1 deletion XPCKit/NSDictionary+XPCParse.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ +(NSDictionary *)dictionaryWithContentsOfXPCObject:(xpc_object_t)object{
}
return true;
});
return [[dict copy] autorelease];
return [dict copy];
}

-(xpc_object_t)newXPCObject{
Expand Down
2 changes: 1 addition & 1 deletion XPCKit/NSFileHandle+XPCParse.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ @implementation NSFileHandle (XPCParse)

+(NSFileHandle *)fileHandleWithXPCObject:(xpc_object_t)xpc{
int fd = xpc_fd_dup(xpc);
NSFileHandle *handle = [[[NSFileHandle alloc] initWithFileDescriptor:fd closeOnDealloc:YES] autorelease];
NSFileHandle *handle = [[NSFileHandle alloc] initWithFileDescriptor:fd closeOnDealloc:YES];
return handle;
}

Expand Down
41 changes: 3 additions & 38 deletions XPCKit/XPCConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,20 @@ @implementation XPCConnection

- (id)initWithServiceName:(NSString *)serviceName{
xpc_connection_t connection = xpc_connection_create([serviceName cStringUsingEncoding:NSUTF8StringEncoding], NULL);
self = [self initWithConnection:connection];
if (connection) {
xpc_release(connection);
}
return self;
return [self initWithConnection:connection];
}

-(id)initWithConnection:(xpc_connection_t)connection{
if(!connection){
[self release];
return nil;
}

if(self = [super init]){
_connection = xpc_retain(connection);
_connection = connection;
[self receiveConnection:_connection];

dispatch_queue_t queue = dispatch_queue_create(xpc_connection_get_name(_connection), 0);
self.dispatchQueue = queue;
if (queue) {
dispatch_release(queue);
}

[self resume];
}
return self;
Expand All @@ -64,38 +55,20 @@ -(id)initWithConnection:(xpc_connection_t)connection{
-(void)dealloc{
if(_connection){
xpc_connection_cancel(_connection);
xpc_release(_connection);
_connection = NULL;
}
if(_eventHandler){
[_eventHandler release];
_eventHandler = nil;
}

[super dealloc];
}

-(void)setDispatchQueue:(dispatch_queue_t)dispatchQueue{
if(dispatchQueue){
dispatch_retain(dispatchQueue);
}

if(_dispatchQueue){
dispatch_release(_dispatchQueue);
}
_dispatchQueue = dispatchQueue;

xpc_connection_set_target_queue(self.connection, self.dispatchQueue);
}

-(void)setReplyDispatchQueue:(dispatch_queue_t)dispatchQueue{
if(dispatchQueue){
dispatch_retain(dispatchQueue);
}

if(_replyDispatchQueue){
dispatch_release(_replyDispatchQueue);
}
_replyDispatchQueue = dispatchQueue;
}

Expand All @@ -114,7 +87,6 @@ -(void)receiveConnection:(xpc_connection_t)connection
xpc_object_t errorDict = xpc_dictionary_create(NULL, NULL, 0);
xpc_dictionary_set_value(errorDict, "__XPCError", object);
message = [XPCMessage messageWithXPCDictionary:errorDict];
xpc_release(errorDict);
}else{
message = [XPCMessage messageWithXPCDictionary:object];

Expand Down Expand Up @@ -184,8 +156,7 @@ -(void)sendMessage:(XPCMessage *)inMessage
[inMessage setNeedsDirectReply:YES];

dispatch_queue_t replyQueue = self.replyDispatchQueue ? self.replyDispatchQueue : dispatch_get_current_queue();
dispatch_retain(replyQueue);


XPCReplyHandler replyHandler = [inReplyHandler copy];
XPCErrorHandler errorHandler = [inErrorHandler copy];

Expand Down Expand Up @@ -215,10 +186,6 @@ -(void)sendMessage:(XPCMessage *)inMessage
XPCMessage *replyMessage = [XPCMessage messageWithXPCDictionary:event];
replyHandler(replyMessage);
}

[replyHandler release];
[errorHandler release];
dispatch_release(replyQueue);
});
});
}
Expand All @@ -243,12 +210,10 @@ -(void)sendSelector:(SEL)inSelector withTarget:(id)inTarget object:(id)inObject
NSError *error = nil;
id returnValue = [inReply invocationReturnValue:&error];
returnHandler(returnValue, error); // Handle method-level errors here
[returnHandler release];
}
errorHandler:^(NSError* inError) // Handle connection-level errors here
{
returnHandler(nil, inError);
[returnHandler release];
}];
}

Expand Down
2 changes: 1 addition & 1 deletion XPCKit/XPCKit-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.mustacheware.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
24 changes: 8 additions & 16 deletions XPCKit/XPCMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ - (void) setXPCDictionary:(xpc_object_t)inXPCDictionary

+ (id)message
{
return [[[XPCMessage alloc] init] autorelease];
return [[XPCMessage alloc] init];
}


+ (id)messageWithXPCDictionary:(xpc_object_t)inXPCDictionary
{
return [[[XPCMessage alloc] initWithXPCDictionary:inXPCDictionary] autorelease];
return [[XPCMessage alloc] initWithXPCDictionary:inXPCDictionary];
}


Expand All @@ -62,19 +62,19 @@ + (id)messageWithXPCDictionary:(xpc_object_t)inXPCDictionary

+ (id)messageReplyForMessage:(XPCMessage *)inOriginalMessage
{
return [[[XPCMessage alloc] initReplyForMessage:inOriginalMessage] autorelease];
return [[XPCMessage alloc] initReplyForMessage:inOriginalMessage];
}


+ (id)messageWithObjects:(NSArray *)inObjects forKeys:(NSArray *)inKeys
{
return [[[XPCMessage alloc] initWithObjects:inObjects forKeys:inKeys] autorelease];
return [[XPCMessage alloc] initWithObjects:inObjects forKeys:inKeys];
}


+ (id)messageWithObject:(id)inObject forKey:(NSString *)inKey
{
return [[[XPCMessage alloc] initWithObject:inObject forKey:inKey] autorelease];
return [[XPCMessage alloc] initWithObject:inObject forKey:inKey];
}


Expand All @@ -87,15 +87,15 @@ + (id)messageWithObjectsAndKeys:(id)firstObject, ...
this = [this _initWithFirstObject:firstObject arguments:argumentList];
va_end(argumentList);

return [this autorelease];
return this;
}


// Returns a message that is suited for invocation

+ (id)messageWithSelector:(SEL)inSelector target:(id)inTarget object:(id)inObject
{
return [[[XPCMessage alloc] initWithSelector:inSelector target:inTarget object:inObject] autorelease];
return [[XPCMessage alloc] initWithSelector:inSelector target:inTarget object:inObject];
}


Expand Down Expand Up @@ -240,7 +240,6 @@ - (void)dealloc
if (_XPCDictionary) {
xpc_release(_XPCDictionary);
}
[super dealloc];
}


Expand Down Expand Up @@ -389,14 +388,7 @@ - (XPCMessage *) invoke
XPCMessage *reply = [XPCMessage messageReplyForMessage:self];

NSError* error = nil;
id result = nil;

if (object) {
result = [target performSelector:selector withObject:object withObject:(id)&error];
} else {
result = [target performSelector:selector withObject:(id)&error];
}

id result = XPCKitInvokeSelector(target, selector, object, &error);
if (result) [reply setObject:result forKey:@"result"];
if (error) [reply setObject:error forKey:@"error"];

Expand Down
5 changes: 1 addition & 4 deletions XPCKit/XPCService.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
static void XPCServiceConnectionHandler(xpc_connection_t handler){
XPCConnection *connection = [[XPCConnection alloc] initWithConnection:handler];
[[NSNotificationCenter defaultCenter] postNotificationName:XPCConnectionReceivedNotification object:connection];
[connection release];
}

@implementation XPCService
Expand Down Expand Up @@ -67,11 +66,9 @@ -(void)handleConnection:(XPCConnection *)connection{
}

+(void)runServiceWithConnectionHandler:(XPCConnectionHandler)connectionHandler{
XPCService *service = [[XPCService alloc] initWithConnectionHandler:connectionHandler];
(void)[[XPCService alloc] initWithConnectionHandler:connectionHandler];

[XPCService runService];

[service release];
}

@end
7 changes: 3 additions & 4 deletions XPCKit/XPCUUID.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ @implementation XPCUUID

+(XPCUUID *)uuid{
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
XPCUUID *uuid = [[[self alloc] initWithUUIDRef:uuidRef] autorelease];
XPCUUID *uuid = [[self alloc] initWithUUIDRef:uuidRef];
CFRelease(uuidRef);
return uuid;
}
Expand Down Expand Up @@ -60,7 +60,7 @@ +(XPCUUID *)uuidWithXPCObject:(xpc_object_t)xpc{
#undef CopyByte

CFUUIDRef uuidRef = CFUUIDCreateFromUUIDBytes(NULL, uuidBytes);
XPCUUID *uuid = [[[self alloc] initWithUUIDRef:uuidRef] autorelease];
XPCUUID *uuid = [[self alloc] initWithUUIDRef:uuidRef];

CFRelease(uuidRef);

Expand Down Expand Up @@ -97,7 +97,7 @@ -(xpc_object_t)newXPCObject{
}

-(NSString *)string{
return [((NSString *)CFMakeCollectable(CFUUIDCreateString(NULL, self.uuidRef))) autorelease];
return CFBridgingRelease(CFUUIDCreateString(NULL, self.uuidRef));
}

-(NSString *)description{
Expand Down Expand Up @@ -128,7 +128,6 @@ -(void)dealloc{
_uuidRef = nil;
}

[super dealloc];
}

@end
4 changes: 3 additions & 1 deletion XPCKit/XPCUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void XPCSetLogLevel(XPCLogLevel inLogLevel);
// (i.e. target and object must conform to NSCoding when connection is not nil).
// When XPCConnection is nil (e.g. running on Snow Leopard) message will be dispatched asynchronously via GCD.

void XPCPerformSelectorAsync(XPCConnection *inConnection,
extern void XPCPerformSelectorAsync(XPCConnection *inConnection,
id inTarget, SEL inSelector, id inObject,
XPCReturnValueHandler inCompletionHandler);

extern id XPCKitInvokeSelector(id inTarget, SEL inSelector, id inObject, NSError **perror);
35 changes: 24 additions & 11 deletions XPCKit/XPCUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,41 @@ void XPCPerformSelectorAsync(XPCConnection *inConnection,
id objectCopy = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:inObject]];

dispatch_queue_t currentQueue = dispatch_get_current_queue();
dispatch_retain(currentQueue);


dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^()
{
NSError* error = nil;
id result = nil;

if (objectCopy) {
result = [targetCopy performSelector:inSelector withObject:objectCopy withObject:(id)&error];
} else {
result = [targetCopy performSelector:inSelector withObject:(id)&error];
}

id result = XPCKitInvokeSelector(targetCopy, inSelector, objectCopy, &error);
dispatch_async(currentQueue,^()
{
inReturnHandler(result, error);
dispatch_release(currentQueue);
});
});
}
}

id XPCKitInvokeSelector(id inTarget, SEL inSelector, id inObject, NSError **perror)
{
__unsafe_unretained id ierror = nil;
__unsafe_unretained id *errorPtr = &ierror;
void *tempResult;
int index = 2;
__unsafe_unretained id unsafeObject = inObject;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [inTarget methodSignatureForSelector: inSelector]];
[invocation setTarget: inTarget];
[invocation setSelector: inSelector];
// Note: Indexes 0 and 1 correspond to the implicit arguments self and _cmd,
// which are set using setTarget and setSelector.
if (inObject)
[invocation setArgument: &unsafeObject atIndex: index++];
[invocation setArgument: &errorPtr atIndex: index++];
[invocation retainArguments];
[invocation invoke];
[invocation getReturnValue: &tempResult];
if (perror)
*perror = ierror;
return (__bridge id)tempResult;
}

#pragma mark - Log Levels

Expand Down
Loading