/** * @author Edouard DUPIN, Kevin BILLONNEAU * * @copyright 2011, Edouard DUPIN, all right reserved * * @license APACHE v2.0 (see license file) */ #include #include #include #include #include #include #include #include #include /* include auto generated file */ #include #include int64_t gale::getTime() { struct timeval now; gettimeofday(&now, nullptr); //GALE_VERBOSE("current time : " << now.tv_sec << "s " << now.tv_usec << "us"); return (int64_t)((int64_t)now.tv_sec*(int64_t)1000000 + (int64_t)now.tv_usec); } // jni doc : /usr/lib/jvm/java-1.6.0-openjdk/include std::mutex g_interfaceMutex; class AndroidContext : public gale::Context { public: enum application { appl_unknow, appl_application, appl_wallpaper }; private: enum application m_javaApplicationType; // get a resources from the java environement : JNIEnv* m_JavaVirtualMachinePointer; //!< the JVM jclass m_javaClassGale; //!< main activity class (android ...) jclass m_javaClassGaleCallback; jobject m_javaObjectGaleCallback; jmethodID m_javaMethodGaleCallbackStop; //!< Stop function identifier jmethodID m_javaMethodGaleCallbackEventNotifier; //!< basic methode to call ... jmethodID m_javaMethodGaleCallbackKeyboardUpdate; //!< basic methode to call ... jmethodID m_javaMethodGaleCallbackOrientationUpdate; jmethodID m_javaMethodGaleActivitySetTitle; jmethodID m_javaMethodGaleActivityOpenURI; jmethodID m_javaMethodGaleActivitySetClipBoardString; jmethodID m_javaMethodGaleActivityGetClipBoardString; jclass m_javaDefaultClassString; //!< default string class int32_t m_currentHeight; gale::key::Special m_guiKeyBoardSpecialKeyMode;//!< special key of the android system : bool m_clipBoardOwnerStd; private: bool safeInitMethodID(jmethodID& _mid, jclass& _cls, const char* _name, const char* _sign) { _mid = m_JavaVirtualMachinePointer->GetMethodID(_cls, _name, _sign); if(_mid == nullptr) { GALE_ERROR("C->java : Can't find the method " << _name); /* remove access on the virtual machine : */ m_JavaVirtualMachinePointer = nullptr; return false; } return true; } public: AndroidContext(gale::context::Application* _application, JNIEnv* _env, jclass _classBase, jobject _objCallback, enum application _typeAPPL) : gale::Context(_application), m_javaApplicationType(_typeAPPL), m_JavaVirtualMachinePointer(nullptr), m_javaClassGale(0), m_javaClassGaleCallback(0), m_javaObjectGaleCallback(0), m_javaMethodGaleCallbackStop(0), m_javaMethodGaleCallbackEventNotifier(0), m_javaMethodGaleCallbackKeyboardUpdate(0), m_javaMethodGaleCallbackOrientationUpdate(0), m_javaMethodGaleActivitySetTitle(0), m_javaMethodGaleActivityOpenURI(0), m_javaMethodGaleActivitySetClipBoardString(0), m_javaMethodGaleActivityGetClipBoardString(0), m_javaDefaultClassString(0), m_currentHeight(0), m_clipBoardOwnerStd(false) { GALE_DEBUG("*******************************************"); if (m_javaApplicationType == appl_application) { GALE_DEBUG("** set JVM Pointer (application) **"); } else { GALE_DEBUG("** set JVM Pointer (LiveWallpaper) **"); } GALE_DEBUG("*******************************************"); m_JavaVirtualMachinePointer = _env; // get default needed all time elements : if (nullptr != m_JavaVirtualMachinePointer) { GALE_DEBUG("C->java : try load org/gale/Gale class"); m_javaClassGale = m_JavaVirtualMachinePointer->FindClass("org/gale/Gale" ); if (m_javaClassGale == 0) { GALE_ERROR("C->java : Can't find org/gale/Gale class"); // remove access on the virtual machine : m_JavaVirtualMachinePointer = nullptr; return; } /* The object field extends Activity and implement GaleCallback */ m_javaClassGaleCallback = m_JavaVirtualMachinePointer->GetObjectClass(_objCallback); if(m_javaClassGaleCallback == nullptr) { GALE_ERROR("C->java : Can't find org/gale/GaleCallback class"); // remove access on the virtual machine : m_JavaVirtualMachinePointer = nullptr; return; } bool functionCallbackIsMissing = false; bool ret= false; ret = safeInitMethodID(m_javaMethodGaleActivitySetTitle, m_javaClassGaleCallback, "titleSet", "(Ljava/lang/String;)V"); if (ret == false) { jvm_basics::checkExceptionJavaVM(_env); GALE_ERROR("system can not start without function : titleSet"); functionCallbackIsMissing = true; } ret = safeInitMethodID(m_javaMethodGaleActivityOpenURI, m_javaClassGaleCallback, "openURI", "(Ljava/lang/String;)V"); if (ret == false) { jvm_basics::checkExceptionJavaVM(_env); GALE_ERROR("system can not start without function : openURI"); functionCallbackIsMissing = true; } ret = safeInitMethodID(m_javaMethodGaleCallbackStop, m_javaClassGaleCallback, "stop", "()V"); if (ret == false) { jvm_basics::checkExceptionJavaVM(_env); GALE_ERROR("system can not start without function : stop"); functionCallbackIsMissing = true; } ret = safeInitMethodID(m_javaMethodGaleCallbackEventNotifier, m_javaClassGaleCallback, "eventNotifier", "([Ljava/lang/String;)V"); if (ret == false) { jvm_basics::checkExceptionJavaVM(_env); GALE_ERROR("system can not start without function : eventNotifier"); functionCallbackIsMissing = true; } ret = safeInitMethodID(m_javaMethodGaleCallbackKeyboardUpdate, m_javaClassGaleCallback, "keyboardUpdate", "(Z)V"); if (ret == false) { jvm_basics::checkExceptionJavaVM(_env); GALE_ERROR("system can not start without function : keyboardUpdate"); functionCallbackIsMissing = true; } ret = safeInitMethodID(m_javaMethodGaleCallbackOrientationUpdate, m_javaClassGaleCallback, "orientationUpdate", "(I)V"); if (ret == false) { jvm_basics::checkExceptionJavaVM(_env); GALE_ERROR("system can not start without function : orientationUpdate"); functionCallbackIsMissing = true; } ret = safeInitMethodID(m_javaMethodGaleActivitySetClipBoardString, m_javaClassGaleCallback, "setClipBoardString", "(Ljava/lang/String;)V"); if (ret == false) { jvm_basics::checkExceptionJavaVM(_env); GALE_ERROR("system can not start without function : setClipBoardString"); functionCallbackIsMissing = true; } ret = safeInitMethodID(m_javaMethodGaleActivityGetClipBoardString, m_javaClassGaleCallback, "getClipBoardString", "()Ljava/lang/String;"); if (ret == false) { jvm_basics::checkExceptionJavaVM(_env); GALE_ERROR("system can not start without function : getClipBoardString"); functionCallbackIsMissing = true; } m_javaObjectGaleCallback = _env->NewGlobalRef(_objCallback); //javaObjectGaleCallbackAndActivity = objCallback; if (m_javaObjectGaleCallback == nullptr) { functionCallbackIsMissing = true; } m_javaDefaultClassString = m_JavaVirtualMachinePointer->FindClass("java/lang/String" ); if (m_javaDefaultClassString == 0) { GALE_ERROR("C->java : Can't find java/lang/String" ); // remove access on the virtual machine : m_JavaVirtualMachinePointer = nullptr; functionCallbackIsMissing = true; } if (functionCallbackIsMissing == true) { GALE_CRITICAL(" mission one function ==> system can not work withut it..."); } } } ~AndroidContext() { // TODO ... } void unInit(JNIEnv* _env) { _env->DeleteGlobalRef(m_javaObjectGaleCallback); m_javaObjectGaleCallback = nullptr; } int32_t run() { // might never be called !!! return -1; } void stop() { GALE_DEBUG("C->java : send message to the java : STOP REQUESTED"); int status; if(!java_attach_current_thread(&status)) { return; } //Call java ... m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectGaleCallback, m_javaMethodGaleCallbackStop); // manage execption : jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer); java_detach_current_thread(status); } void clipBoardGet(enum gale::context::clipBoard::clipboardListe _clipboardID) { // this is to force the local system to think we have the buffer // TODO : remove this 2 line when code will be writen m_clipBoardOwnerStd = true; switch (_clipboardID) { case gale::context::clipBoard::clipboardSelection: // NOTE : Windows does not support the middle button the we do it internaly // just transmit an event , we have the data in the system OS_ClipBoardArrive(_clipboardID); break; case gale::context::clipBoard::clipboardStd: if (false == m_clipBoardOwnerStd) { // generate a request TO the OS // TODO : Send the message to the OS "We disire to receive the copy buffer ... } else { // just transmit an event , we have the data in the system OS_ClipBoardArrive(_clipboardID); } break; default: GALE_ERROR("Request an unknow ClipBoard ..."); break; } } void clipBoardSet(enum gale::context::clipBoard::clipboardListe _clipboardID) { switch (_clipboardID) { case gale::context::clipBoard::clipboardSelection: // NOTE : nothing to do : Windows deas ot supported Middle button break; case gale::context::clipBoard::clipboardStd: // Request the clipBoard : GALE_DEBUG("C->java : set clipboard"); if (m_javaApplicationType == appl_application) { int status; if(!java_attach_current_thread(&status)) { return; } //Call java ... jstring data = m_JavaVirtualMachinePointer->NewStringUTF(gale::context::clipBoard::get(_clipboardID).c_str()); m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectGaleCallback, m_javaMethodGaleActivityGetClipBoardString, data); m_JavaVirtualMachinePointer->DeleteLocalRef(data); // manage execption : jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer); java_detach_current_thread(status); } else { GALE_ERROR("C->java : can not set clipboard"); } break; default: GALE_ERROR("Request an unknow ClipBoard ..."); break; } } private: bool java_attach_current_thread(int *_rstatus) { GALE_DEBUG("C->java : call java"); if (jvm_basics::getJavaVM() == nullptr) { GALE_ERROR("C->java : JVM not initialised"); m_JavaVirtualMachinePointer = nullptr; return false; } *_rstatus = jvm_basics::getJavaVM()->GetEnv((void **) &m_JavaVirtualMachinePointer, JNI_VERSION_1_6); if (*_rstatus == JNI_EDETACHED) { JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = "GaleNativeThread"; lJavaVMAttachArgs.group = nullptr; int status = jvm_basics::getJavaVM()->AttachCurrentThread(&m_JavaVirtualMachinePointer, &lJavaVMAttachArgs); jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer); if (status != JNI_OK) { GALE_ERROR("C->java : AttachCurrentThread failed : " << status); m_JavaVirtualMachinePointer = nullptr; return false; } } return true; } void java_detach_current_thread(int _status) { if(_status == JNI_EDETACHED) { jvm_basics::getJavaVM()->DetachCurrentThread(); m_JavaVirtualMachinePointer = nullptr; } } void sendJavaKeyboardUpdate(jboolean _showIt) { int status; if(!java_attach_current_thread(&status)) { return; } //Call java ... m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectGaleCallback, m_javaMethodGaleCallbackKeyboardUpdate, _showIt); // manage execption : jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer); java_detach_current_thread(status); } void keyboardShow() { sendJavaKeyboardUpdate(JNI_TRUE); }; void keyboardHide() { sendJavaKeyboardUpdate(JNI_FALSE); }; // mode 0 : auto; 1 landscape, 2 portrait void forceOrientation(enum gale::orientation _orientation) { int status; if(!java_attach_current_thread(&status)) { return; } jint param = (jint)_orientation; //Call java ... m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectGaleCallback, m_javaMethodGaleCallbackOrientationUpdate, param); // manage execption : jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer); java_detach_current_thread(status); } void setTitle(const std::string& _title) { GALE_DEBUG("C->java : send message to the java : \"" << _title << "\""); if (m_javaApplicationType == appl_application) { int status; if(!java_attach_current_thread(&status)) { return; } //Call java ... jstring title = m_JavaVirtualMachinePointer->NewStringUTF(_title.c_str()); m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectGaleCallback, m_javaMethodGaleActivitySetTitle, title); m_JavaVirtualMachinePointer->DeleteLocalRef(title); // manage execption : jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer); java_detach_current_thread(status); } else { GALE_ERROR("C->java : can not set title on appliation that is not real application"); } } void openURL(const std::string& _url) { GALE_DEBUG("C->java : send message to the java : open URL'" << _url << "'"); int status; if(!java_attach_current_thread(&status)) { return; } //Call java ... jstring url = m_JavaVirtualMachinePointer->NewStringUTF(_url.c_str()); m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectGaleCallback, m_javaMethodGaleActivityOpenURI, url); m_JavaVirtualMachinePointer->DeleteLocalRef(url); // manage execption : jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer); java_detach_current_thread(status); } void sendSystemMessage(const char* _dataString) { GALE_DEBUG("C->java : send message to the java : \"" << _dataString << "\""); int status; if(!java_attach_current_thread(&status)) { return; } GALE_DEBUG("C->java : 222"); if (nullptr == _dataString) { GALE_ERROR("C->java : No data to send ..."); return; } GALE_DEBUG("C->java : 333"); // create the string to the java jstring jstr = m_JavaVirtualMachinePointer->NewStringUTF(_dataString); if (jstr == 0) { GALE_ERROR("C->java : Out of memory" ); return; } GALE_DEBUG("C->java : 444"); // create argument list jobjectArray args = m_JavaVirtualMachinePointer->NewObjectArray(1, m_javaDefaultClassString, jstr); if (args == 0) { GALE_ERROR("C->java : Out of memory" ); return; } GALE_DEBUG("C->java : 555"); //Call java ... m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectGaleCallback, m_javaMethodGaleCallbackEventNotifier, args); GALE_DEBUG("C->java : 666"); jvm_basics::checkExceptionJavaVM(m_JavaVirtualMachinePointer); java_detach_current_thread(status); } public: void OS_SetInputMotion(int _pointerID, const vec2& _pos) { gale::Context::OS_SetInputMotion(_pointerID, vec2(_pos.x(),m_currentHeight-_pos.y()) ); } void OS_SetInputState(int _pointerID, bool _isDown, const vec2& _pos) { gale::Context::OS_SetInputState(_pointerID, _isDown, vec2(_pos.x(),m_currentHeight-_pos.y()) ); } void OS_SetMouseMotion(int _pointerID, const vec2& _pos) { gale::Context::OS_SetMouseMotion(_pointerID, vec2(_pos.x(),m_currentHeight-_pos.y()) ); } void OS_SetMouseState(int _pointerID, bool _isDown, const vec2& _pos) { gale::Context::OS_SetMouseState(_pointerID, _isDown, vec2(_pos.x(),m_currentHeight-_pos.y()) ); } void ANDROID_SetKeyboard(char32_t _myChar, bool _isDown, bool _isARepeateKey=false) { OS_SetKeyboard(m_guiKeyBoardSpecialKeyMode, _myChar, _isDown, _isARepeateKey); } bool ANDROID_systemKeyboradEvent(enum gale::key::keyboardSystem _key, bool _down) { return systemKeyboradEvent(_key, _down); } void ANDROID_SetKeyboardMove(int _move, bool _isDown, bool _isARepeateKey=false) { // direct wrapping : enum gale::key::keyboard move = (enum gale::key::keyboard)_move; m_guiKeyBoardSpecialKeyMode.update(move, _isDown); OS_SetKeyboardMove(m_guiKeyBoardSpecialKeyMode, move, _isDown, _isARepeateKey); } void OS_Resize(const vec2& _size) { m_currentHeight = _size.y(); gale::Context::OS_Resize(_size); } }; static std::vector s_listInstance; gale::context::Application* s_applicationInit = NULL; extern "C" { /* Call to initialize the graphics state */ void Java_org_gale_Gale_EWparamSetArchiveDir(JNIEnv* _env, jclass _cls, jint _id, jint _mode, jstring _myString) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } //GALE_CRITICAL(" call with ID : " << _id); // direct setting of the date in the string system ... jboolean isCopy; const char* str = _env->GetStringUTFChars(_myString, &isCopy); s_listInstance[_id]->setArchiveDir(_mode, str); if (isCopy == JNI_TRUE) { // from here str is reset ... _env->ReleaseStringUTFChars(_myString, str); str = nullptr; } } // declare main application instance like an application: int main(int argc, char**argv); jint Java_org_gale_Gale_EWsetJavaVirtualMachineStart(JNIEnv* _env, jclass _classBase, jobject _objCallback, int _typeApplication) { std::unique_lock lock(g_interfaceMutex); GALE_DEBUG("*******************************************"); GALE_DEBUG("** Creating GALE context **"); GALE_DEBUG("*******************************************"); AndroidContext* tmpContext = nullptr; s_applicationInit = NULL; gale::context::Application* localApplication = NULL; // call the basic init of all application (that call us ...) main(0,NULL); localApplication = s_applicationInit; s_applicationInit = NULL; if (org_gale_GaleConstants_GALE_APPL_TYPE_ACTIVITY == _typeApplication) { tmpContext = new AndroidContext(localApplication, _env, _classBase, _objCallback, AndroidContext::appl_application); } else if (org_gale_GaleConstants_GALE_APPL_TYPE_WALLPAPER == _typeApplication) { tmpContext = new AndroidContext(localApplication, _env, _classBase, _objCallback, AndroidContext::appl_wallpaper); } else { GALE_CRITICAL(" try to create an instance with no apply type: " << _typeApplication); return -1; } if (nullptr == tmpContext) { GALE_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.size()-1)); return -1; } // for future case : all time this ... s_listInstance.push_back(tmpContext); int32_t newID = s_listInstance.size()-1; return newID; } void Java_org_gale_Gale_EWsetJavaVirtualMachineStop(JNIEnv* _env, jclass _cls, jint _id) { std::unique_lock lock(g_interfaceMutex); GALE_DEBUG("*******************************************"); GALE_DEBUG("** remove JVM Pointer **"); GALE_DEBUG("*******************************************"); if( _id >= (int32_t)s_listInstance.size() || _id<0) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); return; } if (nullptr == s_listInstance[_id]) { GALE_ERROR("the requested instance _id=" << (int32_t)_id << " is already removed ..."); return; } s_listInstance[_id]->unInit(_env); delete(s_listInstance[_id]); s_listInstance[_id]=nullptr; } void Java_org_gale_Gale_EWtouchEvent(JNIEnv* _env, jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); GALE_DEBUG(" == > Touch Event"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } jvm_basics::checkExceptionJavaVM(_env); } void Java_org_gale_Gale_EWonCreate(JNIEnv* _env, jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); GALE_DEBUG("*******************************************"); GALE_DEBUG("** Activity on Create **"); GALE_DEBUG("*******************************************"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } //s_listInstance[_id]->init(); } void Java_org_gale_Gale_EWonStart(JNIEnv* _env, jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); GALE_DEBUG("*******************************************"); GALE_DEBUG("** Activity on Start **"); GALE_DEBUG("*******************************************"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } //SendSystemMessage(" testmessages ... "); } void Java_org_gale_Gale_EWonReStart(JNIEnv* _env, jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); GALE_DEBUG("*******************************************"); GALE_DEBUG("** Activity on Re-Start **"); GALE_DEBUG("*******************************************"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } } void Java_org_gale_Gale_EWonResume(JNIEnv* _env, jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); GALE_DEBUG("*******************************************"); GALE_DEBUG("** Activity on resume **"); GALE_DEBUG("*******************************************"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } s_listInstance[_id]->OS_Resume(); } void Java_org_gale_Gale_EWonPause(JNIEnv* _env, jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); GALE_DEBUG("*******************************************"); GALE_DEBUG("** Activity on pause **"); GALE_DEBUG("*******************************************"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } // All the openGl has been destroyed ... s_listInstance[_id]->getResourcesManager().contextHasBeenDestroyed(); s_listInstance[_id]->OS_Suspend(); } void Java_org_gale_Gale_EWonStop(JNIEnv* _env, jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); GALE_DEBUG("*******************************************"); GALE_DEBUG("** Activity on Stop **"); GALE_DEBUG("*******************************************"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } s_listInstance[_id]->OS_Stop(); } void Java_org_gale_Gale_EWonDestroy(JNIEnv* _env, jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); GALE_DEBUG("*******************************************"); GALE_DEBUG("** Activity on Destroy **"); GALE_DEBUG("*******************************************"); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } //s_listInstance[_id]->UnInit(); } /* ********************************************************************************************** * ** IO section : * ********************************************************************************************** */ void Java_org_gale_Gale_EWinputEventMotion(JNIEnv* _env, jobject _thiz, jint _id, jint _pointerID, jfloat _x, jfloat _y) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } s_listInstance[_id]->OS_SetInputMotion(_pointerID+1, vec2(_x,_y)); } void Java_org_gale_Gale_EWinputEventState(JNIEnv* _env, jobject _thiz, jint _id, jint _pointerID, jboolean _isUp, jfloat _x, jfloat _y) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } s_listInstance[_id]->OS_SetInputState(_pointerID+1, _isUp, vec2(_x,_y)); } void Java_org_gale_Gale_EWmouseEventMotion(JNIEnv* _env, jobject _thiz, jint _id, jint _pointerID, jfloat _x, jfloat _y) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } s_listInstance[_id]->OS_SetMouseMotion(_pointerID+1, vec2(_x,_y)); } void Java_org_gale_Gale_EWmouseEventState(JNIEnv* _env, jobject _thiz, jint _id, jint _pointerID, jboolean _isUp, jfloat _x, jfloat _y) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } s_listInstance[_id]->OS_SetMouseState(_pointerID+1, _isUp, vec2(_x,_y)); } void Java_org_gale_Gale_EWunknowEvent(JNIEnv* _env, jobject _thiz, jint _id, jint _pointerID) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } GALE_DEBUG("Unknown IO event : " << _pointerID << " ???"); } void Java_org_gale_Gale_EWkeyboardEventMove(JNIEnv* _env, jobject _thiz, jint _id, jint _type, jboolean _isdown) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } GALE_DEBUG("IO keyboard Move event : \"" << _type << "\" is down=" << _isdown); s_listInstance[_id]->ANDROID_SetKeyboardMove(_type, _isdown); } void Java_org_gale_Gale_EWkeyboardEventKey(JNIEnv* _env, jobject _thiz, jint _id, jint _uniChar, jboolean _isdown) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } GALE_DEBUG("IO keyboard Key event : \"" << _uniChar << "\" is down=" << _isdown); s_listInstance[_id]->ANDROID_SetKeyboard(_uniChar, _isdown); } void Java_org_gale_Gale_EWdisplayPropertyMetrics(JNIEnv* _env, jobject _thiz, jint _id, jfloat _ratioX, jfloat _ratioY) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } // set the internal system ratio properties ... gale::Dimension::setPixelRatio(vec2(_ratioX,_ratioY), gale::Dimension::Inch); } // TODO : set a return true or false if we want to grep this event ... bool Java_org_gale_Gale_EWkeyboardEventKeySystem(JNIEnv* _env, jobject _thiz, jint _id, jint _keyVal, jboolean _isdown) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return false; } switch (_keyVal) { case org_gale_GaleConstants_GALE_SYSTEM_KEY_VOLUME_UP: GALE_VERBOSE("IO keyboard Key system \"VOLUME_UP\" is down=" << _isdown); return s_listInstance[_id]->ANDROID_systemKeyboradEvent(gale::key::keyboardSystemVolumeUp, _isdown); case org_gale_GaleConstants_GALE_SYSTEM_KEY_VOLUME_DOWN: GALE_DEBUG("IO keyboard Key system \"VOLUME_DOWN\" is down=" << _isdown); return s_listInstance[_id]->ANDROID_systemKeyboradEvent(gale::key::keyboardSystemVolumeDown, _isdown); case org_gale_GaleConstants_GALE_SYSTEM_KEY_MENU: GALE_DEBUG("IO keyboard Key system \"MENU\" is down=" << _isdown); return s_listInstance[_id]->ANDROID_systemKeyboradEvent(gale::key::keyboardSystemMenu, _isdown); case org_gale_GaleConstants_GALE_SYSTEM_KEY_CAMERA: GALE_DEBUG("IO keyboard Key system \"CAMERA\" is down=" << _isdown); return s_listInstance[_id]->ANDROID_systemKeyboradEvent(gale::key::keyboardSystemCamera, _isdown); case org_gale_GaleConstants_GALE_SYSTEM_KEY_HOME: GALE_DEBUG("IO keyboard Key system \"HOME\" is down=" << _isdown); return s_listInstance[_id]->ANDROID_systemKeyboradEvent(gale::key::keyboardSystemHome, _isdown); case org_gale_GaleConstants_GALE_SYSTEM_KEY_POWER: GALE_DEBUG("IO keyboard Key system \"POWER\" is down=" << _isdown); return s_listInstance[_id]->ANDROID_systemKeyboradEvent(gale::key::keyboardSystemPower, _isdown); case org_gale_GaleConstants_GALE_SYSTEM_KEY_BACK: GALE_DEBUG("IO keyboard Key system \"BACK\" is down=" << _isdown); return s_listInstance[_id]->ANDROID_systemKeyboradEvent(gale::key::keyboardSystemBack, _isdown); default: GALE_ERROR("IO keyboard Key system event : \"" << _keyVal << "\" is down=" << _isdown); break; } return false; } /* ********************************************************************************************** * ** Renderer section : * ********************************************************************************************** */ void Java_org_gale_Gale_EWrenderInit(JNIEnv* _env, jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } } void Java_org_gale_Gale_EWrenderResize(JNIEnv* _env, jobject _thiz, jint _id, jint _w, jint _h) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } s_listInstance[_id]->OS_Resize(vec2(_w, _h)); } // TODO : Return true or false to not redraw when the under draw has not be done (processing gain of time) void Java_org_gale_Gale_EWrenderDraw(JNIEnv* _env, jobject _thiz, jint _id) { std::unique_lock lock(g_interfaceMutex); if( _id >= (int32_t)s_listInstance.size() || _id<0 || nullptr == s_listInstance[_id] ) { GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); // TODO : generate error in java to stop the current instance return; } s_listInstance[_id]->OS_Draw(true); } }; int gale::run(gale::context::Application* _application, int _argc, const char *_argv[]) { s_applicationInit = _application; return 0; }