Add a fifo messaging template and simplify the main event system
This commit is contained in:
parent
536c62c0fc
commit
b4c0735990
2
Build
2
Build
@ -1 +1 @@
|
||||
Subproject commit 4747bc90b663557fc049ebf55ec251eecee6e1d8
|
||||
Subproject commit b4c2998dc8054173f0dd055ecd66411b96eaf8cd
|
120
Sources/libetk/etk/MessageFifo.h
Normal file
120
Sources/libetk/etk/MessageFifo.h
Normal file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file etk/Mutex.h
|
||||
* @brief Ewol Tool Kit : basic mutex system (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 15/08/2012
|
||||
* @par Project
|
||||
* Ewol TK
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __ETK_MESSAGE_FIFO_H__
|
||||
#define __ETK_MESSAGE_FIFO_H__
|
||||
|
||||
#include <etk/Mutex.h>
|
||||
#include <etk/Semaphore.h>
|
||||
#include <etk/Vector.h>
|
||||
|
||||
namespace etk
|
||||
{
|
||||
template<class MY_TYPE=int32_t> class MessageFifo
|
||||
{
|
||||
private :
|
||||
etk::Mutex m_mutex;
|
||||
etk::Semaphore m_semaphore;
|
||||
etk::Vector<MY_TYPE> m_data;
|
||||
public :
|
||||
MessageFifo(void)
|
||||
{
|
||||
// nothing to do ...
|
||||
};
|
||||
~MessageFifo(void)
|
||||
{
|
||||
// nothing to do ...
|
||||
};
|
||||
|
||||
bool Wait(MY_TYPE &data)
|
||||
{
|
||||
m_mutex.Lock();
|
||||
// Check if data is not previously here
|
||||
while(0==m_data.Size()) {
|
||||
m_mutex.UnLock();
|
||||
m_semaphore.Wait();
|
||||
m_mutex.Lock();
|
||||
}
|
||||
// End Waiting message :
|
||||
if (0<m_data.Size()) {
|
||||
// copy element :
|
||||
data = m_data[0];
|
||||
// remove element :
|
||||
m_data.Erase(0);
|
||||
// remove lock
|
||||
m_mutex.UnLock();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
bool Wait(MY_TYPE &data, uint32_t timeOutInUs)
|
||||
{
|
||||
m_mutex.Lock();
|
||||
// Check if data is not previously here
|
||||
while(0==m_data.Size()) {
|
||||
m_mutex.UnLock();
|
||||
if (false == m_semaphore.Wait(timeOutInUs)) {
|
||||
return false;
|
||||
}
|
||||
m_mutex.Lock();
|
||||
}
|
||||
// End Waiting message :
|
||||
if (0<m_data.Size()) {
|
||||
// copy element :
|
||||
data = m_data[0];
|
||||
// remove element :
|
||||
m_data.Erase(0);
|
||||
// remove lock
|
||||
m_mutex.UnLock();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
int32_t Count(void)
|
||||
{
|
||||
m_mutex.Lock();
|
||||
int32_t nbElement = m_data.Size();
|
||||
m_mutex.UnLock();
|
||||
return nbElement;
|
||||
};
|
||||
void Post(MY_TYPE &data)
|
||||
{
|
||||
m_mutex.Lock();
|
||||
m_data.PushBack(data);
|
||||
m_semaphore.Post();
|
||||
m_mutex.UnLock();
|
||||
};
|
||||
void Clean(void)
|
||||
{
|
||||
m_mutex.Lock();
|
||||
// remove data
|
||||
m_data.Clear();
|
||||
m_mutex.UnLock();
|
||||
// remove semaphore
|
||||
m_semaphore.Wait(0);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
@ -27,7 +27,7 @@
|
||||
#include <etk/File.h>
|
||||
#include <ewol/ewol.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/threadMsg.h>
|
||||
#include <etk/MessageFifo.h>
|
||||
#include <ewol/os/eSystem.h>
|
||||
#include <ewol/os/gui.h>
|
||||
#include <ewol/texture/Texture.h>
|
||||
@ -39,16 +39,11 @@
|
||||
#include <ewol/openGl.h>
|
||||
#include <ewol/os/Fps.h>
|
||||
|
||||
static ewol::Windows* windowsCurrent = NULL;
|
||||
static Vector2D<int32_t> windowsSize(320, 480);
|
||||
|
||||
static ewol::threadMsg::threadMsg_ts androidJniMsg;
|
||||
|
||||
static ewol::Windows* windowsCurrent = NULL;
|
||||
static Vector2D<int32_t> windowsSize(320, 480);
|
||||
static ewol::eSystemInput l_managementInput;
|
||||
|
||||
enum {
|
||||
THREAD_INIT,
|
||||
THREAD_UN_INIT,
|
||||
THREAD_RECALCULATE_SIZE,
|
||||
THREAD_RESIZE,
|
||||
THREAD_HIDE,
|
||||
@ -59,7 +54,6 @@ enum {
|
||||
|
||||
THREAD_KEYBORAD_KEY,
|
||||
THREAD_KEYBORAD_MOVE,
|
||||
THREAD_JUST_DISPLAY,
|
||||
|
||||
THREAD_CLIPBOARD_ARRIVE,
|
||||
};
|
||||
@ -71,21 +65,28 @@ typedef struct {
|
||||
int w;
|
||||
int h;
|
||||
} eventResize_ts;
|
||||
|
||||
typedef struct {
|
||||
ewol::inputType_te type;
|
||||
int pointerID;
|
||||
float x;
|
||||
float y;
|
||||
} eventInputMotion_ts;
|
||||
|
||||
typedef struct {
|
||||
ewol::inputType_te type;
|
||||
int pointerID;
|
||||
bool state;
|
||||
float x;
|
||||
float y;
|
||||
} eventInputState_ts;
|
||||
} eventInput_ts;
|
||||
|
||||
typedef struct {
|
||||
int32_t TypeMessage;
|
||||
union {
|
||||
ewol::clipBoard::clipboardListe_te clipboardID;
|
||||
eventResize_ts resize;
|
||||
eventInput_ts input;
|
||||
eSystem::keyboardMove_ts keyboardMove;
|
||||
eSystem::keyboardKey_ts keyboardKey;
|
||||
};
|
||||
} eSystemMessage_ts;
|
||||
|
||||
// deblare the message system
|
||||
static etk::MessageFifo<eSystemMessage_ts> l_msgSystem;
|
||||
|
||||
|
||||
extern eSystem::specialKey_ts specialCurrentKey;
|
||||
|
||||
@ -95,113 +96,100 @@ void ewolProcessEvents(void)
|
||||
{
|
||||
int32_t nbEvent = 0;
|
||||
//EWOL_DEBUG(" ******** Event");
|
||||
ewol::threadMsg::threadMsgContent_ts data;
|
||||
data.type = THREAD_JUST_DISPLAY;
|
||||
while (ewol::threadMsg::WaitingMessage(androidJniMsg)>0)
|
||||
eSystemMessage_ts data;
|
||||
while (l_msgSystem.Count()>0)
|
||||
{
|
||||
nbEvent++;
|
||||
ewol::threadMsg::WaitMessage(androidJniMsg, data);
|
||||
if (data.type != THREAD_JUST_DISPLAY) {
|
||||
//EWOL_DEBUG("EVENT");
|
||||
switch (data.type) {
|
||||
case THREAD_INIT:
|
||||
EWOL_DEBUG("Receive MSG : THREAD_INIT");
|
||||
break;
|
||||
case THREAD_UN_INIT:
|
||||
EWOL_DEBUG("Receive MSG : THREAD_UN_INIT");
|
||||
requestEndProcessing = true;
|
||||
break;
|
||||
case THREAD_RECALCULATE_SIZE:
|
||||
eSystem::ForceRedrawAll();
|
||||
break;
|
||||
case THREAD_RESIZE:
|
||||
//EWOL_DEBUG("Receive MSG : THREAD_RESIZE");
|
||||
{
|
||||
eventResize_ts * tmpData = (eventResize_ts*)data.data;
|
||||
windowsSize.x = tmpData->w;
|
||||
windowsSize.y = tmpData->h;
|
||||
eSystem::ForceRedrawAll();
|
||||
}
|
||||
break;
|
||||
case THREAD_INPUT_MOTION:
|
||||
//EWOL_DEBUG("Receive MSG : THREAD_INPUT_MOTION");
|
||||
{
|
||||
eventInputMotion_ts * tmpData = (eventInputMotion_ts*)data.data;
|
||||
Vector2D<float> pos;
|
||||
pos.x = tmpData->x;
|
||||
pos.y = tmpData->y;
|
||||
l_managementInput.Motion(tmpData->type, tmpData->pointerID, pos);
|
||||
}
|
||||
break;
|
||||
case THREAD_INPUT_STATE:
|
||||
//EWOL_DEBUG("Receive MSG : THREAD_INPUT_STATE");
|
||||
{
|
||||
eventInputState_ts * tmpData = (eventInputState_ts*)data.data;
|
||||
Vector2D<float> pos;
|
||||
pos.x = tmpData->x;
|
||||
pos.y = tmpData->y;
|
||||
l_managementInput.State(tmpData->type, tmpData->pointerID, tmpData->state, pos);
|
||||
}
|
||||
break;
|
||||
case THREAD_KEYBORAD_KEY:
|
||||
//EWOL_DEBUG("Receive MSG : THREAD_KEYBORAD_KEY");
|
||||
{
|
||||
eSystem::keyboardKey_ts * tmpData = (eSystem::keyboardKey_ts*)data.data;
|
||||
specialCurrentKey = tmpData->special;
|
||||
if (false==ewol::shortCut::Process(tmpData->special.shift, tmpData->special.ctrl, tmpData->special.alt, tmpData->special.meta, tmpData->myChar, tmpData->isDown)) {
|
||||
// Get the current Focused Widget :
|
||||
ewol::Widget * tmpWidget = ewol::widgetManager::FocusGet();
|
||||
if (NULL != tmpWidget) {
|
||||
if(true == tmpData->isDown) {
|
||||
EWOL_VERBOSE("GUI PRESSED : \"" << tmpData->myChar << "\"");
|
||||
tmpWidget->OnEventKb(ewol::EVENT_KB_TYPE_DOWN, tmpData->myChar);
|
||||
} else {
|
||||
EWOL_VERBOSE("GUI Release : \"" << tmpData->myChar << "\"");
|
||||
tmpWidget->OnEventKb(ewol::EVENT_KB_TYPE_UP, tmpData->myChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case THREAD_KEYBORAD_MOVE:
|
||||
//EWOL_DEBUG("Receive MSG : THREAD_KEYBORAD_MOVE");
|
||||
{
|
||||
eSystem::keyboardMove_ts * tmpData = (eSystem::keyboardMove_ts*)data.data;
|
||||
specialCurrentKey = tmpData->special;
|
||||
l_msgSystem.Wait(data);
|
||||
//EWOL_DEBUG("EVENT");
|
||||
switch (data.TypeMessage) {
|
||||
case THREAD_RECALCULATE_SIZE:
|
||||
eSystem::ForceRedrawAll();
|
||||
break;
|
||||
case THREAD_RESIZE:
|
||||
//EWOL_DEBUG("Receive MSG : THREAD_RESIZE");
|
||||
windowsSize.x = data.resize.w;
|
||||
windowsSize.y = data.resize.h;
|
||||
eSystem::ForceRedrawAll();
|
||||
break;
|
||||
case THREAD_INPUT_MOTION:
|
||||
//EWOL_DEBUG("Receive MSG : THREAD_INPUT_MOTION");
|
||||
{
|
||||
Vector2D<float> pos;
|
||||
pos.x = data.input.x;
|
||||
pos.y = data.input.y;
|
||||
l_managementInput.Motion(data.input.type, data.input.pointerID, pos);
|
||||
}
|
||||
break;
|
||||
case THREAD_INPUT_STATE:
|
||||
//EWOL_DEBUG("Receive MSG : THREAD_INPUT_STATE");
|
||||
{
|
||||
Vector2D<float> pos;
|
||||
pos.x = data.input.x;
|
||||
pos.y = data.input.y;
|
||||
l_managementInput.State(data.input.type, data.input.pointerID, data.input.state, pos);
|
||||
}
|
||||
break;
|
||||
case THREAD_KEYBORAD_KEY:
|
||||
//EWOL_DEBUG("Receive MSG : THREAD_KEYBORAD_KEY");
|
||||
{
|
||||
specialCurrentKey = data.keyboardKey.special;
|
||||
if (false==ewol::shortCut::Process(data.keyboardKey.special.shift,
|
||||
data.keyboardKey.special.ctrl,
|
||||
data.keyboardKey.special.alt,
|
||||
data.keyboardKey.special.meta,
|
||||
data.keyboardKey.myChar,
|
||||
data.keyboardKey.isDown)) {
|
||||
// Get the current Focused Widget :
|
||||
ewol::Widget * tmpWidget = ewol::widgetManager::FocusGet();
|
||||
if (NULL != tmpWidget) {
|
||||
if(true == tmpData->isDown) {
|
||||
tmpWidget->OnEventKbMove(ewol::EVENT_KB_TYPE_DOWN, tmpData->move);
|
||||
if(true == data.keyboardKey.isDown) {
|
||||
EWOL_VERBOSE("GUI PRESSED : \"" << data.keyboardKey.myChar << "\"");
|
||||
tmpWidget->OnEventKb(ewol::EVENT_KB_TYPE_DOWN, data.keyboardKey.myChar);
|
||||
} else {
|
||||
tmpWidget->OnEventKbMove(ewol::EVENT_KB_TYPE_UP, tmpData->move);
|
||||
EWOL_VERBOSE("GUI Release : \"" << data.keyboardKey.myChar << "\"");
|
||||
tmpWidget->OnEventKb(ewol::EVENT_KB_TYPE_UP, data.keyboardKey.myChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case THREAD_CLIPBOARD_ARRIVE:
|
||||
{
|
||||
ewol::clipBoard::clipboardListe_te * tmpdata = (ewol::clipBoard::clipboardListe_te*)data.data;
|
||||
ewol::Widget * tmpWidget = ewol::widgetManager::FocusGet();
|
||||
if (tmpWidget != NULL) {
|
||||
tmpWidget->OnEventClipboard(*tmpdata);
|
||||
}
|
||||
break;
|
||||
case THREAD_KEYBORAD_MOVE:
|
||||
//EWOL_DEBUG("Receive MSG : THREAD_KEYBORAD_MOVE");
|
||||
{
|
||||
specialCurrentKey = data.keyboardMove.special;
|
||||
// Get the current Focused Widget :
|
||||
ewol::Widget * tmpWidget = ewol::widgetManager::FocusGet();
|
||||
if (NULL != tmpWidget) {
|
||||
if(true == data.keyboardMove.isDown) {
|
||||
tmpWidget->OnEventKbMove(ewol::EVENT_KB_TYPE_DOWN, data.keyboardMove.move);
|
||||
} else {
|
||||
tmpWidget->OnEventKbMove(ewol::EVENT_KB_TYPE_UP, data.keyboardMove.move);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case THREAD_HIDE:
|
||||
EWOL_DEBUG("Receive MSG : THREAD_HIDE");
|
||||
//guiAbstraction::SendKeyboardEventMove(tmpData->isDown, tmpData->move);
|
||||
//gui_uniqueWindows->SysOnHide();
|
||||
break;
|
||||
case THREAD_SHOW:
|
||||
EWOL_DEBUG("Receive MSG : THREAD_SHOW");
|
||||
//guiAbstraction::SendKeyboardEventMove(tmpData->isDown, tmpData->move);
|
||||
//gui_uniqueWindows->SysOnShow();
|
||||
break;
|
||||
default:
|
||||
EWOL_DEBUG("Receive MSG : UNKNOW");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case THREAD_CLIPBOARD_ARRIVE:
|
||||
{
|
||||
ewol::Widget * tmpWidget = ewol::widgetManager::FocusGet();
|
||||
if (tmpWidget != NULL) {
|
||||
tmpWidget->OnEventClipboard(data.clipboardID);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case THREAD_HIDE:
|
||||
EWOL_DEBUG("Receive MSG : THREAD_HIDE");
|
||||
//guiAbstraction::SendKeyboardEventMove(tmpData->isDown, tmpData->move);
|
||||
//gui_uniqueWindows->SysOnHide();
|
||||
break;
|
||||
case THREAD_SHOW:
|
||||
EWOL_DEBUG("Receive MSG : THREAD_SHOW");
|
||||
//guiAbstraction::SendKeyboardEventMove(tmpData->isDown, tmpData->move);
|
||||
//gui_uniqueWindows->SysOnShow();
|
||||
break;
|
||||
default:
|
||||
EWOL_DEBUG("Receive MSG : UNKNOW");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,9 +234,7 @@ void eSystem::Init(void)
|
||||
{
|
||||
EWOL_INFO("==> Ewol System Init (BEGIN)");
|
||||
if (false == isGlobalSystemInit) {
|
||||
// create message system ...
|
||||
EWOL_DEBUG("Init thread message system");
|
||||
ewol::threadMsg::Init(androidJniMsg);
|
||||
l_msgSystem.Clean();
|
||||
requestEndProcessing = false;
|
||||
EWOL_INFO("v" EWOL_VERSION_TAG_NAME);
|
||||
EWOL_INFO("Build Date: " BUILD_TIME);
|
||||
@ -262,10 +248,8 @@ void eSystem::Init(void)
|
||||
ewol::shortCut::Init();
|
||||
APP_Init();
|
||||
isGlobalSystemInit = true;
|
||||
EWOL_DEBUG("Send Init message to the thread");
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_INIT, ewol::threadMsg::MSG_PRIO_REAL_TIME);
|
||||
EWOL_DEBUG("end basic init");
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_RECALCULATE_SIZE, ewol::threadMsg::MSG_PRIO_MEDIUM);
|
||||
// force a recalculation
|
||||
ewol::RequestUpdateSize();
|
||||
}
|
||||
EWOL_INFO("==> Ewol System Init (END)");
|
||||
}
|
||||
@ -275,6 +259,7 @@ void eSystem::UnInit(void)
|
||||
EWOL_INFO("==> Ewol System Un-Init (BEGIN)");
|
||||
if (true == isGlobalSystemInit) {
|
||||
isGlobalSystemInit = false;
|
||||
requestEndProcessing = true;
|
||||
// unset all windows
|
||||
ewol::DisplayWindows(NULL);
|
||||
// call application to uninit
|
||||
@ -286,7 +271,7 @@ void eSystem::UnInit(void)
|
||||
ewol::EObjectMessageMultiCast::UnInit();
|
||||
ewol::EObjectManager::UnInit();
|
||||
l_managementInput.Reset();
|
||||
ewol::threadMsg::UnInit(androidJniMsg);
|
||||
l_msgSystem.Clean();
|
||||
}
|
||||
EWOL_INFO("==> Ewol System Un-Init (END)");
|
||||
}
|
||||
@ -294,29 +279,31 @@ void eSystem::UnInit(void)
|
||||
void ewol::RequestUpdateSize(void)
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_RECALCULATE_SIZE, ewol::threadMsg::MSG_PRIO_MEDIUM);
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_RECALCULATE_SIZE;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void eSystem::Resize(int w, int h )
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
eventResize_ts tmpData;
|
||||
tmpData.w = w;
|
||||
tmpData.h = h;
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_RESIZE, ewol::threadMsg::MSG_PRIO_MEDIUM, &tmpData, sizeof(eventResize_ts) );
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_RESIZE;
|
||||
data.resize.w = w;
|
||||
data.resize.h = h;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
void eSystem::Move(int w, int h )
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
/*
|
||||
eventResize_ts tmpData;
|
||||
tmpData.w = w;
|
||||
tmpData.h = h;
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_RESIZE, ewol::threadMsg::MSG_PRIO_MEDIUM, &tmpData, sizeof(eventResize_ts) );
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_RESIZE;
|
||||
data.resize.w = w;
|
||||
data.resize.h = h;
|
||||
l_msgSystem.Post(data);
|
||||
*/
|
||||
}
|
||||
}
|
||||
@ -324,12 +311,13 @@ void eSystem::Move(int w, int h )
|
||||
void eSystem::SetInputMotion(int pointerID, float x, float y )
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
eventInputMotion_ts tmpData;
|
||||
tmpData.type = ewol::INPUT_TYPE_FINGER;
|
||||
tmpData.pointerID = pointerID;
|
||||
tmpData.x = x;
|
||||
tmpData.y = y;
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_INPUT_MOTION, ewol::threadMsg::MSG_PRIO_LOW, &tmpData, sizeof(eventInputMotion_ts) );
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_INPUT_MOTION;
|
||||
data.input.type = ewol::INPUT_TYPE_FINGER;
|
||||
data.input.pointerID = pointerID;
|
||||
data.input.x = x;
|
||||
data.input.y = y;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,25 +325,28 @@ void eSystem::SetInputMotion(int pointerID, float x, float y )
|
||||
void eSystem::SetInputState(int pointerID, bool isUp, float x, float y )
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
eventInputState_ts tmpData;
|
||||
tmpData.type = ewol::INPUT_TYPE_FINGER;
|
||||
tmpData.pointerID = pointerID;
|
||||
tmpData.state = isUp;
|
||||
tmpData.x = x;
|
||||
tmpData.y = y;
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_INPUT_STATE, ewol::threadMsg::MSG_PRIO_LOW, &tmpData, sizeof(eventInputState_ts) );
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_INPUT_STATE;
|
||||
data.input.type = ewol::INPUT_TYPE_FINGER;
|
||||
data.input.pointerID = pointerID;
|
||||
data.input.state = isUp;
|
||||
data.input.x = x;
|
||||
data.input.y = y;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void eSystem::SetMouseMotion(int pointerID, float x, float y )
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
eventInputMotion_ts tmpData;
|
||||
tmpData.type = ewol::INPUT_TYPE_MOUSE;
|
||||
tmpData.pointerID = pointerID;
|
||||
tmpData.x = x;
|
||||
tmpData.y = y;
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_INPUT_MOTION, ewol::threadMsg::MSG_PRIO_LOW, &tmpData, sizeof(eventInputMotion_ts) );
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_INPUT_MOTION;
|
||||
data.input.type = ewol::INPUT_TYPE_MOUSE;
|
||||
data.input.pointerID = pointerID;
|
||||
data.input.x = x;
|
||||
data.input.y = y;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,41 +354,53 @@ void eSystem::SetMouseMotion(int pointerID, float x, float y )
|
||||
void eSystem::SetMouseState(int pointerID, bool isUp, float x, float y )
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
eventInputState_ts tmpData;
|
||||
tmpData.type = ewol::INPUT_TYPE_MOUSE;
|
||||
tmpData.pointerID = pointerID;
|
||||
tmpData.state = isUp;
|
||||
tmpData.x = x;
|
||||
tmpData.y = y;
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_INPUT_STATE, ewol::threadMsg::MSG_PRIO_LOW, &tmpData, sizeof(eventInputState_ts) );
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_INPUT_STATE;
|
||||
data.input.type = ewol::INPUT_TYPE_MOUSE;
|
||||
data.input.pointerID = pointerID;
|
||||
data.input.state = isUp;
|
||||
data.input.x = x;
|
||||
data.input.y = y;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
|
||||
void eSystem::SetKeyboard(eSystem::keyboardKey_ts& keyInput)
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_KEYBORAD_KEY, ewol::threadMsg::MSG_PRIO_LOW, &keyInput, sizeof(eSystem::keyboardKey_ts) );
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_KEYBORAD_KEY;
|
||||
data.keyboardKey = keyInput;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
|
||||
void eSystem::SetKeyboardMove(eSystem::keyboardMove_ts& keyInput)
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_KEYBORAD_MOVE, ewol::threadMsg::MSG_PRIO_LOW, &keyInput, sizeof(eSystem::keyboardMove_ts) );
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_KEYBORAD_MOVE;
|
||||
data.keyboardMove = keyInput;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void eSystem::Hide(void)
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_HIDE, ewol::threadMsg::MSG_PRIO_LOW);
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_HIDE;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
|
||||
void eSystem::Show(void)
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_SHOW, ewol::threadMsg::MSG_PRIO_LOW);
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_SHOW;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -405,7 +408,10 @@ void eSystem::Show(void)
|
||||
void eSystem::ClipBoardArrive(ewol::clipBoard::clipboardListe_te clipboardID)
|
||||
{
|
||||
if (true == isGlobalSystemInit) {
|
||||
ewol::threadMsg::SendMessage(androidJniMsg, THREAD_CLIPBOARD_ARRIVE, ewol::threadMsg::MSG_PRIO_LOW, &clipboardID, sizeof(uint8_t));
|
||||
eSystemMessage_ts data;
|
||||
data.TypeMessage = THREAD_CLIPBOARD_ARRIVE;
|
||||
data.clipboardID = clipboardID;
|
||||
l_msgSystem.Post(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,272 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file threadMsg.cpp
|
||||
* @brief User abstraction for message to a specific thread (Sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 26/01/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <ewol/ewol.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/threadMsg.h>
|
||||
|
||||
void ewol::threadMsg::Init(ewol::threadMsg::threadMsg_ts& messageData)
|
||||
{
|
||||
for (int32_t iii=0; MSG_PRIO_NUMBER>iii; iii++) {
|
||||
messageData.nbMessages[iii] = 0;
|
||||
for (int32_t jjj=0; NUMBER_OF_ELEMENT_IN_THE_FIFO>jjj; jjj++) {
|
||||
messageData.listOfMessages[iii][jjj].isActive = false;
|
||||
}
|
||||
}
|
||||
messageData.isInit = true;
|
||||
}
|
||||
|
||||
void ewol::threadMsg::UnInit(ewol::threadMsg::threadMsg_ts& messageData)
|
||||
{
|
||||
if (true == messageData.isInit) {
|
||||
// remove data ????
|
||||
messageData.isInit = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ewol::threadMsg::WaitMessage(ewol::threadMsg::threadMsg_ts& messageData, ewol::threadMsg::threadMsgContent_ts &data)
|
||||
{
|
||||
if (false == messageData.isInit) {
|
||||
return false;
|
||||
}
|
||||
messageData.m_mutex.Lock();
|
||||
bool findAnOtherMessageInStack = false;
|
||||
for (int32_t iii=0; MSG_PRIO_NUMBER>iii; iii++) {
|
||||
if (0 < messageData.nbMessages[iii]) {
|
||||
findAnOtherMessageInStack = true;
|
||||
}
|
||||
}
|
||||
if (false == findAnOtherMessageInStack) {
|
||||
messageData.m_mutex.UnLock();
|
||||
messageData.m_semaphore.Wait();
|
||||
messageData.m_mutex.Lock();
|
||||
}
|
||||
// find the message :
|
||||
for (int32_t iii=0; MSG_PRIO_NUMBER>iii; iii++) {
|
||||
if (0 < messageData.nbMessages[iii]) {
|
||||
// find a message :
|
||||
if (false == messageData.listOfMessages[iii][0].isActive) {
|
||||
EWOL_ERROR( "an error occured ==> bad case ...");
|
||||
data.isActive = false;
|
||||
data.type = 0;
|
||||
data.data[0] = '\0';
|
||||
} else {
|
||||
data = messageData.listOfMessages[iii][0];
|
||||
messageData.listOfMessages[iii][0].isActive = false;
|
||||
}
|
||||
memmove(&messageData.listOfMessages[iii][0], &messageData.listOfMessages[iii][1], (NUMBER_OF_ELEMENT_IN_THE_FIFO-1)*sizeof(ewol::threadMsg::threadMsgContent_ts) );
|
||||
|
||||
messageData.listOfMessages[iii][NUMBER_OF_ELEMENT_IN_THE_FIFO-1].isActive = false;
|
||||
/*
|
||||
for (int32_t jjj=0; NUMBER_OF_ELEMENT_IN_THE_FIFO>jjj; jjj++) {
|
||||
if (true == messageData.listOfMessages[iii][jjj].isActive) {
|
||||
// copy the data :
|
||||
data = messageData.listOfMessages[iii][jjj];
|
||||
// disable the current message :
|
||||
messageData.listOfMessages[iii][jjj].isActive = false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
// decrement the number of message :
|
||||
messageData.nbMessages[iii]--;
|
||||
if (0>messageData.nbMessages[iii]) {
|
||||
messageData.nbMessages[iii] = 0;
|
||||
}
|
||||
// exit the waiting system ...
|
||||
break;
|
||||
}
|
||||
}
|
||||
messageData.m_mutex.UnLock();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ewol::threadMsg::SendMessage(ewol::threadMsg::threadMsg_ts& messageData, uint32_t type, ewol::threadMsg::msgPriority_te prio, void * data, uint32_t size)
|
||||
{
|
||||
if (false == messageData.isInit) {
|
||||
return false;
|
||||
}
|
||||
if ( 0>prio || MSG_PRIO_NUMBER <= prio) {
|
||||
EWOL_ERROR("Send message with an unknown priority ... " << prio);
|
||||
return false;
|
||||
}
|
||||
if (size > MAX_MSG_DATA_SIZE) {
|
||||
EWOL_ERROR("Send message with an biger size than predictible " << size << " > " << MAX_MSG_DATA_SIZE);
|
||||
return false;
|
||||
}
|
||||
messageData.m_mutex.Lock();
|
||||
int32_t lastNbMessage = messageData.nbMessages[prio];
|
||||
for (int32_t jjj=0; NUMBER_OF_ELEMENT_IN_THE_FIFO>jjj; jjj++) {
|
||||
if (messageData.listOfMessages[prio][jjj].isActive == false) {
|
||||
// we find a slot ...
|
||||
messageData.listOfMessages[prio][jjj].isActive = true;
|
||||
messageData.listOfMessages[prio][jjj].type = type;
|
||||
memset(messageData.listOfMessages[prio][jjj].data, 0, MAX_MSG_DATA_SIZE*sizeof(char) );
|
||||
if (data!=NULL) {
|
||||
memcpy(messageData.listOfMessages[prio][jjj].data, data, size);
|
||||
}
|
||||
//EWOL_DEBUG("Find Slot : (" << prio << "," << jjj << ")");
|
||||
messageData.nbMessages[prio]++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
EWOL_DEBUG("send message (" << messageData.nbMessages[MSG_PRIO_REAL_TIME] << ","
|
||||
<< messageData.nbMessages[MSG_PRIO_HIGH] << ","
|
||||
<< messageData.nbMessages[MSG_PRIO_MEDIUM] << ","
|
||||
<< messageData.nbMessages[MSG_PRIO_LOW] << ","
|
||||
<< messageData.nbMessages[MSG_PRIO_NONE] << ")");
|
||||
*/
|
||||
bool returnValue = false;
|
||||
if (lastNbMessage != messageData.nbMessages[prio]) {
|
||||
returnValue = true;
|
||||
} else {
|
||||
EWOL_ERROR("Send message Add error");
|
||||
returnValue = false;
|
||||
}
|
||||
messageData.m_semaphore.Post();
|
||||
messageData.m_mutex.UnLock();
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
int32_t ewol::threadMsg::WaitingMessage(threadMsg_ts& messageData)
|
||||
{
|
||||
if (false == messageData.isInit) {
|
||||
return false;
|
||||
}
|
||||
messageData.m_mutex.Lock();
|
||||
int32_t nbMessage = 0;
|
||||
for (int32_t iii=0; MSG_PRIO_NUMBER>iii; iii++) {
|
||||
nbMessage += messageData.nbMessages[iii];
|
||||
}
|
||||
messageData.m_mutex.UnLock();
|
||||
return nbMessage;
|
||||
}
|
||||
|
||||
bool ewol::threadMsg::HaveMessage(threadMsg_ts& messageData)
|
||||
{
|
||||
if (0 < WaitingMessage(messageData)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ewol::threadMsg::SendDisplayDone(threadMsg_ts& messageData)
|
||||
{
|
||||
if (false == messageData.isInit) {
|
||||
return;
|
||||
}
|
||||
messageData.m_mutex.Lock();
|
||||
messageData.displayHasDone = true;
|
||||
messageData.m_semaphore.Post();
|
||||
messageData.m_mutex.UnLock();
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool ewol::threadMsg::HasDisplayDone(threadMsg_ts& messageData)
|
||||
{
|
||||
if (false == messageData.isInit) {
|
||||
return false;
|
||||
}
|
||||
bool state = false;
|
||||
messageData.m_mutex.Lock();
|
||||
state = messageData.displayHasDone;
|
||||
messageData.displayHasDone = false;;
|
||||
messageData.m_mutex.UnLock();
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
|
||||
void ewol::simpleMsg::Init(ewol::simpleMsg::simpleMsg_ts& handle)
|
||||
{
|
||||
handle.messageValue = 0;
|
||||
handle.isInit = true;
|
||||
}
|
||||
|
||||
void ewol::simpleMsg::UnInit(ewol::simpleMsg::simpleMsg_ts& handle)
|
||||
{
|
||||
if (true == handle.isInit) {
|
||||
// remove data ????
|
||||
handle.isInit = false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ewol::simpleMsg::WaitingMessage(ewol::simpleMsg::simpleMsg_ts& handle, int32_t timeOut)
|
||||
{
|
||||
if (false == handle.isInit) {
|
||||
return 0;
|
||||
}
|
||||
handle.m_mutex.Lock();
|
||||
|
||||
if (0 == handle.messageValue) {
|
||||
handle.m_mutex.UnLock();
|
||||
if (handle.m_semaphore.Wait(timeOut)==false) {
|
||||
return false;
|
||||
}
|
||||
handle.m_mutex.Lock();
|
||||
}
|
||||
// copy message
|
||||
int32_t messageCopy = handle.messageValue;
|
||||
// reset it ...
|
||||
handle.messageValue = 0;
|
||||
|
||||
handle.m_mutex.UnLock();
|
||||
return messageCopy;
|
||||
}
|
||||
|
||||
void ewol::simpleMsg::SendMessage(ewol::simpleMsg::simpleMsg_ts& handle, uint32_t message)
|
||||
{
|
||||
if (false == handle.isInit) {
|
||||
return;
|
||||
}
|
||||
handle.m_mutex.Lock();
|
||||
handle.messageValue = message;
|
||||
handle.m_semaphore.Post();
|
||||
handle.m_mutex.UnLock();
|
||||
}
|
||||
|
||||
|
||||
void ewol::simpleMsg::Clear(simpleMsg_ts& handle)
|
||||
{
|
||||
if (false == handle.isInit) {
|
||||
return;
|
||||
}
|
||||
handle.m_mutex.Lock();
|
||||
if (handle.messageValue !=0) {
|
||||
handle.m_mutex.UnLock();
|
||||
handle.m_semaphore.Wait();
|
||||
return;
|
||||
}
|
||||
handle.m_mutex.UnLock();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,90 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file threadMsg.h
|
||||
* @brief User abstraction for message to a specific thread (Header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 26/01/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef __EWOL_TREAD_MSG_H__
|
||||
#define __EWOL_TREAD_MSG_H__
|
||||
|
||||
#include <etk/Mutex.h>
|
||||
#include <etk/Semaphore.h>
|
||||
|
||||
namespace ewol {
|
||||
namespace threadMsg {
|
||||
typedef enum {
|
||||
MSG_PRIO_REAL_TIME,
|
||||
MSG_PRIO_HIGH,
|
||||
MSG_PRIO_MEDIUM,
|
||||
MSG_PRIO_LOW,
|
||||
MSG_PRIO_NONE,
|
||||
MSG_PRIO_NUMBER,
|
||||
} msgPriority_te;
|
||||
|
||||
#define NUMBER_OF_ELEMENT_IN_THE_FIFO (1024)
|
||||
#define MAX_MSG_DATA_SIZE (128)
|
||||
typedef struct {
|
||||
bool isActive;
|
||||
uint32_t type;
|
||||
char data[MAX_MSG_DATA_SIZE];
|
||||
} threadMsgContent_ts;
|
||||
|
||||
|
||||
typedef struct {
|
||||
bool isInit;
|
||||
etk::Mutex m_mutex;
|
||||
etk::Semaphore m_semaphore;
|
||||
//etk::Vector<threadMsgContent_ts>
|
||||
threadMsgContent_ts listOfMessages[MSG_PRIO_NUMBER][NUMBER_OF_ELEMENT_IN_THE_FIFO];
|
||||
int32_t nbMessages[MSG_PRIO_NUMBER];
|
||||
bool displayHasDone;
|
||||
} threadMsg_ts;
|
||||
|
||||
void Init(threadMsg_ts& messageData);
|
||||
void UnInit(threadMsg_ts& messageData);
|
||||
bool WaitMessage(threadMsg_ts& messageData, threadMsgContent_ts &data);
|
||||
int32_t WaitingMessage(threadMsg_ts& messageData);
|
||||
bool HaveMessage(threadMsg_ts& messageData);
|
||||
bool SendMessage(threadMsg_ts& messageData, uint32_t type, msgPriority_te prio = MSG_PRIO_NONE, void * data = NULL, uint32_t size = 0);
|
||||
void SendDisplayDone(threadMsg_ts& messageData);
|
||||
bool HasDisplayDone(threadMsg_ts& messageData);
|
||||
};
|
||||
|
||||
namespace simpleMsg {
|
||||
typedef struct {
|
||||
bool isInit;
|
||||
etk::Mutex m_mutex;
|
||||
etk::Semaphore m_semaphore;
|
||||
uint32_t messageValue;
|
||||
} simpleMsg_ts;
|
||||
|
||||
void Init( simpleMsg_ts& handle);
|
||||
void UnInit( simpleMsg_ts& handle);
|
||||
uint32_t WaitingMessage(simpleMsg_ts& handle, int32_t timeOut=0);
|
||||
void SendMessage( simpleMsg_ts& handle, uint32_t message);
|
||||
void Clear( simpleMsg_ts& handle);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
# Basic elements
|
||||
FILE_LIST = ewol/ewol.cpp \
|
||||
ewol/threadMsg.cpp \
|
||||
ewol/openGl.cpp \
|
||||
ewol/ClipBoard.cpp \
|
||||
ewol/Debug.cpp \
|
||||
|
Loading…
x
Reference in New Issue
Block a user