Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3 from jfro/master

- Added support for Mach services as XPCConnection objects
- Used @rpath for framework embedding
- 32-bit support (lol)

Thanks jfro!
  • Loading branch information...
commit c81d83c2d92ca92ae0cdbd8690ba2cb0cbb886fb 2 parents 0613148 + e26d54a
Steve Streza authored
8 XPCKit.xcodeproj/project.pbxproj
View
@@ -771,7 +771,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
@@ -788,7 +788,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
- ONLY_ACTIVE_ARCH = YES;
+ ONLY_ACTIVE_ARCH = NO;
SDKROOT = macosx;
};
name = Debug;
@@ -797,7 +797,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -933,6 +933,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "XPCKit/XPCKit-Prefix.pch";
INFOPLIST_FILE = "XPCKit/XPCKit-Info.plist";
+ INSTALL_PATH = "@rpath/../Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = framework;
};
@@ -947,6 +948,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "XPCKit/XPCKit-Prefix.pch";
INFOPLIST_FILE = "XPCKit/XPCKit-Info.plist";
+ INSTALL_PATH = "@rpath/../Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = framework;
};
6 XPCKit/XPCConnection.h 100644 → 100755
View
@@ -24,12 +24,16 @@
@interface XPCConnection : NSObject{
xpc_connection_t _connection;
dispatch_queue_t _dispatchQueue;
+ XPCEventHandler _eventHandler;
+ XPCConnectionHandler _connectionHandler;
}
+- (id)initWithMachName:(NSString *)name listener:(BOOL)listen;
- (id)initWithServiceName:(NSString *)serviceName;
- (id)initWithConnection: (xpc_connection_t)connection;
-@property (nonatomic, copy) XPCEventHandler eventHandler;
+@property (nonatomic, copy) XPCEventHandler eventHandler;
+@property (nonatomic, copy) XPCConnectionHandler connectionHandler;
@property (nonatomic, readonly) xpc_connection_t connection;
@property (nonatomic, assign) dispatch_queue_t dispatchQueue;
37 XPCKit/XPCConnection.m 100644 → 100755
View
@@ -26,7 +26,14 @@
@implementation XPCConnection
-@synthesize eventHandler=_eventHandler, dispatchQueue=_dispatchQueue, connection=_connection;
+@synthesize eventHandler=_eventHandler, dispatchQueue=_dispatchQueue, connection=_connection, connectionHandler=_connectionHandler;
+
+- (id)initWithMachName:(NSString *)name listener:(BOOL)listen{
+ xpc_connection_t connection = xpc_connection_create_mach_service([name UTF8String], NULL, (listen ? XPC_CONNECTION_MACH_SERVICE_LISTENER : 0));
+ self = [self initWithConnection:connection];
+ xpc_release(connection);
+ return self;
+}
- (id)initWithServiceName:(NSString *)serviceName{
xpc_connection_t connection = xpc_connection_create([serviceName cStringUsingEncoding:NSUTF8StringEncoding], NULL);
@@ -60,6 +67,10 @@ -(void)dealloc{
xpc_release(_connection);
_connection = NULL;
}
+ if(_dispatchQueue){
+ dispatch_release(_dispatchQueue);
+ _dispatchQueue = NULL;
+ }
[super dealloc];
}
@@ -80,11 +91,21 @@ -(void)setDispatchQueue:(dispatch_queue_t)dispatchQueue{
-(void)receiveConnection:(xpc_connection_t)connection{
__block XPCConnection *this = self;
xpc_connection_set_event_handler(connection, ^(xpc_object_t object){
- if (object == XPC_ERROR_CONNECTION_INTERRUPTED){
- }else if (object == XPC_ERROR_CONNECTION_INVALID){
- }else if (object == XPC_ERROR_KEY_DESCRIPTION){
- }else if (object == XPC_ERROR_TERMINATION_IMMINENT){
- }else{
+ xpc_type_t type = xpc_get_type(object);
+ if (type == XPC_TYPE_ERROR){
+ // TODO: error handler or pass error to event handler
+ char *errorDescription = xpc_copy_description(object);
+ NSLog(@"XPCConnection - Error: %s", errorDescription);
+ free(errorDescription);
+ }else if(type == XPC_TYPE_CONNECTION){
+ // used by mach listener connections, send to connection handler for accept/denial
+ XPCConnection *connection = [[XPCConnection alloc] initWithConnection:object];
+ if(this.connectionHandler){
+ this.connectionHandler(connection);
+ }
+ [connection release];
+ return;
+ }else if(type == XPC_TYPE_DICTIONARY){
id message = [NSObject objectWithXPCObject: object];
#if XPCSendLogMessages
@@ -97,6 +118,10 @@ -(void)receiveConnection:(xpc_connection_t)connection{
if(this.eventHandler){
this.eventHandler(message, this);
}
+ }else{
+ char *description = xpc_copy_description(object);
+ NSLog(@"XPCConnection - unexpected event object: %s", description);
+ free(description);
}
});
}
5 XPCKit/XPCService.h
View
@@ -21,7 +21,10 @@
#import "XPCTypes.h"
#import "XPCConnection.h"
-@interface XPCService : NSObject
+@interface XPCService : NSObject {
+ NSArray *_connections;
+ XPCConnectionHandler _connectionHandler;
+}
@property (nonatomic, copy) XPCConnectionHandler connectionHandler;
@property (nonatomic, readonly) NSArray *connections;
2  XPCKit/XPCService.m
View
@@ -28,7 +28,7 @@ static void XPCServiceConnectionHandler(xpc_connection_t handler){
@implementation XPCService
-@synthesize connectionHandler, connections=_connections;
+@synthesize connectionHandler=_connectionHandler, connections=_connections;
-(id)initWithConnectionHandler:(XPCConnectionHandler)aConnectionHandler
{
4 XPCKit/XPCUUID.h
View
@@ -19,7 +19,9 @@
#import <Foundation/Foundation.h>
-@interface XPCUUID : NSObject
+@interface XPCUUID : NSObject {
+ CFUUIDRef _uuidRef;
+}
@property (nonatomic, readonly) CFUUIDRef uuidRef;
@property (nonatomic, readonly) NSString *string;
Please sign in to comment.
Something went wrong with that request. Please try again.