public class Client
extends java.lang.Object
An object-oriented wrapper around the RuntimeUtils static methods for interacting with the Objective-C runtime.
A client object stores settings about whether to coerce inputs and/or outputs from messages. There are two global instances of this class that are used most often:
Client.getInstance()
: The default
client with settings to coerce both inputs and outputs. If you
need to make a direct call to the Objective-C runtime, this
is usually the client that you would use.
Client.getRawClient()
: Reference
to a simple client that is set to not coerce input and
output. This is handy if you want to pass in the raw Pointers
as parameters, and receive raw pointers as output.
Constructor and Description |
---|
Client() |
Modifier and Type | Method and Description |
---|---|
Message[] |
buildMessageChain(java.lang.Object... parameters)
Builds a chain of messages that can be executed together at a later time.
|
Proxy |
chain(java.lang.String cls,
com.sun.jna.Pointer selector,
java.lang.Object... args) |
Proxy |
chain(java.lang.String cls,
java.lang.String selector,
java.lang.Object... args)
Deprecated.
|
boolean |
getCoerceInputs()
Returns the coerceInputs flag.
|
boolean |
getCoerceOutputs()
Returns the coerceOutputs flag.
|
static Client |
getInstance()
Retrieves the global reference to a client that has both input coercion
and output coercion enabled.
|
static Client |
getRawClient()
Retrieves singleton instance to a simple client that has type coercion
disabled for both inputs and outputs.
|
PeerableRecipient |
newObject(java.lang.Class<? extends PeerableRecipient> cls)
Creates a new peerable and receivable object of the specified class.
|
java.lang.Object |
send(Message... messages)
Sends an array of messages in a chain.
|
java.lang.Object |
send(Peerable proxy,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Sends a message to an Objective-C object.
|
java.lang.Object |
send(Peerable proxy,
java.lang.String selector,
java.lang.Object... args)
Sends a message to an Objective-C object.
|
java.lang.Object |
send(com.sun.jna.Pointer receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Sends a message to an Objective-C object.
|
java.lang.Object |
send(com.sun.jna.Pointer receiver,
java.lang.String selector,
java.lang.Object... args)
Sends a message to an Objective-C object.
|
java.lang.Object |
send(java.lang.String receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Sends a message to an Objective-C object.
|
java.lang.Object |
send(java.lang.String receiver,
java.lang.String selector,
java.lang.Object... args)
Sends a message to an Objective-C object.
|
com.sun.jna.Pointer |
sendPointer(com.sun.jna.Pointer receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
A wrapper around send() to ensure that a pointer is returned from the
message.
|
com.sun.jna.Pointer |
sendPointer(com.sun.jna.Pointer receiver,
java.lang.String selector,
java.lang.Object... args)
A wrapper around send() to ensure that a pointer is returned from the
message.
|
com.sun.jna.Pointer |
sendPointer(java.lang.String receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
A wrapper around send() to ensure that a pointer is returned from the
message.
|
com.sun.jna.Pointer |
sendPointer(java.lang.String receiver,
java.lang.String selector,
java.lang.Object... args)
A wrapper around send() to ensure that a pointer is returned from the
message.
|
Proxy |
sendProxy(com.sun.jna.Pointer receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
A wrapper around send() to ensure that a Proxy object is returned from the
message.
|
Proxy |
sendProxy(com.sun.jna.Pointer receiver,
java.lang.String selector,
java.lang.Object... args)
A wrapper around send() to ensure that a Proxy object is returned from the
message.
|
Proxy |
sendProxy(java.lang.String receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
A wrapper around send() to ensure that a Proxy object is returned from the
message.
|
Proxy |
sendProxy(java.lang.String receiver,
java.lang.String selector,
java.lang.Object... args)
A wrapper around send() to ensure that a Proxy object is returned from the
message.
|
Client |
setCoerceInputs(boolean coerceInputs)
Set the coerceInputs flag.
|
Client |
setCoerceOutputs(boolean coerceOutputs)
Sets the coerceOutputs flag.
|
public static Client getInstance()
public static Client getRawClient()
public Client setCoerceInputs(boolean coerceInputs)
coerceInputs
- Whether to coerce inputs to messages.TypeMapper
,
TypeMapping
public Client setCoerceOutputs(boolean coerceOutputs)
coerceOutputs
- Whether to coerce the outputs of messages.TypeMapper
,
TypeMapping
public boolean getCoerceInputs()
TypeMapper
,
TypeMapping
public boolean getCoerceOutputs()
TypeMapper
,
TypeMapping
public java.lang.Object send(com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
String hello = (String)Client.getInstance()
.send(cls("NSString"), sel("stringWithUTF8String:"), "Hello");
receiver
- A pointer to the object to which the message is being sent.selector
- A pointer to the selector to call on the target.args
- Variable arguments of the message.public java.lang.Object send(com.sun.jna.Pointer receiver, java.lang.String selector, java.lang.Object... args)
String hello = (String)Client.getInstance()
.send(cls("NSString"), "stringWithUTF8String:", "Hello");
receiver
- A pointer to the object to which the message is being sent.selector
- The string selector. (E.g. "addObject:atIndex:")args
- Variable arguments of the message.public java.lang.Object send(java.lang.String receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
String hello = (String)Client.getInstance()
.send("NSString", sel("stringWithUTF8String:"), "Hello");
receiver
- The name of a class to send the message to.selector
- Pointer to the selector.args
- Variable arguments of the message.public java.lang.Object send(java.lang.String receiver, java.lang.String selector, java.lang.Object... args)
String hello = (String)Client.getInstance()
.send("NSString", "stringWithUTF8String:", "Hello");
receiver
- The name of a class to send the message to.selector
- Pointer to the selector.args
- Variable arguments of the message.public java.lang.Object send(Peerable proxy, com.sun.jna.Pointer selector, java.lang.Object... args)
Proxy array = Client.getInstance().sendProxy("NSMutableArray", sel("array"));
String hello = (String)Client
.getInstance().send(array, sel("addObject:atIndex"), "Hello", 2);
receiver
- The object to which we are sending the message.selector
- Pointer to the selector.args
- Variable arguments of the message.public java.lang.Object send(Peerable proxy, java.lang.String selector, java.lang.Object... args)
Proxy array = Client.getInstance().sendProxy("NSMutableArray", "array");
String hello = (String)Client
.getInstance().send(array, "addObject:atIndex", "Hello", 2);
receiver
- The object to which we are sending the message.selector
- Pointer to the selector.args
- Variable arguments of the message.public com.sun.jna.Pointer sendPointer(com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The object to which the message is being sent.selector
- The selector to call on the receiver.args
- Variable arguments to the message.public com.sun.jna.Pointer sendPointer(com.sun.jna.Pointer receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The object to which the message is being sent.selector
- The selector to call on the receiver.args
- Variable arguments to the message.public com.sun.jna.Pointer sendPointer(java.lang.String receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The object to which the message is being sent.selector
- The selector to call on the receiver.args
- Variable arguments to the message.public com.sun.jna.Pointer sendPointer(java.lang.String receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The object to which the message is being sent.selector
- The selector to call on the receiver.args
- Variable arguments to the message.public Proxy sendProxy(com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The object to which the message is being sent.selector
- The selector to call on the receiver.args
- Variable arguments to the message.public Proxy sendProxy(java.lang.String receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The object to which the message is being sent.selector
- The selector to call on the receiver.args
- Variable arguments to the message.public Proxy sendProxy(java.lang.String receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The object to which the message is being sent.selector
- The selector to call on the receiver.args
- Variable arguments to the message.public Proxy sendProxy(com.sun.jna.Pointer receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The object to which the message is being sent.selector
- The selector to call on the receiver.args
- Variable arguments to the message.public Proxy chain(java.lang.String cls, com.sun.jna.Pointer selector, java.lang.Object... args)
public Proxy chain(java.lang.String cls, java.lang.String selector, java.lang.Object... args)
cls
- selector
- args
- public PeerableRecipient newObject(java.lang.Class<? extends PeerableRecipient> cls)
cls
- The class of the instance that should be created.public java.lang.Object send(Message... messages)
messages
- public Message[] buildMessageChain(java.lang.Object... parameters)
parameters
-