示例#1
0
文件: osal.c 项目: PheeL79/diOS
Status OS_StorageItemDelete(OS_StorageItem* item_p)
{
    if (OS_NULL == item_p) { return S_INVALID_PTR; }
    if (0 == --(item_p->owners)) {
        OS_MutexDelete(item_p->mutex);
        OS_Free(item_p->data_p);
        OS_Free(item_p);
    }
    return S_OK;
}
示例#2
0
static void Add_File_Events(REBGOB *gob, REBINT flags, HDROP drop)
{
	REBEVT evt;
	REBINT num;
	REBINT len;
	REBINT i;
	REBCHR* buf;
	POINT xy;

	//Get the mouse position
	DragQueryPoint(drop, &xy);

	evt.type  = EVT_DROP_FILE;
	evt.flags = (u8) (flags | (1<<EVF_HAS_XY));
	evt.info = 0;
	evt.data = xy.x | xy.y<<16;


	num = DragQueryFile(drop, -1, NULL, 0);

	for (i = 0; i < num; i++){
		len = DragQueryFile(drop, i, NULL, 0);
		buf = OS_Make(len+1);
		DragQueryFile(drop, i, buf, len+1);
		//Reb_Print("DROP: %s", buf);
		buf[len] = 0;
		// ?! convert to REBOL format? E.g.: evt.ser = OS_To_REBOL_File(buf, &len);
		OS_Free(buf);
		if (!Reb_Event(&evt)) break;	// queue is full
	}
}
示例#3
0
文件: dev-net.c 项目: earl/r3-hostkit
*/	 DEVICE_CMD Close_Socket(REBREQ *sock)
/*
**		Close a socket.
**
**		Returns 0 on success.
**		On failure, error code is OS local.
**
***********************************************************************/
{
	sock->error = 0;

	if (GET_FLAG(sock->state, RSM_OPEN)) {

		sock->state = 0;  // clear: RSM_OPEN, RSM_CONNECT

		// If DNS pending, abort it:
		if (sock->net.host_info) {  // indicates DNS phase active
#ifdef HAS_ASYNC_DNS
			if (sock->handle) WSACancelAsyncRequest(sock->handle);
#endif
			OS_Free(sock->net.host_info);
			sock->socket = sock->length; // Restore TCP socket (see Lookup)
		}

		if (CLOSE_SOCKET(sock->socket)) {
			sock->error = GET_ERROR;
			return DR_ERROR;
		}
	}

	return DR_DONE;
}
*/ void rebcmp_destroy(REBCMP_CTX* ctx)
/*
**	Destroy existing Compositor instance.
**
***********************************************************************/
{
#ifdef USE_XSHM
	if (global_x_info->has_xshm) {
		if (ctx->x_shminfo.shmid != 0) {
			XShmDetach(global_x_info->display, &ctx->x_shminfo);
			if (ctx->x_shminfo.shmaddr != NULL) {
				shmdt(ctx->x_shminfo.shmaddr);
			}
			//RL_Print("Removing SHM %x\n", ctx->x_shminfo.shmid);
			shmctl(ctx->x_shminfo.shmid, IPC_RMID, NULL);
		}
		if (ctx->x_shminfo_back.shmid != 0) {
			XShmDetach(global_x_info->display, &ctx->x_shminfo_back);
			if (ctx->x_shminfo_back.shmaddr != NULL) {
				shmdt(ctx->x_shminfo_back.shmaddr);
			}
			//RL_Print("Removing SHM %x\n", ctx->x_shminfo.shmid);
			shmctl(ctx->x_shminfo_back.shmid, IPC_RMID, NULL);
		}
		if (ctx->x_image_back) {
			XDestroyImage(ctx->x_image_back);
		}
	}
#endif
	if (ctx->x_image) {
		XDestroyImage(ctx->x_image); //frees ctx->pixbuf as well
	} else { //no display
		OS_Free(ctx->pixbuf);
	}

	if (ctx->x_gc != 0) {
		XFreeGC(global_x_info->display, ctx->x_gc);
	}

	if (ctx->Win_Region) {
		XDestroyRegion(ctx->Win_Region);
	}
	OS_Free(ctx);
}
示例#5
0
*/	DEVICE_CMD Read_DNS(REBREQ *sock)
/*
**		Initiate the GetHost request and return immediately.
**		Note the temporary results buffer (must be freed later).
**
***********************************************************************/
{
	void *host;
#ifdef HAS_ASYNC_DNS
	HANDLE handle;
#else
	HOSTENT *he;
#endif

	host = OS_Make(MAXGETHOSTSTRUCT); // be sure to free it

#ifdef HAS_ASYNC_DNS
	if (!GET_FLAG(sock->modes, RST_REVERSE)) // hostname lookup
		handle = WSAAsyncGetHostByName(Event_Handle, WM_DNS, sock->data, host, MAXGETHOSTSTRUCT);
	else
		handle = WSAAsyncGetHostByAddr(Event_Handle, WM_DNS, (char*)&(sock->net.remote_ip), 4, AF_INET, host, MAXGETHOSTSTRUCT);

	if (handle != 0) {
		sock->net.host_info = host;
		sock->handle = handle;
		return DR_PEND; // keep it on pending list
	}
#else
	// Use old-style blocking DNS (mainly for testing purposes):
	if (GET_FLAG(sock->modes, RST_REVERSE)) {
		he = gethostbyaddr((char*)&sock->net.remote_ip, 4, AF_INET);
		if (he) {
			sock->net.host_info = host; //???
			sock->data = he->h_name;
			SET_FLAG(sock->flags, RRF_DONE);
			return DR_DONE;
		}
	}
	else {
		he = gethostbyname(sock->data);
		if (he) {
			sock->net.host_info = host; // ?? who deallocs?
			COPY_MEM((char*)&(sock->net.remote_ip), (char *)(*he->h_addr_list), 4); //he->h_length);
			SET_FLAG(sock->flags, RRF_DONE);
			return DR_DONE;
		}
	}
#endif

	OS_Free(host);
	sock->net.host_info = 0;

	sock->error = GET_ERROR;
	//Signal_Device(sock, EVT_ERROR);
	return DR_ERROR; // Remove it from pending list
}
*/ void rebcmp_destroy(REBCMP_CTX* ctx)
/*
**	Destroy existing Compositor instance.
**
***********************************************************************/
{
	//------------------------------
	//Put backend specific code here
	//------------------------------
	OS_Free(ctx);
}
示例#7
0
文件: task.c 项目: ahmedeng165/ercos
void OS_ThreadExit(void)
{
    int tid = current->tid;

    DEBUG ("(); tid=%d", tid);
    KTRACE (KTRACE_EXIT, current->tid, 0);

    /*  Init the thread status  */
    task_table[tid].status = 0;
    /*  Traps off, set S, PS and FP unit    */
    //task_table[tid].context.psr = 0x000010c0;

    /*  Free the thread stack   */
    OS_Free(task_table[tid].stack.addr);

    /*  Add the TCB into the free TCB queue   */
    OS_ListAppend(&tcb_list, &task_table[tid].node);
}
示例#8
0
*/	DEVICE_CMD Close_DNS(REBREQ *sock)
/*
**		Note: valid even if not open.
**
***********************************************************************/
{
	// Terminate a pending request:
#ifdef HAS_ASYNC_DNS
	if (GET_FLAG(sock->flags, RRF_PENDING)) {
		CLR_FLAG(sock->flags, RRF_PENDING);
		if (sock->handle) WSACancelAsyncRequest(sock->handle);
	}
#endif
	if (sock->net.host_info) OS_Free(sock->net.host_info);
	sock->net.host_info = 0;
	sock->handle = 0;
	SET_CLOSED(sock);
	return DR_DONE; // Removes it from device's pending list (if needed)
}
示例#9
0
*/	DEVICE_CMD Close_IO(REBREQ *req)
/*
 ***********************************************************************/
{
    REBDEV *dev = Devices[req->device];

    if (GET_FLAG(dev->flags, RDF_OPEN)) {
        OS_Free(Std_Buf);
        Std_Buf = 0;
        //FreeConsole();  // problem: causes a delay
    }

    if (Std_Echo) {
        CloseHandle(Std_Echo);
        Std_Echo = 0;
    }

    CLR_FLAG(req->flags, RRF_OPEN);
    //CLR_FLAG(dev->flags, RDF_OPEN);

    return DR_DONE;
}
示例#10
0
*/	RXIEXT int RXD_Text(int cmd, RXIFRM *frm, REBCEC *ctx)
/*
**		DRAW command dispatcher.
**
***********************************************************************/
{
	switch (cmd) {

    case CMD_TEXT_INIT_WORDS:
        //temp hack - will be removed later
        text_ext_words = RL_MAP_WORDS(RXA_SERIES(frm,1));
        break;

    case CMD_TEXT_ANTI_ALIAS:
        rt_anti_alias(ctx->envr, RXA_LOGIC(frm, 1));
        break;

    case CMD_TEXT_BOLD:
        rt_bold(ctx->envr, RXA_LOGIC(frm, 1));
        break;

    case CMD_TEXT_CARET:
        {
            RXIARG val;
            u32 *words, *w;
            REBSER *obj;
            REBCNT type;
            REBXYF caret, highlightStart, highlightEnd;
            REBXYF *pcaret = 0, *phighlightStart = 0;
            obj = RXA_OBJECT(frm, 1);
//Reb_Print("RXI_WORDS_OF_OBJECT() called\n");
            words = RL_WORDS_OF_OBJECT(obj);
//Reb_Print("RXI_WORDS_OF_OBJECT() OK\n");
            w = words;

            while (type = RL_GET_FIELD(obj, w[0], &val))
            {
//                RL_Print("word: %d %d %d\n", w[0],w[1], (REBYTE)w[1]);
                switch(RL_FIND_WORD(text_ext_words,w[0]))
                {
                    case W_TEXT_CARET:
                        if (type == RXT_BLOCK){
                            REBSER* block = val.series;
                            REBINT len = RL_SERIES(block, RXI_SER_TAIL);
                            if (len > 1){
                                RXIARG pos, elem;
                                if (
                                    RL_GET_VALUE(block, 0, &pos) == RXT_BLOCK &&
                                    RL_GET_VALUE(block, 1, &elem) == RXT_STRING
                                ){
                                    caret.x = 1 + pos.index;
                                    caret.y = 1 + elem.index;
                                    pcaret = &caret;
                                }
                            }
                        }
                        break;

                    case W_TEXT_HIGHLIGHT_START:
                        if (type == RXT_BLOCK){
                            REBSER* block = val.series;
                            REBINT len = RL_SERIES(block, RXI_SER_TAIL);
                            if (len > 1){
                                RXIARG pos, elem;
                                if (
                                    RL_GET_VALUE(block, 0, &pos) == RXT_BLOCK &&
                                    RL_GET_VALUE(block, 1, &elem) == RXT_STRING
                                ){
                                    highlightStart.x = 1 + pos.index;
                                    highlightStart.y = 1 + elem.index;
                                    phighlightStart = &highlightStart;
                                }
                            }
                        }
                        break;

                    case W_TEXT_HIGHLIGHT_END:
                        if (type == RXT_BLOCK){
                            REBSER* block = val.series;
                            REBINT len = RL_SERIES(block, RXI_SER_TAIL);
                            if (len > 1){
                                RXIARG pos, elem;
                                if (
                                    RL_GET_VALUE(block, 0, &pos) == RXT_BLOCK &&
                                    RL_GET_VALUE(block, 1, &elem) == RXT_STRING
                                ){
                                    highlightEnd.x = 1 + pos.index;
                                    highlightEnd.y = 1 + elem.index;
                                }
                            }
                        }
                        break;
                }

                w++;
            }
            OS_Free(words);
            rt_caret(ctx->envr, pcaret, phighlightStart, highlightEnd);
        }

        break;

    case CMD_TEXT_CENTER:
        rt_center(ctx->envr);
        break;

    case CMD_TEXT_COLOR:
        rt_color(ctx->envr, RXA_TUPLE(frm,1) + 1);
       break;

    case CMD_TEXT_DROP:
        rt_drop(ctx->envr, RXA_INT32(frm,1));
        break;

    case CMD_TEXT_FONT:
        {
            RXIARG val;
            u32 *words,*w;
            REBSER *obj;
            REBCNT type;
            REBFNT *font = rt_get_font(ctx->envr);

            obj = RXA_OBJECT(frm, 1);
            words = RL_WORDS_OF_OBJECT(obj);
            w = words;

            while (type = RL_GET_FIELD(obj, w[0], &val))
            {
                switch(RL_FIND_WORD(text_ext_words,w[0]))
                {
                    case W_TEXT_NAME:
                        if (type == RXT_STRING){
                            wchar_t* str;
                            REBCNT gc = TRUE;
                            if (RL_GET_STRING(val.series, 0 , (void*)&str) < 0){
                                size_t newSize = mbstowcs(NULL, (char*)str, 0) + 1;
                                size_t origsize = strlen((char*)str) + 1;
                                //note: following string will be deallocated by the rich text module
                                wchar_t* wstr = OS_Make(newSize * sizeof( wchar_t ));
                                mbstowcs(wstr, (char*)str, newSize);
                                str = wstr;
                                gc = FALSE;
                            }
                            font->name = str;
                            font->name_gc = gc;
                        }
                        break;

                    case W_TEXT_STYLE:
                        switch(type)
                        {
                            case RXT_WORD:
                            {
                                u32 styleWord = RL_FIND_WORD(text_ext_words,val.int32a);
                                if (styleWord) rt_set_font_styles(font, styleWord);
                            }
                            break;

                            case RXT_BLOCK:
                            {
                                RXIARG styleVal;
                                REBCNT styleType;
                                REBCNT n;
                                u32 styleWord;
                                for (n = 0; styleType = RL_GET_VALUE(val.series, n, &styleVal); n++) {
                                    if (styleType == RXT_WORD) {
                                        styleWord = RL_FIND_WORD(text_ext_words,styleVal.int32a);
                                        if (styleWord) rt_set_font_styles(font, styleWord);
                                    }
                                }
                            }
                            break;
                        }
                        break;

                    case W_TEXT_SIZE:
                        if (type == RXT_INTEGER)
                            font->size = val.int64;
                        break;

                    case W_TEXT_COLOR:
                        if (type == RXT_TUPLE)
                            memcpy(font->color,val.bytes + 1 , 4);
                        break;

                    case W_TEXT_OFFSET:
                        if (type == RXT_PAIR) {
                            font->offset_x = val.pair.x;
                            font->offset_y = val.pair.y;
                        }
                        break;

                    case W_TEXT_SPACE:
                        if (type == RXT_PAIR) {
                            font->space_x = val.pair.x;
                            font->space_y = val.pair.y;
                        }
                        break;

                    case W_TEXT_SHADOW:
                        switch(type)
                        {
                            case RXT_PAIR:
                            {
                                font->shadow_x = val.pair.x;
                                font->shadow_y = val.pair.y;
                            }
                            break;

                            case RXT_BLOCK:
                            {
                                RXIARG shadowVal;
                                REBCNT shadowType;
                                REBCNT n;
                                for (n = 0; shadowType = RL_GET_VALUE(val.series, n, &shadowVal); n++) {
                                    switch (shadowType)
                                    {
                                        case RXT_PAIR:
                                            font->shadow_x = shadowVal.pair.x;
                                            font->shadow_y = shadowVal.pair.y;
                                            break;

                                        case RXT_TUPLE:
                                            memcpy(font->shadow_color,shadowVal.bytes + 1 , 4);
                                            break;

                                        case RXT_INTEGER:
                                            font->shadow_blur = shadowVal.int64;
                                            break;
                                    }
                                }
                            }
                            break;
                        }
                        break;
                }

                w++;
            }
            OS_Free(words);
            rt_font(ctx->envr, font);
        }
        break;

    case CMD_TEXT_ITALIC:
        rt_italic(ctx->envr, RXA_LOGIC(frm, 1));
        break;

    case CMD_TEXT_LEFT:
        rt_left(ctx->envr);
        break;

	case CMD_TEXT_NEWLINE:
        rt_newline(ctx->envr, ctx->index + 1);
		break;

    case CMD_TEXT_PARA:
        {
            RXIARG val;
            u32 *words,*w;
            REBSER *obj;
            REBCNT type;
            REBPRA *para = rt_get_para(ctx->envr);

            obj = RXA_OBJECT(frm, 1);
            words = RL_WORDS_OF_OBJECT(obj);
            w = words;

            while (type = RL_GET_FIELD(obj, w[0], &val))
            {
                switch(RL_FIND_WORD(text_ext_words,w[0]))
                {
                    case W_TEXT_ORIGIN:
                       if (type == RXT_PAIR) {
                            para->origin_x = val.pair.x;
                            para->origin_y = val.pair.y;
                        }
                        break;
                    case W_TEXT_MARGIN:
                       if (type == RXT_PAIR) {
                            para->margin_x = val.pair.x;
                            para->margin_y = val.pair.y;
                        }
                        break;
                    case W_TEXT_INDENT:
                       if (type == RXT_PAIR) {
                            para->indent_x = val.pair.x;
                            para->indent_y = val.pair.y;
                        }
                        break;
                    case W_TEXT_TABS:
                       if (type == RXT_INTEGER) {
                            para->tabs = val.int64;
                        }
                        break;
                    case W_TEXT_WRAPQ:
                       if (type == RXT_LOGIC) {
                            para->wrap = val.int32a;
                        }
                        break;
                    case W_TEXT_SCROLL:
                       if (type == RXT_PAIR) {
                            para->scroll_x = val.pair.x;
                            para->scroll_y = val.pair.y;
                        }
                        break;
                    case W_TEXT_ALIGN:
                        if (type == RXT_WORD) {
                            para->align = RL_FIND_WORD(text_ext_words,val.int32a);
                        }
                        break;
                    case W_TEXT_VALIGN:
                        if (type == RXT_WORD) {
                            para->valign = RL_FIND_WORD(text_ext_words,val.int32a);
                        }
                        break;
                }

                w++;
            }
            OS_Free(words);
            rt_para(ctx->envr, para);
        }
        break;

    case CMD_TEXT_RIGHT:
        rt_right(ctx->envr);
        break;

	case CMD_TEXT_SCROLL:
		rt_scroll(ctx->envr, RXA_PAIR(frm, 1));
		break;

    case CMD_TEXT_SHADOW:
        rt_shadow(ctx->envr, RXA_PAIR(frm, 1), RXA_TUPLE(frm,2) + 1, RXA_INT32(frm,3));
        break;

	case CMD_TEXT_SIZE:
		rt_font_size(ctx->envr, RXA_INT32(frm,1));
		break;

    case CMD_TEXT_TEXT:
        {
            REBCHR* str;
            REBCNT gc = TRUE;
            if (RL_GET_STRING(RXA_SERIES(frm, 1), 0 , (void*)&str) < 0){
                size_t newSize = mbstowcs(NULL, (char*)str, 0) + 1;
                size_t origsize = strlen((char*)str) + 1;
                //note: following string will be deallocated by the rich text module
                wchar_t* wstr = OS_Make(newSize * sizeof( wchar_t ));
                mbstowcs(wstr, (char*)str, newSize);
                str = (REBCHR*)wstr;
                gc = FALSE;
            }
            rt_text(ctx->envr, str, ctx->index + 2, gc);
        }
        break;

    case CMD_TEXT_UNDERLINE:
        rt_underline(ctx->envr, RXA_LOGIC(frm, 1));
		break;

	default:
		return RXR_NO_COMMAND;
	}
    return RXR_UNSET;
}
示例#11
0
文件: dev-net.c 项目: earl/r3-hostkit
*/	DEVICE_CMD Lookup_Socket(REBREQ *sock)
/*
**		Initiate the GetHost request and return immediately.
**		This is very similar to the DNS device.
**		The request will pend until the main event handler gets WM_DNS.
**		Note the temporary results buffer (must be freed later).
**		Note we use the sock->handle for the DNS handle. During use,
**		we store the TCP socket in the length field.
**
***********************************************************************/
{
#ifdef TO_WIN32
	HANDLE handle;
#endif
	HOSTENT *host;

#ifdef HAS_ASYNC_DNS
	// Check if we are polling for completion:
	if (host = (HOSTENT*)(sock->net.host_info)) {
		// The windows main event handler will change this when it gets WM_DNS event:
		if (!GET_FLAG(sock->flags, RRF_DONE)) return DR_PEND; // still waiting
		CLR_FLAG(sock->flags, RRF_DONE);
		if (!sock->error) { // Success!
			host = (HOSTENT*)sock->net.host_info;
			COPY_MEM((char*)&(sock->net.remote_ip), (char *)(*host->h_addr_list), 4); //he->h_length);
			Signal_Device(sock, EVT_LOOKUP);
		}
		else
			Signal_Device(sock, EVT_ERROR);
		OS_Free(host);	// free what we allocated earlier
		sock->socket = sock->length; // Restore TCP socket saved below
		sock->net.host_info = 0;
		return DR_DONE;
	}

	// Else, make the lookup request:
	host = OS_Make(MAXGETHOSTSTRUCT); // be sure to free it
	handle = WSAAsyncGetHostByName(Event_Handle, WM_DNS, sock->data, (char*)host, MAXGETHOSTSTRUCT);
	if (handle != 0) {
		sock->net.host_info = host;
		sock->length = sock->socket; // save TCP socket temporarily
		sock->handle = handle;
		return DR_PEND; // keep it on pending list
	}
	OS_Free(host);
#else
	// Use old-style blocking DNS (mainly for testing purposes):
	host = gethostbyname(sock->data);
	sock->net.host_info = 0; // no allocated data

	if (host) {
		COPY_MEM((char*)&(sock->net.remote_ip), (char *)(*host->h_addr_list), 4); //he->h_length);
		CLR_FLAG(sock->flags, RRF_DONE);
		Signal_Device(sock, EVT_LOOKUP);
		return DR_DONE;
	}
#endif

	sock->error = GET_ERROR;
	//Signal_Device(sock, EVT_ERROR);
	return DR_ERROR; // Remove it from pending list
}
示例#12
0
static void
BalloonChunk_Destroy(BalloonChunk *chunk) // IN
{
   /* reclaim storage */
   OS_Free(chunk, sizeof *chunk);
}
示例#13
0
文件: os_mailbox.c 项目: PheeL79/diOS
void OS_MessageDelete(OS_Message* msg_p)
{
    OS_Free(msg_p);
}