GithubHelp home page GithubHelp logo

isabella232 / detoxipc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wix-incubator/detoxipc

0.0 0.0 0.0 68 KB

DetoxIPC is an asynchronous, bi-directional inter-process remote invocation library for Apple platforms with an API similar to Apple's NSXPCConnection.

License: MIT License

Objective-C 99.50% C 0.50%

detoxipc's Introduction

DetoxIPC

DetoxIPC is an asynchronous, bi-directional inter-process remote invocation library for Apple platforms with an API similar to Apple's NSXPCConnection.

Once a connection is established, messages sent to remote proxies are serialized over mach ports to their remote counterparts. Block parameters are supported, and their lifetime is mirrored to their remote proxy counterparts (if a proxy block is retained and remains active for use, so is the local proxy).

Note: This framework is intended primarily for testing purposes, such as between a test runner process and the tested app process. The framework uses private API and is not suitable for App Store submission. On macOS, use an XPC service. On iOS and tvOS, due to the limited viability of multiple processes running at the same time, the framework is less useful there anyway.

Usage

Include the project in your projects and link it.

Read the DTXIPCConnection.h header for full documentation.

First, create a common protocol, which will be used to define the interface between remote objects.

@protocol ExampleProtocol <NSObject>

- (void)performOperationWithCompletionHandler:(dispatch_block_t)block;
- (void)performOperationWithOptions:(NSDictionary*)options completionHandler:(NSDictionary* options)block;

@end

On the server process, create an class which implements the common protocol you have defined. Create a DTXIPCConnection object with a named service, set an exported interface and finally set the exported object. Optionally, you can also set the remote object interface for bi-directional communication.

@interface MyObject : NSObject <ExampleProtocol> @end
@implementation MyObject
  
- (void)performOperationWithCompletionHandler:(dispatch_block_t)block {
  NSLog(@"Called performOperationWithCompletionHandler:");
  block();
}

- (void)performOperationWithOptions:(NSDictionary*)options completionHandler:(NSDictionary* options)block {
  NSLog(@"Called performOperationWithOptions:completionHandler: with options: %@", options);
  block(options);
}

@end

//
  
_connection = [[DTXIPCConnection alloc] initWithServiceName:@"MyService"];
_connection.exportedInterface = [DTXIPCInterface interfaceWithProtocol:@protocol(ExampleProtocol)];
_connection.exportedObject = [[MyObject alloc] init];

[_connection resume];

On the client process, connect to the registered named service, set the remote object interface and obtain a remote proxy object. You can now use this proxy object as if it is an instance of the remote object.

_connection = [[DTXIPCConnection alloc] initWithServiceName:@"MyService"];
_connection.remoteObjectInterface = [DTXIPCInterface interfaceWithProtocol:@protocol(ExampleProtocol)];

[_connection resume];

id<ExampleProtocol> remoteProxyObject = _connection.remoteObjectProxy;

[remoteProxyObject performOperationWithCompletionHandler:^{
  NSLog("Completion handler called");
}];

[remoteProxyObject performOperationWithOptions:@{@"Test": @"Passed"} completionHandler:^ (NSDictionary* options) {
  NSLog("Completion handler called with options: %@", options);
}];

The expected output on the server process should be:

Called performOperationWithCompletionHandler:
Called performOperationWithOptions:completionHandler: with options: {
    Test = Passed;
}

And the client process:

Completion handler called
Completion handler called with options: {
    Test = Passed;
}

detoxipc's People

Contributors

leonatan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.