This commit is contained in:
Vincent Wei
2020-01-06 15:24:19 +08:00
parent c088a580ca
commit e9d0b3fab8
5 changed files with 137 additions and 108 deletions

View File

@@ -467,7 +467,7 @@ BOOL client_IdleHandler4Client (PMSGQUEUE msg_que)
(!OnTrylockClientReq || !OnUnlockClientReq
|| (OnTrylockClientReq && OnUnlockClientReq && !OnTrylockClientReq()))) {
#if 0
#if 1
if ( (nread = sock_read (conn_fd, &Msg, sizeof (MSG))) < 0) {
if (OnTrylockClientReq && OnUnlockClientReq)
OnUnlockClientReq();

View File

@@ -11,39 +11,39 @@
//
//////////////////////////////////////////////////////////////////////////////
/*
* This file is part of MiniGUI, a mature cross-platform windowing
* 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/blog/minigui-licensing-policy/>.
*/
/*
/*
** error.c: error handling functions
**
** Some code come from APUE by Richard Stevens.
@@ -53,16 +53,16 @@
** Create date: 2000/12/31
*/
#include <errno.h> /* for definition of errno */
#include <stdarg.h> /* ANSI C header file */
#include <errno.h> /* for definition of errno */
#include <stdarg.h> /* ANSI C header file */
#include "common.h"
#ifdef _MGRM_PROCESSES
#include "ourhdr.h"
#include "ourhdr.h"
static void err_doit(int, const char *, va_list);
static void err_doit(int, const char *, va_list);
/* Nonfatal error related to a system call.
* Print a message and return. */
@@ -70,12 +70,12 @@ static void err_doit(int, const char *, va_list);
void
err_ret(const char *fmt, ...)
{
va_list ap;
va_list ap;
va_start(ap, fmt);
err_doit(1, fmt, ap);
va_end(ap);
return;
va_start(ap, fmt);
err_doit(1, fmt, ap);
va_end(ap);
return;
}
/* Fatal error related to a system call.
@@ -84,12 +84,12 @@ err_ret(const char *fmt, ...)
void
err_sys(const char *fmt, ...)
{
va_list ap;
va_list ap;
va_start(ap, fmt);
err_doit(1, fmt, ap);
va_end(ap);
exit(1);
va_start(ap, fmt);
err_doit(1, fmt, ap);
va_end(ap);
exit(1);
}
/* Fatal error related to a system call.
@@ -98,13 +98,13 @@ err_sys(const char *fmt, ...)
void
err_dump(const char *fmt, ...)
{
va_list ap;
va_list ap;
va_start(ap, fmt);
err_doit(1, fmt, ap);
va_end(ap);
abort(); /* dump core and terminate */
exit(1); /* shouldn't get here */
va_start(ap, fmt);
err_doit(1, fmt, ap);
va_end(ap);
abort(); /* dump core and terminate */
exit(1); /* shouldn't get here */
}
/* Nonfatal error unrelated to a system call.
@@ -113,12 +113,12 @@ err_dump(const char *fmt, ...)
void
err_msg(const char *fmt, ...)
{
va_list ap;
va_list ap;
va_start(ap, fmt);
err_doit(0, fmt, ap);
va_end(ap);
return;
va_start(ap, fmt);
err_doit(0, fmt, ap);
va_end(ap);
return;
}
/* Fatal error unrelated to a system call.
@@ -127,12 +127,12 @@ err_msg(const char *fmt, ...)
void
err_quit(const char *fmt, ...)
{
va_list ap;
va_list ap;
va_start(ap, fmt);
err_doit(0, fmt, ap);
va_end(ap);
exit(1);
va_start(ap, fmt);
err_doit(0, fmt, ap);
va_end(ap);
exit(1);
}
/* Print a message and return to caller.
@@ -141,19 +141,30 @@ err_quit(const char *fmt, ...)
static void
err_doit(int errnoflag, const char *fmt, va_list ap)
{
int errno_save;
char buf[MAXLINE];
int errno_save;
char buf[MAXLINE];
errno_save = errno; /* value caller might want printed */
vsprintf(buf, fmt, ap);
if (errnoflag)
sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
strcat(buf, "\n");
fflush(stdout); /* in case stdout and stderr are the same */
fputs(buf, stderr);
fflush(NULL); /* flushes all stdio output streams */
return;
errno_save = errno; /* value caller might want printed */
vsnprintf(buf, MAXLINE, fmt, ap);
#if 0
if (errnoflag)
sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
strcat(buf, "\n");
fflush(stdout); /* in case stdout and stderr are the same */
fputs(buf, stderr);
fflush(NULL); /* flushes all stdio output streams */
#else
fflush(stdout); /* in case stdout and stderr are the same */
if (errnoflag)
_ERR_PRINTF("%s: %s\n", buf, strerror(errno_save));
else
_ERR_PRINTF("%s\n", buf);
fflush(stdout); /* in case stdout and stderr are the same */
#endif
return;
}
#endif
#endif

View File

@@ -11,35 +11,35 @@
//
//////////////////////////////////////////////////////////////////////////////
/*
* This file is part of MiniGUI, a mature cross-platform windowing
* 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/blog/minigui-licensing-policy/>.
*/
@@ -80,8 +80,8 @@ int mgClientSize = 0;
#define off_pointer(p,off) \
do { \
if (p) { \
intptr_t tmp; \
tmp = (intptr_t)p; \
intptr_t tmp; \
tmp = (intptr_t)p; \
tmp += off; \
p = (void*)tmp; \
} \
@@ -117,11 +117,11 @@ static BOOL client_alloc (void)
if (mgClients == NULL)
mgClients = malloc (NALLOC * sizeof(MG_Client));
else {
char* new_head = realloc (mgClients,
char* new_head = realloc (mgClients,
(mgClientSize + NALLOC) * sizeof(MG_Client));
if (new_head) {
offset_pointers ((MG_Client*) new_head, mgClientSize,
offset_pointers ((MG_Client*) new_head, mgClientSize,
new_head - (char*)mgClients);
}
@@ -141,9 +141,9 @@ static BOOL client_alloc (void)
return TRUE;
}
/*
* Called by IdleHandler4Server() when connection request
* from a new client arrives
/*
* Called by IdleHandler4Server() when connection request
* from a new client arrives
*/
int __mg_client_add (int fd, pid_t pid, uid_t uid)
{
@@ -178,7 +178,7 @@ void __mg_client_del (int cli)
MG_Client* deleting = mgClients + cli;
MG_Layer* layer = deleting->layer;
_WRN_PRINTF ("SERVER: Remove a client: %s\n", deleting->name);
_DBG_PRINTF ("SERVER: Remove a client: %s\n", deleting->name);
if (layer == NULL)
goto ret;
@@ -189,7 +189,7 @@ void __mg_client_del (int cli)
if (deleting->next)
deleting->next->prev = deleting->prev;
if (deleting->prev)
if (deleting->prev)
deleting->prev->next = deleting->next;
if (deleting == layer->cli_head) {
@@ -228,12 +228,29 @@ void __mg_remove_client (int cli, int clifd)
close (clifd);
}
int __mg_send2client (const MSG* msg, MG_Client* client)
int __mg_send2client (const MSG* Msg, MG_Client* client)
{
int ret;
if (__mg_timer_counter < (client->last_live_time + THRES_LIVE)) {
ret = sock_write_t (client->fd, msg, sizeof (MSG), TO_SOCKIO);
#if 1
ret = sock_write_t (client->fd, Msg, sizeof (MSG), TO_SOCKIO);
#else /* use sendmsg */
struct iovec iov[1];
struct msghdr msg;
iov[0].iov_base = &Msg;
iov[0].iov_len = sizeof (MSG);
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = iov;
msg.msg_iovlen = 1;
msg.msg_control = NULL;
msg.msg_controllen = 0;
ret = sock_sendmsg_t (client->fd, &msg, 0, TO_SOCKIO);
#endif
switch (ret) {
case SOCKERR_TIMEOUT:
@@ -283,7 +300,7 @@ void __mg_set_active_client (MG_Client* client)
/* send message to client(s) */
int GUIAPI Send2Client (const MSG* msg, int cli)
{
int i, n;
MG_Client* client;
@@ -347,7 +364,7 @@ BOOL GUIAPI Send2TopMostClients (UINT nMsg, WPARAM wParam, LPARAM lParam)
return TRUE;
}
BOOL GUIAPI Send2ActiveWindow (const MG_Layer* layer,
BOOL GUIAPI Send2ActiveWindow (const MG_Layer* layer,
UINT nMsg, WPARAM wParam, LPARAM lParam)
{
int active_win;
@@ -359,7 +376,7 @@ BOOL GUIAPI Send2ActiveWindow (const MG_Layer* layer,
if (active_win <= 0)
return FALSE;
if (__mg_post_msg_by_znode (layer->zorder_info,
if (__mg_post_msg_by_znode (layer->zorder_info,
active_win, nMsg, wParam, lParam) > 0)
return TRUE;
@@ -373,7 +390,7 @@ BOOL GUIAPI SetTopmostClient (int cli)
if (cli < 0 || cli >= mgClientSize || mgClients [cli].fd == -1)
return FALSE;
return ServerSetTopmostLayer (mgClients [cli].layer);
}

View File

@@ -11,41 +11,41 @@
//
//////////////////////////////////////////////////////////////////////////////
/*
* This file is part of MiniGUI, a mature cross-platform windowing
* 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/blog/minigui-licensing-policy/>.
*/
/*
** layer.c: maintain the layers in server.
**
**
** Current maintainer: Wei Yongming.
**
** Create date: 2005/08/14
@@ -83,7 +83,7 @@ ON_CHANGE_LAYER OnChangeLayer = NULL;
static int sg_nr_layers = 0;
static unsigned char sem_usage [(MAX_NR_LAYERS + 7)/8];
static BOOL do_alloc_layer (MG_Layer* layer, const char* name,
static BOOL do_alloc_layer (MG_Layer* layer, const char* name,
int nr_topmosts, int nr_normals)
{
ZORDERINFO* zi;
@@ -97,10 +97,10 @@ static BOOL do_alloc_layer (MG_Layer* layer, const char* name,
/* Attach to the share memory. */
zi = shmat (layer->zorder_shmid, 0, 0);
if (zi == (void*)-1)
if (zi == (void*)-1)
return FALSE;
if (shmctl (layer->zorder_shmid, IPC_RMID, NULL) < 0)
if (shmctl (layer->zorder_shmid, IPC_RMID, NULL) < 0)
return FALSE;
strcpy (layer->name, name);
@@ -148,7 +148,7 @@ static BOOL do_alloc_layer (MG_Layer* layer, const char* name,
memset (maskrect_usage_bmp, 0xFF, zi->size_maskrect_usage_bmp);
/* init z-order node for desktop */
znodes = (ZORDERNODE*) ((char*)(zi + 1) + zi->size_usage_bmp +
znodes = (ZORDERNODE*) ((char*)(zi + 1) + zi->size_usage_bmp +
sizeof (ZORDERNODE) * DEF_NR_POPUPMENUS);
znodes [0].flags = ZOF_TYPE_DESKTOP | ZOF_VISIBLE;
@@ -272,7 +272,7 @@ int __mg_init_layers ()
return -1;
}
semid = semget (sem_key, MAX_NR_LAYERS, SEM_PARAM | IPC_CREAT | IPC_EXCL);
semid = semget (sem_key, MAX_NR_LAYERS, SEM_PARAM | IPC_CREAT | IPC_EXCL);
if (semid == -1)
return -1;
atexit (__mg_delete_zi_sem);
@@ -280,7 +280,7 @@ int __mg_init_layers ()
SHAREDRES_SEMID_LAYER = semid;
/* allocate the first layer for the default layer. */
if (!do_alloc_layer (mgLayers, NAME_DEF_LAYER,
if (!do_alloc_layer (mgLayers, NAME_DEF_LAYER,
SHAREDRES_DEF_NR_TOPMOSTS, SHAREDRES_DEF_NR_NORMALS)) {
free (mgLayers);
@@ -330,7 +330,7 @@ static MG_Layer* alloc_layer (const char* layer_name,
return NULL;
}
_WRN_PRINTF ("SERVER: Create a new layer: %s\n", layer_name);
_DBG_PRINTF ("SERVER: Create a new layer: %s\n", layer_name);
strcpy (new_layer->name, layer_name);
new_layer->cli_head = NULL;
@@ -349,18 +349,18 @@ static MG_Layer* alloc_layer (const char* layer_name,
mgTopmostLayer = new_layer;
_WRN_PRINTF ("SERVER: alloc_layer, mgTopmostLayer->zi = %p\n",
_DBG_PRINTF ("SERVER: alloc_layer, mgTopmostLayer->zi = %p\n",
mgTopmostLayer->zorder_info);
/* Topmost layer changed */
CHANGE_TOPMOST_LAYER(mgTopmostLayer);
__mg_do_change_topmost_layer ();
_WRN_PRINTF ("SERVER: alloc_layer, mgTopmostLayer->zi = %p\n",
_DBG_PRINTF ("SERVER: alloc_layer, mgTopmostLayer->zi = %p\n",
mgTopmostLayer->zorder_info);
/* Notify that a new topmost layer have been set. */
if (OnChangeLayer)
if (OnChangeLayer)
OnChangeLayer (LCO_TOPMOST_CHANGED, mgTopmostLayer, NULL);
PostMessage (HWND_DESKTOP, MSG_ERASEDESKTOP, 0, 0);
@@ -421,7 +421,7 @@ void __mg_get_layer_info (int cli, const char* layer_name, LAYERINFO* info)
}
}
static void do_client_join_layer (int cli,
static void do_client_join_layer (int cli,
const JOINLAYERINFO* info, JOINEDCLIENTINFO* joined_info)
{
MG_Layer* layer = (MG_Layer*)(joined_info->layer);
@@ -433,11 +433,11 @@ static void do_client_join_layer (int cli,
return;
}
_WRN_PRINTF ("SERVER: Join a client (%s) to layer %s\n",
_DBG_PRINTF ("SERVER: Join a client (%s) to layer %s\n",
info->client_name, layer->name);
strcpy (new_client->name, info->client_name);
new_client->layer = layer;
/* Notify that a new client joined to this layer. */
@@ -455,13 +455,13 @@ static void do_client_join_layer (int cli,
}
/* Join a client to a layer, the server side of JoinLayer */
void __mg_client_join_layer (int cli,
void __mg_client_join_layer (int cli,
const JOINLAYERINFO* info, JOINEDCLIENTINFO* joined_info)
{
MG_Layer* layer;
if ((layer = __mg_find_layer_by_name (info->layer_name)) == NULL) {
layer = alloc_layer (info->layer_name,
layer = alloc_layer (info->layer_name,
(info->max_nr_topmosts <= 0)?SHAREDRES_DEF_NR_TOPMOSTS:
info->max_nr_topmosts,
(info->max_nr_normals<= 0)?SHAREDRES_DEF_NR_NORMALS:
@@ -512,7 +512,7 @@ BOOL GUIAPI ServerSetTopmostLayer (MG_Layer* layer)
return TRUE;
}
MG_Layer* GUIAPI ServerCreateLayer (const char* layer_name,
MG_Layer* GUIAPI ServerCreateLayer (const char* layer_name,
int max_nr_topmosts, int max_nr_normals)
{
MG_Layer* new_layer;
@@ -604,7 +604,7 @@ int GUIAPI ServerGetNextZNode (MG_Layer* layer, int idx_znode, int* cli)
return -1;
zi = (ZORDERINFO*)layer->zorder_info;
if (idx_znode > zi->max_nr_globals
if (idx_znode > zi->max_nr_globals
+ zi->max_nr_topmosts + zi->max_nr_normals) {
return -1;
}
@@ -680,7 +680,7 @@ BOOL GUIAPI ServerGetZNodeInfo (MG_Layer* layer, int idx_znode,
return FALSE;
zi = (ZORDERINFO*)layer->zorder_info;
if (idx_znode > zi->max_nr_globals
if (idx_znode > zi->max_nr_globals
+ zi->max_nr_topmosts + zi->max_nr_normals) {
return FALSE;
}
@@ -713,7 +713,7 @@ BOOL GUIAPI ServerDoZNodeOperation (MG_Layer* layer,
return FALSE;
zi = (ZORDERINFO*)layer->zorder_info;
if (idx_znode > zi->max_nr_globals
if (idx_znode > zi->max_nr_globals
+ zi->max_nr_topmosts + zi->max_nr_normals) {
return FALSE;
}

View File

@@ -401,7 +401,7 @@ BOOL server_IdleHandler4Server (PMSGQUEUE msg_queue)
int req_id;
/* read request id from client */
if ( (nread = sock_read (clifd, &req_id, sizeof (int)))
if ((nread = sock_read (clifd, &req_id, sizeof (int)))
== SOCKERR_IO) {
#ifdef _DEBUG
err_msg ("server: read error on fd %d", clifd);
@@ -412,7 +412,8 @@ BOOL server_IdleHandler4Server (PMSGQUEUE msg_queue)
else if (nread == SOCKERR_CLOSED) {
if (OnNewDelClient) OnNewDelClient (LCO_DEL_CLIENT, i);
__mg_remove_client (i, clifd);
} else /* process client's rquest */
}
else /* process client's rquest */
__mg_handle_request (clifd, req_id, i);
}
}