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

Go to the source code of this file.

Classes

struct  rpc_if_method
 
struct  rpc_if_property
 
struct  rpc_if_member
 

Macros

#define __unsafe_unretained
 
#define RPC_FUNCTION_STILL_RUNNING   ((rpc_object_t)1)
 
#define RPC_DISCOVERABLE_INTERFACE   "com.twoporeguys.librpc.Discoverable"
 
#define RPC_INTROSPECTABLE_INTERFACE   "com.twoporeguys.librpc.Introspectable"
 
#define RPC_OBSERVABLE_INTERFACE   "com.twoporeguys.librpc.Observable"
 
#define RPC_DEFAULT_INTERFACE   "com.twoporeguys.librpc.Default"
 
#define RPC_FUNCTION(_fn)
 
#define RPC_PROPERTY_GETTER(_fn)
 
#define RPC_PROPERTY_SETTER(_fn)
 
#define RPC_ABORT_HANDLER(_fn, _arg)
 
#define RPC_EVENT(_name)
 
#define RPC_PROPERTY_RO(_name, _getter)
 
#define RPC_PROPERTY_WO(_name, _setter)
 
#define RPC_PROPERTY_RW(_name, _getter, _setter)
 
#define RPC_METHOD(_name, _fn)
 
#define RPC_METHOD_BLOCK(_name, _block)
 
#define RPC_MEMBER_END   {}
 

Typedefs

typedef struct rpc_context * rpc_context_t
 
typedef struct rpc_instance * rpc_instance_t
 
typedef _Nullable rpc_object_t(^ rpc_function_t) (void *_Nonnull cookie, _Nonnull rpc_object_t args)
 
typedef _Nullable rpc_object_t(* rpc_function_f) (void *_Nonnull cookie, _Nonnull rpc_object_t args)
 
typedef _Nullable rpc_object_t(^ rpc_property_getter_t) (void *_Nonnull cookie)
 
typedef void(^ rpc_property_setter_t) (void *_Nonnull cookie, _Nonnull rpc_object_t value)
 
typedef void(^ rpc_abort_handler_t) (void)
 

Enumerations

enum  rpc_if_member_type { RPC_MEMBER_EVENT, RPC_MEMBER_PROPERTY, RPC_MEMBER_METHOD }
 
enum  rpc_property_rights { RPC_PROPERTY_READ = (1 << 0), RPC_PROPERTY_WRITE = (1 << 1) }
 

Functions

_Nonnull rpc_context_t rpc_context_create (void)
 
void rpc_context_free (_Nonnull rpc_context_t context)
 
_Nullable rpc_instance_t rpc_context_find_instance (_Nonnull rpc_context_t context, const char *_Nonnull path)
 
_Nonnull rpc_instance_t rpc_context_get_root (_Nonnull rpc_context_t context)
 
int rpc_context_register_instance (_Nonnull rpc_context_t context, _Nonnull rpc_instance_t instance)
 
void rpc_context_unregister_instance (_Nonnull rpc_context_t context, const char *_Nonnull path)
 
int rpc_context_register_member (_Nonnull rpc_context_t context, const char *_Nullable interface, struct rpc_if_member *_Nonnull m)
 
int rpc_context_register_block (_Nonnull rpc_context_t context, const char *_Nullable interface, const char *_Nonnull name, void *_Nullable arg, _Nonnull rpc_function_t func)
 
int rpc_context_register_func (_Nonnull rpc_context_t context, const char *_Nullable interface, const char *_Nonnull name, void *_Nullable arg, _Nonnull rpc_function_f func)
 
int rpc_context_unregister_member (_Nonnull rpc_context_t context, const char *_Nullable interface, const char *_Nonnull name)
 
void rpc_context_set_pre_call_hook (_Nonnull rpc_context_t context, _Nonnull rpc_function_t fn)
 
void rpc_context_set_post_call_hook (_Nonnull rpc_context_t context, _Nonnull rpc_function_t fn)
 
_Nullable rpc_call_t rpc_context_dispatch_call (_Nonnull rpc_context_t context, const char *_Nonnull name, _Nullable rpc_object_t args)
 
void rpc_context_emit_event (_Nonnull rpc_context_t context, const char *_Nullable path, const char *_Nullable interface, const char *_Nonnull name, _Nonnull rpc_object_t args)
 
void *_Nullable rpc_function_get_arg (void *_Nonnull cookie)
 
_Nonnull rpc_context_t rpc_function_get_context (void *_Nonnull cookie)
 
_Nullable rpc_connection_t rpc_function_get_connection (void *_Nonnull cookie)
 
_Nonnull rpc_instance_t rpc_function_get_instance (void *_Nonnull cookie)
 
const char *_Nonnull rpc_function_get_name (void *_Nonnull cookie)
 
const char *_Nonnull rpc_function_get_path (void *_Nonnull cookie)
 
const char *_Nonnull rpc_function_get_interface (void *_Nonnull cookie)
 
void rpc_function_respond (void *_Nonnull cookie, _Nullable rpc_object_t object)
 
void rpc_function_error (void *_Nonnull cookie, int code, const char *_Nonnull message,...)
 
void rpc_function_error_ex (void *_Nonnull cookie, _Nonnull rpc_object_t exception)
 
int rpc_function_start_stream (void *_Nonnull cookie)
 
int rpc_function_yield (void *_Nonnull cookie, _Nonnull rpc_object_t fragment)
 
void rpc_function_end (void *_Nonnull cookie)
 
void rpc_function_kill (void *_Nonnull cookie)
 
bool rpc_function_should_abort (void *_Nonnull cookie)
 
void rpc_function_set_async_abort_handler (void *_Nonnull cookie, _Nullable rpc_abort_handler_t handler)
 
int rpc_function_retain (void *_Nonnull cookie)
 
int rpc_function_release (void *_Nonnull cookie)
 
_Nullable rpc_instance_t rpc_instance_new (void *_Nullable arg, const char *_Nonnull fmt,...)
 
void rpc_instance_set_description (_Nonnull rpc_instance_t instance, const char *_Nonnull fmt,...)
 
void *_Nullable rpc_instance_get_arg (_Nonnull rpc_instance_t instance)
 
const char *_Nonnull rpc_instance_get_path (_Nonnull rpc_instance_t instance)
 
int rpc_instance_register_interface (_Nonnull rpc_instance_t instance, const char *_Nonnull interface, const struct rpc_if_member *_Nullable vtable, void *_Nullable arg)
 
void rpc_instance_unregister_interface (_Nonnull rpc_instance_t instance, const char *_Nonnull interface)
 
int rpc_instance_register_member (_Nonnull rpc_instance_t instance, const char *_Nonnull interface, const struct rpc_if_member *_Nonnull member)
 
int rpc_instance_unregister_member (_Nonnull rpc_instance_t instance, const char *_Nonnull interface, const char *_Nonnull name)
 
int rpc_instance_register_block (_Nonnull rpc_instance_t instance, const char *_Nonnull interface, const char *_Nonnull name, void *_Nullable arg, _Nonnull rpc_function_t fn)
 
int rpc_instance_register_func (_Nonnull rpc_instance_t instance, const char *_Nonnull interface, const char *_Nonnull name, void *_Nullable arg, _Nonnull rpc_function_f fn)
 
struct rpc_if_member *_Nullable rpc_instance_find_member (_Nonnull rpc_instance_t instance, const char *_Nullable interface, const char *_Nonnull name)
 
bool rpc_instance_has_interface (_Nonnull rpc_instance_t instance, const char *_Nonnull interface)
 
void rpc_instance_emit_event (_Nonnull rpc_instance_t instance, const char *_Nonnull interface, const char *_Nonnull name, _Nonnull rpc_object_t args)
 
int rpc_instance_register_property (_Nonnull rpc_instance_t instance, const char *_Nonnull interface, const char *_Nonnull name, void *_Nullable arg, _Nullable rpc_property_getter_t getter, _Nullable rpc_property_setter_t setter)
 
int rpc_instance_get_property_rights (_Nonnull rpc_instance_t instance, const char *_Nonnull interface, const char *_Nonnull name)
 
int rpc_instance_register_event (_Nonnull rpc_instance_t instance, const char *_Nonnull interface, const char *_Nonnull name)
 
void rpc_instance_property_changed (_Nonnull rpc_instance_t instance, const char *_Nonnull interface, const char *_Nonnull name, _Nullable rpc_object_t value)
 
_Nonnull rpc_instance_t rpc_property_get_instance (void *_Nonnull cookie)
 
void *_Nullable rpc_property_get_arg (void *_Nonnull cookie)
 
void rpc_property_error (void *_Nonnull cookie, int code, const char *_Nonnull fmt,...)
 
void rpc_instance_free (_Nonnull rpc_instance_t instance)
 

Detailed Description

RPC service API.

Definition in file service.h.

Macro Definition Documentation

◆ RPC_ABORT_HANDLER

#define RPC_ABORT_HANDLER (   _fn,
  _arg 
)
Value:
^(void *_cookie) { \
_fn(_arg); \
}

Definition at line 128 of file service.h.

◆ RPC_EVENT

#define RPC_EVENT (   _name)
Value:
{ \
.rim_type = RPC_MEMBER_EVENT, \
.rim_name = (#_name) \
}

Definition at line 133 of file service.h.

◆ RPC_FUNCTION

#define RPC_FUNCTION (   _fn)
Value:
^(void *_cookie, rpc_object_t _args) { \
return ((rpc_object_t)_fn(_cookie, _args)); \
}
struct rpc_object * rpc_object_t
Definition: object.h:73

A macro to convert function pointer into rpc_function_t block.

Examples:
validation.c.

Definition at line 113 of file service.h.

◆ RPC_FUNCTION_STILL_RUNNING

#define RPC_FUNCTION_STILL_RUNNING   ((rpc_object_t)1)

Marks the function as "still running" even though the implementing call returned.

Definition at line 55 of file service.h.

◆ RPC_METHOD

#define RPC_METHOD (   _name,
  _fn 
)
Value:
{ \
.rim_type = RPC_MEMBER_METHOD, \
.rim_name = (#_name), \
.rim_method = { \
.rm_block = RPC_FUNCTION(_fn), \
.rm_arg = NULL \
} \
}
#define RPC_FUNCTION(_fn)
Definition: service.h:113

A convenience macro to declare RPC method in the vtable array.

Examples:
validation.c.

Definition at line 184 of file service.h.

◆ RPC_METHOD_BLOCK

#define RPC_METHOD_BLOCK (   _name,
  _block 
)
Value:
{ \
.rim_type = RPC_MEMBER_METHOD, \
.rim_name = (#_name), \
.rim_method = { \
.rm_block = (_block), \
} \
}

Same as RPC_METHOD, but takes a block instead of a function pointer.

Definition at line 198 of file service.h.

◆ RPC_PROPERTY_GETTER

#define RPC_PROPERTY_GETTER (   _fn)
Value:
^(void *_cookie) { \
return ((rpc_object_t)_fn(_cookie)); \
}
struct rpc_object * rpc_object_t
Definition: object.h:73

Definition at line 118 of file service.h.

◆ RPC_PROPERTY_RO

#define RPC_PROPERTY_RO (   _name,
  _getter 
)
Value:
{ \
.rim_type = RPC_MEMBER_PROPERTY, \
.rim_name = (#_name), \
.rim_property = { \
.rp_getter = RPC_PROPERTY_GETTER(_getter), \
.rp_setter = NULL, \
.rp_arg = NULL \
} \
}

A convenience macro to declare read-only property in the vtable array.

Definition at line 142 of file service.h.

◆ RPC_PROPERTY_RW

#define RPC_PROPERTY_RW (   _name,
  _getter,
  _setter 
)
Value:
{ \
.rim_type = RPC_MEMBER_PROPERTY, \
.rim_name = (#_name), \
.rim_property = { \
.rp_getter = RPC_PROPERTY_GETTER(_getter), \
.rp_setter = RPC_PROPERTY_SETTER(_setter), \
.rp_arg = NULL \
} \
}

A convenience macro to declare read-write property in the vtable array.

Definition at line 170 of file service.h.

◆ RPC_PROPERTY_SETTER

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

Definition at line 123 of file service.h.

◆ RPC_PROPERTY_WO

#define RPC_PROPERTY_WO (   _name,
  _setter 
)
Value:
{ \
.rim_type = RPC_MEMBER_PROPERTY, \
.rim_name = (#_name), \
.rim_property = { \
.rp_getter = NULL, \
.rp_setter = RPC_PROPERTY_SETTER(_setter), \
.rp_arg = NULL \
} \
}

A convenience macro to declare write-only property in the vtable array.

Definition at line 156 of file service.h.

Typedef Documentation

◆ rpc_abort_handler_t

typedef void(^ rpc_abort_handler_t) (void)

Asynchronous abort handler block type.

Definition at line 108 of file service.h.

◆ rpc_context_t

typedef struct rpc_context* rpc_context_t

RPC context handle.

Definition at line 75 of file service.h.

◆ rpc_function_f

typedef _Nullable rpc_object_t(* rpc_function_f) (void *_Nonnull cookie, _Nonnull rpc_object_t args)

Method function type.

Definition at line 91 of file service.h.

◆ rpc_function_t

typedef _Nullable rpc_object_t(^ rpc_function_t) (void *_Nonnull cookie, _Nonnull rpc_object_t args)

Method block type.

Definition at line 85 of file service.h.

◆ rpc_instance_t

typedef struct rpc_instance* rpc_instance_t

RPC instance handle.

Definition at line 80 of file service.h.

◆ rpc_property_getter_t

typedef _Nullable rpc_object_t(^ rpc_property_getter_t) (void *_Nonnull cookie)

Property getter block type.

Definition at line 97 of file service.h.

◆ rpc_property_setter_t

typedef void(^ rpc_property_setter_t) (void *_Nonnull cookie, _Nonnull rpc_object_t value)

Property setter block type.

Definition at line 102 of file service.h.

Enumeration Type Documentation

◆ rpc_if_member_type

Enumerates possible kinds of RPC interface members.

Enumerator
RPC_MEMBER_EVENT 

Event member

RPC_MEMBER_PROPERTY 

Property member

RPC_MEMBER_METHOD 

Method member

Definition at line 212 of file service.h.

◆ rpc_property_rights

Enumerates possible property right flags.

Enumerator
RPC_PROPERTY_READ 

Property is readable

RPC_PROPERTY_WRITE 

Property is writable

Definition at line 222 of file service.h.

Function Documentation

◆ rpc_context_create()

_Nonnull rpc_context_t rpc_context_create ( void  )

Creates a new RPC context.

Returns
Newly created RPC context object.
Examples:
fd-server.c, fd-transport.c, loopback.c, pack-unpack.c, server.c, shm-server.c, and validation.c.

◆ rpc_context_dispatch_call()

_Nullable rpc_call_t rpc_context_dispatch_call ( _Nonnull rpc_context_t  context,
const char *_Nonnull  name,
_Nullable rpc_object_t  args 
)
Parameters
contextRPC context handle
name
args
Returns

◆ rpc_context_emit_event()

void rpc_context_emit_event ( _Nonnull rpc_context_t  context,
const char *_Nullable  path,
const char *_Nullable  interface,
const char *_Nonnull  name,
_Nonnull rpc_object_t  args 
)
Parameters
context
path
interface
name

◆ rpc_context_find_instance()

_Nullable rpc_instance_t rpc_context_find_instance ( _Nonnull rpc_context_t  context,
const char *_Nonnull  path 
)

Finds an instance registered in context.

Parameters
contextRPC context handle
pathInstance path
Returns
RPC instance handle or NULL if not found

◆ rpc_context_free()

void rpc_context_free ( _Nonnull rpc_context_t  context)

Disposes existing RPC context and frees all associated resources.

Parameters
contextContext to dispose

◆ rpc_context_get_root()

_Nonnull rpc_instance_t rpc_context_get_root ( _Nonnull rpc_context_t  context)

Returns root instance associated with context.

Parameters
contextRPC context handle
Returns
RPC instance handle

◆ rpc_context_register_block()

int rpc_context_register_block ( _Nonnull rpc_context_t  context,
const char *_Nullable  interface,
const char *_Nonnull  name,
void *_Nullable  arg,
_Nonnull rpc_function_t  func 
)

Registers a given block as a RPC method for a given context.

Parameters
contextTarget context.
nameMethod name.
descrMethod description.
argMethod context.
funcRPC method block.
Returns
Status.
Examples:
fd-transport.c, loopback.c, pack-unpack.c, and server.c.

◆ rpc_context_register_func()

int rpc_context_register_func ( _Nonnull rpc_context_t  context,
const char *_Nullable  interface,
const char *_Nonnull  name,
void *_Nullable  arg,
_Nonnull rpc_function_f  func 
)

Registers a given function as a RPC method for a given context.

Parameters
contextTarget context.
nameMethod name.
descrMethod description.
argMethod context.
funcRPC method function
Returns
Status.
Examples:
fd-server.c, server.c, and shm-server.c.

◆ rpc_context_register_instance()

int rpc_context_register_instance ( _Nonnull rpc_context_t  context,
_Nonnull rpc_instance_t  instance 
)

Registers a new instance in context instance tree.

Parameters
contextRPC context handle
instanceRPC instance handle
Returns
0 on success, -1 on error
Examples:
validation.c.

◆ rpc_context_register_member()

int rpc_context_register_member ( _Nonnull rpc_context_t  context,
const char *_Nullable  interface,
struct rpc_if_member *_Nonnull  m 
)

Registers a given rpc_method structure as an RPC method in a given context.

The method must have a non-null name.

Parameters
contextTarget context.
mRPC method structure.
Returns
Status.

◆ rpc_context_set_post_call_hook()

void rpc_context_set_post_call_hook ( _Nonnull rpc_context_t  context,
_Nonnull rpc_function_t  fn 
)

Installs a hook for every RPC function called.

The hook will be called after an actual implementation of RPC function is called.

Parameters
contextTarget context
fnHook function
Examples:
validation.c.

◆ rpc_context_set_pre_call_hook()

void rpc_context_set_pre_call_hook ( _Nonnull rpc_context_t  context,
_Nonnull rpc_function_t  fn 
)

Installs a hook for every RPC function called.

The hook will be called before an actual implementation of RPC function gets called.

Parameters
contextTarget context
fnHook function
Examples:
validation.c.

◆ rpc_context_unregister_instance()

void rpc_context_unregister_instance ( _Nonnull rpc_context_t  context,
const char *_Nonnull  path 
)
Parameters
context
path

◆ rpc_context_unregister_member()

int rpc_context_unregister_member ( _Nonnull rpc_context_t  context,
const char *_Nullable  interface,
const char *_Nonnull  name 
)

Unregisters a given RPC method.

Parameters
contextTarget context.
nameMethod name.
Returns
Status.

◆ rpc_function_end()

void rpc_function_end ( void *_Nonnull  cookie)

Ends a streaming response.

When that function is called, sending further responses (either singular, streaming or error responses) is not allowed. Return value of a method functions is ignored.

Parameters
cookieRunning call handle
Examples:
server.c.

◆ rpc_function_error()

void rpc_function_error ( void *_Nonnull  cookie,
int  code,
const char *_Nonnull  message,
  ... 
)

Sends an error response to a call.

This function may be called only once during the lifetime of a single call (for a given cookie). When called, return value of a method is silently ignored (it is preferred to return NULL).

When called in a streaming function, implicitly ends streaming response.

Parameters
cookieRunning call handle
codeError (errno) code
messageError message format
...Format arguments
Examples:
fd-server.c, and shm-server.c.

◆ rpc_function_error_ex()

void rpc_function_error_ex ( void *_Nonnull  cookie,
_Nonnull rpc_object_t  exception 
)

Reports an exception for a given ongoing call identifier.

Parameters
cookieRunning call handle
exceptionException object

◆ rpc_function_get_arg()

void* _Nullable rpc_function_get_arg ( void *_Nonnull  cookie)

Returns the argument associated with method.

Parameters
cookieRunning call handle

◆ rpc_function_get_connection()

_Nullable rpc_connection_t rpc_function_get_connection ( void *_Nonnull  cookie)

Returns the connection associated with call.

Parameters
cookieRunning call handle
Returns
RPC connection handle or NULL if the connection is closed/aborted.

◆ rpc_function_get_context()

_Nonnull rpc_context_t rpc_function_get_context ( void *_Nonnull  cookie)

Returns the RPC context handle associated with currently executing function.

Parameters
cookieRunning call handle
Returns
RPC context handle

◆ rpc_function_get_instance()

_Nonnull rpc_instance_t rpc_function_get_instance ( void *_Nonnull  cookie)

Returns the instance handle associated with currently executing function.

Parameters
cookieRunning call handle
Returns
RPC context handle

◆ rpc_function_get_interface()

const char* _Nonnull rpc_function_get_interface ( void *_Nonnull  cookie)

Returns the called interface name or NULL.

Parameters
cookieRunning call handle

◆ rpc_function_get_name()

const char* _Nonnull rpc_function_get_name ( void *_Nonnull  cookie)

Returns the called method name.

Parameters
cookieRunning call handle

◆ rpc_function_get_path()

const char* _Nonnull rpc_function_get_path ( void *_Nonnull  cookie)

Returns the path method was called on or NULL.

Parameters
cookieRunning call handle

◆ rpc_function_kill()

void rpc_function_kill ( void *_Nonnull  cookie)

Asynchronously abort a running call on the server.

This function makes rpc_function_should_abort return true and a running rpc_function_yield to return immediately with an error.

Parameters
cookieRunning call handle

◆ rpc_function_release()

int rpc_function_release ( void *_Nonnull  cookie)

Decrements the refcount on a call.

Releases the callers interest in the call.

Parameters
cookieRunning call handle
Returns
0 on success or -1 if the call is no longer valid.

◆ rpc_function_respond()

void rpc_function_respond ( void *_Nonnull  cookie,
_Nullable rpc_object_t  object 
)

Sends a response to a call.

This function may be called only once during the lifetime of a single call (for a given cookie). When called, return value of a method is silently ignored (it is preferred to return NULL).

Parameters
cookieRunning call handle
objectResponse.

◆ rpc_function_retain()

int rpc_function_retain ( void *_Nonnull  cookie)

Increments the refcount on a call.

Indicates that the caller has an interest in tha call and it cannot be freed until that interest is released.

Parameters
cookieRunning call handle
Returns
0 if the call is retained or -1 if the call is no longer valid.

◆ rpc_function_set_async_abort_handler()

void rpc_function_set_async_abort_handler ( void *_Nonnull  cookie,
_Nullable rpc_abort_handler_t  handler 
)

Sets a callback to be called when running method got an abort signal from the client.

Parameters
cookieRunning call handle
handlerAbort handling block

◆ rpc_function_should_abort()

bool rpc_function_should_abort ( void *_Nonnull  cookie)

Returns the value of a flag saying whether or not a method should immediately stop because it was aborted on the client side.

Parameters
cookieRunning call handle
Returns
Whether or not function should abort

◆ rpc_function_start_stream()

int rpc_function_start_stream ( void *_Nonnull  cookie)

Signalizes a start of a streaming response.

Parameters
cookieRunning call handle
Returns
Status. Success is reported by returning 0
Examples:
server.c.

◆ rpc_function_yield()

int rpc_function_yield ( void *_Nonnull  cookie,
_Nonnull rpc_object_t  fragment 
)

Generates a new value in a streaming response.

Parameters
cookieRunning call handle
fragmentNext data fragment
Returns
Status. Success is reported by returning 0
Examples:
server.c.

◆ rpc_instance_emit_event()

void rpc_instance_emit_event ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface,
const char *_Nonnull  name,
_Nonnull rpc_object_t  args 
)
Parameters
instanceInstance handle
interfaceInterface name
name

◆ rpc_instance_find_member()

struct rpc_if_member* _Nullable rpc_instance_find_member ( _Nonnull rpc_instance_t  instance,
const char *_Nullable  interface,
const char *_Nonnull  name 
)

Finds member called name belonging to a interface in instance.

Parameters
instanceInstance handle
interfaceInterface name
nameMember name
Returns
rpc_if_member structure pointer or NULL if not found.

◆ rpc_instance_free()

void rpc_instance_free ( _Nonnull rpc_instance_t  instance)

Releases instance handle.

Parameters
instanceInstance handle

◆ rpc_instance_get_arg()

void* _Nullable rpc_instance_get_arg ( _Nonnull rpc_instance_t  instance)

Returns the user data pointer associated with instance.

Parameters
instanceInstance handle
Returns
User data pointer

◆ rpc_instance_get_path()

const char* _Nonnull rpc_instance_get_path ( _Nonnull rpc_instance_t  instance)

Returns instance path.

Parameters
instanceInstance handle
Returns
Instance path

◆ rpc_instance_get_property_rights()

int rpc_instance_get_property_rights ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface,
const char *_Nonnull  name 
)

Returns access rights of property name of interface interface implemented in instance instance.

Parameters
instanceInstance handle
interfaceInterface name
nameProperty name
Returns

◆ rpc_instance_has_interface()

bool rpc_instance_has_interface ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface 
)

Tells whether or not instance implements interface interface.

Parameters
instanceInstance handle
interfaceInterface name
Returns
true if implemented, otherwise false

◆ rpc_instance_new()

_Nullable rpc_instance_t rpc_instance_new ( void *_Nullable  arg,
const char *_Nonnull  fmt,
  ... 
)

Creates a new instance handle.

Parameters
pathInstance path
argUser data pointer
Returns
Examples:
validation.c.

◆ rpc_instance_property_changed()

void rpc_instance_property_changed ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface,
const char *_Nonnull  name,
_Nullable rpc_object_t  value 
)

Notifies the librpc layer that property value has changed.

This function is used to notify remote property listeners that the value might have changed.

If value is NULL, then librpc will internally query the getter for the value.

Parameters
instanceInstance handle
interfaceInterface name
nameProperty name
valueNew property value

◆ rpc_instance_register_block()

int rpc_instance_register_block ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface,
const char *_Nonnull  name,
void *_Nullable  arg,
_Nonnull rpc_function_t  fn 
)

Registers a new method called name on interface interface under instance instance.

Parameters
instanceInstance handle
interfaceInterface name
nameMethod name
argMethod private data pointer
fnBlock
Returns
0 on success, -1 on error

◆ rpc_instance_register_event()

int rpc_instance_register_event ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface,
const char *_Nonnull  name 
)
Parameters
instanceInstance handle
interfaceInterface name
name
Returns

◆ rpc_instance_register_func()

int rpc_instance_register_func ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface,
const char *_Nonnull  name,
void *_Nullable  arg,
_Nonnull rpc_function_f  fn 
)

Same as rpc_instance_register_block, but takes a function pointer instead.

Parameters
instanceInstance handle
interfaceInterface name
nameMethod name
argMethod private data pointer
fnFunction pointer

◆ rpc_instance_register_interface()

int rpc_instance_register_interface ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface,
const struct rpc_if_member *_Nullable  vtable,
void *_Nullable  arg 
)

Registers interface interface under instance.

Parameters
instanceInstance handle
interfaceInterface name
vtableMember virtual table (vtable)
argUser data pointer
Returns
0 on success, -1 on error
Examples:
validation.c.

◆ rpc_instance_register_member()

int rpc_instance_register_member ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface,
const struct rpc_if_member *_Nonnull  member 
)

Registers a single member of interface interface under instance.

Parameters
instanceIntance handle
interfaceInterface name
memberMember descriptor
Returns
0 on success, -1 on error

◆ rpc_instance_register_property()

int rpc_instance_register_property ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface,
const char *_Nonnull  name,
void *_Nullable  arg,
_Nullable rpc_property_getter_t  getter,
_Nullable rpc_property_setter_t  setter 
)

Registers property named name on interface interface under instance instance.

The property can be:

  • read-only, when getter is non-NULL and setter is NULL
  • write-only, when getter is NULL and setter is non-NULL
  • read-write, when both getter and setter blocks are provided.
Parameters
instanceInstance handle
interfaceInterface name
nameProperty name
argUser data pointer
getterGetter block or NULL if write-only
setterSetter block or NULL if read-nly
Returns
0 on success, -1 on error

◆ rpc_instance_set_description()

void rpc_instance_set_description ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  fmt,
  ... 
)

Sets the description string of an instance.

Parameters
instanceInstance handle
fmtFormat string
...Format arguments

◆ rpc_instance_unregister_interface()

void rpc_instance_unregister_interface ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface 
)

Unregisters interface interface from instance along with all interface members.

Parameters
instanceInstance handle
interfaceInterface name

◆ rpc_instance_unregister_member()

int rpc_instance_unregister_member ( _Nonnull rpc_instance_t  instance,
const char *_Nonnull  interface,
const char *_Nonnull  name 
)

Unregisters a previously registered member named name from interface interface on instance.

Parameters
instanceInstance handle
interfaceInterface name
nameMember name
Returns
0 on success, -1 on error

◆ rpc_property_error()

void rpc_property_error ( void *_Nonnull  cookie,
int  code,
const char *_Nonnull  fmt,
  ... 
)

Indicate that the current getter or setter run should generate an error.

After using this function, return value from the getter is ignored.

Parameters
cookieProperty call handle
codeError code
fmtMessage format string
...Format string arguments

◆ rpc_property_get_arg()

void* _Nullable rpc_property_get_arg ( void *_Nonnull  cookie)

Returns the user data pointer associated with the currently running getter/setter.

Parameters
cookieProperty call handle
Returns
User data pointer

◆ rpc_property_get_instance()

_Nonnull rpc_instance_t rpc_property_get_instance ( void *_Nonnull  cookie)

Returns instance associated with the getter or setter call.

Parameters
cookieRunning call identifier
Returns
Instance handle