2021-10-13 15:39:37 +00:00
|
|
|
#include "flipper.pb.h"
|
2022-07-20 10:56:33 +00:00
|
|
|
#include <core/record.h>
|
2021-10-13 15:39:37 +00:00
|
|
|
#include "rpc_i.h"
|
|
|
|
#include <furi.h>
|
|
|
|
#include <loader/loader.h>
|
2022-07-04 13:09:46 +00:00
|
|
|
#include "rpc_app.h"
|
2021-10-13 15:39:37 +00:00
|
|
|
|
2022-04-14 16:41:15 +00:00
|
|
|
#define TAG "RpcSystemApp"
|
2022-07-04 13:09:46 +00:00
|
|
|
|
|
|
|
struct RpcAppSystem {
|
|
|
|
RpcSession* session;
|
2022-11-29 09:08:08 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
RpcAppSystemCallback callback;
|
|
|
|
void* callback_context;
|
2022-11-29 09:08:08 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
uint32_t error_code;
|
|
|
|
char* error_text;
|
2022-11-29 09:08:08 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
uint32_t last_command_id;
|
|
|
|
RpcAppSystemEventType last_event_type;
|
2022-08-02 12:54:12 +00:00
|
|
|
};
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-08-02 12:54:12 +00:00
|
|
|
#define RPC_SYSTEM_APP_TEMP_ARGS_SIZE 16
|
2022-04-14 16:41:15 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
static void rpc_system_app_send_state_response(
|
|
|
|
RpcAppSystem* rpc_app,
|
|
|
|
PB_App_AppState state,
|
|
|
|
const char* name) {
|
|
|
|
PB_Main* response = malloc(sizeof(PB_Main));
|
|
|
|
|
|
|
|
response->which_content = PB_Main_app_state_response_tag;
|
|
|
|
response->content.app_state_response.state = state;
|
|
|
|
|
|
|
|
FURI_LOG_D(TAG, "%s", name);
|
|
|
|
rpc_send(rpc_app->session, response);
|
|
|
|
|
|
|
|
free(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rpc_system_app_send_error_response(
|
|
|
|
RpcAppSystem* rpc_app,
|
|
|
|
uint32_t command_id,
|
|
|
|
PB_CommandStatus status,
|
|
|
|
const char* name) {
|
|
|
|
// Not describing all possible errors as only APP_NOT_RUNNING is used
|
|
|
|
const char* status_str = status == PB_CommandStatus_ERROR_APP_NOT_RUNNING ? "APP_NOT_RUNNING" :
|
|
|
|
"UNKNOWN";
|
|
|
|
FURI_LOG_E(TAG, "%s: %s, id %lu, status: %d", name, status_str, command_id, status);
|
|
|
|
rpc_send_and_release_empty(rpc_app->session, command_id, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rpc_system_app_set_last_command(
|
|
|
|
RpcAppSystem* rpc_app,
|
|
|
|
uint32_t command_id,
|
|
|
|
const RpcAppSystemEvent* event) {
|
|
|
|
furi_assert(rpc_app->last_command_id == 0);
|
|
|
|
furi_assert(rpc_app->last_event_type == RpcAppEventTypeInvalid);
|
|
|
|
|
|
|
|
rpc_app->last_command_id = command_id;
|
|
|
|
rpc_app->last_event_type = event->type;
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:12:40 +00:00
|
|
|
static void rpc_system_app_start_process(const PB_Main* request, void* context) {
|
2021-10-13 15:39:37 +00:00
|
|
|
furi_assert(request);
|
2021-11-01 16:26:37 +00:00
|
|
|
furi_assert(request->which_content == PB_Main_app_start_request_tag);
|
2022-08-02 12:54:12 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
RpcAppSystem* rpc_app = context;
|
|
|
|
furi_assert(rpc_app);
|
|
|
|
furi_assert(rpc_app->last_command_id == 0);
|
|
|
|
furi_assert(rpc_app->last_event_type == RpcAppEventTypeInvalid);
|
2022-03-16 08:52:11 +00:00
|
|
|
|
2022-12-26 12:13:30 +00:00
|
|
|
FURI_LOG_D(TAG, "StartProcess: id %lu", request->command_id);
|
2022-04-14 16:41:15 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
Loader* loader = furi_record_open(RECORD_LOADER);
|
2021-11-01 16:26:37 +00:00
|
|
|
const char* app_name = request->content.app_start_request.name;
|
2023-11-10 07:22:34 +00:00
|
|
|
|
|
|
|
PB_CommandStatus result;
|
|
|
|
|
2021-10-13 15:39:37 +00:00
|
|
|
if(app_name) {
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_system_app_error_reset(rpc_app);
|
|
|
|
|
|
|
|
char app_args_temp[RPC_SYSTEM_APP_TEMP_ARGS_SIZE];
|
2021-11-01 16:26:37 +00:00
|
|
|
const char* app_args = request->content.app_start_request.args;
|
2023-11-10 07:22:34 +00:00
|
|
|
|
2022-08-02 12:54:12 +00:00
|
|
|
if(app_args && strcmp(app_args, "RPC") == 0) {
|
2022-07-04 13:09:46 +00:00
|
|
|
// If app is being started in RPC mode - pass RPC context via args string
|
2023-11-10 07:22:34 +00:00
|
|
|
snprintf(app_args_temp, RPC_SYSTEM_APP_TEMP_ARGS_SIZE, "RPC %08lX", (uint32_t)rpc_app);
|
|
|
|
app_args = app_args_temp;
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
2023-11-10 07:22:34 +00:00
|
|
|
|
|
|
|
const LoaderStatus status = loader_start(loader, app_name, app_args, NULL);
|
2021-10-13 15:39:37 +00:00
|
|
|
if(status == LoaderStatusErrorAppStarted) {
|
|
|
|
result = PB_CommandStatus_ERROR_APP_SYSTEM_LOCKED;
|
|
|
|
} else if(status == LoaderStatusErrorInternal) {
|
|
|
|
result = PB_CommandStatus_ERROR_APP_CANT_START;
|
|
|
|
} else if(status == LoaderStatusErrorUnknownApp) {
|
|
|
|
result = PB_CommandStatus_ERROR_INVALID_PARAMETERS;
|
|
|
|
} else if(status == LoaderStatusOk) {
|
|
|
|
result = PB_CommandStatus_OK;
|
|
|
|
} else {
|
2023-10-31 10:40:32 +00:00
|
|
|
furi_crash();
|
2021-10-13 15:39:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = PB_CommandStatus_ERROR_INVALID_PARAMETERS;
|
|
|
|
}
|
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_LOADER);
|
2021-10-13 15:39:37 +00:00
|
|
|
|
2022-12-26 12:13:30 +00:00
|
|
|
FURI_LOG_D(TAG, "StartProcess: response id %lu, result %d", request->command_id, result);
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_send_and_release_empty(rpc_app->session, request->command_id, result);
|
2021-10-13 15:39:37 +00:00
|
|
|
}
|
|
|
|
|
2022-01-12 13:12:40 +00:00
|
|
|
static void rpc_system_app_lock_status_process(const PB_Main* request, void* context) {
|
2021-10-13 15:39:37 +00:00
|
|
|
furi_assert(request);
|
|
|
|
furi_assert(request->which_content == PB_Main_app_lock_status_request_tag);
|
2023-11-10 07:22:34 +00:00
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
RpcAppSystem* rpc_app = context;
|
2023-11-10 07:22:34 +00:00
|
|
|
furi_assert(rpc_app);
|
|
|
|
|
2022-12-08 05:49:54 +00:00
|
|
|
rpc_system_app_error_reset(rpc_app);
|
2021-10-13 15:39:37 +00:00
|
|
|
|
2022-04-14 16:41:15 +00:00
|
|
|
FURI_LOG_D(TAG, "LockStatus");
|
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
PB_Main* response = malloc(sizeof(PB_Main));
|
2021-10-13 15:39:37 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
response->command_id = request->command_id;
|
|
|
|
response->which_content = PB_Main_app_lock_status_response_tag;
|
2021-10-13 15:39:37 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
Loader* loader = furi_record_open(RECORD_LOADER);
|
|
|
|
response->content.app_lock_status_response.locked = loader_is_locked(loader);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_LOADER);
|
2021-10-13 15:39:37 +00:00
|
|
|
|
2022-08-02 12:54:12 +00:00
|
|
|
FURI_LOG_D(TAG, "LockStatus: response");
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_send_and_release(rpc_app->session, response);
|
|
|
|
|
|
|
|
free(response);
|
2021-10-13 15:39:37 +00:00
|
|
|
}
|
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
static void rpc_system_app_exit_request(const PB_Main* request, void* context) {
|
2022-07-04 13:09:46 +00:00
|
|
|
furi_assert(request);
|
|
|
|
furi_assert(request->which_content == PB_Main_app_exit_request_tag);
|
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
RpcAppSystem* rpc_app = context;
|
|
|
|
furi_assert(rpc_app);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
if(rpc_app->callback) {
|
2022-12-26 12:13:30 +00:00
|
|
|
FURI_LOG_D(TAG, "ExitRequest: id %lu", request->command_id);
|
2023-11-10 07:22:34 +00:00
|
|
|
|
|
|
|
const RpcAppSystemEvent event = {
|
|
|
|
.type = RpcAppEventTypeAppExit,
|
|
|
|
.data =
|
|
|
|
{
|
|
|
|
.type = RpcAppSystemEventDataTypeNone,
|
|
|
|
{0},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
rpc_system_app_error_reset(rpc_app);
|
|
|
|
rpc_system_app_set_last_command(rpc_app, request->command_id, &event);
|
|
|
|
|
|
|
|
rpc_app->callback(&event, rpc_app->callback_context);
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
} else {
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_system_app_send_error_response(
|
|
|
|
rpc_app, request->command_id, PB_CommandStatus_ERROR_APP_NOT_RUNNING, "ExitRequest");
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rpc_system_app_load_file(const PB_Main* request, void* context) {
|
|
|
|
furi_assert(request);
|
|
|
|
furi_assert(request->which_content == PB_Main_app_load_file_request_tag);
|
2023-11-10 07:22:34 +00:00
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
RpcAppSystem* rpc_app = context;
|
2023-11-10 07:22:34 +00:00
|
|
|
furi_assert(rpc_app);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
if(rpc_app->callback) {
|
2022-12-26 12:13:30 +00:00
|
|
|
FURI_LOG_D(TAG, "LoadFile: id %lu", request->command_id);
|
2023-11-10 07:22:34 +00:00
|
|
|
|
|
|
|
const RpcAppSystemEvent event = {
|
|
|
|
.type = RpcAppEventTypeLoadFile,
|
|
|
|
.data =
|
|
|
|
{
|
|
|
|
.type = RpcAppSystemEventDataTypeString,
|
|
|
|
.string = request->content.app_load_file_request.path,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
rpc_system_app_error_reset(rpc_app);
|
|
|
|
rpc_system_app_set_last_command(rpc_app, request->command_id, &event);
|
|
|
|
|
|
|
|
rpc_app->callback(&event, rpc_app->callback_context);
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
} else {
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_system_app_send_error_response(
|
|
|
|
rpc_app, request->command_id, PB_CommandStatus_ERROR_APP_NOT_RUNNING, "LoadFile");
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rpc_system_app_button_press(const PB_Main* request, void* context) {
|
|
|
|
furi_assert(request);
|
|
|
|
furi_assert(request->which_content == PB_Main_app_button_press_request_tag);
|
2023-11-10 07:22:34 +00:00
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
RpcAppSystem* rpc_app = context;
|
2023-11-10 07:22:34 +00:00
|
|
|
furi_assert(rpc_app);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
if(rpc_app->callback) {
|
2022-08-02 12:54:12 +00:00
|
|
|
FURI_LOG_D(TAG, "ButtonPress");
|
2023-11-10 07:22:34 +00:00
|
|
|
|
|
|
|
RpcAppSystemEvent event;
|
|
|
|
event.type = RpcAppEventTypeButtonPress;
|
|
|
|
|
|
|
|
if(strlen(request->content.app_button_press_request.args) != 0) {
|
|
|
|
event.data.type = RpcAppSystemEventDataTypeString;
|
|
|
|
event.data.string = request->content.app_button_press_request.args;
|
|
|
|
} else {
|
|
|
|
event.data.type = RpcAppSystemEventDataTypeInt32;
|
|
|
|
event.data.i32 = request->content.app_button_press_request.index;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpc_system_app_error_reset(rpc_app);
|
|
|
|
rpc_system_app_set_last_command(rpc_app, request->command_id, &event);
|
|
|
|
|
|
|
|
rpc_app->callback(&event, rpc_app->callback_context);
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
} else {
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_system_app_send_error_response(
|
|
|
|
rpc_app, request->command_id, PB_CommandStatus_ERROR_APP_NOT_RUNNING, "ButtonPress");
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rpc_system_app_button_release(const PB_Main* request, void* context) {
|
|
|
|
furi_assert(request);
|
|
|
|
furi_assert(request->which_content == PB_Main_app_button_release_request_tag);
|
|
|
|
|
|
|
|
RpcAppSystem* rpc_app = context;
|
2023-11-10 07:22:34 +00:00
|
|
|
furi_assert(rpc_app);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
if(rpc_app->callback) {
|
2022-08-02 12:54:12 +00:00
|
|
|
FURI_LOG_D(TAG, "ButtonRelease");
|
2023-11-10 07:22:34 +00:00
|
|
|
|
|
|
|
const RpcAppSystemEvent event = {
|
|
|
|
.type = RpcAppEventTypeButtonRelease,
|
|
|
|
.data =
|
|
|
|
{
|
|
|
|
.type = RpcAppSystemEventDataTypeNone,
|
|
|
|
{0},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
rpc_system_app_error_reset(rpc_app);
|
|
|
|
rpc_system_app_set_last_command(rpc_app, request->command_id, &event);
|
|
|
|
|
|
|
|
rpc_app->callback(&event, rpc_app->callback_context);
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
} else {
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_system_app_send_error_response(
|
|
|
|
rpc_app, request->command_id, PB_CommandStatus_ERROR_APP_NOT_RUNNING, "ButtonRelease");
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-29 09:08:08 +00:00
|
|
|
static void rpc_system_app_get_error_process(const PB_Main* request, void* context) {
|
|
|
|
furi_assert(request);
|
|
|
|
furi_assert(request->which_content == PB_Main_app_get_error_request_tag);
|
|
|
|
|
|
|
|
RpcAppSystem* rpc_app = context;
|
2023-11-10 07:22:34 +00:00
|
|
|
furi_assert(rpc_app);
|
|
|
|
|
|
|
|
PB_Main* response = malloc(sizeof(PB_Main));
|
2022-11-29 09:08:08 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
response->command_id = request->command_id;
|
|
|
|
response->which_content = PB_Main_app_get_error_response_tag;
|
|
|
|
response->content.app_get_error_response.code = rpc_app->error_code;
|
|
|
|
response->content.app_get_error_response.text = rpc_app->error_text;
|
2022-11-29 09:08:08 +00:00
|
|
|
|
|
|
|
FURI_LOG_D(TAG, "GetError");
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_send(rpc_app->session, response);
|
|
|
|
|
|
|
|
free(response);
|
2022-11-29 09:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rpc_system_app_data_exchange_process(const PB_Main* request, void* context) {
|
|
|
|
furi_assert(request);
|
|
|
|
furi_assert(request->which_content == PB_Main_app_data_exchange_request_tag);
|
|
|
|
|
|
|
|
RpcAppSystem* rpc_app = context;
|
2023-11-10 07:22:34 +00:00
|
|
|
furi_assert(rpc_app);
|
2022-11-29 09:08:08 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
if(rpc_app->callback) {
|
|
|
|
FURI_LOG_D(TAG, "DataExchange");
|
2022-11-29 09:08:08 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
const pb_bytes_array_t* data = request->content.app_data_exchange_request.data;
|
|
|
|
|
|
|
|
const RpcAppSystemEvent event = {
|
|
|
|
.type = RpcAppEventTypeDataExchange,
|
|
|
|
.data =
|
|
|
|
{
|
|
|
|
.type = RpcAppSystemEventDataTypeBytes,
|
|
|
|
.bytes =
|
|
|
|
{
|
|
|
|
.ptr = data ? data->bytes : NULL,
|
|
|
|
.size = data ? data->size : 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
rpc_system_app_error_reset(rpc_app);
|
|
|
|
rpc_system_app_set_last_command(rpc_app, request->command_id, &event);
|
|
|
|
|
|
|
|
rpc_app->callback(&event, rpc_app->callback_context);
|
2022-11-29 09:08:08 +00:00
|
|
|
} else {
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_system_app_send_error_response(
|
|
|
|
rpc_app, request->command_id, PB_CommandStatus_ERROR_APP_NOT_RUNNING, "DataExchange");
|
2022-11-29 09:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
void rpc_system_app_send_started(RpcAppSystem* rpc_app) {
|
2024-03-25 10:53:32 +00:00
|
|
|
furi_check(rpc_app);
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_system_app_send_state_response(rpc_app, PB_App_AppState_APP_STARTED, "SendStarted");
|
2022-07-25 14:16:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rpc_system_app_send_exited(RpcAppSystem* rpc_app) {
|
2024-03-25 10:53:32 +00:00
|
|
|
furi_check(rpc_app);
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_system_app_send_state_response(rpc_app, PB_App_AppState_APP_CLOSED, "SendExit");
|
2022-08-02 12:54:12 +00:00
|
|
|
}
|
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
void rpc_system_app_confirm(RpcAppSystem* rpc_app, bool result) {
|
2024-03-25 10:53:32 +00:00
|
|
|
furi_check(rpc_app);
|
|
|
|
furi_check(rpc_app->last_command_id != 0);
|
2023-11-10 07:22:34 +00:00
|
|
|
/* Ensure that only commands of these types can be confirmed */
|
2024-03-25 10:53:32 +00:00
|
|
|
furi_check(
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_app->last_event_type == RpcAppEventTypeAppExit ||
|
|
|
|
rpc_app->last_event_type == RpcAppEventTypeLoadFile ||
|
|
|
|
rpc_app->last_event_type == RpcAppEventTypeButtonPress ||
|
|
|
|
rpc_app->last_event_type == RpcAppEventTypeButtonRelease ||
|
|
|
|
rpc_app->last_event_type == RpcAppEventTypeDataExchange);
|
|
|
|
|
|
|
|
const uint32_t last_command_id = rpc_app->last_command_id;
|
|
|
|
const RpcAppSystemEventType last_event_type = rpc_app->last_event_type;
|
|
|
|
|
|
|
|
rpc_app->last_command_id = 0;
|
|
|
|
rpc_app->last_event_type = RpcAppEventTypeInvalid;
|
|
|
|
|
|
|
|
const PB_CommandStatus status = result ? PB_CommandStatus_OK :
|
|
|
|
PB_CommandStatus_ERROR_APP_CMD_ERROR;
|
|
|
|
FURI_LOG_D(
|
|
|
|
TAG,
|
|
|
|
"AppConfirm: event %d last_id %lu status %d",
|
|
|
|
last_event_type,
|
|
|
|
last_command_id,
|
|
|
|
status);
|
|
|
|
|
|
|
|
rpc_send_and_release_empty(rpc_app->session, last_command_id, status);
|
2022-08-02 12:54:12 +00:00
|
|
|
}
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
void rpc_system_app_set_callback(RpcAppSystem* rpc_app, RpcAppSystemCallback callback, void* ctx) {
|
2024-03-25 10:53:32 +00:00
|
|
|
furi_check(rpc_app);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_app->callback = callback;
|
|
|
|
rpc_app->callback_context = ctx;
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 09:08:08 +00:00
|
|
|
void rpc_system_app_set_error_code(RpcAppSystem* rpc_app, uint32_t error_code) {
|
2024-03-25 10:53:32 +00:00
|
|
|
furi_check(rpc_app);
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_app->error_code = error_code;
|
2022-11-29 09:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rpc_system_app_set_error_text(RpcAppSystem* rpc_app, const char* error_text) {
|
2024-03-25 10:53:32 +00:00
|
|
|
furi_check(rpc_app);
|
2022-11-29 09:08:08 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
if(rpc_app->error_text) {
|
|
|
|
free(rpc_app->error_text);
|
2022-11-29 09:08:08 +00:00
|
|
|
}
|
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_app->error_text = error_text ? strdup(error_text) : NULL;
|
2022-11-29 09:08:08 +00:00
|
|
|
}
|
|
|
|
|
2022-12-08 05:49:54 +00:00
|
|
|
void rpc_system_app_error_reset(RpcAppSystem* rpc_app) {
|
2024-03-25 10:53:32 +00:00
|
|
|
furi_check(rpc_app);
|
2022-12-08 05:49:54 +00:00
|
|
|
|
|
|
|
rpc_system_app_set_error_code(rpc_app, 0);
|
|
|
|
rpc_system_app_set_error_text(rpc_app, NULL);
|
|
|
|
}
|
|
|
|
|
2022-11-29 09:08:08 +00:00
|
|
|
void rpc_system_app_exchange_data(RpcAppSystem* rpc_app, const uint8_t* data, size_t data_size) {
|
2024-03-25 10:53:32 +00:00
|
|
|
furi_check(rpc_app);
|
2022-11-29 09:08:08 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
PB_Main* request = malloc(sizeof(PB_Main));
|
2022-11-29 09:08:08 +00:00
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
request->which_content = PB_Main_app_data_exchange_request_tag;
|
|
|
|
PB_App_DataExchangeRequest* content = &request->content.app_data_exchange_request;
|
2022-11-29 09:08:08 +00:00
|
|
|
|
|
|
|
if(data && data_size) {
|
|
|
|
content->data = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data_size));
|
|
|
|
content->data->size = data_size;
|
|
|
|
memcpy(content->data->bytes, data, data_size);
|
|
|
|
} else {
|
|
|
|
content->data = NULL;
|
|
|
|
}
|
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
rpc_send_and_release(rpc_app->session, request);
|
|
|
|
|
|
|
|
free(request);
|
2022-11-29 09:08:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-16 08:52:11 +00:00
|
|
|
void* rpc_system_app_alloc(RpcSession* session) {
|
|
|
|
furi_assert(session);
|
2021-10-13 15:39:37 +00:00
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
RpcAppSystem* rpc_app = malloc(sizeof(RpcAppSystem));
|
|
|
|
rpc_app->session = session;
|
|
|
|
|
2021-10-13 15:39:37 +00:00
|
|
|
RpcHandler rpc_handler = {
|
|
|
|
.message_handler = NULL,
|
|
|
|
.decode_submessage = NULL,
|
2022-07-04 13:09:46 +00:00
|
|
|
.context = rpc_app,
|
2021-10-13 15:39:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
rpc_handler.message_handler = rpc_system_app_start_process;
|
2022-03-16 08:52:11 +00:00
|
|
|
rpc_add_handler(session, PB_Main_app_start_request_tag, &rpc_handler);
|
2021-10-13 15:39:37 +00:00
|
|
|
|
|
|
|
rpc_handler.message_handler = rpc_system_app_lock_status_process;
|
2022-03-16 08:52:11 +00:00
|
|
|
rpc_add_handler(session, PB_Main_app_lock_status_request_tag, &rpc_handler);
|
2021-10-13 15:39:37 +00:00
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
rpc_handler.message_handler = rpc_system_app_exit_request;
|
2022-07-04 13:09:46 +00:00
|
|
|
rpc_add_handler(session, PB_Main_app_exit_request_tag, &rpc_handler);
|
|
|
|
|
|
|
|
rpc_handler.message_handler = rpc_system_app_load_file;
|
|
|
|
rpc_add_handler(session, PB_Main_app_load_file_request_tag, &rpc_handler);
|
|
|
|
|
|
|
|
rpc_handler.message_handler = rpc_system_app_button_press;
|
|
|
|
rpc_add_handler(session, PB_Main_app_button_press_request_tag, &rpc_handler);
|
|
|
|
|
|
|
|
rpc_handler.message_handler = rpc_system_app_button_release;
|
|
|
|
rpc_add_handler(session, PB_Main_app_button_release_request_tag, &rpc_handler);
|
|
|
|
|
2022-11-29 09:08:08 +00:00
|
|
|
rpc_handler.message_handler = rpc_system_app_get_error_process;
|
|
|
|
rpc_add_handler(session, PB_Main_app_get_error_request_tag, &rpc_handler);
|
|
|
|
|
|
|
|
rpc_handler.message_handler = rpc_system_app_data_exchange_process;
|
|
|
|
rpc_add_handler(session, PB_Main_app_data_exchange_request_tag, &rpc_handler);
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
return rpc_app;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rpc_system_app_free(void* context) {
|
|
|
|
RpcAppSystem* rpc_app = context;
|
2022-08-22 16:36:45 +00:00
|
|
|
furi_assert(rpc_app);
|
2023-11-10 07:22:34 +00:00
|
|
|
furi_assert(rpc_app->session);
|
|
|
|
|
|
|
|
if(rpc_app->callback) {
|
|
|
|
const RpcAppSystemEvent event = {
|
|
|
|
.type = RpcAppEventTypeSessionClose,
|
|
|
|
.data =
|
|
|
|
{
|
|
|
|
.type = RpcAppSystemEventDataTypeNone,
|
|
|
|
{0},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
rpc_app->callback(&event, rpc_app->callback_context);
|
2022-08-02 12:54:12 +00:00
|
|
|
}
|
|
|
|
|
2023-11-10 07:22:34 +00:00
|
|
|
while(rpc_app->callback) {
|
2022-08-02 12:54:12 +00:00
|
|
|
furi_delay_tick(1);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(rpc_app);
|
2021-10-13 15:39:37 +00:00
|
|
|
}
|