RT-Thread GUI - Server

RT-Thread GUI 2019-02-23 332

基本事件結構#

server 掌管整個 GUI system 的所有事件 (event),而根據不同的事件定義不同的結構;在每個不同的結構中都有基本的欄位 _RTGUI_EVENT_WIN_ELEMENTS

File: event.c

149
150
151
152
153
154
/*
* RTGUI Window Event
*/
#define _RTGUI_EVENT_WIN_ELEMENTS \
struct rtgui_event parent; \
struct rtgui_win *wid;

rtgui_event 即為事件的基本結構:

108
109
110
111
112
113
114
115
116
117
118
119
120
121
struct rtgui_event
{
/* the event type */
enum _rtgui_event_type type;
/* user field of event */
rt_uint16_t user;

/* the event sender */
struct rtgui_app *sender;

/* mailbox to acknowledge request */
rt_mailbox_t ack;
};
typedef struct rtgui_event rtgui_event_t;

基本結構設定#

126
127
128
129
130
131
132
#define RTGUI_EVENT_INIT(e, t)  do      \
{ \
(e)->type = (t); \
(e)->user = 0; \
(e)->sender = rtgui_app_self(); \
(e)->ack = RT_NULL; \
} while (0)

啟動 server#

File: server.c

首先,定義一個 app 名叫 server :

38
static struct rtgui_app *rtgui_server_app = RT_NULL;

接著透過 rtgui_server_entry 啟動 app,也就是 server:

功能 回傳值 *parameter
啟動 server void 未使用
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/**
* rtgui server thread's entry
*/
static void rtgui_server_entry(void *parameter)
{
#ifdef _WIN32_NATIVE
/* set the server thread to highest */
HANDLE hCurrentThread = GetCurrentThread();
SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST);
#endif

/* create rtgui server application */
rtgui_server_app = rtgui_app_create("rtgui");
if (rtgui_server_app == RT_NULL)
{
rt_kprintf("Create GUI server failed.\n");
return;
}

rtgui_object_set_event_handler(RTGUI_OBJECT(rtgui_server_app),
rtgui_server_event_handler);
/* init mouse and show */
rtgui_mouse_init();
#ifdef RTGUI_USING_MOUSE_CURSOR
rtgui_mouse_show_cursor();
#endif

rtgui_app_run(rtgui_server_app);

rtgui_app_destroy(rtgui_server_app);
rtgui_server_app = RT_NULL;
}

最後會進入 rtgui_app_run 並正式開始執行 server,也就是進入所屬的 event handler


Event Handler#

Event handler 也就是 server 的進入點