开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 27

MicroOS/MiniGUI

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (9)
标签 (1)
master
rel-3-2
drm
dev-3-4
complex-scripts
tmp-3-2-2
dev-3-2-2
rel-3-0
64b
ver-4-0-0
master
分支 (9)
标签 (1)
master
rel-3-2
drm
dev-3-4
complex-scripts
tmp-3-2-2
dev-3-2-2
rel-3-0
64b
ver-4-0-0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (9)
标签 (1)
master
rel-3-2
drm
dev-3-4
complex-scripts
tmp-3-2-2
dev-3-2-2
rel-3-0
64b
ver-4-0-0
MiniGUI
/
src
/
client
/
client.c
MiniGUI
/
src
/
client
/
client.c
client.c 15.66 KB
一键复制 编辑 原始数据 按行查看 历史
Vincent Wei 提交于 2019年07月15日 14:17 +08:00 . prepend excpetion list statement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 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 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
///////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT NOTICE
//
// The following open source license statement does not apply to any
// entity in the Exception List published by FMSoft.
//
// For more information, please visit:
//
// https://www.fmsoft.cn/exception-list
//
//////////////////////////////////////////////////////////////////////////////
/*
* This file is part of MiniGUI, a mature cross-platform windowing
* and Graphics User Interface (GUI) support system for embedded systems
* and smart IoT devices.
*
* Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd.
* Copyright (C) 1998~2002, WEI Yongming
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Or,
*
* As this program is a library, any link to this program must follow
* GNU General Public License version 3 (GPLv3). If you cannot accept
* GPLv3, you need to be licensed from FMSoft.
*
* If you have got a commercial license of this program, please use it
* under the terms and conditions of the commercial license.
*
* For more information about the commercial license, please refer to
* <http://www.minigui.com/en/about/licensing-policy/>.
*/
/*
** client.c: routines for client.
**
** The idea comes from sample code in APUE.
** Thank Mr. Richard Stevens for his perfect work.
**
** Create date: 2000年12月20日
*/
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include "common.h"
#include "minigui.h"
#include "gdi.h"
#include "window.h"
#include "gal.h"
#include "cliprect.h"
#include "internals.h"
#include "timer.h"
#include "ourhdr.h"
#include "client.h"
#include "server.h"
#include "sockio.h"
#include "sharedres.h"
#include "drawsemop.h"
#include "cursor.h"
int __mg_client_id;
static int conn_fd = -1; /* connected socket */
ON_LOCK_CLIENT_REQ OnLockClientReq = NULL;
ON_TRYLOCK_CLIENT_REQ OnTrylockClientReq = NULL;
ON_UNLOCK_CLIENT_REQ OnUnlockClientReq = NULL;
#define TIMEOUT_START_REPEAT 20
#define TIMEOUT_REPEAT 10
static struct timeval my_timeout;
void __mg_set_select_timeout (unsigned int usec)
{
my_timeout.tv_sec = 0;
#if 0
if (usec > 0) {
if (usec > USEC_10MS * TIMEOUT_START_REPEAT)
my_timeout.tv_usec = USEC_10MS * TIMEOUT_REPEAT;
else if (usec > USEC_10MS * TIMEOUT_REPEAT)
my_timeout.tv_usec = USEC_10MS * TIMEOUT_REPEAT >> 1;
else
my_timeout.tv_usec = USEC_10MS;
}
else {
my_timeout.tv_usec = USEC_10MS * TIMEOUT_START_REPEAT;
}
#else /* set the timer to 10ms can make the client respond more faster */
my_timeout.tv_usec = USEC_10MS;
#endif
}
BOOL client_ClientStartup (void)
{
struct sigaction siga;
/* connect to server */
if ( (conn_fd = cli_conn (CS_PATH, 'a')) < 0)
return FALSE;
FD_ZERO (&mg_rfdset);
FD_SET (conn_fd, &mg_rfdset);
mg_maxfd = conn_fd;
__mg_set_select_timeout (0);
/* ignore the SIGPIPE signal */
siga.sa_handler = SIG_IGN;
siga.sa_flags = 0;
memset (&siga.sa_mask, 0, sizeof (sigset_t));
sigaction (SIGPIPE, &siga, NULL);
return TRUE;
}
void client_ClientCleanup (void)
{
close (conn_fd);
conn_fd = -1;
}
int GUIAPI GetSockFD2Server (void)
{
if (mgIsServer)
return -1;
return conn_fd;
}
static void process_network_message(MSG *msg) {
if (msg->message == MSG_UPDATECLIWIN &&
__mg_client_check_hwnd (msg->hwnd, __mg_client_id)) {
__mg_update_window (msg->hwnd,
LOSWORD(msg->wParam), HISWORD(msg->wParam),
LOSWORD(msg->lParam), HISWORD(msg->lParam));
} else {
if (msg->hwnd == 0) {
msg->hwnd = HWND_DESKTOP;
QueueDeskMessage (msg);
} else if (__mg_client_check_hwnd (msg->hwnd, __mg_client_id)) {
QueueDeskMessage (msg);
}
}
}
int GUIAPI ClientRequestEx (const REQUEST* request, const void* ex_data, int ex_data_len,
void* result, int len_rslt)
{
int n;
size_t len_data;
MSG msg;
if (mgIsServer)
return -1;
#ifdef _MGGAL_MLSHADOW
if ((request->id != REQID_MLSHADOW_CLIREQ)
&& (__mg_client_id == 0 && request->id != REQID_JOINLAYER)) {
#elif defined(_MGGAL_NEXUS)
if ((request->id != REQID_NEXUS_CLIENT_GET_SURFACE)
&& (__mg_client_id == 0 && request->id != REQID_JOINLAYER)) {
#else
if (__mg_client_id == 0 && request->id != REQID_JOINLAYER) {
#endif
fprintf (stderr, "CLIENT: please call JoinLayer first.\n");
exit (255);
return -1;
}
if (OnLockClientReq && OnUnlockClientReq)
OnLockClientReq();
n = sock_write (conn_fd, &request->id, sizeof (int));
if (n < 0) goto sock_error;
if (ex_data_len <= 0 || ex_data == NULL) {
ex_data = NULL;
ex_data_len = 0;
}
len_data = request->len_data + ex_data_len;
n = sock_write (conn_fd, &len_data, sizeof (size_t));
if (n < 0) goto sock_error;
n = sock_write (conn_fd, request->data, request->len_data);
if (n < 0) goto sock_error;
if (ex_data_len > 0) {
n = sock_write (conn_fd, ex_data, ex_data_len);
if (n < 0) goto sock_error;
}
if (result == NULL || len_rslt == 0) {
if (OnLockClientReq && OnUnlockClientReq)
OnUnlockClientReq();
return 0;
}
do {
n = sock_read (conn_fd, &msg, sizeof (MSG));
if (n < 0) {
goto sock_error;
}
if (msg.hwnd == HWND_INVALID) {
break;
} else {
process_network_message(&msg);
}
} while (TRUE);
n = sock_read (conn_fd, result, len_rslt);
if (n < 0) goto sock_error;
if (OnLockClientReq && OnUnlockClientReq)
OnUnlockClientReq();
return 0;
sock_error:
if (n == SOCKERR_IO) {
if (OnLockClientReq && OnUnlockClientReq)
OnUnlockClientReq();
}
else if (n == SOCKERR_CLOSED) {
if (OnLockClientReq && OnUnlockClientReq)
OnUnlockClientReq();
exit (255);
}
return -1;
}
static void check_live (void)
{
REQUEST req;
if (__mg_timer_counter != SHAREDRES_TIMER_COUNTER) {
SetDesktopTimerFlag ();
__mg_timer_counter = SHAREDRES_TIMER_COUNTER;
}
/* Tell server that I am live */
req.id = REQID_IAMLIVE;
req.data = &__mg_timer_counter;
req.len_data = sizeof (unsigned int);
ClientRequest (&req, NULL, 0);
}
BOOL client_IdleHandler4Client (PMSGQUEUE msg_que)
{
static DWORD old_timer;
static long repeat_timeout = TIMEOUT_START_REPEAT;
fd_set rset, wset, eset;
fd_set* wsetptr = NULL;
fd_set* esetptr = NULL;
int i, n, nread;
struct timeval sel_timeout;
MSG Msg;
check_live ();
rset = mg_rfdset; /* rset gets modified each time around */
if (mg_wfdset) {
wset = *mg_wfdset;
wsetptr = &wset;
}
if (mg_efdset) {
eset = *mg_efdset;
esetptr = &eset;
}
if (msg_que)
sel_timeout = my_timeout;
else { /* check fd only: for HavePendingMessage function */
sel_timeout.tv_sec = 0;
sel_timeout.tv_usec = 0;
}
if ((n = select (mg_maxfd + 1,
&rset, wsetptr, esetptr, &sel_timeout)) < 0) {
if (errno == EINTR) {
/* it is time to check message again. */
return FALSE;
}
err_sys ("client: select error");
}
else if (n == 0) {
check_live ();
if (msg_que
&& (__mg_timer_counter - old_timer) >= repeat_timeout) {
Msg.hwnd = HWND_DESKTOP;
Msg.message = MSG_TIMEOUT;
Msg.wParam = (WPARAM)__mg_timer_counter;
Msg.lParam = 0;
Msg.time = __mg_timer_counter;
kernel_QueueMessage (msg_que, &Msg);
old_timer = __mg_timer_counter;
repeat_timeout = TIMEOUT_REPEAT;
}
#ifdef _MG_CONFIG_FAST_MOUSEMOVE
{
static int old_mouse_x = -1, old_mouse_y = -1, old_buttons = -1;
static unsigned int old_mouse_move_serial = 0xdeadbeef;
int flag = 0, mouse_x = -1, mouse_y = -1, buttons = -1;
lock_mousemove_sem();
if (SHAREDRES_MOUSEMOVECLIENT == __mg_client_id
&& SHAREDRES_MOUSEMOVESERIAL != old_mouse_move_serial) {
mouse_x = SHAREDRES_MOUSEX;
mouse_y = SHAREDRES_MOUSEY;
buttons = SHAREDRES_SHIFTSTATUS;
flag = 1;
}
old_mouse_move_serial = SHAREDRES_MOUSEMOVESERIAL;
unlock_mousemove_sem();
if (flag && (mouse_x != old_mouse_x || mouse_y != old_mouse_y || buttons != old_buttons)) {
MSG msg;
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
old_buttons = buttons;
msg.hwnd = HWND_DESKTOP;
msg.message = MSG_MOUSEMOVE;
msg.wParam = buttons;
msg.lParam = MAKELONG(mouse_x, mouse_y);
QueueDeskMessage(&msg);
}
}
#endif
return FALSE;
}
/* check fd only: for HavePendingMessage function. */
else if (msg_que == NULL)
return TRUE;
old_timer = __mg_timer_counter;
repeat_timeout = TIMEOUT_START_REPEAT;
if (FD_ISSET (conn_fd, &rset) &&
(!OnTrylockClientReq || !OnUnlockClientReq
|| (OnTrylockClientReq && OnUnlockClientReq && !OnTrylockClientReq()))) {
if ( (nread = sock_read (conn_fd, &Msg, sizeof (MSG))) < 0) {
if (OnTrylockClientReq && OnUnlockClientReq)
OnUnlockClientReq();
err_sys ("client: read error on fd %d", conn_fd);
}
else if (nread == 0) {
if (OnTrylockClientReq && OnUnlockClientReq)
OnUnlockClientReq();
err_sys ("client: server closed");
close (conn_fd);
}
else { /* process event from server */
if (OnTrylockClientReq && OnUnlockClientReq)
OnUnlockClientReq();
process_network_message(&Msg);
}
}
/* go through registered listen fds */
for (i = 0; i < MAX_NR_LISTEN_FD; i++) {
MSG Msg;
Msg.message = MSG_FDEVENT;
if (mg_listen_fds [i].fd) {
fd_set* temp = NULL;
int type = mg_listen_fds [i].type;
switch (type) {
case POLLIN:
temp = &rset;
break;
case POLLOUT:
temp = wsetptr;
break;
case POLLERR:
temp = esetptr;
break;
}
if (temp && FD_ISSET (mg_listen_fds [i].fd, temp)) {
Msg.hwnd = (HWND)mg_listen_fds [i].hwnd;
Msg.wParam = MAKELONG (mg_listen_fds [i].fd, type);
Msg.lParam = (LPARAM)mg_listen_fds [i].context;
kernel_QueueMessage (msg_que, &Msg);
}
}
}
check_live ();
return TRUE;
}
GHANDLE GUIAPI JoinLayer (const char* layer_name, const char* client_name,
int max_nr_topmosts, int max_nr_normals)
{
GHANDLE layer_handle = INV_LAYER_HANDLE;
REQUEST req;
JOINLAYERINFO info;
JOINEDCLIENTINFO joined_info;
if (mgIsServer)
return layer_handle;
if (__mg_client_id != 0) /* Already joined, return the handle */
return GetLayerInfo (NAME_SELF_LAYER, NULL, NULL, NULL);
if (layer_name) {
strncpy (info.layer_name, layer_name, LEN_LAYER_NAME);
info.layer_name [LEN_LAYER_NAME] = '0円';
}
else {
/* treat as the topmost layer */
info.layer_name [0] = '0円';
}
if (client_name) {
strncpy (info.client_name, client_name, LEN_CLIENT_NAME);
info.client_name [LEN_CLIENT_NAME] = '0円';
}
else
info.client_name [0] = '0円';
if (max_nr_topmosts <= 0) max_nr_topmosts = DEF_NR_TOPMOSTS;
if (max_nr_normals <= 0) max_nr_normals = DEF_NR_NORMALS;
info.max_nr_topmosts = (max_nr_topmosts + 7) & ~0x07;
info.max_nr_normals = (max_nr_normals + 7) & ~0x07;
req.id = REQID_JOINLAYER;
req.data = &info;
req.len_data = sizeof (JOINLAYERINFO);
if (ClientRequest (&req, &joined_info, sizeof (JOINEDCLIENTINFO)) < 0)
goto ret;
__mg_client_id = joined_info.cli_id;
layer_handle = joined_info.layer;
if (layer_handle != INV_LAYER_HANDLE) {
ZORDERINFO* zi;
__mg_layer = layer_handle;
zi = (ZORDERINFO*) shmat (joined_info.zo_shmid, 0, SHM_RDONLY);
if (zi == (void*)-1) {
return INV_LAYER_HANDLE;
}
__mg_zorder_info = zi;
}
__mg_start_client_desktop ();
ret:
return layer_handle;
}
GHANDLE GUIAPI GetLayerInfo (const char* layer_name,
int* nr_clients, BOOL* is_topmost, int* cli_active)
{
if (mgIsServer)
return INV_LAYER_HANDLE;
if (layer_name) {
LAYERINFO info;
REQUEST req;
req.id = REQID_LAYERINFO;
req.data = layer_name;
req.len_data = strlen (layer_name) + 1;
if (ClientRequest (&req, &info, sizeof (LAYERINFO)) < 0)
goto ret;
if (info.handle) {
if (nr_clients) *nr_clients = info.nr_clients;
if (is_topmost) *is_topmost = info.is_topmost;
if (cli_active) *cli_active = info.cli_active;
}
return info.handle;
}
ret:
return INV_LAYER_HANDLE;
}
BOOL GUIAPI SetTopmostLayer (BOOL handle_name,
GHANDLE handle, const char* name)
{
BOOL ret = FALSE;
LAYEROPINFO info;
REQUEST req;
if (mgIsServer)
return ret;
if (!handle_name && name == NULL)
return ret;
if (handle_name && handle == INV_LAYER_HANDLE)
return ret;
info.id_op = ID_LAYEROP_SETTOP;
info.handle_name = handle_name;
if (handle_name) {
info.layer.handle = handle;
}
else {
strncpy (info.layer.name, name, LEN_LAYER_NAME);
info.layer.name [LEN_LAYER_NAME] = '0円';
}
req.id = REQID_LAYEROP;
req.data = &info;
req.len_data = sizeof (LAYEROPINFO);
if (ClientRequest (&req, &ret, sizeof (BOOL)) < 0)
ret = FALSE;
return ret;
}
BOOL GUIAPI DeleteLayer (BOOL handle_name,
GHANDLE handle, const char* name)
{
BOOL ret = FALSE;
LAYEROPINFO info;
REQUEST req;
if (mgIsServer)
return ret;
if (!handle_name && name == NULL)
return ret;
if (handle_name && handle == INV_LAYER_HANDLE)
return ret;
info.id_op = ID_LAYEROP_DELETE;
info.handle_name = handle_name;
if (handle_name) {
info.layer.handle = handle;
}
else {
strncpy (info.layer.name, name, LEN_LAYER_NAME);
info.layer.name [LEN_LAYER_NAME] = '0円';
}
req.id = REQID_LAYEROP;
req.data = &info;
req.len_data = sizeof (LAYEROPINFO);
if (ClientRequest (&req, &ret, sizeof (BOOL)) < 0)
ret = FALSE;
return ret;
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

MiniGUI 是一个自由软件项目。其目标是提供一个快速、稳定、跨操作系统的图形用户界面(GUI)支持系统,尤其是基于 Linux/uClinux、eCos 以及其他传统 RTOS(如 VxWorks、ThreadX、uC/OS-II、Nucleus 等)的实时嵌入式操作系统。
暂无标签
GPL-3.0
使用 GPL-3.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/MicroOS/MiniGUI.git
git@gitee.com:MicroOS/MiniGUI.git
MicroOS
MiniGUI
MiniGUI
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /