clean up new code for supporting RTEMS

This commit is contained in:
Vincent Wei
2019-10-31 09:38:25 +08:00
parent 6b2039c151
commit 4ea6912024
15 changed files with 1142 additions and 1190 deletions
-6
View File
@@ -2728,12 +2728,6 @@ MG_EXPORT HCURSOR GUIAPI GetSystemCursor (int csrid);
MG_EXPORT HCURSOR GUIAPI GetCurrentCursor (void);
#else
// #define LoadCursorFromFile(filename) (do_nothing(), 0)
// #define CreateCursor(x, y, w, h, ANDbs, XORbs, cr) (do_nothing(), 0)
// #define DestroyCursor(hcsr) (do_nothing(), 0)
//// #define GetSystemCursor(csrid) (do_nothing(), 0)
// #define GetCurrentCursor() (do_nothing(), 0)
//static inline HCURSOR GetSystemCursor(int csrid) { return (HCURSOR) 0;}
static inline HCURSOR LoadCursorFromFile(const char* filename) {
return (HCURSOR)0;
+168 -170
View File
File diff suppressed because it is too large Load Diff
+217 -219
View File
File diff suppressed because it is too large Load Diff
+396 -396
View File
File diff suppressed because it is too large Load Diff
+6 -5
View File
@@ -35,22 +35,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <linux/input.h>
#include <unistd.h>
#include <fcntl.h>
#include "common.h"
#ifdef _MGIAL_NET
#include <linux/input.h>
#include <unistd.h>
#include <fcntl.h>
#include "minigui.h"
#include "netial.h"
#include <sys/ioctl.h>
//#include <sys/poll.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/stat.h>
//#include <linux/kd.h>
#include <linux/kd.h>
#include <sys/socket.h>
#include <netinet/in.h>
+22 -23
View File
@@ -1,33 +1,33 @@
/*
* 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/en/about/licensing-policy/>.
*/
@@ -37,7 +37,7 @@
** Current maintainer: Wei Yongming.
**
** Create date: 1999/04/21
*/
*/
#include <stdio.h>
#include <stdlib.h>
@@ -127,15 +127,14 @@ static OS_TIMER_ID __mg_os_timer = 0;
#else /* __AOS__ */
static void* TimerEntry (void* data)
{
sem_post ((sem_t*)data);
sem_post ((sem_t*)data);
#ifdef _MG_USE_BETTER_TIMER
g_timer_started = times(NULL);
g_last_tick = 0;
#endif /* _MG_USE_BETTER_TIMER */
while (__mg_quiting_stage > _MG_QUITING_STAGE_TIMER)
{
while (__mg_quiting_stage > _MG_QUITING_STAGE_TIMER) {
__mg_os_time_delay (10);
__mg_timer_action (NULL);
}
@@ -152,14 +151,14 @@ int __mg_timer_init (void)
}
#ifdef __AOS__
__mg_os_timer = tp_os_timer_create ("mgtimer", __mg_timer_action,
NULL, AOS_TIMER_TICKT,
__mg_os_timer = tp_os_timer_create ("mgtimer", __mg_timer_action,
NULL, AOS_TIMER_TICKT,
OS_AUTO_ACTIVATE | OS_AUTO_LOAD);
#else /* NOT __AOS__ */
{
sem_t wait;
sem_t wait;
sem_init (&wait, 0, 0);
pthread_create (&__mg_timer, NULL, TimerEntry, &wait);
sem_wait (&wait);
sem_destroy (&wait);
@@ -196,7 +195,7 @@ BOOL mg_InstallIntervalTimer (void)
{
struct itimerval timerv;
struct sigaction siga;
sigaction (SIGALRM, NULL, &old_alarm_handler);
siga = old_alarm_handler;
@@ -307,7 +306,7 @@ void mg_dispatch_timer_message (DWORD inter)
timerstr[i]->tick_count = __mg_timer_counter;
#endif
/* setting timer flag is simple, we do not need to lock msgq,
or else we may encounter dead lock here */
or else we may encounter dead lock here */
SetMsgQueueTimerFlag (timerstr[i]->msg_queue, i);
timerstr[i]->count -= timerstr[i]->speed;
}
@@ -378,7 +377,7 @@ void __mg_move_timer_last (TIMER* timer, int slot)
}
#endif
BOOL GUIAPI SetTimerEx (HWND hWnd, LINT id, DWORD speed,
BOOL GUIAPI SetTimerEx (HWND hWnd, LINT id, DWORD speed,
TIMERPROC timer_proc)
{
int i;
@@ -439,7 +438,7 @@ BOOL GUIAPI SetTimerEx (HWND hWnd, LINT id, DWORD speed,
TIMER_UNLOCK ();
return TRUE;
badret:
TIMER_UNLOCK ();
return FALSE;
@@ -520,7 +519,7 @@ int GUIAPI KillTimer (HWND hWnd, LINT id)
TIMER_LOCK ();
for (i = 0; i < DEF_NR_TIMERS; i++) {
if ((timerstr [i] && timerstr [i]->hWnd == hWnd) &&
if ((timerstr [i] && timerstr [i]->hWnd == hWnd) &&
(id == 0 || timerstr [i]->id == id)) {
RemoveMsgQueueTimerFlag (pMsgQueue, i);
free (timerstr[i]);
@@ -540,7 +539,7 @@ int GUIAPI KillTimer (HWND hWnd, LINT id)
return killed;
}
BOOL GUIAPI ResetTimerEx (HWND hWnd, LINT id, DWORD speed,
BOOL GUIAPI ResetTimerEx (HWND hWnd, LINT id, DWORD speed,
TIMERPROC timer_proc)
{
int i;
+23 -25
View File
@@ -1,39 +1,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/en/about/licensing-policy/>.
*/
/*
** gif.c: Low-level GIF file read/save routines.
**
**
** Current maintainer: Wei Yongming
**
** Create date: 2000/08/29
@@ -98,7 +98,7 @@ static int ReadColorMap(MG_RWops* src, int number, unsigned char buffer[3][MAXCO
static int GetDataBlock(MG_RWops* src, unsigned char *buf ,void * info_data);
static int GetCode(MG_RWops* src, int code_size, int flag , void * info);
static int LWZReadByte(MG_RWops* src, int flag, int input_code_size, void * info_data);
static int ReadImage(MG_RWops* src, MYBITMAP* bmp, int len, int height,
static int ReadImage(MG_RWops* src, MYBITMAP* bmp, int len, int height,
int interlace , CB_ONE_SCANLINE cb, void* context , void * info);
/*
*
@@ -132,7 +132,7 @@ void* __mg_init_gif (MG_RWops* fp, MYBITMAP *gif, RGB *pal)
info->width = 0;
info->height = 0;
info->interlace = 0;
info->gif89.transparent = -1;
info->gif89.delayTime = -1;
info->gif89.inputFlag = -1;
@@ -168,10 +168,10 @@ void* __mg_init_gif (MG_RWops* fp, MYBITMAP *gif, RGB *pal)
_MG_PRINTF ("MYBMP>Gif: no image \n" );
goto fini;
}
if ('!' == c) /* Start of the Extension*/
{
if (!ReadOK (fp, &c, 1))
if (!ReadOK (fp, &c, 1))
goto fini;
if (0xfe == c) {
while (GetDataBlock(fp, (unsigned char *) buf , info) != 0);
@@ -179,18 +179,18 @@ void* __mg_init_gif (MG_RWops* fp, MYBITMAP *gif, RGB *pal)
if (0xff == c) {
while (GetDataBlock(fp, (unsigned char *) buf , info) != 0);
}
if (0xf9 == c) {
GetDataBlock (fp, (unsigned char *) buf , info);
info->gif89.disposal = (buf[0] >> 2) & 0x7;//000 000 0 0 the middle 2 bit is disposal
info->gif89.inputFlag = (buf[0] >> 1) & 0x1;//000 000 0 0 the secand last bit
info->gif89.inputFlag = (buf[0] >> 1) & 0x1;//000 000 0 0 the secand last bit
//is user input flag
info->gif89.delayTime = LM_to_uint(buf[1], buf[2]);
if ((buf[0] & 0x1) != 0)// 000 000 0 0 the last bit is transparent flag
info->gif89.transparent = buf[3];
}
}
if (',' == c) /* Start of the Image Descriptor*/
break;
@@ -227,13 +227,13 @@ void* __mg_init_gif (MG_RWops* fp, MYBITMAP *gif, RGB *pal)
info->width = LM_to_uint(buf[4], buf[5]);
info->height = LM_to_uint(buf[6], buf[7]);
info->interlace = BitSet(buf[8], INTERLACE);
gif->w = info->width;
gif->h = info->height;
gif->frames = 1;
gif->depth = 8;
bmp_ComputePitch (8, info->width, &gif->pitch, TRUE);
gif->flags |= MYBMP_FLOW_DOWN;
if ( info->gif89.transparent > 0 ) {
gif->flags |= MYBMP_TRANSPARENT;
@@ -254,7 +254,7 @@ int __mg_load_gif (MG_RWops* fp, void* init_info, MYBITMAP *gif, CB_ONE_SCANLINE
GifInfo * info = (GifInfo *)init_info;
if (!info ->useGColormap) {
ok = ReadImage (fp, gif, info->width,
ok = ReadImage (fp, gif, info->width,
info->height,
info->interlace,
cb, context, info);
@@ -273,7 +273,7 @@ int __mg_load_gif (MG_RWops* fp, void* init_info, MYBITMAP *gif, CB_ONE_SCANLINE
void __mg_cleanup_gif (void* init_info)
{
free (init_info); /* free the GifInfo struct */
free (init_info); /* free the GifInfo struct */
}
static int
@@ -371,7 +371,7 @@ LWZReadByte(MG_RWops *src, int flag, int input_code_size , void * info_data)
static int clear_code, end_code;
static int table[2][(1 << MAX_LWZ_BITS)];
static int stack[(1 << (MAX_LWZ_BITS)) * 2], *sp;
GifInfo * info = info_data;
if (flag) {
@@ -470,7 +470,7 @@ LWZReadByte(MG_RWops *src, int flag, int input_code_size , void * info_data)
}
static int
ReadImage(MG_RWops* src, MYBITMAP* bmp, int len, int height,
ReadImage(MG_RWops* src, MYBITMAP* bmp, int len, int height,
int interlace , CB_ONE_SCANLINE cb, void* context , void * info)
{
unsigned char c;
@@ -539,9 +539,7 @@ ReadImage(MG_RWops* src, MYBITMAP* bmp, int len, int height,
else {
/* emit line at here */
if (bmp->flags &= MYBMP_LOAD_ALLOCATE_ONE)
{
(*cb)(context, bmp, ypos);
}
++ypos;
}
}
+3 -3
View File
@@ -246,9 +246,9 @@ static GAL_Surface *COMMLCD_SetVideoMode(_THIS, GAL_Surface *current,
Bmask = 0x001F;
break;
case COMMLCD_TRUE_RGB565:
Rmask = 0x07E0;
Gmask = 0x001F;
Bmask = 0xF800;
Rmask = 0xF800;
Gmask = 0x07E0;
Bmask = 0x001F;
break;
case COMMLCD_TRUE_RGB888:
case COMMLCD_TRUE_RGB0888:
+9 -30
View File
@@ -1,33 +1,33 @@
/*
* 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/en/about/licensing-policy/>.
*/
@@ -58,27 +58,6 @@ struct GAL_PrivateVideoData {
pthread_mutex_t update_lock;
};
/* The pixel format defined by depth */
//#define COMMLCD_PSEUDO_RGB332 1
//#define COMMLCD_TRUE_RGB555 2
//#define COMMLCD_TRUE_RGB565 3
//#define COMMLCD_TRUE_RGB888 4
//#define COMMLCD_TRUE_RGB0888 5
//#define COMMLCD_TRUE_ARGB1555 6
//#define COMMLCD_TRUE_ARGB8888 7
//#define COMMLCD_TRUE_AGBR8888 8
//struct commlcd_info {
// short height; // vertical resolution of the screen
// short width; // horinzontal resolution of the screen
// short bpp; // Depth (bits-per-pixel)
// short type; // Pixel type
// short rlen; // Length of one scan line in bytes
// void *fb; // Frame buffer
// short async_update; // update asynchronously or synchronously. 0 for synchronously; others for asynchronously.
//};
struct commlcd_ops {
/* return value: zero for OK */
int (*init) (void);
-3
View File
@@ -38,9 +38,6 @@
#include "common.h"
//#ifdef _MGGAL_COMMLCD
//#if defined (__VXWORKS__) || defined (__TARGET_UNKNOWN__) || defined(__RTEMS__)
#if defined(_MGGAL_COMMLCD) && defined(__TARGET_EXTERNAL__)
#include "minigui.h"
+13 -13
View File
@@ -1,33 +1,33 @@
/*
* 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/en/about/licensing-policy/>.
*/
@@ -219,7 +219,7 @@ GAL_PixelFormat *GAL_AllocFormat(int bpp,
format->Amask = Amask;
break;
}
/* Calculate some standard bitmasks, if necessary
/* Calculate some standard bitmasks, if necessary
* Note: This could conflict with an alpha mask, if given.
*/
if ( (bpp > 8) && !format->Rmask && !format->Gmask && !format->Bmask ) {
@@ -248,7 +248,7 @@ GAL_PixelFormat *GAL_ReallocFormat(GAL_Surface *surface, int bpp,
GAL_FormatChanged(surface);
}
surface->format = GAL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
surface->format = GAL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
return surface->format;
}
@@ -327,7 +327,7 @@ Uint8 GAL_FindDitheredColor (int bpp, Uint8 r, Uint8 g, Uint8 b)
return r | g | b;
}
/*
/*
* Calculate the pad-aligned scanline width of a surface
*/
Uint32 GAL_CalculatePitch(GAL_Surface *surface)
@@ -361,7 +361,7 @@ Uint8 GAL_FindColor(GAL_Palette *pal, Uint8 r, Uint8 g, Uint8 b)
int rd, gd, bd;
int i;
Uint8 pixel=0;
smallest = ~0;
for ( i=0; i<pal->ncolors; ++i ) {
rd = pal->colors[i].r - r;
+110 -112
View File
File diff suppressed because it is too large Load Diff
-2
View File
@@ -668,7 +668,6 @@ GAL_Surface *GAL_DisplayFormatAlpha(GAL_Surface *surface)
optimised alpha format is written, add the converter here */
break;
}
printf("============================================================================================== in GAL_DisplayFormatAlpha\n");
format = GAL_AllocFormat(32, rmask, gmask, bmask, amask);
flags = GAL_PublicSurface->flags & GAL_HWSURFACE;
flags |= surface->flags & (GAL_SRCALPHA | GAL_RLEACCELOK);
@@ -1072,7 +1071,6 @@ static GAL_Surface *Slave_CreateSurface (GAL_VideoDevice *this,
if (Amask){
surface->flags |= GAL_SRCPIXELALPHA;
}
printf("============================================================================================== in Slave_CreateSurface\n");
surface->format = GAL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask);
if ( surface->format == NULL ) {
+31 -33
View File
@@ -1,33 +1,33 @@
/*
* 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/en/about/licensing-policy/>.
*/
@@ -367,15 +367,15 @@ BOOL InitializeResManager(int hash_table_size)
#if !defined(__NOUNIX__) || defined(WIN32) || !defined(__RTEMS__)
char* p = NULL;
#endif
pwd_res_path = strdup("./");
pwd_res_path = strdup("./");
//initialize paths
#if !defined(__NOUNIX__) || defined(WIN32)
#if !defined(__NOUNIX__) || defined(WIN32) || !defined(__RTEMS__)
if ((p = getenv ("MG_RES_PATH"))) {
int len = strlen(p);
if (p[len-1] == '/')
if (p[len-1] == '/')
sprintf(szpath, "%s", p);
else
else
sprintf(szpath, "%s/", p);
cfg_res_path = strdup(szpath);
}
@@ -636,20 +636,17 @@ int UnregisterResType(int type)
static char* get_res_file(const char* res_name, char* filename)
{
#ifndef __RTEMS__
#ifndef _MGINCORE_RES
int i;
#endif
if (res_name == NULL || filename == NULL)
return NULL;
#ifdef __RTEMS__
return NULL;
#else
//test it is a full path or not
for(i=0; res_name[i] && res_name[i] == '/'; i++);
if(i>0) //is full path
{
for (i=0; res_name[i] && res_name[i] == '/'; i++)
;
if (i > 0) {
#ifndef __NOUNIX__
struct stat buf;
if(stat(res_name, &buf) == 0
@@ -661,8 +658,8 @@ static char* get_res_file(const char* res_name, char* filename)
}
}
for(i=0; res_paths[i]; i++)
{
for(i=0; res_paths[i]; i++) {
#ifndef __NOUNIX__
struct stat buf;
sprintf(filename,"%s/%s", res_paths[i], res_name);
@@ -678,7 +675,8 @@ static char* get_res_file(const char* res_name, char* filename)
return filename;
}
}
#endif
#endif /* !_MGINCORE_RES */
return NULL;
}
@@ -709,7 +707,7 @@ void* LoadResource(const char* res_name, int type, DWORD usr_param)
RES_ENTRY * entry;
RES_KEY key;
RES_TYPE_INFO *ti = NULL;
int src_type = 0;
int src_type = 0;
void *data = NULL;
char szfilename[MAX_PATH+1]={0};
@@ -760,11 +758,11 @@ void* LoadResource(const char* res_name, int type, DWORD usr_param)
{
//add type info's
ti->ops_ref ++;
src_type = GetSourceType(entry);
if(src_type == REF_SRC_NOTYPE){
src_type = ti->def_source;
SetSourceType(entry, src_type);
}
src_type = GetSourceType(entry);
if(src_type == REF_SRC_NOTYPE){
src_type = ti->def_source;
SetSourceType(entry, src_type);
}
switch(src_type)
{
case REF_SRC_FILE:
@@ -845,7 +843,7 @@ static void delete_entry(HASH_TABLE *table, RES_ENTRY* entry)
int ReleaseRes(RES_KEY key)
{
int ref = 0;
int ref = 0;
RES_ENTRY *entry = NULL;
RES_LOCK();
entry = get_entry(&hash_table, key, FALSE);
@@ -853,7 +851,7 @@ int ReleaseRes(RES_KEY key)
RES_UNLOCK();
return -1;
}
ref = --entry->refcnt;
ref = --entry->refcnt;
if(ref <= 0)
delete_entry(&hash_table, entry);
RES_UNLOCK();
+144 -150
View File
@@ -1,33 +1,33 @@
/*
* 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/en/about/licensing-policy/>.
*/
@@ -51,134 +51,134 @@
static void mObject_construct(mObject* self, DWORD addData)
{
//do nothing
//to avoid NULL pointer
//do nothing
//to avoid NULL pointer
}
static void mObject_destroy(mObject* self)
{
/* ncsRemoveObjectBindProps(self);
ncsRemoveEventSource(self);
ncsRemoveEventListener(self);
*/
/* ncsRemoveObjectBindProps(self);
ncsRemoveEventSource(self);
ncsRemoveEventListener(self);
*/
}
static DWORD mObject_hash(mObject *self)
{
return (DWORD)self;
return (DWORD)self;
}
static const char* mObject_toString(mObject *self, char* str, int max)
{
if(!str)
return NULL;
if(!str)
return NULL;
snprintf(str, max, "NCS Object %s[@%p]", TYPENAME(self),self);
return str;
snprintf(str, max, "NCS Object %s[@%p]", TYPENAME(self),self);
return str;
}
static mObjectClass* mObjectClassConstructor(mObjectClass* _class)
{
_class->super = NULL;
_class->typeName = "mObject";
_class->objSize = sizeof(mObject);
_class->super = NULL;
_class->typeName = "mObject";
_class->objSize = sizeof(mObject);
CLASS_METHOD_MAP(mObject, construct)
CLASS_METHOD_MAP(mObject, destroy)
CLASS_METHOD_MAP(mObject, hash)
CLASS_METHOD_MAP(mObject, toString)
return _class;
CLASS_METHOD_MAP(mObject, construct)
CLASS_METHOD_MAP(mObject, destroy)
CLASS_METHOD_MAP(mObject, hash)
CLASS_METHOD_MAP(mObject, toString)
return _class;
}
mObjectClass Class(mObject) = {
(PClassConstructor)mObjectClassConstructor
(PClassConstructor)mObjectClassConstructor
};
mObject * mg_newObject(mObjectClass *_class)
{
mObject * obj;
mObject * obj;
if(_class == NULL)
return NULL;
if(_class == NULL)
return NULL;
obj = (mObject*)calloc(1, _class->objSize);
obj = (mObject*)calloc(1, _class->objSize);
if(!obj)
return NULL;
if(!obj)
return NULL;
return initObject(obj, _class);
return initObject(obj, _class);
}
mObject * mgNewObject(mObjectClass *_class,DWORD addData){
mObject * obj = newObject(_class);
if(!obj)
return NULL;
mObject * obj = newObject(_class);
if(!obj)
return NULL;
_class->construct(obj, addData);
return obj;
_class->construct(obj, addData);
return obj;
}
mObject * mgNewObjectArgs(mObjectClass* _class, ...)
{
va_list va;
mObject * obj;
va_start(va, _class);
obj = newObject(_class);
if(obj)
((PCONSTRUCT_VALIST)(_class->construct))(obj, va);
va_end(va);
return obj;
va_list va;
mObject * obj;
va_start(va, _class);
obj = newObject(_class);
if(obj)
((PCONSTRUCT_VALIST)(_class->construct))(obj, va);
va_end(va);
return obj;
}
void mgDeleteObject(mObject *obj)
{
if(obj == NULL || obj->_class == NULL)
return;
if(obj == NULL || obj->_class == NULL)
return;
_c(obj)->destroy(obj);
_c(obj)->destroy(obj);
free(obj);
free(obj);
}
mObject* mgInitObject(mObject* pobj, mObjectClass* _class) {
IInterface* piobj;
IInterfaceVTable* _ivtable;
int next_intf_offset ;
pobj->_class = _class;
IInterface* piobj;
IInterfaceVTable* _ivtable;
int next_intf_offset ;
pobj->_class = _class;
next_intf_offset = _class->intfOffset;
while(next_intf_offset > 0)
{
_ivtable = (IInterfaceVTable*)((unsigned char*)_class + next_intf_offset);
piobj = (IInterface*)((unsigned char*)pobj + _ivtable->_obj_offset);
piobj->_vtable = _ivtable;
next_intf_offset = _ivtable->_next_offset;
}
next_intf_offset = _class->intfOffset;
while(next_intf_offset > 0)
{
_ivtable = (IInterfaceVTable*)((unsigned char*)_class + next_intf_offset);
piobj = (IInterface*)((unsigned char*)pobj + _ivtable->_obj_offset);
piobj->_vtable = _ivtable;
next_intf_offset = _ivtable->_next_offset;
}
return pobj;
return pobj;
}
mObject* mg_initObject(mObject* pobj, mObjectClass* _class,DWORD param)
mObject* mg_initObject(mObject* pobj, mObjectClass* _class,DWORD param)
{
memset(pobj, 0, _class->objSize);
initObject(pobj, _class);
_class->construct(pobj, param);
return pobj;
memset(pobj, 0, _class->objSize);
initObject(pobj, _class);
_class->construct(pobj, param);
return pobj;
}
mObject* mgInitObjectArgs(mObject* pobj, mObjectClass* _class, ...)
{
va_list va;
va_start(va, _class);
memset(pobj, 0, _class->objSize);
initObject(pobj, _class);
((PCONSTRUCT_VALIST)(_class->construct))(pobj, va);
va_end(va);
return pobj;
va_list va;
va_start(va, _class);
memset(pobj, 0, _class->objSize);
initObject(pobj, _class);
((PCONSTRUCT_VALIST)(_class->construct))(pobj, va);
va_end(va);
return pobj;
}
@@ -188,60 +188,60 @@ mObject* mgInitObjectArgs(mObject* pobj, mObjectClass* _class, ...)
mObjectClass *ncsSafeCastClass(mObjectClass* clss, mObjectClass* castCls)
{
mObjectClass * clssSuper;
if(clss == castCls)
return NULL;
mObjectClass * clssSuper;
if(clss == castCls)
return NULL;
clssSuper = clss;
while(clssSuper && clssSuper != castCls)
clssSuper = clssSuper->super;
clssSuper = clss;
while(clssSuper && clssSuper != castCls)
clssSuper = clssSuper->super;
return clssSuper?clss:NULL;
return clssSuper?clss:NULL;
}
mObject* ncsSafeCast(mObject* obj, mObjectClass *clss)
{
mObjectClass * objClass;
if(obj == NULL || clss == NULL)
return NULL;
mObjectClass * objClass;
if(obj == NULL || clss == NULL)
return NULL;
objClass = _c(obj);
objClass = _c(obj);
while(objClass && objClass != clss)
objClass = objClass->super;
while(objClass && objClass != clss)
objClass = objClass->super;
return objClass?obj:NULL;
return objClass?obj:NULL;
}
BOOL ncsInstanceOf(mObject *object, mObjectClass* clss)
{
mObjectClass* objClss;
if(object == NULL || clss == NULL)
return FALSE;
mObjectClass* objClss;
if(object == NULL || clss == NULL)
return FALSE;
objClss = _c(object);
objClss = _c(object);
while(objClss && clss != objClss){
objClss = objClss->super;
}
while(objClss && clss != objClss){
objClss = objClss->super;
}
return objClss != NULL;
return objClss != NULL;
}
static inline int _va_check (va_list va)
{
#if 0
union {
va_list va;
DWORD dva;
} _va;
union {
va_list va;
DWORD dva;
} _va;
if (va == 0)
return 0;
va_copy (_va.va, va);
if(_va.dva == 0)
return 0;
va_copy (_va.va, va);
if(_va.dva == 0)
return 0;
return 1;
#else
@@ -258,69 +258,63 @@ static inline int _va_check (va_list va)
int ncsParseConstructParams(va_list args, const char* signature, ...)
{
va_list params;
int argc;
int i;
va_list params;
int argc;
int i;
/*
** the implementation of GET_ARG_COUNT is bad, because some systems
** define va_list as a pointer, and others define it as an array of
** define va_list as a pointer, and others define it as an array of
** pointers (of length 1).
if(GET_ARG_COUNT(args) <= 0)
return 0;
if(GET_ARG_COUNT(args) <= 0)
return 0;
*/
if (_va_check (args) == 0)
{
return 0;
}
argc = va_arg(args, int);
argc = va_arg(args, int);
if(argc <= 0)
{
return 0;
}
va_start(params, signature);
va_start(params, signature);
i = 0;
while(i < argc)
{
switch(signature[i])
{
case 'd': //double
*(va_arg(params, double*)) = va_arg(args, double);
break;
case 'f': //float
i = 0;
while(i < argc) {
switch(signature[i]) {
case 'd': //double
*(va_arg(params, double*)) = va_arg(args, double);
break;
case 'f': //float
/* FIXME gcc says:
** warning: 'float' is promoted to 'double' when passed through '...'
** warning: (so you should pass 'double' not 'float' to 'va_arg')
** note: if this code is reached, the program will abort.
*/
*(va_arg(params, float*)) = va_arg(args, double);
break;
case 'i': //integer
*(va_arg(params, int*)) = va_arg(args, int);
break;
case 's': //const char*
*(va_arg(params, const char**)) = va_arg(args, const char*);
break;
case 'u': //unsigned int
*(va_arg(params, unsigned int*)) = va_arg(args, unsigned int);
break;
case 'p': //void *
*(va_arg(params, void**)) = va_arg(args, void*);
break;
default:
*(va_arg(params, void**)) = va_arg(args, void*);
}
i ++;
}
*(va_arg(params, float*)) = va_arg(args, double);
break;
case 'i': //integer
*(va_arg(params, int*)) = va_arg(args, int);
break;
case 's': //const char*
*(va_arg(params, const char**)) = va_arg(args, const char*);
break;
case 'u': //unsigned int
*(va_arg(params, unsigned int*)) = va_arg(args, unsigned int);
break;
case 'p': //void *
*(va_arg(params, void**)) = va_arg(args, void*);
break;
default:
*(va_arg(params, void**)) = va_arg(args, void*);
}
va_end(params);
i ++;
}
return i;
va_end(params);
return i;
}
#endif /* defined(_MGCTRL_TEXTEDIT_USE_NEW_IMPL) || defined(__MGNCS_TEXTEDITOR) */