Mercurial > dwindows
comparison android/dw.cpp @ 2584:2acc7ba5dea0
Add HTIMER type and change dw_timer_() functions to use it.
On existing platforms, HTIMER will be int for now allowing API backward compatibility.
On new platforms, iOS and Android, these will be pointers to the timer objects.
This allows simplifying the code paths on those platforms. May change it on other
platforms such as Mac in a future major version.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 23 May 2021 21:39:25 +0000 |
parents | 01fca1937806 |
children | 60ec91d23746 |
comparison
equal
deleted
inserted
replaced
2583:1d2f5c4eccc5 | 2584:2acc7ba5dea0 |
---|---|
278 case 0: | 278 case 0: |
279 { | 279 { |
280 int (*timerfunc)(void *) = (int (* API)(void *))handler->signalfunction; | 280 int (*timerfunc)(void *) = (int (* API)(void *))handler->signalfunction; |
281 | 281 |
282 if(!timerfunc(handler->data)) | 282 if(!timerfunc(handler->data)) |
283 dw_timer_disconnect(handler->id); | 283 dw_timer_disconnect(handler->window); |
284 retval = 0; | 284 retval = 0; |
285 break; | 285 break; |
286 } | 286 } |
287 /* Configure/Resize event */ | 287 /* Configure/Resize event */ |
288 case 1: | 288 case 1: |
5798 * sigfunc: The pointer to the function to be used as the callback. | 5798 * sigfunc: The pointer to the function to be used as the callback. |
5799 * data: User data to be passed to the handler function. | 5799 * data: User data to be passed to the handler function. |
5800 * Returns: | 5800 * Returns: |
5801 * Timer ID for use with dw_timer_disconnect(), 0 on error. | 5801 * Timer ID for use with dw_timer_disconnect(), 0 on error. |
5802 */ | 5802 */ |
5803 int API dw_timer_connect(int interval, void *sigfunc, void *data) | 5803 HTIMER API dw_timer_connect(int interval, void *sigfunc, void *data) |
5804 { | 5804 { |
5805 JNIEnv *env; | 5805 JNIEnv *env; |
5806 int retval = 0; | 5806 HTIMER retval = 0; |
5807 | 5807 |
5808 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 5808 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
5809 { | 5809 { |
5810 // Use a long paramater | 5810 // Use a long paramater |
5811 jlong longinterval = (jlong)interval; | 5811 jlong longinterval = (jlong)interval; |
5813 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 5813 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
5814 // Get the method that you want to call | 5814 // Get the method that you want to call |
5815 jmethodID timerConnect = env->GetMethodID(clazz, "timerConnect", | 5815 jmethodID timerConnect = env->GetMethodID(clazz, "timerConnect", |
5816 "(JJJ)Ljava/util/Timer;"); | 5816 "(JJJ)Ljava/util/Timer;"); |
5817 // Call the method on the object | 5817 // Call the method on the object |
5818 retval = DW_POINTER_TO_INT(_dw_jni_check_result(env, env->CallObjectMethod(_dw_obj, | 5818 retval = _dw_jni_check_result(env, env->CallObjectMethod(_dw_obj, |
5819 timerConnect, longinterval, (jlong)sigfunc, (jlong)data), _DW_REFERENCE_STRONG)); | 5819 timerConnect, longinterval, (jlong)sigfunc, (jlong)data), _DW_REFERENCE_STRONG); |
5820 } | 5820 } |
5821 return retval; | 5821 return retval; |
5822 } | 5822 } |
5823 | 5823 |
5824 /* | 5824 /* |
5825 * Removes timer callback. | 5825 * Removes timer callback. |
5826 * Parameters: | 5826 * Parameters: |
5827 * id: Timer ID returned by dw_timer_connect(). | 5827 * id: Timer ID returned by dw_timer_connect(). |
5828 */ | 5828 */ |
5829 void API dw_timer_disconnect(int timerid) | 5829 void API dw_timer_disconnect(HTIMER timerid) |
5830 { | 5830 { |
5831 JNIEnv *env; | 5831 JNIEnv *env; |
5832 | 5832 |
5833 if(timerid && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 5833 if(timerid && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
5834 { | 5834 { |
5835 // Use a long parameter | |
5836 jobject timer = (jobject)timerid; | |
5837 // First get the class that contains the method you need to call | 5835 // First get the class that contains the method you need to call |
5838 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 5836 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
5839 // Get the method that you want to call | 5837 // Get the method that you want to call |
5840 jmethodID timerDisconnect = env->GetMethodID(clazz, "timerDisconnect", | 5838 jmethodID timerDisconnect = env->GetMethodID(clazz, "timerDisconnect", |
5841 "(Ljava/util/Timer;)V"); | 5839 "(Ljava/util/Timer;)V"); |
5842 // Call the method on the object | 5840 // Call the method on the object |
5843 env->CallVoidMethod(_dw_obj, timerDisconnect, timer); | 5841 env->CallVoidMethod(_dw_obj, timerDisconnect, timerid); |
5844 _dw_jni_check_exception(env); | 5842 _dw_jni_check_exception(env); |
5845 } | 5843 } |
5846 } | 5844 } |
5847 | 5845 |
5848 /* | 5846 /* |