[FL-2505] Active RPC session icon (#2583)

* Active RPC session icon
* Add RpcOwner, don't show the RPC icon when the session was started from BLE
* Fix rpc_test and f18 api
* Bump API version

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Astra 2023-04-19 11:30:26 +03:00 committed by GitHub
parent f68c3b2a65
commit 2c7eb53cac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 60 additions and 11 deletions

View file

@ -84,7 +84,7 @@ static void test_rpc_setup(void) {
rpc = furi_record_open(RECORD_RPC);
for(int i = 0; !(rpc_session[0].session) && (i < 10000); ++i) {
rpc_session[0].session = rpc_session_open(rpc);
rpc_session[0].session = rpc_session_open(rpc, RpcOwnerUnknown);
furi_delay_tick(1);
}
furi_check(rpc_session[0].session);
@ -104,7 +104,7 @@ static void test_rpc_setup_second_session(void) {
furi_check(!(rpc_session[1].session));
for(int i = 0; !(rpc_session[1].session) && (i < 10000); ++i) {
rpc_session[1].session = rpc_session_open(rpc);
rpc_session[1].session = rpc_session_open(rpc, RpcOwnerUnknown);
furi_delay_tick(1);
}
furi_check(rpc_session[1].session);

View file

@ -225,7 +225,7 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
if(bt->profile == BtProfileSerial) {
// Open RPC session
bt->rpc_session = rpc_session_open(bt->rpc);
bt->rpc_session = rpc_session_open(bt->rpc, RpcOwnerBle);
if(bt->rpc_session) {
FURI_LOG_I(TAG, "Open RPC connection");
rpc_session_set_send_bytes_callback(bt->rpc_session, bt_rpc_send_bytes_callback);

View file

@ -76,6 +76,7 @@ struct RpcSession {
RpcBufferIsEmptyCallback buffer_is_empty_callback;
RpcSessionClosedCallback closed_callback;
RpcSessionTerminatedCallback terminated_callback;
RpcOwner owner;
void* context;
};
@ -83,6 +84,11 @@ struct Rpc {
FuriMutex* busy_mutex;
};
RpcOwner rpc_session_get_owner(RpcSession* session) {
furi_assert(session);
return session->owner;
}
static void rpc_close_session_process(const PB_Main* request, void* context) {
furi_assert(request);
furi_assert(context);
@ -348,7 +354,7 @@ static void rpc_session_free_callback(FuriThreadState thread_state, void* contex
}
}
RpcSession* rpc_session_open(Rpc* rpc) {
RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner) {
furi_assert(rpc);
RpcSession* session = malloc(sizeof(RpcSession));
@ -357,6 +363,7 @@ RpcSession* rpc_session_open(Rpc* rpc) {
session->rpc = rpc;
session->terminate = false;
session->decode_error = false;
session->owner = owner;
RpcHandlerDict_init(session->handlers);
session->decoded_message = malloc(sizeof(PB_Main));

View file

@ -30,6 +30,21 @@ typedef void (*RpcSessionClosedCallback)(void* context);
* and all operations were finished */
typedef void (*RpcSessionTerminatedCallback)(void* context);
/** RPC owner */
typedef enum {
RpcOwnerUnknown = 0,
RpcOwnerBle,
RpcOwnerUsb,
RpcOwnerCount,
} RpcOwner;
/** Get RPC session owner
*
* @param session pointer to RpcSession descriptor
* @return session owner
*/
RpcOwner rpc_session_get_owner(RpcSession* session);
/** Open RPC session
*
* USAGE:
@ -44,10 +59,11 @@ typedef void (*RpcSessionTerminatedCallback)(void* context);
*
*
* @param rpc instance
* @param owner owner of session
* @return pointer to RpcSession descriptor, or
* NULL if RPC is busy and can't open session now
*/
RpcSession* rpc_session_open(Rpc* rpc);
RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner);
/** Close RPC session
* It is guaranteed that no callbacks will be called

View file

@ -47,7 +47,7 @@ void rpc_cli_command_start_session(Cli* cli, FuriString* args, void* context) {
FURI_LOG_D(TAG, "Free memory %lu", mem_before);
furi_hal_usb_lock();
RpcSession* rpc_session = rpc_session_open(rpc);
RpcSession* rpc_session = rpc_session_open(rpc, RpcOwnerUsb);
if(rpc_session == NULL) {
printf("Session start error\r\n");
furi_hal_usb_unlock();

View file

@ -2,6 +2,7 @@
#include "rpc_i.h"
#include "gui.pb.h"
#include <gui/gui_i.h>
#include <assets_icons.h>
#define TAG "RpcGui"
@ -31,6 +32,8 @@ typedef struct {
uint32_t input_key_counter[InputKeyMAX];
uint32_t input_counter;
ViewPort* rpc_session_active_viewport;
} RpcGuiSystem;
static const PB_Gui_ScreenOrientation rpc_system_gui_screen_orientation_map[] = {
@ -352,6 +355,12 @@ static void rpc_system_gui_virtual_display_frame_process(const PB_Main* request,
(void)session;
}
static void rpc_active_session_icon_draw_callback(Canvas* canvas, void* context) {
UNUSED(context);
furi_assert(canvas);
canvas_draw_icon(canvas, 0, 0, &I_Rpc_active_7x8);
}
void* rpc_system_gui_alloc(RpcSession* session) {
furi_assert(session);
@ -359,6 +368,18 @@ void* rpc_system_gui_alloc(RpcSession* session) {
rpc_gui->gui = furi_record_open(RECORD_GUI);
rpc_gui->session = session;
// Active session icon
rpc_gui->rpc_session_active_viewport = view_port_alloc();
view_port_set_width(rpc_gui->rpc_session_active_viewport, icon_get_width(&I_Rpc_active_7x8));
view_port_draw_callback_set(
rpc_gui->rpc_session_active_viewport, rpc_active_session_icon_draw_callback, session);
if(rpc_session_get_owner(rpc_gui->session) != RpcOwnerBle) {
view_port_enabled_set(rpc_gui->rpc_session_active_viewport, true);
} else {
view_port_enabled_set(rpc_gui->rpc_session_active_viewport, false);
}
gui_add_view_port(rpc_gui->gui, rpc_gui->rpc_session_active_viewport, GuiLayerStatusBarLeft);
RpcHandler rpc_handler = {
.message_handler = NULL,
.decode_submessage = NULL,
@ -399,6 +420,9 @@ void rpc_system_gui_free(void* context) {
rpc_gui->virtual_display_not_empty = false;
}
gui_remove_view_port(rpc_gui->gui, rpc_gui->rpc_session_active_viewport);
view_port_free(rpc_gui->rpc_session_active_viewport);
if(rpc_gui->is_streaming) {
rpc_gui->is_streaming = false;
// Remove GUI framebuffer callback

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,22.0,,
Version,+,23.0,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
@ -1596,7 +1596,8 @@ Function,-,rindex,char*,"const char*, int"
Function,+,rpc_session_close,void,RpcSession*
Function,+,rpc_session_feed,size_t,"RpcSession*, uint8_t*, size_t, TickType_t"
Function,+,rpc_session_get_available_size,size_t,RpcSession*
Function,+,rpc_session_open,RpcSession*,Rpc*
Function,+,rpc_session_get_owner,RpcOwner,RpcSession*
Function,+,rpc_session_open,RpcSession*,"Rpc*, RpcOwner"
Function,+,rpc_session_set_buffer_is_empty_callback,void,"RpcSession*, RpcBufferIsEmptyCallback"
Function,+,rpc_session_set_close_callback,void,"RpcSession*, RpcSessionClosedCallback"
Function,+,rpc_session_set_context,void,"RpcSession*, void*"

1 entry status name type params
2 Version + 22.0 23.0
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
1596 Function + rpc_session_close void RpcSession*
1597 Function + rpc_session_feed size_t RpcSession*, uint8_t*, size_t, TickType_t
1598 Function + rpc_session_get_available_size size_t RpcSession*
1599 Function + rpc_session_open rpc_session_get_owner RpcSession* RpcOwner Rpc* RpcSession*
1600 Function + rpc_session_open RpcSession* Rpc*, RpcOwner
1601 Function + rpc_session_set_buffer_is_empty_callback void RpcSession*, RpcBufferIsEmptyCallback
1602 Function + rpc_session_set_close_callback void RpcSession*, RpcSessionClosedCallback
1603 Function + rpc_session_set_context void RpcSession*, void*

View file

@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,22.0,,
Version,+,23.0,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
@ -2373,7 +2373,8 @@ Function,-,roundl,long double,long double
Function,+,rpc_session_close,void,RpcSession*
Function,+,rpc_session_feed,size_t,"RpcSession*, uint8_t*, size_t, TickType_t"
Function,+,rpc_session_get_available_size,size_t,RpcSession*
Function,+,rpc_session_open,RpcSession*,Rpc*
Function,+,rpc_session_get_owner,RpcOwner,RpcSession*
Function,+,rpc_session_open,RpcSession*,"Rpc*, RpcOwner"
Function,+,rpc_session_set_buffer_is_empty_callback,void,"RpcSession*, RpcBufferIsEmptyCallback"
Function,+,rpc_session_set_close_callback,void,"RpcSession*, RpcSessionClosedCallback"
Function,+,rpc_session_set_context,void,"RpcSession*, void*"

1 entry status name type params
2 Version + 22.0 23.0
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
2373 Function + rpc_session_close void RpcSession*
2374 Function + rpc_session_feed size_t RpcSession*, uint8_t*, size_t, TickType_t
2375 Function + rpc_session_get_available_size size_t RpcSession*
2376 Function + rpc_session_open rpc_session_get_owner RpcSession* RpcOwner Rpc* RpcSession*
2377 Function + rpc_session_open RpcSession* Rpc*, RpcOwner
2378 Function + rpc_session_set_buffer_is_empty_callback void RpcSession*, RpcBufferIsEmptyCallback
2379 Function + rpc_session_set_close_callback void RpcSession*, RpcSessionClosedCallback
2380 Function + rpc_session_set_context void RpcSession*, void*