Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Can not get event by kdWaitEvent(): (4 Items)
   
Can not get event by kdWaitEvent()  
Hi,every body.

  I need to send/receive openkode event in multi thread.  I follow the OpenKode1.0.2 and I think my source will be Ok. 
But it does not work.

1).kdWaitEvent(-1) , err code is  KD_EAGAIN (5):
In OpenKode1.0.2, this means:The timeout expired while the event queue was empty.

2).kdPostThreadEvent(), err code is  KD_EAGAIN (5):
In OpenKode1.0.2, this means:Resource unavailable, try again.

  I think it may be the reason of init of event queue , but I can not found any function to init the queue.

 How can i do for it, thanks.

 
 This is my source code
---------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/keycodes.h>
#include <time.h>
#include <EGL/egl.h>
#include <KD/kd.h>
#include <GLES/gl.h>

KDThread * pRecvThread = KD_NULL;

void  * kdSendThreadFun(void * arg)
{
	printf("SubThreadFunc: Enter\n");
	
	KDEvent *  pSendEvent 	= KD_NULL;
	
	KDint looCnt = 0;
	while(looCnt < 1)
	{
		pSendEvent = kdCreateEvent();
		
		if(KD_NULL == pSendEvent)
		{
			printf("SubThreadFunc: Failed to create KdEvent, and the errCode is:%d\n", kdGetError());
		}
		else
		{
			printf("SubThreadFunc: Successed to create KdEvent\n");
			
			if(-1 == kdPostThreadEvent(pSendEvent, pRecvThread))
			{
				printf("SubTheadFunc: Failed to send KdEvent, and the errCode is:%d\n", kdGetError());				
			}
			else
			{
				printf("SubTheadFunc: Successed to send KdEvent\n");				
			}
		}
		//sleep(5);
		looCnt++;
	}
	
	return KD_NULL;
}


KDint kdMain(KDint argc, const KDchar *const *argv)
{
	KDThread 		* pSendThread 	= KD_NULL; 
	const KDEvent  	* pRecvEvent 	= KD_NULL;
	
	KDust recvTimeout = -1;
	
	pRecvThread = kdThreadSelf();
	
	pSendThread = kdThreadCreate(KD_NULL, &kdSendThreadFun, KD_NULL);
	
	if(KD_NULL == pSendThread)
	{
		printf("MainThread: Failed to create sub thread, and errCode is:%d\n", kdGetError());
	}
	else
	{
		printf("MainThread: Successed to create sub thread\n");
	}
	
	while ((pRecvEvent = kdWaitEvent(recvTimeout)) != 0)
	{
		printf("MainThread: Successed to recv KdEvent\n");	
		
		kdDefaultEvent(pRecvEvent);
	}
	
	printf("MainThread: Failed To Receive Event,and the errCode is:%d\n", kdGetError());
	
	return 0;
}
---------------------------------------------------------------------------------------------


 This is the result
---------------------------------------------------------------------------------------------
SubThreadFunc: Enter
SubThreadFunc: Successed to create KdEvent
MainThread: Successed to create sub thread
SubTheadFunc: Failed to send KdEvent, and the errCode is:5
MainThread: Failed To Receive Event,and the errCode is:5
---------------------------------------------------------------------------------------------
RE: Can not get event by kdWaitEvent()  
I ran into this issue. The thread receiving OpenKode events must be the
same one that initialized the OpenKode window (realization, etc). I
solved this by calling my OpenKode initialization function from my input
thread.

Regards,
Max 

-----Original Message-----
From: liu liming [mailto:community-noreply@qnx.com] 
Sent: Sunday, June 07, 2009 7:20 AM
To: cwm-graphics
Subject: Can not get event by kdWaitEvent()

Hi,every body.

  I need to send/receive openkode event in multi thread.  I follow the
OpenKode1.0.2 and I think my source will be Ok. But it does not work.

1).kdWaitEvent(-1) , err code is  KD_EAGAIN (5):
In OpenKode1.0.2, this means:The timeout expired while the event queue
was empty.

2).kdPostThreadEvent(), err code is  KD_EAGAIN (5):
In OpenKode1.0.2, this means:Resource unavailable, try again.

  I think it may be the reason of init of event queue , but I can not
found any function to init the queue.

 How can i do for it, thanks.

 
 This is my source code
------------------------------------------------------------------------
---------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/keycodes.h>
#include <time.h>
#include <EGL/egl.h>
#include <KD/kd.h>
#include <GLES/gl.h>

KDThread * pRecvThread = KD_NULL;

void  * kdSendThreadFun(void * arg)
{
	printf("SubThreadFunc: Enter\n");
	
	KDEvent *  pSendEvent 	= KD_NULL;
	
	KDint looCnt = 0;
	while(looCnt < 1)
	{
		pSendEvent = kdCreateEvent();
		
		if(KD_NULL == pSendEvent)
		{
			printf("SubThreadFunc: Failed to create KdEvent,
and the errCode is:%d\n", kdGetError());
		}
		else
		{
			printf("SubThreadFunc: Successed to create
KdEvent\n");
			
			if(-1 == kdPostThreadEvent(pSendEvent,
pRecvThread))
			{
				printf("SubTheadFunc: Failed to send
KdEvent, and the errCode is:%d\n", kdGetError());

			}
			else
			{
				printf("SubTheadFunc: Successed to send
KdEvent\n");				
			}
		}
		//sleep(5);
		looCnt++;
	}
	
	return KD_NULL;
}


KDint kdMain(KDint argc, const KDchar *const *argv)
{
	KDThread 		* pSendThread 	= KD_NULL; 
	const KDEvent  	* pRecvEvent 	= KD_NULL;
	
	KDust recvTimeout = -1;
	
	pRecvThread = kdThreadSelf();
	
	pSendThread = kdThreadCreate(KD_NULL, &kdSendThreadFun,
KD_NULL);
	
	if(KD_NULL == pSendThread)
	{
		printf("MainThread: Failed to create sub thread, and
errCode is:%d\n", kdGetError());
	}
	else
	{
		printf("MainThread: Successed to create sub thread\n");
	}
	
	while ((pRecvEvent = kdWaitEvent(recvTimeout)) != 0)
	{
		printf("MainThread: Successed to recv KdEvent\n");	
		
		kdDefaultEvent(pRecvEvent);
	}
	
	printf("MainThread: Failed To Receive Event,and the errCode
is:%d\n", kdGetError());
	
	return 0;
}
------------------------------------------------------------------------
---------------------


 This is the result
------------------------------------------------------------------------
---------------------
SubThreadFunc: Enter
SubThreadFunc: Successed to create KdEvent
MainThread: Successed to create sub thread
SubTheadFunc: Failed to send KdEvent, and the errCode is:5
MainThread: Failed To Receive Event,and the errCode is:5
------------------------------------------------------------------------
---------------------


_______________________________________________
CWM/OpenKODE
http://community.qnx.com/sf/go/post31051
Re: Can not get event by kdWaitEvent()  
Right now, kdPostThreadEvent is not implemented. KD_EAGAIN typically is the error when the OpenKODE library can't 
connect to io-winmgr.
Re: Can not get event by kdWaitEvent()  
OK, I had fix the problem.

1.In qnx , kdPostThreadEvent is not implemented and we should use the function of "kdPostWindowEventQNX" to send kdevent
.

2.The receive thread must create a window and initialized it.

Thanks all very much.