ca.weblite.objc
Class Client

java.lang.Object
  extended by ca.weblite.objc.Client

public class Client
extends 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:

  1. 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.
  2. 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.

Author:
shannah

Constructor Summary
Client()
           
 
Method Summary
 Message[] buildMessageChain(Object... parameters)
          Builds a chain of messages that can be executed together at a later time.
 Proxy chain(String cls, com.sun.jna.Pointer selector, Object... args)
           
 Proxy chain(String cls, String selector, 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(Class<? extends PeerableRecipient> cls)
          Creates a new peerable and receivable object of the specified class.
 Object send(Message... messages)
          Sends an array of messages in a chain.
 Object send(Peerable proxy, com.sun.jna.Pointer selector, Object... args)
          Sends a message to an Objective-C object.
 Object send(Peerable proxy, String selector, Object... args)
          Sends a message to an Objective-C object.
 Object send(com.sun.jna.Pointer receiver, com.sun.jna.Pointer selector, Object... args)
          Sends a message to an Objective-C object.
 Object send(com.sun.jna.Pointer receiver, String selector, Object... args)
          Sends a message to an Objective-C object.
 Object send(String receiver, com.sun.jna.Pointer selector, Object... args)
          Sends a message to an Objective-C object.
 Object send(String receiver, String selector, 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, 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, String selector, Object... args)
          A wrapper around send() to ensure that a pointer is returned from the message.
 com.sun.jna.Pointer sendPointer(String receiver, com.sun.jna.Pointer selector, Object... args)
          A wrapper around send() to ensure that a pointer is returned from the message.
 com.sun.jna.Pointer sendPointer(String receiver, String selector, 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, Object... args)
          A wrapper around send() to ensure that a Proxy object is returned from the message.
 Proxy sendProxy(com.sun.jna.Pointer receiver, String selector, Object... args)
          A wrapper around send() to ensure that a Proxy object is returned from the message.
 Proxy sendProxy(String receiver, com.sun.jna.Pointer selector, Object... args)
          A wrapper around send() to ensure that a Proxy object is returned from the message.
 Proxy sendProxy(String receiver, String selector, 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Client

public Client()
Method Detail

getInstance

public static Client getInstance()
Retrieves the global reference to a client that has both input coercion and output coercion enabled.

Returns:
Singleton instance.

getRawClient

public static Client getRawClient()
Retrieves singleton instance to a simple client that has type coercion disabled for both inputs and outputs.

Returns:

setCoerceInputs

public Client setCoerceInputs(boolean coerceInputs)
Set the coerceInputs flag. Setting this to true will cause all subsequent requests to coerce the input (i.e. convert Java parameters to corresponding C-types).

Parameters:
coerceInputs - Whether to coerce inputs to messages.
Returns:
Self for chaining.
See Also:
TypeMapper, TypeMapping

setCoerceOutputs

public Client setCoerceOutputs(boolean coerceOutputs)
Sets the coerceOutputs flag. Setting this to true will cause all subsequent requests to coerce the output (i.e.convert C return values to corresponding Java types.

Parameters:
coerceOutputs - Whether to coerce the outputs of messages.
Returns:
Self for chaining.
See Also:
TypeMapper, TypeMapping

getCoerceInputs

public boolean getCoerceInputs()
Returns the coerceInputs flag. If this returns true, then it means that the client is currently set to coerce all inputs to messages.

Returns:
True if input coercion is enabled.
See Also:
TypeMapper, TypeMapping

getCoerceOutputs

public boolean getCoerceOutputs()
Returns the coerceOutputs flag. If this returns true, then it means that the client is currently set to coerce all outputs of messages.

Returns:
True if output coercion is enabled.
See Also:
TypeMapper, TypeMapping

send

public Object send(com.sun.jna.Pointer receiver,
                   com.sun.jna.Pointer selector,
                   Object... args)
Sends a message to an Objective-C object.
 String hello = (String)Client.getInstance()
      .send(cls("NSString"), sel("stringWithUTF8String:"), "Hello");
 
 

Parameters:
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.
Returns:
The return value of the message call.

send

public Object send(com.sun.jna.Pointer receiver,
                   String selector,
                   Object... args)
Sends a message to an Objective-C object. String selector version.
 String hello = (String)Client.getInstance()
      .send(cls("NSString"), "stringWithUTF8String:", "Hello");
 
 

Parameters:
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.
Returns:
The return value of the message call.

send

public Object send(String receiver,
                   com.sun.jna.Pointer selector,
                   Object... args)
Sends a message to an Objective-C object. String target and Pointer selector version. Typically this variant is used when you need to call a class method (e.g. to instantiate a new object). In this case the receiver is interpreted as a class name.
 String hello = (String)Client.getInstance()
      .send("NSString", sel("stringWithUTF8String:"), "Hello");
 
 

Parameters:
receiver - The name of a class to send the message to.
selector - Pointer to the selector.
args - Variable arguments of the message.
Returns:
The return value of the message call.

send

public Object send(String receiver,
                   String selector,
                   Object... args)
Sends a message to an Objective-C object. String target and String selector version. Typically this variant is used when you need to call a class method (e.g. to instantiate a new object). In this case the receiver is interpreted as a class name.
 String hello = (String)Client.getInstance()
      .send("NSString", "stringWithUTF8String:", "Hello");
 
 

Parameters:
receiver - The name of a class to send the message to.
selector - Pointer to the selector.
args - Variable arguments of the message.
Returns:
The return value of the message call.

send

public Object send(Peerable proxy,
                   com.sun.jna.Pointer selector,
                   Object... args)
Sends a message to an Objective-C object. Peerable target/Pointer selector variant. This variant is used if you have a Peerable object that is wrapping the Object pointer. E.g. Both the Proxy class and NSObject class implement this interface.
 Proxy array = Client.getInstance().sendProxy("NSMutableArray", sel("array"));
 String hello = (String)Client
      .getInstance().send(array, sel("addObject:atIndex"), "Hello", 2);
 
 

Parameters:
receiver - The object to which we are sending the message.
selector - Pointer to the selector.
args - Variable arguments of the message.
Returns:
The return value of the message call.

send

public Object send(Peerable proxy,
                   String selector,
                   Object... args)
Sends a message to an Objective-C object. Peerable target/String selector variant. This variant is used if you have a Peerable object that is wrapping the Object pointer. E.g. Both the Proxy class and NSObject class implement this interface.
 Proxy array = Client.getInstance().sendProxy("NSMutableArray", "array");
 String hello = (String)Client
      .getInstance().send(array, "addObject:atIndex", "Hello", 2);
 
 

Parameters:
receiver - The object to which we are sending the message.
selector - Pointer to the selector.
args - Variable arguments of the message.
Returns:
The return value of the message call.

sendPointer

public com.sun.jna.Pointer sendPointer(com.sun.jna.Pointer receiver,
                                       com.sun.jna.Pointer selector,
                                       Object... args)
A wrapper around send() to ensure that a pointer is returned from the message.

Parameters:
receiver - The object to which the message is being sent.
selector - The selector to call on the receiver.
args - Variable arguments to the message.
Returns:
A pointer result from the message invocation.

sendPointer

public com.sun.jna.Pointer sendPointer(com.sun.jna.Pointer receiver,
                                       String selector,
                                       Object... args)
A wrapper around send() to ensure that a pointer is returned from the message.

Parameters:
receiver - The object to which the message is being sent.
selector - The selector to call on the receiver.
args - Variable arguments to the message.
Returns:
A pointer result from the message invocation.

sendPointer

public com.sun.jna.Pointer sendPointer(String receiver,
                                       com.sun.jna.Pointer selector,
                                       Object... args)
A wrapper around send() to ensure that a pointer is returned from the message.

Parameters:
receiver - The object to which the message is being sent.
selector - The selector to call on the receiver.
args - Variable arguments to the message.
Returns:
A pointer result from the message invocation.

sendPointer

public com.sun.jna.Pointer sendPointer(String receiver,
                                       String selector,
                                       Object... args)
A wrapper around send() to ensure that a pointer is returned from the message.

Parameters:
receiver - The object to which the message is being sent.
selector - The selector to call on the receiver.
args - Variable arguments to the message.
Returns:
A pointer result from the message invocation.

sendProxy

public Proxy sendProxy(com.sun.jna.Pointer receiver,
                       com.sun.jna.Pointer selector,
                       Object... args)
A wrapper around send() to ensure that a Proxy object is returned from the message.

Parameters:
receiver - The object to which the message is being sent.
selector - The selector to call on the receiver.
args - Variable arguments to the message.
Returns:
A Proxy object wrapper of the result from the message invocation.

sendProxy

public Proxy sendProxy(String receiver,
                       com.sun.jna.Pointer selector,
                       Object... args)
A wrapper around send() to ensure that a Proxy object is returned from the message.

Parameters:
receiver - The object to which the message is being sent.
selector - The selector to call on the receiver.
args - Variable arguments to the message.
Returns:
A Proxy object wrapper of the result from the message invocation.

sendProxy

public Proxy sendProxy(String receiver,
                       String selector,
                       Object... args)
A wrapper around send() to ensure that a Proxy object is returned from the message.

Parameters:
receiver - The object to which the message is being sent.
selector - The selector to call on the receiver.
args - Variable arguments to the message.
Returns:
A Proxy object wrapper of the result from the message invocation.

sendProxy

public Proxy sendProxy(com.sun.jna.Pointer receiver,
                       String selector,
                       Object... args)
A wrapper around send() to ensure that a Proxy object is returned from the message.

Parameters:
receiver - The object to which the message is being sent.
selector - The selector to call on the receiver.
args - Variable arguments to the message.
Returns:
A Proxy object wrapper of the result from the message invocation.

chain

public Proxy chain(String cls,
                   com.sun.jna.Pointer selector,
                   Object... args)

chain

public Proxy chain(String cls,
                   String selector,
                   Object... args)
Deprecated. 

Parameters:
cls -
selector -
args -
Returns:

newObject

public PeerableRecipient newObject(Class<? extends PeerableRecipient> cls)
Creates a new peerable and receivable object of the specified class. This will create the Objective-C peer and link it to this new class.

Parameters:
cls - The class of the instance that should be created.
Returns:
A PeerableRecipient object that is connected to an objective-c peer object.

send

public Object send(Message... messages)
Sends an array of messages in a chain.

Parameters:
messages -
Returns:

buildMessageChain

public Message[] buildMessageChain(Object... parameters)
Builds a chain of messages that can be executed together at a later time.

Parameters:
parameters -
Returns:


Copyright © 2012–2014 Web Lite Solutions Corp.. All rights reserved.