public class RuntimeUtils
extends java.lang.Object
It is helpful to perform a static import of the methods in this class if you will be using the objc runtime library, as it contains many utility methods to deal with Objective-C primitives. E.g. the cls() method can return the Pointer to a class given its name. The clsName() returns the name of the class specified by a Pointer().
There are also many variants of the msg() method for sendng messages to objects in the Objective-C runtime.
Modifier and Type | Field and Description |
---|---|
static boolean |
loaded
Flag to indicate whether the jcocoa native library was loaded successfully.
|
static Runtime |
rt
Short reference to the runtime instance for interacting with Objective-C
|
Constructor and Description |
---|
RuntimeUtils() |
Modifier and Type | Method and Description |
---|---|
static com.sun.jna.Pointer |
addr(Peerable peer)
Returns the pointer to the Native peer for a Peerable object.
|
static int |
arraySize(java.lang.String signature)
Returns the size of an array that is specified in a signature.
|
static com.sun.jna.Pointer |
cls(Peerable peer)
Returns a pointer to a class given a Peerable object which wraps
the pointer.
|
static com.sun.jna.Pointer |
cls(java.lang.String name)
Returns a pointer to the class for specific class name.
|
static java.lang.String |
clsName(Peerable peer)
A wrapper for the clsName() method given a Peerable object that wraps
the class pointer.
|
static java.lang.String |
clsName(com.sun.jna.Pointer cls)
Returns the name of an objective C class specified by the given class pointer.
|
static long |
createProxy(Recipient client)
Registers a Java object with the Objective-C runtime so that it can begin
to receive messages from it.
|
static com.sun.jna.Pointer |
getAsReference(java.lang.Object val,
java.lang.String signature)
Wraps the given value in the appropriate ByReference subclass according
to the provided signature.
|
static com.sun.jna.ptr.ByReference |
getAsReferenceWrapper(java.lang.Object val,
java.lang.String signature)
Wraps the given value in the appropriate ByReference subclass according
to the provided signature.
|
static Recipient |
getJavaPeer(long nsObject)
Returns the Java peer recipient for a native Objective-C object if it
exists.
|
static void |
init()
Initializes the libjcocoa library.
|
static java.lang.Object |
msg(boolean coerceReturn,
boolean coerceArgs,
com.sun.jna.Pointer receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Sends a message with the option of coercing the inputs and outputs.
|
static java.lang.Object |
msg(Message... messages)
Sends a batch of messages in sequence.
|
static long |
msg(com.sun.jna.Pointer receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Sends a message to a specified class using the given selector.
|
static long |
msg(com.sun.jna.Pointer receiver,
java.lang.String msg,
java.lang.Object... args)
Sends a message to a specified class using the given selector.
|
static long |
msg(java.lang.String cls,
com.sun.jna.Pointer msg,
java.lang.Object... args)
Sends a message to a specified class using the given selector.
|
static long |
msg(java.lang.String cls,
java.lang.String msg,
java.lang.Object... args)
Sends a message to a specified class using the given selector.
|
static boolean |
msgBoolean(com.sun.jna.Pointer receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Wrapper around msg() that returns a boolean value.
|
static boolean |
msgBoolean(com.sun.jna.Pointer receiver,
java.lang.String selector,
java.lang.Object... args)
Wrapper around msg() that returns a boolean value.
|
static boolean |
msgBoolean(java.lang.String receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Wrapper around msg() that returns a boolean value.
|
static boolean |
msgBoolean(java.lang.String receiver,
java.lang.String selector,
java.lang.Object... args)
Wrapper around msg() that returns a boolean value.
|
static double |
msgDouble(com.sun.jna.Pointer receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Sends a message that returns a double value.
|
static double |
msgDouble(com.sun.jna.Pointer receiver,
java.lang.String selector,
java.lang.Object... args)
Sends a message that returns a double value.
|
static double |
msgDouble(java.lang.String receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Sends a message that returns a double value.
|
static double |
msgDouble(java.lang.String receiver,
java.lang.String selector,
java.lang.Object... args)
Sends a message that returns a double value.
|
static int |
msgInt(com.sun.jna.Pointer receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Wrapper around msg() that returns an int.
|
static int |
msgInt(com.sun.jna.Pointer receiver,
java.lang.String selector,
java.lang.Object... args)
Wrapper around msg() that returns an int.
|
static int |
msgInt(java.lang.String receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Wrapper around msg() that returns an int.
|
static int |
msgInt(java.lang.String receiver,
java.lang.String selector,
java.lang.Object... args)
Wrapper around msg() that returns an int.
|
static com.sun.jna.Pointer |
msgPointer(com.sun.jna.Pointer receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Wrapper around msg() that returns a Pointer.
|
static com.sun.jna.Pointer |
msgPointer(com.sun.jna.Pointer receiver,
java.lang.String selector,
java.lang.Object... args)
Wrapper around msg() that returns a Pointer.
|
static com.sun.jna.Pointer |
msgPointer(java.lang.String receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Wrapper around msg() that returns a Pointer.
|
static com.sun.jna.Pointer |
msgPointer(java.lang.String receiver,
java.lang.String selector,
java.lang.Object... args)
Wrapper around msg() that returns a Pointer.
|
static java.lang.String |
msgString(com.sun.jna.Pointer receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Wrapper around msg() that returns a string value.
|
static java.lang.String |
msgString(com.sun.jna.Pointer receiver,
java.lang.String selector,
java.lang.Object... args)
Wrapper around msg() that returns a string value.
|
static java.lang.String |
msgString(java.lang.String receiver,
com.sun.jna.Pointer selector,
java.lang.Object... args)
Wrapper around msg() that returns a string value.
|
static java.lang.String |
msgString(java.lang.String receiver,
java.lang.String selector,
java.lang.Object... args)
Wrapper around msg() that returns a string value.
|
static com.sun.jna.Pointer |
sel(Peerable peer)
Returns a pointer to the selector that is wrapped by a Peerable object.
|
static com.sun.jna.Pointer |
sel(java.lang.String name)
Returns a pointer to the selector specified by the given selector name.
|
static java.lang.String |
selName(Peerable peer)
Returns the name of a selector.
|
static java.lang.String |
selName(com.sun.jna.Pointer sel)
Returns the name of a selector.
|
static java.lang.String |
str(com.sun.jna.Pointer str)
Converts A native NSString object to a Java string.
|
static com.sun.jna.Pointer |
str(java.lang.String str)
Converts a Java string to an NSString object.
|
public static Runtime rt
public static boolean loaded
public static com.sun.jna.Pointer cls(java.lang.String name)
Pointer nsObject = cls("NSObject");
name
- The name of the class to retrieve.public static com.sun.jna.Pointer cls(Peerable peer)
peer
- The peer object that is wrapping the Objective-C class
object.public static java.lang.String clsName(com.sun.jna.Pointer cls)
cls
- The pointer to the class whose name we wish to retrieve.Runtime.class_getName()
public static java.lang.String clsName(Peerable peer)
peer
- Runtime.class_getName()
public static com.sun.jna.Pointer sel(java.lang.String name)
name
- public static com.sun.jna.Pointer sel(Peerable peer)
peer
- public static java.lang.String selName(com.sun.jna.Pointer sel)
sel
- Pointer to a selector.public static java.lang.String selName(Peerable peer)
sel
- Peerable that wraps a pointer to a selector.public static long msg(java.lang.String cls, java.lang.String msg, java.lang.Object... args)
cls
- The name of the class.msg
- The name of the selector.args
- The arguments passed to the method. These are passed raw
and will not be coerced.msgDouble()
public static long msg(java.lang.String cls, com.sun.jna.Pointer msg, java.lang.Object... args)
cls
- The name of the class.msg
- The name of the selector.args
- The arguments passed to the method. These are passed raw
and will not be coerced.msgDouble()
public static long msg(com.sun.jna.Pointer receiver, java.lang.String msg, java.lang.Object... args)
cls
- The name of the class.msg
- The name of the selector.args
- The arguments passed to the method. These are passed raw
and will not be coerced.msgDouble()
public static long msg(com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
cls
- The name of the class.msg
- The name of the selector.args
- The arguments passed to the method. These are passed raw
and will not be coerced.msgDouble()
public static com.sun.jna.Pointer msgPointer(com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static com.sun.jna.Pointer msgPointer(com.sun.jna.Pointer receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static com.sun.jna.Pointer msgPointer(java.lang.String receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static com.sun.jna.Pointer msgPointer(java.lang.String receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static int msgInt(com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static int msgInt(java.lang.String receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static int msgInt(java.lang.String receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static int msgInt(com.sun.jna.Pointer receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static boolean msgBoolean(com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- Arguments passed to the message.public static boolean msgBoolean(java.lang.String receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- Arguments passed to the message.public static boolean msgBoolean(java.lang.String receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- Arguments passed to the message.public static boolean msgBoolean(com.sun.jna.Pointer receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- Arguments passed to the message.public static java.lang.String msgString(com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- Arguments passed to the message.public static java.lang.String msgString(java.lang.String receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- Arguments passed to the message.public static java.lang.String msgString(java.lang.String receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- Arguments passed to the message.public static java.lang.String msgString(com.sun.jna.Pointer receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- Arguments passed to the message.public static double msgDouble(com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static double msgDouble(java.lang.String receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static double msgDouble(java.lang.String receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static double msgDouble(com.sun.jna.Pointer receiver, java.lang.String selector, java.lang.Object... args)
receiver
- The target of the message.selector
- The selector for the message.args
- The arguments passed to the message.public static java.lang.Object msg(boolean coerceReturn, boolean coerceArgs, com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, java.lang.Object... args)
Furthermore, this variant is smart about which variable of msg() to call behind the scenes. E.g. if the message signature specifies that this message returns a double, it will automatically use the double variant of msg().
coerceReturn
- If true, then the return value will be mapped to an appropriate
Java value using the TypeMapper class.coerceArgs
- If true, then the inputs will be mapped from Java to appropriate
C values using the TypeMapper class.receiver
- The target of the message.selector
- The selector for the message.args
- The arguments to be passed in the message.public static int arraySize(java.lang.String signature)
signature
- The signature for a parameter using Objective-C type encodings.public static com.sun.jna.Pointer addr(Peerable peer)
peer
- public static java.lang.Object msg(Message... messages)
messages
- public static com.sun.jna.Pointer str(java.lang.String str)
str
- The Java string to convert.public static java.lang.String str(com.sun.jna.Pointer str)
str
- public static com.sun.jna.Pointer getAsReference(java.lang.Object val, java.lang.String signature)
val
- The value to be wrapped in a byReference.signature
- The signature (using Objective-C type encodings) of the value.public static com.sun.jna.ptr.ByReference getAsReferenceWrapper(java.lang.Object val, java.lang.String signature)
val
- The value to be wrapped in a byReference.signature
- The signature (using Objective-C type encodings) of the value.public static void init()
public static long createProxy(Recipient client)
client
- public static Recipient getJavaPeer(long nsObject)
nsObject
-