开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (23)
标签 (17)
master
drm
rel-5-0
subpixel
optimize-ths-desktop-idle-handler
cleanup-timer
dev-5-2
drm-dma
rel-3-0
dblbuff4fbcon
dev-webp
rockchip-px30
update_threads
gengyue
rel-4-0
dev-4-1
rel-3-2
gpu-integration
dev-3-4
complex-scripts
ver-5-0-16
ver-5-0-15
ver-5-0-11
ver-5-0-10
ver-5-0-9
ver-5-0-6
ver-5-0-3
ver-4-0-8
ver-5-0-2
ver-5-0-0
ver-4-0-7
dev-4-9-1
ver-4-0-5
ver-4-0-4
ver-4-0-2
ver-3-2-3
ver-4-0-0
master
分支 (23)
标签 (17)
master
drm
rel-5-0
subpixel
optimize-ths-desktop-idle-handler
cleanup-timer
dev-5-2
drm-dma
rel-3-0
dblbuff4fbcon
dev-webp
rockchip-px30
update_threads
gengyue
rel-4-0
dev-4-1
rel-3-2
gpu-integration
dev-3-4
complex-scripts
ver-5-0-16
ver-5-0-15
ver-5-0-11
ver-5-0-10
ver-5-0-9
ver-5-0-6
ver-5-0-3
ver-4-0-8
ver-5-0-2
ver-5-0-0
ver-4-0-7
dev-4-9-1
ver-4-0-5
ver-4-0-4
ver-4-0-2
ver-3-2-3
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
分支 (23)
标签 (17)
master
drm
rel-5-0
subpixel
optimize-ths-desktop-idle-handler
cleanup-timer
dev-5-2
drm-dma
rel-3-0
dblbuff4fbcon
dev-webp
rockchip-px30
update_threads
gengyue
rel-4-0
dev-4-1
rel-3-2
gpu-integration
dev-3-4
complex-scripts
ver-5-0-16
ver-5-0-15
ver-5-0-11
ver-5-0-10
ver-5-0-9
ver-5-0-6
ver-5-0-3
ver-4-0-8
ver-5-0-2
ver-5-0-0
ver-4-0-7
dev-4-9-1
ver-4-0-5
ver-4-0-4
ver-4-0-2
ver-3-2-3
ver-4-0-0
MiniGUI
/
src
/
server
/
request.c
MiniGUI
/
src
/
server
/
request.c
request.c 32.09 KB
一键复制 编辑 原始数据 按行查看 历史
Vincent Wei 提交于 2023年09月08日 18:14 +08:00 . remove code about semaphhore for shared surface
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 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
///////////////////////////////////////////////////////////////////////////////
//
// 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~2020, 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/blog/minigui-licensing-policy/>.
*/
/*
** request.c: handle request of clients.
**
** Current maintainer: Wei Yongming.
**
** Create date: 2000年12月21日
**
** NOTE: The idea comes from sample code in APUE.
*/
#include <signal.h>
#include "common.h"
#include "minigui.h"
#include "gdi.h"
#include "window.h"
#include "cliprect.h"
#include "internals.h"
#include "cursor.h"
#include "gal.h"
#include "ourhdr.h"
#include "sockio.h"
#include "client.h"
#include "server.h"
#include "sharedres.h"
#include "misc.h"
#include "map.h"
#include "dc.h"
typedef void (* ReleaseProc) (void* );
struct GlobalRes
{
struct GlobalRes* next;
struct GlobalRes* prev;
void* key;
void* res;
ReleaseProc release_proc;
};
static void add_global_res (int cli, void* key,
void* res, ReleaseProc release_proc)
{
MG_Client* client = mgClients + cli;
struct GlobalRes *global_res = malloc (sizeof (struct GlobalRes));
if (global_res) {
global_res->key = key;
global_res->res = res;
global_res->release_proc = release_proc;
if (client->global_res == NULL) {
global_res->next = NULL;
global_res->prev = NULL;
client->global_res = global_res;
}
else {
global_res->next = client->global_res;
global_res->prev = NULL;
global_res->next->prev = global_res;
client->global_res = global_res;
}
}
}
#ifdef _MGGAL_MLSHADOW
extern int MLSHADOW_Server(void* request, void* reply);
extern void srvMLSHADOW_DelSurface(void *res);
#endif
static void del_global_res (int cli, void* key, void* res)
{
MG_Client* client = mgClients + cli;
struct GlobalRes *global_res = client->global_res, *next;
while (global_res) {
next = global_res->next;
if (global_res->key == key && global_res->res == res) {
if (global_res->release_proc)
global_res->release_proc (global_res->res);
if (global_res->prev)
global_res->prev->next = global_res->next;
if (global_res->next)
global_res->next->prev = global_res->prev;
if (global_res == client->global_res) {
client->global_res = global_res->next;
}
free (global_res);
break;
}
global_res = next;
}
}
void __mg_release_global_res (int cli)
{
MG_Client* client = mgClients + cli;
struct GlobalRes *global_res = client->global_res, *next;
while (global_res) {
next = global_res->next;
if (global_res->release_proc)
global_res->release_proc (global_res->res);
free (global_res);
global_res = next;
}
}
int GUIAPI ServerSendReplyEx (int clifd,
const void* reply, int len, int fd_to_send)
{
if (!mgIsServer)
return SOCKERR_IO;
{
MSG msg = {HWND_INVALID, 0};
/* send a reply message to indicate this is a reply of request */
if (sock_write (clifd, &msg, sizeof (MSG)) < 0)
return SOCKERR_IO;
}
#if 0
{
if (sock_write (clifd, reply, len) < 0)
return SOCKERR_IO;
return SOCKERR_OK;
}
#else /* use sendmsg */
{
struct iovec iov[1];
struct msghdr msg;
struct cmsghdr *cmsg = NULL;
iov[0].iov_base = (void*)reply;
iov[0].iov_len = len;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_name = NULL;
msg.msg_namelen = 0;
if (fd_to_send >= 0) {
cmsg = alloca (CMSG_LEN (sizeof (int)));
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN (sizeof (int));
memcpy (CMSG_DATA (cmsg), &fd_to_send, sizeof (int));
msg.msg_control = cmsg;
msg.msg_controllen = CMSG_LEN (sizeof (int));
}
else {
msg.msg_control = NULL;
msg.msg_controllen = 0;
}
return sock_sendmsg (clifd, &msg, 0);
}
#endif
}
static int load_cursor (int cli, int clifd, void* buff, size_t len)
{
HCURSOR hcsr;
hcsr = LoadCursorFromFile (buff);
#ifdef _MGHAVE_CURSOR
if (hcsr) {
add_global_res (cli, hcsr, hcsr, (ReleaseProc)DestroyCursor);
}
#endif
return ServerSendReply (clifd, &hcsr, sizeof (HCURSOR));
}
#if IS_COMPOSITING_SCHEMA
static int load_cursor_png_file (int cli, int clifd, void* buff, size_t len)
{
int hotspot[2];
HCURSOR hcsr = 0;
if (len <= (sizeof (hotspot) + 1)) // length of file name is 0.
goto ret;
memcpy (hotspot, buff, sizeof(hotspot));
hcsr = LoadCursorFromPNGFile (buff + sizeof(hotspot), hotspot[0], hotspot[1]);
#ifdef _MGHAVE_CURSOR
if (hcsr) {
add_global_res (cli, hcsr, hcsr, (ReleaseProc)DestroyCursor);
}
#endif
ret:
return ServerSendReply (clifd, &hcsr, sizeof (HCURSOR));
}
static int load_cursor_png_mem (int cli, int clifd, void* buff, size_t len)
{
int hotspot[2];
HCURSOR hcsr;
/* check whether has enough PNG data.
* see: https://garethrees.org/2007/11/14/pngcrush/
*/
if (len < (sizeof (hotspot) + 67))
goto ret;
memcpy (hotspot, buff, sizeof(hotspot));
hcsr = LoadCursorFromPNGMem (buff + sizeof(hotspot), len - sizeof (hotspot),
hotspot[0], hotspot[1]);
#ifdef _MGHAVE_CURSOR
if (hcsr) {
add_global_res (cli, hcsr, hcsr, (ReleaseProc)DestroyCursor);
}
#endif
ret:
return ServerSendReply (clifd, &hcsr, sizeof (HCURSOR));
}
#if 0 // Deprecated since 5.2.0
static void my_release_sem_for_shared_surf (void* res)
{
int sem_num = (int)(intptr_t)res;
if (__mg_free_sem_for_shared_surf (sem_num)) {
_WRN_PRINTF("Failed to call __mg_free_sem_for_shared_surf (%d)\n",
sem_num);
}
}
static int alloc_sem_for_shared_surf (int cli, int clifd, void* buff, size_t len)
{
int sem_num;
sem_num = __mg_alloc_sem_for_shared_surf ();
if (sem_num >= 0) {
add_global_res (cli, (void*)alloc_sem_for_shared_surf,
(void*)(intptr_t)sem_num,
my_release_sem_for_shared_surf);
}
return ServerSendReply (clifd, &sem_num, sizeof (int));
}
static int free_sem_for_shared_surf (int cli, int clifd, void* buff, size_t len)
{
int ret_value = 0;
int sem_num;
sem_num = *((int*)buff);
del_global_res (cli, (void*)alloc_sem_for_shared_surf,
(void*)(intptr_t)sem_num);
return ServerSendReply (clifd, &ret_value, sizeof (int));
}
#endif
#endif /* IS_COMPOSITING_SCHEMA */
static int move_to_layer (int cli, int clifd, void* buff, size_t len)
{
MOVETOLAYERINFO* info = (MOVETOLAYERINFO*)buff;
MOVEDCLIENTINFO moved_info = { INV_LAYER_HANDLE };
MG_Layer* dst_layer;
if (!info->handle_name) {
if (info->layer.name[0] == '0円')
dst_layer = mgClients [cli].layer;
else
dst_layer = __mg_find_layer_by_name (info->layer.name);
}
else
dst_layer = (MG_Layer*)info->layer.handle;
if (dst_layer == NULL)
goto ret;
if (!__mg_is_valid_layer (dst_layer))
goto ret;
if (__mg_move_client_to_layer (mgClients + cli, dst_layer)) {
moved_info.layer = dst_layer;
moved_info.zo_shmid = dst_layer->zorder_shmid;
}
else {
moved_info.layer = INV_LAYER_HANDLE;
moved_info.zo_shmid = 0;
}
ret:
return ServerSendReply (clifd, &moved_info, sizeof (MOVEDCLIENTINFO));
}
static int calc_position (int cli, int clifd, void* buff, size_t len)
{
CALCPOSINFO* info = (CALCPOSINFO*)buff;
SendMessage (HWND_DESKTOP, MSG_CALC_POSITION, (WPARAM)cli, (LPARAM)info);
return ServerSendReply (clifd, &info->rc, sizeof (RECT));
}
static int create_cursor (int cli, int clifd, void* buff, size_t len)
{
HCURSOR hcsr;
int* tmp;
BYTE* and_bits, *xor_bits;
tmp = (int*)buff;
and_bits = (BYTE*)(tmp + 6);
xor_bits = and_bits + tmp [5];
hcsr = CreateCursor (tmp [0], tmp [1], tmp [2], tmp [3],
and_bits, xor_bits, tmp [4]);
#ifdef _MGHAVE_CURSOR
if (hcsr) {
add_global_res (cli, hcsr, hcsr, NULL);
}
#endif
return ServerSendReply (clifd, &hcsr, sizeof (HCURSOR));
}
static int copy_cursor (int cli, int clifd, void* buff, size_t len)
{
HCURSOR hcsr = CopyCursor ((HCURSOR)*(intptr_t*)buff);
#ifdef _MGHAVE_CURSOR
if (hcsr) {
add_global_res (cli, hcsr, hcsr, NULL);
}
#endif
return ServerSendReply (clifd, &hcsr, sizeof (HCURSOR));
}
static int destroy_cursor (int cli, int clifd, void* buff, size_t len)
{
BOOL ret_value;
HCURSOR hcsr;
hcsr = *((HCURSOR*)buff);
ret_value = DestroyCursor(hcsr);
del_global_res (cli, hcsr, hcsr);
return ServerSendReply (clifd, &ret_value, sizeof (BOOL));
}
static int clip_cursor (int cli, int clifd, void* buff, size_t len)
{
RECT cliprc;
memcpy (&cliprc, buff, sizeof (RECT));
ClipCursor (&cliprc);
return SOCKERR_OK;
}
static int get_clip_cursor (int cli, int clifd, void* buff, size_t len)
{
RECT cliprc;
GetClipCursor (&cliprc);
return ServerSendReply (clifd, &cliprc, sizeof (RECT));
}
static int set_cursor (int cli, int clifd, void* buff, size_t len)
{
HCURSOR hcsr;
HCURSOR old;
memcpy (&hcsr, buff, sizeof (HCURSOR));
old = SetCursorEx (hcsr, FALSE);
return ServerSendReply (clifd, &old, sizeof (HCURSOR));
}
static int get_current_cursor (int cli, int clifd, void* buff, size_t len)
{
HCURSOR hcsr;
hcsr = GetCurrentCursor ();
return ServerSendReply (clifd, &hcsr, sizeof (HCURSOR));
}
#if 0
static int show_cursor_for_gdi (int cli, int clifd, void* buff, size_t len)
{
RECT rc;
BOOL show_hide;
BOOL ret_value = TRUE;
memcpy (&show_hide, buff, sizeof (BOOL));
memcpy (&rc, buff + sizeof (BOOL), sizeof (RECT));
ShowCursorForClientGDI (show_hide, &rc);
return ServerSendReply (clifd, &ret_value, sizeof (BOOL));
}
#endif
static int show_cursor (int cli, int clifd, void* buff, size_t len)
{
BOOL show_hide;
int ret_value;
memcpy (&show_hide, buff, sizeof (BOOL));
ret_value = ShowCursor (show_hide);
return ServerSendReply (clifd, &ret_value, sizeof (BOOL));
}
static int set_cursor_pos (int cli, int clifd, void* buff, size_t len)
{
POINT pt;
memcpy (&pt, buff, sizeof (POINT));
SetCursorPos (pt.x, pt.y);
return SOCKERR_OK;
}
static int layer_info (int cli, int clifd, void* buff, size_t len)
{
LAYERINFO info;
__mg_get_layer_info (cli, (const char*) buff, &info);
return ServerSendReply (clifd, &info, sizeof (LAYERINFO));
}
static int join_layer (int cli, int clifd, void* buff, size_t len)
{
static int nr_layers = 0, nr_clients = 0;
JOINLAYERINFO* info;
JOINEDCLIENTINFO joined_info = {INV_LAYER_HANDLE};
info = (JOINLAYERINFO*) buff;
if (info->layer_name [0] == '0円') {
strcpy (info->layer_name, mgTopmostLayer->name);
nr_layers ++;
}
if (info->client_name [0] == '0円') {
sprintf (info->client_name, "Client-%d", nr_clients);
nr_clients ++;
}
__mg_client_join_layer (cli, info, &joined_info);
return ServerSendReply (clifd, &joined_info, sizeof (JOINEDCLIENTINFO));
}
static int layer_op (int cli, int clifd, void* buff, size_t len)
{
BOOL ret_value = FALSE;
LAYEROPINFO* info = (LAYEROPINFO*)buff;
MG_Layer* layer;
if (!info->handle_name) {
if (info->layer.name[0] == '0円')
layer = mgClients [cli].layer;
else
layer = __mg_find_layer_by_name (info->layer.name);
}
else
layer = (MG_Layer*)info->layer.handle;
if (layer == NULL)
goto ret;
if (!__mg_is_valid_layer (layer))
goto ret;
switch (info->id_op) {
case ID_LAYEROP_DELETE:
ret_value = ServerDeleteLayer (layer);
break;
case ID_LAYEROP_SETTOP:
ret_value = ServerSetTopmostLayer (layer);
break;
}
ret:
return ServerSendReply (clifd, &ret_value, sizeof (BOOL));
}
/* Since 5.0.0: handle fd received for shared surface */
static int zorder_op (int cli, int clifd, void* buff, size_t len, int fd)
{
intptr_t ret_value;
ZORDEROPINFO* info = (ZORDEROPINFO*)buff;
ret_value = __mg_do_zorder_operation (cli, info,
buff + sizeof (ZORDEROPINFO), fd);
return ServerSendReply (clifd, &ret_value, sizeof (intptr_t));
}
static int change_zorder_maskrect (int cli, int clifd, void* buff, size_t len)
{
intptr_t ret_value;
ZORDERMASKRECTOPINFO* info = (ZORDERMASKRECTOPINFO *)buff;
info->rc = (RECT4MASK*)(buff + sizeof (ZORDERMASKRECTOPINFO));
ret_value = __mg_do_zorder_maskrect_operation (cli, info);
return ServerSendReply (clifd, &ret_value, sizeof (intptr_t));
}
#ifdef _MGGAL_SIGMA8654
extern int Sigma8654_ServerOnGetSurface(REQ_SIGMA8654_GETSURFACE *request,
REP_SIGMA8654_GETSURFACE *reply);
static int sigma8654_client_get_surface(int cli, int clifd, void* buff, size_t len)
{
REQ_SIGMA8654_GETSURFACE *request;
REP_SIGMA8654_GETSURFACE reply;
if (Sigma8654_ServerOnGetSurface(request, &reply) < 0) {
_ERR_PRINTF ("Nexus_ServerOnGetSurface() failed\n");
return -1;
}
return ServerSendReply (clifd, &reply, sizeof (reply));
}
#endif
#ifdef _MGGAL_NEXUS
extern int Nexus_ServerOnGetSurface(REQ_NEXUS_GETSURFACE *request,
REP_NEXUS_GETSURFACE *reply);
static int nexus_client_get_surface(int cli, int clifd, void* buff, size_t len)
{
REQ_NEXUS_GETSURFACE *request;
REP_NEXUS_GETSURFACE reply;
if (Nexus_ServerOnGetSurface(request, &reply) < 0)
{
_ERR_PRINTF ("Nexus_ServerOnGetSurface() failed\n");
return -1;
}
return ServerSendReply (clifd, &reply, sizeof (reply));
}
#endif
static int im_live (int cli, int clifd, void* buff, size_t len)
{
unsigned int time;
memcpy (&time, buff, sizeof (unsigned int));
mgClients [cli].last_live_time = time;
return SOCKERR_OK;
}
extern HWND __mg_ime_wnd;
static int open_ime_wnd (int cli, int clifd, void* buff, size_t len)
{
BOOL open;
memcpy (&open, buff, sizeof (BOOL));
if (__mg_ime_wnd) {
if (open)
SendNotifyMessage (__mg_ime_wnd, MSG_IME_OPEN, 0, 0);
else
SendNotifyMessage (__mg_ime_wnd, MSG_IME_CLOSE, 0, 0);
}
return SOCKERR_OK;
}
static int register_hook (int cli, int clifd, void* buff, size_t len)
{
REGHOOKINFO* info;
int ret_value;
info = (REGHOOKINFO*)buff;
ret_value = __mg_do_reghook_operation (cli, info);
return ServerSendReply (clifd, &ret_value, sizeof (int));
}
static int set_ime_stat (int cli, int clifd, void* buff, size_t len)
{
int ret, data;
memcpy(&data, buff, sizeof(int));
ret = SendMessage (HWND_DESKTOP, MSG_IME_SETSTATUS,
HISWORD(data), LOSWORD(data));
return ServerSendReply (clifd, &ret, sizeof (int));
}
static int get_ime_stat (int cli, int clifd, void* buff, size_t len)
{
int ret, data;
memcpy(&data, buff, sizeof(int));
ret = SendMessage (HWND_DESKTOP, MSG_IME_GETSTATUS, (WPARAM)data, 0);
return ServerSendReply (clifd, &ret , sizeof (int));
}
static int set_ime_targetinfo (int cli, int clifd, void* buff, size_t len)
{
int ret;
IME_TARGET_INFO data;
memcpy (&data, buff, sizeof (IME_TARGET_INFO));
ret = SendMessage (HWND_DESKTOP, MSG_IME_SET_TARGET_INFO,
0, (LPARAM)&data);
return ServerSendReply (clifd, &ret, sizeof (int));
}
static int get_ime_targetinfo (int cli, int clifd, void* buff, size_t len)
{
IME_TARGET_INFO data;
SendMessage (HWND_DESKTOP, MSG_IME_GET_TARGET_INFO, 0, (LPARAM)&data);
return ServerSendReply (clifd, &data, sizeof (IME_TARGET_INFO));
}
#ifdef _MGGAL_MLSHADOW
static int handle_mlshadow_req (int cli, int clifd, void* buff, size_t len)
{
int *op_id;
op_id = buff;
switch(*op_id) {
case MLSOP_ID_GET_MASTERINFO:
{
MLSHADOW_REPLY_MASTER_INFO reply;
MLSHADOW_Server(buff, &reply);
ServerSendReply (clifd, &reply, sizeof(reply));
break;
}
case MLSOP_ID_CREATE_SURFACE:
{
MLSHADOW_REPLY_SURFACE_CREATE reply;
MLSHADOW_Server(buff, &reply);
add_global_res (cli, (void*)reply.surface_key,
(void*)reply.surface_key, (ReleaseProc)srvMLSHADOW_DelSurface);
ServerSendReply (clifd, &reply, sizeof(reply));
break;
}
case MLSOP_ID_GET_SLAVEINFO:
{
MLSHADOW_REPLY_SLAVE_GETINFO reply;
MLSHADOW_Server(buff, &reply);
ServerSendReply (clifd, &reply, sizeof(reply));
break;
}
case MLSOP_ID_SET_SLAVEINFO:
{
BOOL reply;
MLSHADOW_Server(buff, &reply);
ServerSendReply (clifd, &reply, sizeof(reply));
break;
}
case MLSOP_ID_DESTROY_SLAVE:
{
BOOL reply;
MLSHADOW_Server(buff, &reply);
ServerSendReply (clifd, &reply, sizeof(reply));
break;
}
}
return 0;
}
#endif
#if IS_SHAREDFB_SCHEMA_PROCS
void release_hw_surface (REQ_HWSURFACE* allocated)
{
/*[humingming./2010/11/24]: don't call GAL_RequestHWSurface,
* this will casue double free or same other problem */
#if 0
REP_HWSURFACE reply;
GAL_RequestHWSurface (allocated, &reply);
#endif
free (allocated);
}
static int req_hw_surface (int cli, int clifd, void* buff, size_t len)
{
REQ_HWSURFACE* request = (REQ_HWSURFACE*) buff;
REP_HWSURFACE reply;
GAL_RequestHWSurface (request, &reply);
if (request->bucket == NULL) {
REQ_HWSURFACE* allocated;
allocated = malloc (sizeof (REQ_HWSURFACE));
if (allocated) {
allocated->w = request->w;
allocated->h = request->h;
allocated->pitch = reply.pitch;
allocated->offset = reply.offset;
allocated->bucket = reply.bucket;
add_global_res (cli, (void*)req_hw_surface,
allocated, (ReleaseProc)release_hw_surface);
}
}
else {
del_global_res (cli, (void*)req_hw_surface, request->bucket);
}
return ServerSendReply (clifd, &reply, sizeof (REP_HWSURFACE));
}
#endif /* IS_SHAREDFB_SCHEMA_PROCS */
#ifdef _MGHAVE_CLIPBOARD
extern int __mg_clipboard_op (int cli, int clifd, void* buff, size_t len);
#endif
#if IS_COMPOSITING_SCHEMA
static map_t *__nssurf_map;
struct nssurf_info {
int creator;
int fd;
size_t map_size;
};
int __mg_nssurf_map_new(void)
{
__nssurf_map = __mg_map_create(copy_key_string,
free_key_string, NULL, NULL, comp_key_string);
if (__nssurf_map == NULL)
return -1;
return 0;
}
void __mg_nssurf_map_delete(void)
{
assert(__nssurf_map);
int sz = __mg_map_get_size(__nssurf_map);
if (sz > 0) {
_WRN_PRINTF("There are still not freed named shared surface(s): %d\n", sz);
}
__mg_map_destroy(__nssurf_map);
}
static void release_nssurf_info(void *res)
{
map_entry_t *entry;
entry = __mg_map_find(__nssurf_map, res);
if (entry) {
struct nssurf_info *nssurf_info = entry->val;
if (nssurf_info->fd >= 0)
close(nssurf_info->fd);
free(nssurf_info);
__mg_map_erase(__nssurf_map, res);
}
}
int __mg_nssurf_map_operate_srv(const OPERATENSSURFINFO* req_info,
int cli, int fd)
{
int result = -1;
map_entry_t *entry;
struct nssurf_info *nssurf_info;
switch (req_info->id_op) {
case ID_NAMEDSSURFOP_REGISTER:
_DBG_PRINTF("Registering name: %s from client: %d\n", req_info->name, cli);
entry = __mg_map_find(__nssurf_map, req_info->name);
if (entry)
goto done;
nssurf_info = malloc(sizeof(*nssurf_info));
if (nssurf_info == NULL)
goto done;
nssurf_info->creator = cli;
nssurf_info->fd = -1;
nssurf_info->map_size = 0;
entry = __mg_map_insert_ex2(__nssurf_map, req_info->name,
nssurf_info, NULL);
if (entry == NULL) {
free(nssurf_info);
goto done;
}
add_global_res(cli, __nssurf_map, entry->key, release_nssurf_info);
result = 0;
break;
case ID_NAMEDSSURFOP_SET:
if (fd == -1) {
goto done;
}
entry = __mg_map_find(__nssurf_map, req_info->name);
if (entry == NULL)
goto done;
assert(entry->val);
nssurf_info = entry->val;
if (nssurf_info->creator != cli)
goto done;
nssurf_info->fd = fd;
nssurf_info->map_size = req_info->map_size;
_DBG_PRINTF("fd set for named ssurf %s: %d\n", req_info->name, fd);
result = 0;
break;
case ID_NAMEDSSURFOP_REVOKE:
entry = __mg_map_find(__nssurf_map, req_info->name);
if (entry == NULL)
goto done;
assert(entry->val);
nssurf_info = entry->val;
if (nssurf_info->creator != cli)
goto done;
del_global_res(cli, __nssurf_map, entry->key);
result = 0;
break;
default:
break;
}
done:
return result;
}
int __mg_get_shared_surface_srv(const char *itn_name, SHAREDSURFINFO *info)
{
int fd = -1;
assert (__gal_fake_screen);
if (strcmp(itn_name, SYSSF_WALLPAPER_PATTER) == 0 &&
__gal_fake_screen->shared_header) {
info->flags = __gal_fake_screen->flags;
info->size = __gal_fake_screen->shared_header->map_size;
fd = __gal_fake_screen->fd;
}
else if (strncmp(itn_name, APPSF_NAME_PREFIX,
sizeof(APPSF_NAME_PREFIX) - 1) == 0) {
const char *name = itn_name + sizeof(APPSF_NAME_PREFIX) - 1;
map_entry_t *entry = __mg_map_find(__nssurf_map, name);
if (entry == NULL) {
_DBG_PRINTF("Not found named ssurf: %s\n", name);
goto done;
}
struct nssurf_info *nssurf_info = entry->val;
assert(nssurf_info);
info->size = nssurf_info->map_size;
fd = nssurf_info->fd;
}
else if (strncmp(itn_name, APPSF_HWND_PREFIX,
sizeof(APPSF_HWND_PREFIX) - 1) == 0) {
int client;
HWND hwnd;
int ret = sscanf(itn_name, APPSF_HWND_PATTER, &client, &hwnd);
if (ret != 2) {
_WRN_PRINTF("Failed sscanf: %s\n", itn_name);
goto done;
}
ZORDERNODE *znode = __mg_find_znode_by_client_hwnd(client, hwnd);
if (znode == NULL)
goto done;
PDC pdc = dc_HDC2PDC(znode->mem_dc);
assert(pdc->surface->shared_header);
info->size = pdc->surface->shared_header->map_size;
info->width = pdc->surface->shared_header->width;
info->height = pdc->surface->shared_header->height;
info->pitch = pdc->surface->shared_header->pitch;
info->offset = pdc->surface->shared_header->pixels_off;
fd = pdc->surface->fd;
}
done:
return fd;
}
/* get the fake screen surface (wallpaper pattern surface) */
static int get_shared_surface (int cli, int clifd, void* buff, size_t len)
{
SHAREDSURFINFO info = {};
int fd = __mg_get_shared_surface_srv(buff, &info);
return ServerSendReplyEx (clifd, &info, sizeof (SHAREDSURFINFO), fd);
}
static int
operate_nssurface(int cli, int clifd, void* buff, size_t len, int fd)
{
int result = -1;
assert(len >= sizeof(OPERATENSSURFINFO));
OPERATENSSURFINFO* req_info = (OPERATENSSURFINFO*)buff;
result = __mg_nssurf_map_operate_srv(req_info, cli, fd);
return ServerSendReply(clifd, &result, sizeof(int));
}
#else /* IS_COMPOSITING_SCHEMA */
/* get the rendering surface */
static int get_shared_surface (int cli, int clifd, void* buff, size_t len)
{
const char* name = buff;
SHAREDSURFINFO info = { 0, 0 };
#ifdef _MGGAL_DRM
extern int __drm_get_shared_screen_surface (const char*, SHAREDSURFINFO*);
__drm_get_shared_screen_surface (name, &info);
#endif
return ServerSendReply (clifd, &info, sizeof (SHAREDSURFINFO));
}
#endif /* not IS_COMPOSITING_SCHEMA */
static int authenticate_client (int cli, int clifd, void* buff, size_t len)
{
int auth_result = 1;
#ifdef _MGGAL_DRM
uint32_t magic;
extern int __drm_auth_client(int, uint32_t);
magic = *(uint32_t*)buff;
auth_result = __drm_auth_client (cli, magic);
#endif
return ServerSendReply (clifd, &auth_result, sizeof (int));
}
static struct req_request {
void* handler;
int version;
} handlers [MAX_REQID] =
{
{ load_cursor, 0 },
{ create_cursor, 0 },
{ destroy_cursor, 0 },
{ clip_cursor, 0 },
{ get_clip_cursor, 0 },
{ set_cursor, 0 },
{ get_current_cursor, 0 },
{ show_cursor, 0 },
{ set_cursor_pos, 0 },
{ layer_info, 0 },
{ join_layer, 0 },
{ layer_op, 0 },
{ zorder_op, 1 },
{ im_live, 0 },
{ open_ime_wnd, 0 },
{ set_ime_stat, 0 },
{ get_ime_stat, 0 },
{ register_hook, 0 },
#if IS_SHAREDFB_SCHEMA_PROCS
{ req_hw_surface, 0 },
#else
{ NULL, 0 },
#endif
#ifdef _MGHAVE_CLIPBOARD
{ __mg_clipboard_op, 0 },
#else
{ NULL, 0 },
#endif
#ifdef _MGGAL_MLSHADOW
{ handle_mlshadow_req, 0 },
#else
{ NULL, 0 },
#endif
{ change_zorder_maskrect, 0 },
#ifdef _MGGAL_NEXUS
{ nexus_client_get_surface, 0 },
#else
{ NULL, 0 },
#endif
#ifdef _MGGAL_SIGMA8654
{ sigma8654_client_get_surface, 0 },
#else
{ NULL, 0 },
#endif
{ get_ime_targetinfo, 0 },
{ set_ime_targetinfo, 0 },
{ copy_cursor, 0 },
{ get_shared_surface, 0 }, // REQID_GETSHAREDSURFACE
#if IS_COMPOSITING_SCHEMA
{ load_cursor_png_file, 0 }, // REQID_LOADCURSOR_PNG
{ load_cursor_png_mem, 0 }, // REQID_LOADCURSOR_PNG_MEM
{ operate_nssurface, 1 }, // REQID_OPERATENSSURF
{ NULL, 0 },
#if 0 // Deprecated since 5.2.0
{ alloc_sem_for_shared_surf, 0 }, // REQID_ALLOC_SURF_SEM
{ free_sem_for_shared_surf, 0 }, // REQID_FREE_SURF_SEM
#endif
#else
{ NULL, 0 },
{ NULL, 0 },
{ NULL, 0 },
{ NULL, 0 },
#endif
{ move_to_layer, 0 }, // REQID_MOVETOLAYER
{ calc_position, 0 }, // REQID_CALCPOSITION
{ authenticate_client, 0 }, // REQID_AUTHCLIENT
};
BOOL GUIAPI RegisterRequestHandler (int req_id, REQ_HANDLER your_handler)
{
if (req_id <= MAX_SYS_REQID || req_id > MAX_REQID)
return FALSE;
handlers[req_id - 1].handler = your_handler;
handlers[req_id - 1].version = 0;
return TRUE;
}
BOOL GUIAPI RegisterRequestHandlerV1 (int req_id, REQ_HANDLER_V1 your_handler)
{
if (req_id <= MAX_SYS_REQID || req_id > MAX_REQID)
return FALSE;
handlers[req_id - 1].handler = your_handler;
handlers[req_id - 1].version = 1;
return TRUE;
}
REQ_HANDLER GUIAPI GetRequestHandler (int req_id)
{
if (req_id <= 0 || req_id > MAX_REQID)
return NULL;
if (handlers[req_id - 1].version == 0)
return handlers [req_id - 1].handler;
return NULL;
}
REQ_HANDLER_V1 GUIAPI GetRequestHandlerV1 (int req_id)
{
if (req_id <= 0 || req_id > MAX_REQID)
return NULL;
if (handlers[req_id - 1].version == 1)
return handlers [req_id - 1].handler;
return NULL;
}
void* GUIAPI GetRequestHandlerEx (int req_id, int* version)
{
if (req_id <= 0 || req_id > MAX_REQID)
return NULL;
if (version) {
*version = handlers [req_id - 1].version;
}
return handlers [req_id - 1].handler;
}
static char _request_data_buff [1024];
int __mg_handle_request (int clifd, int req_id, int cli)
{
int n;
char* buff;
size_t req_data_len, ex_data_len;
size_t len_data;
int fd_received = -1;
if ((n = sock_read (clifd, &req_data_len, sizeof (size_t))) == SOCKERR_IO)
return SOCKERR_IO;
else if (n == SOCKERR_CLOSED) {
goto error;
}
if ((n = sock_read (clifd, &ex_data_len, sizeof (size_t))) == SOCKERR_IO)
return SOCKERR_IO;
else if (n == SOCKERR_CLOSED) {
goto error;
}
len_data = req_data_len + ex_data_len;
if (len_data <= sizeof (_request_data_buff)) {
buff = _request_data_buff;
}
else {
buff = malloc (len_data);
if (buff == NULL)
return SOCKERR_INVARG;
}
#if 0
if ((n = sock_read (clifd, buff, len_data)) == SOCKERR_IO)
return SOCKERR_IO;
else if (n == SOCKERR_CLOSED) {
goto error;
}
#else /* use recvmsg */
{
struct iovec iov[2];
struct msghdr msg;
struct cmsghdr *cmsg = NULL;
iov[0].iov_base = buff;
iov[0].iov_len = req_data_len;
iov[1].iov_base = buff + req_data_len;
iov[1].iov_len = ex_data_len;
msg.msg_iov = iov;
msg.msg_iovlen = 2;
msg.msg_name = NULL;
msg.msg_namelen = 0;
cmsg = alloca (CMSG_LEN (sizeof (int)));
msg.msg_control = cmsg;
msg.msg_controllen = CMSG_LEN (sizeof (int));
if ((n = sock_recvmsg (clifd, &msg, 0)) == SOCKERR_IO) {
return SOCKERR_IO;
}
else if (n == SOCKERR_CLOSED) {
goto error;
}
if (msg.msg_controllen == CMSG_LEN (sizeof (int))) {
memcpy (&fd_received, CMSG_DATA(cmsg), sizeof (int));
}
}
#endif
req_id &= ~REQMASK_FLAGS;
if (req_id > MAX_REQID || req_id <= 0 ||
handlers [req_id - 1].handler == NULL)
return SOCKERR_INVARG;
if (handlers [req_id - 1].version == 1) {
REQ_HANDLER_V1 handler = handlers [req_id - 1].handler;
n = handler (cli, clifd, buff, len_data, fd_received);
}
else {
REQ_HANDLER handler = handlers [req_id - 1].handler;
if (fd_received >= 0) {
close (fd_received);
_WRN_PRINTF ("A file descriptor received, but the request handler is version 0.\n");
}
n = handler (cli, clifd, buff, len_data);
}
if (len_data > sizeof (_request_data_buff))
free (buff);
if (n == SOCKERR_IO)
goto error;
if (req_id == REQID_IAMLIVE && mgClients [cli].has_dirty)
__mg_check_dirty_znode (cli);
return n;
error:
__mg_remove_client (cli, clifd);
return SOCKERR_CLOSED;
}
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/uesoft/MiniGUI.git
git@gitee.com:uesoft/MiniGUI.git
uesoft
MiniGUI
MiniGUI
master
点此查找更多帮助

搜索帮助

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

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