|
librpc
|


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) |
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) |
RPC connection API.
Definition in file connection.h.
| #define RPC_CALLBACK | ( | _fn, | |
| _arg | |||
| ) |
Converts function pointer to a rpc_callback_t block type.
Definition at line 166 of file connection.h.
| #define RPC_ERROR_HANDLER | ( | _fn, | |
| _arg | |||
| ) |
Converts function pointer to a rpc_error_handler_t block type.
Definition at line 150 of file connection.h.
| #define RPC_HANDLER | ( | _fn, | |
| _arg | |||
| ) |
Converts function pointer to a rpc_handler_t block type.
Definition at line 133 of file connection.h.
| #define RPC_NULL_FORMAT "[]" |
Definition of Null-argument fmt to pass to rpc_connection_call_simple()
Definition at line 174 of file connection.h.
| #define RPC_PROPERTY_HANDLER | ( | _fn, | |
| _arg | |||
| ) |
Converts function pointer to a rpc_property_handler_t block type.
Definition at line 142 of file connection.h.
| #define RPC_RAW_HANDLER | ( | _fn, | |
| _arg | |||
| ) |
Converts function pointer to a rpc_message_handler_t block type.
Definition at line 158 of file connection.h.
| typedef enum rpc_call_status rpc_call_status_t |
Enumerates possible remote procedure call status values.
| typedef struct rpc_call* rpc_call_t |
Definition of RPC call pointer.
Definition at line 99 of file connection.h.
| typedef enum rpc_call_type rpc_call_type_t |
Enumerates possible remote procedure call status values.
| typedef bool(^ rpc_callback_t) (_Nonnull rpc_call_t call) |
Definition of RPC callback block type.
Definition at line 128 of file connection.h.
| typedef struct rpc_connection* rpc_connection_t |
Definition of RPC connection pointer.
Definition at line 94 of file connection.h.
| typedef enum rpc_error_code rpc_error_code_t |
Enumerates possible RPC error codes.
| 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.
| 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.
| 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.
| 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.
| enum rpc_call_status |
Enumerates possible remote procedure call status values.
Definition at line 71 of file connection.h.
| enum 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.
| enum rpc_error_code |
Enumerates possible RPC error codes.
Definition at line 56 of file connection.h.
| int rpc_call_abort | ( | _Nonnull rpc_call_t | call | ) |
Aborts a pending call.
| call | Call to be aborted |
| 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.
| call | Call to be continued |
| sync | Synchronous continue flag |
| void rpc_call_free | ( | _Nonnull rpc_call_t | call | ) |
Frees a rpc_call_t object.
| call | Call to free |
| _Nullable rpc_object_t rpc_call_result | ( | _Nonnull rpc_call_t | call | ) |
Returns a call result (or a current fragment).
| call | Call to get result from |
| int rpc_call_set_prefetch | ( | _Nonnull rpc_call_t | call, |
| size_t | nitems | ||
| ) |
Sets how many items librpc should prefetch in a streaming call.
| call | |
| nitems |
| rpc_call_status_t rpc_call_status | ( | _Nonnull rpc_call_t | call | ) |
Returns a current status of a given call as an integer value castable to rpc_call_status_t.
| call | Call to be checked |
| int rpc_call_success | ( | _Nonnull rpc_call_t | call | ) |
Checks whether a call has been completed successfully.
| call | Call to be checked |
| 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.
| call | Call to wait on |
| ts | Timeout value |
| int rpc_call_wait | ( | _Nonnull rpc_call_t | call | ) |
Waits for a call to change status.
| call | Call to wait on. |
| _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.
| conn | Connection to do a call on |
| name | Name of a method to be called |
| args | Variable length RPC method arguments list |
| callback | Callback function pointer to be called on RPC completion |
| _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.
| name | |
| fmt | |
| ... |
| _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.
| conn | Connection to do a call on |
| method | Name of a method to be called |
| ... | Called method arguments |
| _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.
| conn | Connection handle |
| method | Name of a method to be called |
| fmt | Format string |
| ... | Called method arguments |
| _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.
| conn | Connection handle |
| path | |
| interface | |
| method | |
| fmt | |
| ap |
| _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.
| conn | Connection to do a call on |
| method | Name of a method to be called |
| ap | Variable arguments list structure describing a method arguments |
| int rpc_connection_close | ( | _Nonnull rpc_connection_t | conn | ) |
Closes the connection and frees all resources associated with it.
| conn | Connection to close |
| _Nullable rpc_connection_t rpc_connection_create | ( | void *_Nonnull | cookie, |
| _Nullable rpc_object_t | params | ||
| ) |
Creates a new connection from the provided opaque cookie.
| cookie | Opaque data |
| params | Transport-specific parameters |
| void rpc_connection_free | ( | _Nonnull rpc_connection_t | conn | ) |
Frees resources associated with rpc_connection_t.
| conn | Connection handle |
| struct rpc_context* _Nullable rpc_connection_get_context | ( | _Nonnull rpc_connection_t | conn | ) |
Returns context associated with the connection.
| conn | Client connection |
NULL if not set | int rpc_connection_get_fd | ( | _Nonnull rpc_connection_t | conn | ) |
Returns file descriptor associated with the connection.
| conn | Connection handle |
| _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 | ||
| ) |
| conn | |
| path | |
| interface | |
| name |
| const char* _Nullable rpc_connection_get_remote_address | ( | _Nonnull rpc_connection_t | conn | ) |
| gid_t rpc_connection_get_remote_gid | ( | _Nonnull rpc_connection_t | conn | ) |
| conn | Connection handle |
| pid_t rpc_connection_get_remote_pid | ( | _Nonnull rpc_connection_t | conn | ) |
| uid_t rpc_connection_get_remote_uid | ( | _Nonnull rpc_connection_t | conn | ) |
Gets remote side UID.
| conn | Connection handle |
| bool rpc_connection_has_credentials | ( | _Nonnull rpc_connection_t | conn | ) |
Returns true if a connection has associated remote credentials information.
| conn | Connection handle |
| 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.
| conn | Connection handle |
true if connection is open, otherwise false | 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.
| conn | Connection handle |
true if connection is valid, otherwise false | int rpc_connection_ping | ( | _Nonnull rpc_connection_t | conn | ) |
Ping the other end of a connection.
| 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.
| conn | Connection to register an event handler for |
| name | Name of an event to be handled |
| handler | Event handler of rpc_handler_t type |
| 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.
| conn | Connection to send event across |
| name | Event name |
| args | Event arguments or NULL |
| 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 | ||
| ) |
| conn | |
| msg | |
| len | |
| fds | |
| nfds |
| 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.
| conn | Client connection |
| ctx | Client context |
| void rpc_connection_set_error_handler | ( | _Nonnull rpc_connection_t | conn, |
| _Nullable rpc_error_handler_t | handler | ||
| ) |
Sets global error handler for a connection.
| conn | Connection to set error handler for |
| handler | Error handler block |
| void rpc_connection_set_event_handler | ( | _Nonnull rpc_connection_t | conn, |
| _Nullable rpc_handler_t | handler | ||
| ) |
Sets global event handler for a connection.
| conn | Connection to set event handler for |
| handler | Handler block |
| _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 | ||
| ) |
| conn | |
| path | |
| interface | |
| name | |
| 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, | ||
| ... | |||
| ) |
| conn | |
| path | |
| interface | |
| name | |
| 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 | ||
| ) |
| conn | |
| path | |
| interface | |
| name | |
| fmt | |
| ap |
| void rpc_connection_set_raw_message_handler | ( | _Nonnull rpc_connection_t | conn, |
| _Nullable rpc_raw_handler_t | handler | ||
| ) |
| conn | |
| handler |
| 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().
| conn | Connection to subscribe on |
| name | Event name |
| bool rpc_connection_supports_credentials | ( | _Nonnull rpc_connection_t | conn | ) |
Checks whether a given connection does support credentials.
| conn | Connection handle |
| bool rpc_connection_supports_fd_passing | ( | _Nonnull rpc_connection_t | conn | ) |
Checks whether a given connection does support file descriptor passing.
| conn | Connection handle |
| 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).
| conn | Connection to remove event handler from |
| cookie | Void pointer to event handler itself |
| 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:
| conn | Connection to undo the subscription on |
| name | Event name |
| 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 | ||
| ) |
| conn | |
| path | |
| interface | |
| property | |
| handler |
1.8.13