Class Client

extends Object
A client for sending and receiving messages to an external process.
Each Toit process can only create one client for any given external process.

Class summary


open id/string --on-notify/Lambda= -> Client
Opens a client for an external process with the given id.

Statics

open id/string --on-notify/Lambda=null -> Client
Opens a client for an external process with the given id.
Throws, if no external process with the given id is found, or if there already exists an open client for that id.
If provided, then the on-notify lambda is registered as notification callback for messages from the external process. It is possible to change or delete the callback later by calling set-on-notify.

Methods

close -> none
Closes the client.

Whether the client is already closed.

notify message/Data --copy/bool=true -> none
Sends a notification message to the external process.
If the message is a string, then the receiver is guaranteed to receive the string data with an additional 0-terminator. The external process can safely interpret it as a C string. The length argument to the receiver does *not* include the 0-terminator.
If copy is true (the default) copies the given message before sending it.
If copy is false, attempts to transfer ownership of the message to the external process. This is only possible for ByteArray instances that have their data stored in external memory, that is, not in the Toit heap. In that case, the message object is neutered and can no longer be used.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

request function/int message/Data --copy/bool=true -> any
Sends an RPC request to the external process.
The function id is an integer that the external process receives as argument. External processes are free to interpret this id as they see fit.
If the message is a string, then the receiver is guaranteed to receive the string data with an additional 0-terminator. The external process can safely interpret it as a C string. The length argument to the receiver does *not* include the 0-terminator.
If copy is true (the default), copies the given message before sending it.
If copy is false, attempts to transfer ownership of the message to the external process. This is only possible for ByteArray instances that have their data stored in external memory, that is, not in the Toit heap. In that case, the message object is neutered and can no longer be used.

set-on-notify callback/Lambda -> none
Sets, updates or deletes the notification callback for messages from the external process.
If callback is null, then the current callback is deleted.
If callback is not null, then the current callback is updated.

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

Fields