librpc
Macros | Typedefs | Enumerations | Functions
connection.h File Reference
#include <Block.h>
#include <sys/time.h>
#include <rpc/config.h>
#include <rpc/object.h>
Include dependency graph for connection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RPC_HANDLER(_fn, _arg)
 
#define RPC_PROPERTY_HANDLER(_fn, _arg)
 
#define RPC_ERROR_HANDLER(_fn, _arg)
 
#define RPC_RAW_HANDLER(_fn, _arg)
 
#define RPC_CALLBACK(_fn, _arg)
 
#define RPC_NULL_FORMAT   "[]"
 

Typedefs

typedef enum rpc_error_code rpc_error_code_t
 
typedef enum rpc_call_status rpc_call_status_t
 
typedef enum rpc_call_type rpc_call_type_t
 
typedef struct rpc_connection * rpc_connection_t
 
typedef struct rpc_call * rpc_call_t
 
typedef void(^ rpc_handler_t) (const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name, _Nonnull rpc_object_t args)
 
typedef void(^ rpc_property_handler_t) (_Nonnull rpc_object_t value)
 
typedef void(^ rpc_error_handler_t) (rpc_error_code_t code, _Nullable rpc_object_t args)
 
typedef int(^ rpc_raw_handler_t) (const void *_Nonnull msg, size_t len, const int *_Nullable fds, size_t nfds)
 
typedef bool(^ rpc_callback_t) (_Nonnull rpc_call_t call)
 

Enumerations

enum  rpc_error_code {
  RPC_INVALID_RESPONSE = 1, RPC_CONNECTION_TIMEOUT, RPC_CONNECTION_CLOSED, RPC_CALL_TIMEOUT,
  RPC_SPURIOUS_RESPONSE, RPC_LOGOUT, RPC_TRANSPORT_ERROR, RPC_OTHER
}
 
enum  rpc_call_status {
  RPC_CALL_IN_PROGRESS, RPC_CALL_STREAM_START, RPC_CALL_MORE_AVAILABLE, RPC_CALL_DONE,
  RPC_CALL_ERROR, RPC_CALL_ABORTED, RPC_CALL_ENDED
}
 
enum  rpc_call_type { RPC_OUTBOUND_CALL, RPC_INBOUND_CALL }
 

Functions

_Nullable rpc_connection_t rpc_connection_create (void *_Nonnull cookie, _Nullable rpc_object_t params)
 
int rpc_connection_close (_Nonnull rpc_connection_t conn)
 
struct rpc_context *_Nullable rpc_connection_get_context (_Nonnull rpc_connection_t conn)
 
int rpc_connection_set_context (_Nonnull rpc_connection_t conn, struct rpc_context *_Nonnull ctx)
 
bool rpc_connection_is_open (_Nonnull rpc_connection_t conn)
 
bool rpc_connection_is_valid (_Nonnull rpc_connection_t conn)
 
int rpc_connection_get_fd (_Nonnull rpc_connection_t conn)
 
void rpc_connection_free (_Nonnull rpc_connection_t conn)
 
int rpc_connection_subscribe_event (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name)
 
int rpc_connection_unsubscribe_event (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name)
 
void *_Nullable rpc_connection_register_event_handler (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name, _Nullable rpc_handler_t handler)
 
int rpc_connection_unregister_event_handler (_Nonnull rpc_connection_t conn, void *_Nonnull cookie)
 
_Nullable rpc_object_t rpc_connection_call_sync (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull method,...)
 
_Nullable rpc_object_t rpc_connection_call_syncv (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull method, va_list ap)
 
_Nullable rpc_object_t rpc_connection_call_syncp (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull method, const char *_Nonnull fmt,...)
 
_Nullable rpc_object_t rpc_connection_call_syncpv (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull method, const char *_Nonnull fmt, va_list ap)
 
_Nullable rpc_object_t rpc_connection_call_simple (_Nonnull rpc_connection_t conn, const char *_Nonnull name, const char *_Nonnull fmt,...)
 
_Nullable rpc_call_t rpc_connection_call (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name, _Nullable rpc_object_t args, _Nullable rpc_callback_t callback)
 
_Nullable rpc_object_t rpc_connection_get_property (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name)
 
_Nullable rpc_object_t rpc_connection_set_property (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name, rpc_object_t _Nonnull value)
 
_Nullable rpc_object_t rpc_connection_set_propertyp (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name, const char *_Nonnull fmt,...)
 
_Nullable rpc_object_t rpc_connection_set_propertypv (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name, const char *_Nonnull fmt, va_list ap)
 
void *_Nullable rpc_connection_watch_property (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull property, _Nonnull rpc_property_handler_t handler)
 
int rpc_connection_send_event (_Nonnull rpc_connection_t conn, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name, _Nonnull rpc_object_t args)
 
int rpc_connection_ping (_Nonnull rpc_connection_t conn)
 
int rpc_connection_send_raw_message (_Nonnull rpc_connection_t conn, const void *_Nonnull msg, size_t len, const int *_Nullable fds, size_t nfds)
 
void rpc_connection_set_raw_message_handler (_Nonnull rpc_connection_t conn, _Nullable rpc_raw_handler_t handler)
 
void rpc_connection_set_event_handler (_Nonnull rpc_connection_t conn, _Nullable rpc_handler_t handler)
 
void rpc_connection_set_error_handler (_Nonnull rpc_connection_t conn, _Nullable rpc_error_handler_t handler)
 
const char *_Nullable rpc_connection_get_remote_address (_Nonnull rpc_connection_t conn)
 
bool rpc_connection_supports_fd_passing (_Nonnull rpc_connection_t conn)
 
bool rpc_connection_supports_credentials (_Nonnull rpc_connection_t conn)
 
bool rpc_connection_has_credentials (_Nonnull rpc_connection_t conn)
 
uid_t rpc_connection_get_remote_uid (_Nonnull rpc_connection_t conn)
 
gid_t rpc_connection_get_remote_gid (_Nonnull rpc_connection_t conn)
 
pid_t rpc_connection_get_remote_pid (_Nonnull rpc_connection_t conn)
 
int rpc_call_wait (_Nonnull rpc_call_t call)
 
int rpc_call_continue (_Nonnull rpc_call_t call, bool sync)
 
int rpc_call_abort (_Nonnull rpc_call_t call)
 
int rpc_call_set_prefetch (_Nonnull rpc_call_t call, size_t nitems)
 
int rpc_call_timedwait (_Nonnull rpc_call_t call, const struct timespec *_Nonnull ts)
 
int rpc_call_success (_Nonnull rpc_call_t call)
 
rpc_call_status_t rpc_call_status (_Nonnull rpc_call_t call)
 
_Nullable rpc_object_t rpc_call_result (_Nonnull rpc_call_t call)
 
void rpc_call_free (_Nonnull rpc_call_t call)
 

Detailed Description

RPC connection API.

Definition in file connection.h.

Macro Definition Documentation

◆ RPC_CALLBACK

#define RPC_CALLBACK (   _fn,
  _arg 
)
Value:
^(rpc_object_t _args, rpc_call_status_t _status) { \
return ((bool)_fn(_arg, _args, _status)); \
}
enum rpc_call_status rpc_call_status_t
struct rpc_object * rpc_object_t
Definition: object.h:73

Converts function pointer to a rpc_callback_t block type.

Definition at line 166 of file connection.h.

◆ RPC_ERROR_HANDLER

#define RPC_ERROR_HANDLER (   _fn,
  _arg 
)
Value:
^(rpc_error_code_t _code, rpc_object_t _args) { \
_fn(_arg, _code, _args); \
}
struct rpc_object * rpc_object_t
Definition: object.h:73
enum rpc_error_code rpc_error_code_t

Converts function pointer to a rpc_error_handler_t block type.

Definition at line 150 of file connection.h.

◆ RPC_HANDLER

#define RPC_HANDLER (   _fn,
  _arg 
)
Value:
^(const char *_path, const char *_iface, const char *_name, \
rpc_object_t _args) { \
_fn(_arg, _path, _iface, _name, _args); \
}

Converts function pointer to a rpc_handler_t block type.

Definition at line 133 of file connection.h.

◆ RPC_NULL_FORMAT

#define RPC_NULL_FORMAT   "[]"

Definition of Null-argument fmt to pass to rpc_connection_call_simple()

Definition at line 174 of file connection.h.

◆ RPC_PROPERTY_HANDLER

#define RPC_PROPERTY_HANDLER (   _fn,
  _arg 
)
Value:
^(rpc_object_t _value) { \
_fn(_arg, _value); \
}
struct rpc_object * rpc_object_t
Definition: object.h:73

Converts function pointer to a rpc_property_handler_t block type.

Definition at line 142 of file connection.h.

◆ RPC_RAW_HANDLER

#define RPC_RAW_HANDLER (   _fn,
  _arg 
)
Value:
^(const void *_msg, size_t _len, const int *_fds, size_t _nfd) {\
return (_fn(_arg, _msg, _len, _fds, _nfd)); \
}

Converts function pointer to a rpc_message_handler_t block type.

Definition at line 158 of file connection.h.

Typedef Documentation

◆ rpc_call_status_t

Enumerates possible remote procedure call status values.

◆ rpc_call_t

typedef struct rpc_call* rpc_call_t

Definition of RPC call pointer.

Definition at line 99 of file connection.h.

◆ rpc_call_type_t

Enumerates possible remote procedure call status values.

◆ rpc_callback_t

typedef bool(^ rpc_callback_t) (_Nonnull rpc_call_t call)

Definition of RPC callback block type.

Definition at line 128 of file connection.h.

◆ rpc_connection_t

typedef struct rpc_connection* rpc_connection_t

Definition of RPC connection pointer.

Definition at line 94 of file connection.h.

◆ rpc_error_code_t

Enumerates possible RPC error codes.

◆ rpc_error_handler_t

typedef void(^ rpc_error_handler_t) (rpc_error_code_t code, _Nullable rpc_object_t args)

Definition of RPC error handler block type.

Definition at line 116 of file connection.h.

◆ rpc_handler_t

typedef void(^ rpc_handler_t) (const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name, _Nonnull rpc_object_t args)

Definition of RPC event handler block type.

Definition at line 104 of file connection.h.

◆ rpc_property_handler_t

typedef void(^ rpc_property_handler_t) (_Nonnull rpc_object_t value)

Definition of RPC property change handler block type.

Definition at line 111 of file connection.h.

◆ rpc_raw_handler_t

typedef int(^ rpc_raw_handler_t) (const void *_Nonnull msg, size_t len, const int *_Nullable fds, size_t nfds)

Definition of raw message handler block type.

Definition at line 122 of file connection.h.

Enumeration Type Documentation

◆ rpc_call_status

Enumerates possible remote procedure call status values.

Enumerator
RPC_CALL_IN_PROGRESS 

Call in progress

RPC_CALL_STREAM_START 

Streaming response, stream starts

RPC_CALL_MORE_AVAILABLE 

Streaming response, more data available

RPC_CALL_DONE 

Call finished, response received

RPC_CALL_ERROR 

Call finished, error received

RPC_CALL_ABORTED 

Call was aborted by the user

RPC_CALL_ENDED 

Streaming call ended

Examples:
client.c.

Definition at line 71 of file connection.h.

◆ rpc_call_type

Enumerates possible remote procedure call status values.

Enumerator
RPC_OUTBOUND_CALL 

Call that is made by requestor

RPC_INBOUND_CALL 

Call to be delivered to responder

Definition at line 85 of file connection.h.

◆ rpc_error_code

Enumerates possible RPC error codes.

Enumerator
RPC_INVALID_RESPONSE 

Received unreadable response

RPC_CONNECTION_TIMEOUT 

Connection timed out

RPC_CONNECTION_CLOSED 

Disconnect received

RPC_CALL_TIMEOUT 

Request timed out

RPC_SPURIOUS_RESPONSE 

Response to unknown request

RPC_LOGOUT 

Logged out by server

RPC_TRANSPORT_ERROR 

Transport-specific error

RPC_OTHER 

Other or unknown reason

Definition at line 56 of file connection.h.

Function Documentation

◆ rpc_call_abort()

int rpc_call_abort ( _Nonnull rpc_call_t  call)

Aborts a pending call.

Parameters
callCall to be aborted
Returns
Function status - success is being reported as 0

◆ rpc_call_continue()

int rpc_call_continue ( _Nonnull rpc_call_t  call,
bool  sync 
)

Requests a next chunk of a result from a call.

When sync is set to true the function waits until the call finishes and returns 1 if it has completed successfully - otherwise the function returns 0.

Parameters
callCall to be continued
syncSynchronous continue flag
Returns
1 for successfully completed RPC when sync flag was set, otherwise 0
Examples:
client.c.

◆ rpc_call_free()

void rpc_call_free ( _Nonnull rpc_call_t  call)

Frees a rpc_call_t object.

Parameters
callCall to free

◆ rpc_call_result()

_Nullable rpc_object_t rpc_call_result ( _Nonnull rpc_call_t  call)

Returns a call result (or a current fragment).

Parameters
callCall to get result from
Returns
Result
Examples:
client.c, and libdispatch.c.

◆ rpc_call_set_prefetch()

int rpc_call_set_prefetch ( _Nonnull rpc_call_t  call,
size_t  nitems 
)

Sets how many items librpc should prefetch in a streaming call.

Parameters
call
nitems
Returns
Examples:
client.c.

◆ rpc_call_status()

Returns a current status of a given call as an integer value castable to rpc_call_status_t.

Parameters
callCall to be checked
Returns
Call status

◆ rpc_call_success()

int rpc_call_success ( _Nonnull rpc_call_t  call)

Checks whether a call has been completed successfully.

Parameters
callCall to be checked
Returns
1 when call was successfully completed, otherwise 0

◆ rpc_call_timedwait()

int rpc_call_timedwait ( _Nonnull rpc_call_t  call,
const struct timespec *_Nonnull  ts 
)

Waits for a call to change status.

If a timeout specified by a ts argument occurs, before a call changes its status, function returns -1 value.

Parameters
callCall to wait on
tsTimeout value
Returns
0 on success, -1 on failure or timeout

◆ rpc_call_wait()

int rpc_call_wait ( _Nonnull rpc_call_t  call)

Waits for a call to change status.

Parameters
callCall to wait on.
Returns
0 on success, -1 on failure.
Examples:
client.c.

◆ rpc_connection_call()

_Nullable rpc_call_t rpc_connection_call ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  name,
_Nullable rpc_object_t  args,
_Nullable rpc_callback_t  callback 
)

Performs a RPC method call using a given connection.

Function returns immediately without waiting for a RPC completion and returns rpc_call_t object representing the ongoing call.

Function supports a callback argument of rpc_callback_t type, which is a pointer to a function to be called on RPC completion. Can be set to NULL when that functionality is not needed by the caller.

Parameters
connConnection to do a call on
nameName of a method to be called
argsVariable length RPC method arguments list
callbackCallback function pointer to be called on RPC completion
Returns
RPC call object
Examples:
client.c, and libdispatch.c.

◆ rpc_connection_call_simple()

_Nullable rpc_object_t rpc_connection_call_simple ( _Nonnull rpc_connection_t  conn,
const char *_Nonnull  name,
const char *_Nonnull  fmt,
  ... 
)

Performs a synchronous RPC function call using a given connection.

Function blocks until a result is ready and returns it, or cancels and returns a NULL pointer if a timeout has occurred.

This function can be only used to call pure functions (not operating on objects, that is, like rpc_connection_call_syncp() but with path and interface parameters set to NULL). Use RPC_NULL_FORMAT to indicate a null format string.

Parameters
name
fmt
...
Returns
Examples:
client.c, fd-transport.c, loopback.c, pack-unpack.c, and shm-client.c.

◆ rpc_connection_call_sync()

_Nullable rpc_object_t rpc_connection_call_sync ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  method,
  ... 
)

Performs a synchronous RPC method call using a given connection.

Function blocks until a result is ready and returns it, or cancels and returns a NULL pointer if a timeout has occurred.

Method call arguments need to be rpc_object_t instances, followed with a NULL, denoting end of variable argument list.

Parameters
connConnection to do a call on
methodName of a method to be called
...Called method arguments
Returns
Result of the call
Examples:
fd-client.c.

◆ rpc_connection_call_syncp()

_Nullable rpc_object_t rpc_connection_call_syncp ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  method,
const char *_Nonnull  fmt,
  ... 
)

Performs a synchronous RPC method call using a given connection.

This function is similar to rpc_connection_call_sync(), but instead of taking rpc_object_t arguments, it accepts a format string and a list of values to pack, in format used by the rpc_object_pack() function.

Parameters
connConnection handle
methodName of a method to be called
fmtFormat string
...Called method arguments
Returns
Result of the call

◆ rpc_connection_call_syncpv()

_Nullable rpc_object_t rpc_connection_call_syncpv ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  method,
const char *_Nonnull  fmt,
va_list  ap 
)

A variation of rpc_connection_call_syncp that takes a va_list instead of the variable argument list.

Parameters
connConnection handle
path
interface
method
fmt
ap
Returns

◆ rpc_connection_call_syncv()

_Nullable rpc_object_t rpc_connection_call_syncv ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  method,
va_list  ap 
)

Performs a synchronous RPC method call using a given connection.

Function blocks until a result is ready and returns it, or cancels and returns a NULL pointer if a timeout has occurred.

Instead of variable arguments length in rpc_connection_call() example, this function takes previously assembled variable arguments list structure as its argument.

Parameters
connConnection to do a call on
methodName of a method to be called
apVariable arguments list structure describing a method arguments
Returns
Result of the call

◆ rpc_connection_close()

int rpc_connection_close ( _Nonnull rpc_connection_t  conn)

Closes the connection and frees all resources associated with it.

Parameters
connConnection to close
Returns
0 on success, -1 on failure

◆ rpc_connection_create()

_Nullable rpc_connection_t rpc_connection_create ( void *_Nonnull  cookie,
_Nullable rpc_object_t  params 
)

Creates a new connection from the provided opaque cookie.

Parameters
cookieOpaque data
paramsTransport-specific parameters
Returns
Connection handle or NULL on failure

◆ rpc_connection_free()

void rpc_connection_free ( _Nonnull rpc_connection_t  conn)

Frees resources associated with rpc_connection_t.

Parameters
connConnection handle

◆ rpc_connection_get_context()

struct rpc_context* _Nullable rpc_connection_get_context ( _Nonnull rpc_connection_t  conn)

Returns context associated with the connection.

Parameters
connClient connection
Returns
Context handle or NULL if not set

◆ rpc_connection_get_fd()

int rpc_connection_get_fd ( _Nonnull rpc_connection_t  conn)

Returns file descriptor associated with the connection.

Parameters
connConnection handle
Returns
File descriptor number

◆ rpc_connection_get_property()

_Nullable rpc_object_t rpc_connection_get_property ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  name 
)
Parameters
conn
path
interface
name
Returns

◆ rpc_connection_get_remote_address()

const char* _Nullable rpc_connection_get_remote_address ( _Nonnull rpc_connection_t  conn)
Parameters
conn
Returns
Examples:
server.c.

◆ rpc_connection_get_remote_gid()

gid_t rpc_connection_get_remote_gid ( _Nonnull rpc_connection_t  conn)
Parameters
connConnection handle
Returns

◆ rpc_connection_get_remote_pid()

pid_t rpc_connection_get_remote_pid ( _Nonnull rpc_connection_t  conn)
Parameters
connConnection handle
Returns
Examples:
client.c.

◆ rpc_connection_get_remote_uid()

uid_t rpc_connection_get_remote_uid ( _Nonnull rpc_connection_t  conn)

Gets remote side UID.

Parameters
connConnection handle
Returns

◆ rpc_connection_has_credentials()

bool rpc_connection_has_credentials ( _Nonnull rpc_connection_t  conn)

Returns true if a connection has associated remote credentials information.

Parameters
connConnection handle
Returns
true if credentials information is available, otherwise false
Examples:
client.c.

◆ rpc_connection_is_open()

bool rpc_connection_is_open ( _Nonnull rpc_connection_t  conn)

Returns true if connection is open, otherwise false.

This function allows the caller to determine if a connection is in the 'open' state, that is, not aborted or closed. It should only be called on a connection that can't have been freed as its validity is not checked.

Parameters
connConnection handle
Returns
true if connection is open, otherwise false

◆ rpc_connection_is_valid()

bool rpc_connection_is_valid ( _Nonnull rpc_connection_t  conn)

Returns true if connection is valid, otherwise false.

Unless the caller can guarantee that the connection can't be removed (by for example having created a call on the connection and not freeing it), the connection may become not-valid at any time. This function can be used to safely determine if the connection has been freed.

Parameters
connConnection handle
Returns
true if connection is valid, otherwise false

◆ rpc_connection_ping()

int rpc_connection_ping ( _Nonnull rpc_connection_t  conn)

Ping the other end of a connection.

◆ rpc_connection_register_event_handler()

void* _Nullable rpc_connection_register_event_handler ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  name,
_Nullable rpc_handler_t  handler 
)

Registers an event handler block for an event of a given name.

Each time an event occurs, a handler block is going to be called.

If the connection is no longer valid a NULL cookie will be returned and the last RPC error will be set to ECONNRESET. If the subscription is currently being iterated, it temporarily cannot be modified and a NULL cookie will also be returned, with the last error set to EBUSY.

Parameters
connConnection to register an event handler for
nameName of an event to be handled
handlerEvent handler of rpc_handler_t type
Returns
Cookie for rpc_connection_unregister_event_handler or NULL.

◆ rpc_connection_send_event()

int rpc_connection_send_event ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  name,
_Nonnull rpc_object_t  args 
)

Sends an event.

Parameters
connConnection to send event across
nameEvent name
argsEvent arguments or NULL
Returns
0 on success, -1 on failure

◆ rpc_connection_send_raw_message()

int rpc_connection_send_raw_message ( _Nonnull rpc_connection_t  conn,
const void *_Nonnull  msg,
size_t  len,
const int *_Nullable  fds,
size_t  nfds 
)
Parameters
conn
msg
len
fds
nfds
Returns

◆ rpc_connection_set_context()

int rpc_connection_set_context ( _Nonnull rpc_connection_t  conn,
struct rpc_context *_Nonnull  ctx 
)

Sets a context into the connection structure to allow a client to receive calls.

It is an error to submit a new context for a server-side connection or for a connection that is not open.

Parameters
connClient connection
ctxClient context
Returns
0 on success, -1 on failure.

◆ rpc_connection_set_error_handler()

void rpc_connection_set_error_handler ( _Nonnull rpc_connection_t  conn,
_Nullable rpc_error_handler_t  handler 
)

Sets global error handler for a connection.

Parameters
connConnection to set error handler for
handlerError handler block

◆ rpc_connection_set_event_handler()

void rpc_connection_set_event_handler ( _Nonnull rpc_connection_t  conn,
_Nullable rpc_handler_t  handler 
)

Sets global event handler for a connection.

Parameters
connConnection to set event handler for
handlerHandler block

◆ rpc_connection_set_property()

_Nullable rpc_object_t rpc_connection_set_property ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  name,
rpc_object_t _Nonnull  value 
)
Parameters
conn
path
interface
name
value
Returns

◆ rpc_connection_set_propertyp()

_Nullable rpc_object_t rpc_connection_set_propertyp ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  name,
const char *_Nonnull  fmt,
  ... 
)
Parameters
conn
path
interface
name
fmt
...
Returns

◆ rpc_connection_set_propertypv()

_Nullable rpc_object_t rpc_connection_set_propertypv ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  name,
const char *_Nonnull  fmt,
va_list  ap 
)
Parameters
conn
path
interface
name
fmt
ap
Returns

◆ rpc_connection_set_raw_message_handler()

void rpc_connection_set_raw_message_handler ( _Nonnull rpc_connection_t  conn,
_Nullable rpc_raw_handler_t  handler 
)
Parameters
conn
handler
Returns

◆ rpc_connection_subscribe_event()

int rpc_connection_subscribe_event ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  name 
)

Subscribes for an event.

This function can be called multiple times on a single event name - subsequent calls will not send a subscribe message to the server, but instead increment internal reference count for a subscription.

Calls to rpc_connection_subscribe_event() must be paired with rpc_connection_unsubscribe_event().

Parameters
connConnection to subscribe on
nameEvent name
Returns
0 on success, -1 on failure

◆ rpc_connection_supports_credentials()

bool rpc_connection_supports_credentials ( _Nonnull rpc_connection_t  conn)

Checks whether a given connection does support credentials.

Parameters
connConnection handle
Returns
true if credentials are supported, otherwise false

◆ rpc_connection_supports_fd_passing()

bool rpc_connection_supports_fd_passing ( _Nonnull rpc_connection_t  conn)

Checks whether a given connection does support file descriptor passing.

Parameters
connConnection handle
Returns
true if fd passing is supported, otherwise false

◆ rpc_connection_unregister_event_handler()

int rpc_connection_unregister_event_handler ( _Nonnull rpc_connection_t  conn,
void *_Nonnull  cookie 
)

Cancels further execution of a given event handler block for ongoing events of a given name.

An error will be indicated if the connection is not valid (ECONNRESET) or if the handler can't be unregistered because the subscription is currently being iterated (EBUSY).

Parameters
connConnection to remove event handler from
cookieVoid pointer to event handler itself
Returns
0 on success, -1 on error

◆ rpc_connection_unsubscribe_event()

int rpc_connection_unsubscribe_event ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  name 
)

Undoes previous event subscription.

This function may either:

  • decrement reference count of subscription for given event
  • send unsubscribe message to the server (when subscription reference count reached value of 0)
Parameters
connConnection to undo the subscription on
nameEvent name
Returns
0 on success, -1 on failure

◆ rpc_connection_watch_property()

void* _Nullable rpc_connection_watch_property ( _Nonnull rpc_connection_t  conn,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  property,
_Nonnull rpc_property_handler_t  handler 
)
Parameters
conn
path
interface
property
handler
Returns