unleashed-firmware/applications/services/rpc/rpc_app.h
Georgii Surkov 49dcf81743
[FL-3618] Infrared remote button index support (#3180)
* Do not load all signals at once (Draft)
* Minor cleanup
* Refactor remote renaming
* Improve function signatures
* Rename infrared_remote functions
* Optimise signal loading
* Implement adding signals to remote
* Add read_name() method
* Deprecate a function
* Partially implement deleting signals (draft)
* Use m-array instead of m-list for signal name directory
* Use plain C strings instead of furi_string
* Implement deleting signals
* Implement deleting signals via generalised callback
* Implement renaming signals
* Rename some types
* Some more renaming
* Remove unused type
* Implement inserting signals (internal use)
* Improve InfraredMoveView
* Send an event to move a signal
* Remove unused type
* Implement moving signals
* Implement creating new remotes with one signal
* Un-deprecate and rename a function
* Add InfraredRemote API docs
* Add InfraredSignal API docs
* Better error messages
* Show progress pop-up when moving buttons in a remote
* Copy labels to the InfraredMoveView to avoid pointer invalidation
* Improve file selection scene
* Show progress pop-up when renaming buttons in a remote
* Refactor a scene
* Show progress when deleting a button from remote
* Use a random name for temp files
* Add docs to infrared_brute_force.h
* Rename Infrared type to InfraredApp
* Add docs to infrared_app_i.h
* Deliver event data via a callback
* Bundle event data together with event type
* Change DataExchange behaviour
* Adapt RPC debug app to new API
* Remove rogue output
* Add Doxygen comments to rpc_app.h
* Simplify rpc_app.c code
* Remove superflous parameter
* Do not allocate protobuf messages on the stack
* Fix GetError response
* Support for button indices
* Comment out shallow submodules
* Fix F18 api
* Fix logical error and add more debug output
* fbt: testing unshallow for protobuf
* github: lint&checks: unshallow prior to checks
* Fix a TODO
* github: do not unshallow the unshallowed
* fbt: assets: only attempt to unshallow if cannot describe
* Do not use the name when loading a signal by index (duh)
* Simplify loading infrared signals by name
* Sync with protobuf release
* Infrared: use compact furi_crash macros

Co-authored-by: hedger <hedger@nanode.su>
Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2023-11-10 16:22:34 +09:00

216 lines
7.6 KiB
C

/**
* @file rpc_app.h
* @brief Application RPC subsystem interface.
*
* The application RPC subsystem provides facilities for interacting with applications,
* such as starting/stopping, passing parameters, sending commands and exchanging arbitrary data.
*
* All commands are handled asynchronously via a user-settable callback.
*
* For a complete description of message types handled in this subsystem,
* see https://github.com/flipperdevices/flipperzero-protobuf/blob/dev/application.proto
*/
#pragma once
#include "rpc.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Enumeration of possible event data types.
*/
typedef enum {
RpcAppSystemEventDataTypeNone, /**< No data is provided by the event. */
RpcAppSystemEventDataTypeString, /**< Event data contains a zero-terminated string. */
RpcAppSystemEventDataTypeInt32, /**< Event data contains a signed 32-bit integer. */
RpcAppSystemEventDataTypeBytes, /**< Event data contains zero or more bytes. */
} RpcAppSystemEventDataType;
/**
* @brief Event data structure, containing the type and associated data.
*
* All below fields except for type are valid only if the respective type is set.
*/
typedef struct {
RpcAppSystemEventDataType
type; /**< Type of the data. The meaning of other fields depends on this one. */
union {
const char* string; /**< Pointer to a zero-terminated character string. */
int32_t i32; /**< Signed 32-bit integer value. */
struct {
const uint8_t* ptr; /**< Pointer to the byte array data. */
size_t size; /**< Size of the byte array, in bytes. */
} bytes; /**< Byte array of arbitrary length. */
};
} RpcAppSystemEventData;
/**
* @brief Enumeration of possible event types.
*/
typedef enum {
/**
* @brief Denotes an invalid state.
*
* An event of this type shall never be passed into the callback.
*/
RpcAppEventTypeInvalid,
/**
* @brief The client side has closed the session.
*
* After receiving this event, the RPC context is no more valid.
*/
RpcAppEventTypeSessionClose,
/**
* @brief The client has requested the application to exit.
*
* The application must exit after receiving this command.
*/
RpcAppEventTypeAppExit,
/**
* @brief The client has requested the application to load a file.
*
* This command's meaning is application-specific, i.e. the application might or
* might not require additional commands after loading a file to do anything useful.
*/
RpcAppEventTypeLoadFile,
/**
* @brief The client has informed the application that a button has been pressed.
*
* This command's meaning is application-specific, e.g. to select a part of the
* previously loaded file or to invoke a particular function within the application.
*/
RpcAppEventTypeButtonPress,
/**
* @brief The client has informed the application that a button has been released.
*
* This command's meaning is application-specific, e.g. to cease
* all activities to be conducted while a button is being pressed.
*/
RpcAppEventTypeButtonRelease,
/**
* @brief The client has sent a byte array of arbitrary size.
*
* This command's purpose is bi-directional exchange of arbitrary raw data.
* Useful for implementing higher-level protocols while using the RPC as a transport layer.
*/
RpcAppEventTypeDataExchange,
} RpcAppSystemEventType;
/**
* @brief RPC application subsystem event structure.
*/
typedef struct {
RpcAppSystemEventType type; /**< Type of the event. */
RpcAppSystemEventData data; /**< Data associated with the event. */
} RpcAppSystemEvent;
/**
* @brief Callback function type.
*
* A function of this type must be passed to rpc_system_app_set_callback() by the user code.
*
* @warning The event pointer is valid ONLY inside the callback function.
*
* @param[in] event pointer to the event object. Valid only inside the callback function.
* @param[in,out] context pointer to the user-defined context object.
*/
typedef void (*RpcAppSystemCallback)(const RpcAppSystemEvent* event, void* context);
/**
* @brief RPC application subsystem opaque type declaration.
*/
typedef struct RpcAppSystem RpcAppSystem;
/**
* @brief Set the callback function for use by an RpcAppSystem instance.
*
* @param[in,out] rpc_app pointer to the instance to be configured.
* @param[in] callback pointer to the function to be called upon message reception.
* @param[in,out] context pointer to the user-defined context object. Will be passed to the callback.
*/
void rpc_system_app_set_callback(
RpcAppSystem* rpc_app,
RpcAppSystemCallback callback,
void* context);
/**
* @brief Send a notification that an RpcAppSystem instance has been started and is ready.
*
* Call this function once right after acquiring an RPC context and setting the callback.
*
* @param[in,out] rpc_app pointer to the instance to be used.
*/
void rpc_system_app_send_started(RpcAppSystem* rpc_app);
/**
* @brief Send a notification that the application using an RpcAppSystem instance is about to exit.
*
* Call this function when the application is about to exit (usually in the *_free() function).
*
* @param[in,out] rpc_app pointer to the instance to be used.
*/
void rpc_system_app_send_exited(RpcAppSystem* rpc_app);
/**
* @brief Send a confirmation that the application using an RpcAppSystem instance has handled the event.
*
* An explicit confirmation is required for the following event types:
* - RpcAppEventTypeAppExit
* - RpcAppEventTypeLoadFile
* - RpcAppEventTypeButtonPress
* - RpcAppEventTypeButtonRelease
* - RpcAppEventTypeDataExchange
*
* Not confirming these events will result in a client-side timeout.
*
* @param[in,out] rpc_app pointer to the instance to be used.
* @param[in] result whether the command was successfully handled or not (true for success).
*/
void rpc_system_app_confirm(RpcAppSystem* rpc_app, bool result);
/**
* @brief Set the error code stored in an RpcAppSystem instance.
*
* The error code can be retrieved by the client at any time by using the GetError request.
* The error code value has no meaning within the subsystem, i.e. it is only passed through to the client.
*
* @param[in,out] rpc_app pointer to the instance to be modified.
* @param[in] error_code arbitrary error code to be set.
*/
void rpc_system_app_set_error_code(RpcAppSystem* rpc_app, uint32_t error_code);
/**
* @brief Set the error text stored in an RpcAppSystem instance.
*
* The error text can be retrieved by the client at any time by using the GetError request.
* The text has no meaning within the subsystem, i.e. it is only passed through to the client.
*
* @param[in,out] rpc_app pointer to the instance to be modified.
* @param[in] error_text Pointer to a zero-terminated string containing the error text.
*/
void rpc_system_app_set_error_text(RpcAppSystem* rpc_app, const char* error_text);
/**
* @brief Reset the error code and text stored in an RpcAppSystem instance.
*
* Resets the error code to 0 and error text to "" (empty string).
*
* @param[in,out] rpc_app pointer to the instance to be reset.
*/
void rpc_system_app_error_reset(RpcAppSystem* rpc_app);
/**
* @brief Send a byte array of arbitrary data to the client using an RpcAppSystem instance.
*
* @param[in,out] rpc_app pointer to the instance to be used.
* @param[in] data pointer to the data buffer to be sent.
* @param[in] data_size size of the data buffer, in bytes.
*/
void rpc_system_app_exchange_data(RpcAppSystem* rpc_app, const uint8_t* data, size_t data_size);
#ifdef __cplusplus
}
#endif