librpc
|
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) |
RPC service API.
Definition in file service.h.
#define RPC_ABORT_HANDLER | ( | _fn, | |
_arg | |||
) |
#define RPC_EVENT | ( | _name | ) |
#define RPC_FUNCTION | ( | _fn | ) |
A macro to convert function pointer into rpc_function_t block.
#define RPC_FUNCTION_STILL_RUNNING ((rpc_object_t)1) |
#define RPC_METHOD | ( | _name, | |
_fn | |||
) |
A convenience macro to declare RPC method in the vtable array.
#define RPC_METHOD_BLOCK | ( | _name, | |
_block | |||
) |
Same as RPC_METHOD, but takes a block instead of a function pointer.
#define RPC_PROPERTY_GETTER | ( | _fn | ) |
#define RPC_PROPERTY_RO | ( | _name, | |
_getter | |||
) |
A convenience macro to declare read-only property in the vtable array.
#define RPC_PROPERTY_RW | ( | _name, | |
_getter, | |||
_setter | |||
) |
A convenience macro to declare read-write property in the vtable array.
#define RPC_PROPERTY_SETTER | ( | _fn | ) |
#define RPC_PROPERTY_WO | ( | _name, | |
_setter | |||
) |
A convenience macro to declare write-only property in the vtable array.
typedef void(^ rpc_abort_handler_t) (void) |
typedef struct rpc_context* rpc_context_t |
typedef _Nullable rpc_object_t(* rpc_function_f) (void *_Nonnull cookie, _Nonnull rpc_object_t args) |
typedef _Nullable rpc_object_t(^ rpc_function_t) (void *_Nonnull cookie, _Nonnull rpc_object_t args) |
typedef struct rpc_instance* rpc_instance_t |
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) |
enum rpc_if_member_type |
enum rpc_property_rights |
_Nonnull rpc_context_t rpc_context_create | ( | void | ) |
Creates a new RPC context.
_Nullable rpc_call_t rpc_context_dispatch_call | ( | _Nonnull rpc_context_t | context, |
const char *_Nonnull | name, | ||
_Nullable rpc_object_t | args | ||
) |
context | RPC context handle |
name | |
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 | ||
) |
context | |
path | |
interface | |
name |
_Nullable rpc_instance_t rpc_context_find_instance | ( | _Nonnull rpc_context_t | context, |
const char *_Nonnull | path | ||
) |
Finds an instance registered in context
.
context | RPC context handle |
path | Instance path |
void rpc_context_free | ( | _Nonnull rpc_context_t | context | ) |
Disposes existing RPC context and frees all associated resources.
context | Context to dispose |
_Nonnull rpc_instance_t rpc_context_get_root | ( | _Nonnull rpc_context_t | context | ) |
Returns root instance associated with context
.
context | RPC context handle |
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.
context | Target context. |
name | Method name. |
descr | Method description. |
arg | Method context. |
func | RPC method block. |
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.
context | Target context. |
name | Method name. |
descr | Method description. |
arg | Method context. |
func | RPC method function |
int rpc_context_register_instance | ( | _Nonnull rpc_context_t | context, |
_Nonnull rpc_instance_t | instance | ||
) |
Registers a new instance in context
instance tree.
context | RPC context handle |
instance | RPC instance handle |
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.
context | Target context. |
m | RPC method structure. |
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.
context | Target context |
fn | Hook function |
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.
context | Target context |
fn | Hook function |
void rpc_context_unregister_instance | ( | _Nonnull rpc_context_t | context, |
const char *_Nonnull | path | ||
) |
context | |
path |
int rpc_context_unregister_member | ( | _Nonnull rpc_context_t | context, |
const char *_Nullable | interface, | ||
const char *_Nonnull | name | ||
) |
Unregisters a given RPC method.
context | Target context. |
name | Method name. |
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.
cookie | Running call handle |
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.
cookie | Running call handle |
code | Error (errno) code |
message | Error message format |
... | Format arguments |
void rpc_function_error_ex | ( | void *_Nonnull | cookie, |
_Nonnull rpc_object_t | exception | ||
) |
Reports an exception for a given ongoing call identifier.
cookie | Running call handle |
exception | Exception object |
void* _Nullable rpc_function_get_arg | ( | void *_Nonnull | cookie | ) |
Returns the argument associated with method.
cookie | Running call handle |
_Nullable rpc_connection_t rpc_function_get_connection | ( | void *_Nonnull | cookie | ) |
Returns the connection associated with call.
cookie | Running call handle |
_Nonnull rpc_context_t rpc_function_get_context | ( | void *_Nonnull | cookie | ) |
Returns the RPC context handle associated with currently executing function.
cookie | Running call handle |
_Nonnull rpc_instance_t rpc_function_get_instance | ( | void *_Nonnull | cookie | ) |
Returns the instance handle associated with currently executing function.
cookie | Running call handle |
const char* _Nonnull rpc_function_get_interface | ( | void *_Nonnull | cookie | ) |
Returns the called interface name or NULL.
cookie | Running call handle |
const char* _Nonnull rpc_function_get_name | ( | void *_Nonnull | cookie | ) |
Returns the called method name.
cookie | Running call handle |
const char* _Nonnull rpc_function_get_path | ( | void *_Nonnull | cookie | ) |
Returns the path method was called on or NULL.
cookie | Running call handle |
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.
cookie | Running call handle |
int rpc_function_release | ( | void *_Nonnull | cookie | ) |
Decrements the refcount on a call.
Releases the callers interest in the call.
cookie | Running call handle |
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).
cookie | Running call handle |
object | Response. |
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.
cookie | Running call handle |
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.
cookie | Running call handle |
handler | Abort handling block |
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.
cookie | Running call handle |
int rpc_function_start_stream | ( | void *_Nonnull | cookie | ) |
Signalizes a start of a streaming response.
cookie | Running call handle |
int rpc_function_yield | ( | void *_Nonnull | cookie, |
_Nonnull rpc_object_t | fragment | ||
) |
Generates a new value in a streaming response.
cookie | Running call handle |
fragment | Next data fragment |
void rpc_instance_emit_event | ( | _Nonnull rpc_instance_t | instance, |
const char *_Nonnull | interface, | ||
const char *_Nonnull | name, | ||
_Nonnull rpc_object_t | args | ||
) |
instance | Instance handle |
interface | Interface name |
name |
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
.
instance | Instance handle |
interface | Interface name |
name | Member name |
NULL
if not found. void rpc_instance_free | ( | _Nonnull rpc_instance_t | instance | ) |
Releases instance handle.
instance | Instance handle |
void* _Nullable rpc_instance_get_arg | ( | _Nonnull rpc_instance_t | instance | ) |
Returns the user data pointer associated with instance
.
instance | Instance handle |
const char* _Nonnull rpc_instance_get_path | ( | _Nonnull rpc_instance_t | instance | ) |
Returns instance
path.
instance | Instance handle |
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
.
instance | Instance handle |
interface | Interface name |
name | Property name |
bool rpc_instance_has_interface | ( | _Nonnull rpc_instance_t | instance, |
const char *_Nonnull | interface | ||
) |
Tells whether or not instance
implements interface interface
.
instance | Instance handle |
interface | Interface name |
true
if implemented, otherwise false
_Nullable rpc_instance_t rpc_instance_new | ( | void *_Nullable | arg, |
const char *_Nonnull | fmt, | ||
... | |||
) |
Creates a new instance handle.
path | Instance path |
arg | User data pointer |
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.
instance | Instance handle |
interface | Interface name |
name | Property name |
value | New property value |
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
.
instance | Instance handle |
interface | Interface name |
name | Method name |
arg | Method private data pointer |
fn | Block |
int rpc_instance_register_event | ( | _Nonnull rpc_instance_t | instance, |
const char *_Nonnull | interface, | ||
const char *_Nonnull | name | ||
) |
instance | Instance handle |
interface | Interface name |
name |
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.
instance | Instance handle |
interface | Interface name |
name | Method name |
arg | Method private data pointer |
fn | Function pointer |
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
.
instance | Instance handle |
interface | Interface name |
vtable | Member virtual table (vtable) |
arg | User data pointer |
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
.
instance | Intance handle |
interface | Interface name |
member | Member descriptor |
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:
instance | Instance handle |
interface | Interface name |
name | Property name |
arg | User data pointer |
getter | Getter block or NULL if write-only |
setter | Setter block or NULL if read-nly |
void rpc_instance_set_description | ( | _Nonnull rpc_instance_t | instance, |
const char *_Nonnull | fmt, | ||
... | |||
) |
Sets the description string of an instance.
instance | Instance handle |
fmt | Format string |
... | Format arguments |
void rpc_instance_unregister_interface | ( | _Nonnull rpc_instance_t | instance, |
const char *_Nonnull | interface | ||
) |
Unregisters interface interface
from instance
along with all interface members.
instance | Instance handle |
interface | Interface name |
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
.
instance | Instance handle |
interface | Interface name |
name | Member name |
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.
cookie | Property call handle |
code | Error code |
fmt | Message format string |
... | Format string arguments |
void* _Nullable rpc_property_get_arg | ( | void *_Nonnull | cookie | ) |
Returns the user data pointer associated with the currently running getter/setter.
cookie | Property call handle |
_Nonnull rpc_instance_t rpc_property_get_instance | ( | void *_Nonnull | cookie | ) |
Returns instance associated with the getter or setter call.
cookie | Running call identifier |