- use mqueue to execute ua_stop_all Api function on re thread

This commit is contained in:
Juha Heinanen
2018-12-04 01:48:17 +02:00
parent 38e48917c4
commit f899675f45
4 changed files with 34 additions and 10 deletions
+31 -7
View File
@@ -153,9 +153,9 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
break; break;
case UA_EVENT_AUDIO_ERROR: case UA_EVENT_AUDIO_ERROR:
mem_deref(call); mem_deref(call);
return; goto out;
default: default:
return; goto out;
} }
event = event_buf; event = event_buf;
@@ -166,8 +166,8 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
if (res != JNI_OK) { if (res != JNI_OK) {
res = (*javaVM)->AttachCurrentThread(javaVM, &env, NULL); res = (*javaVM)->AttachCurrentThread(javaVM, &env, NULL);
if (JNI_OK != res) { if (JNI_OK != res) {
LOGE("failed to AttachCurrentThread, ErrorCode = %d", res); LOGE("failed to AttachCurrentThread, ErrorCode = %d\n", res);
return; goto out;
} }
} }
jmethodID methodId = (*env)->GetMethodID(env, pctx->mainActivityClz, jmethodID methodId = (*env)->GetMethodID(env, pctx->mainActivityClz,
@@ -183,6 +183,9 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
(*env)->DeleteLocalRef(env, javaUA); (*env)->DeleteLocalRef(env, javaUA);
(*env)->DeleteLocalRef(env, javaCall); (*env)->DeleteLocalRef(env, javaCall);
(*env)->DeleteLocalRef(env, javaEvent); (*env)->DeleteLocalRef(env, javaEvent);
out:
return;
} }
static void message_handler(struct ua *ua, const struct pl *peer, const struct pl *ctype, static void message_handler(struct ua *ua, const struct pl *peer, const struct pl *ctype,
@@ -204,7 +207,7 @@ static void message_handler(struct ua *ua, const struct pl *peer, const struct p
if (res != JNI_OK) { if (res != JNI_OK) {
res = (*javaVM)->AttachCurrentThread(javaVM, &env, NULL); res = (*javaVM)->AttachCurrentThread(javaVM, &env, NULL);
if (JNI_OK != res) { if (JNI_OK != res) {
LOGE("Failed to AttachCurrentThread, ErrorCode = %d", res); LOGE("failed to AttachCurrentThread, ErrorCode = %d\n", res);
return; return;
} }
} }
@@ -250,7 +253,7 @@ static void send_resp_handler(int err, const struct sip_msg *msg, void *arg)
if (res != JNI_OK) { if (res != JNI_OK) {
res = (*javaVM)->AttachCurrentThread(javaVM, &env, NULL); res = (*javaVM)->AttachCurrentThread(javaVM, &env, NULL);
if (JNI_OK != res) { if (JNI_OK != res) {
LOGE("Failed to AttachCurrentThread, ErrorCode = %d", res); LOGE("failed to AttachCurrentThread, ErrorCode = %d\n", res);
return; return;
} }
} }
@@ -262,6 +265,21 @@ static void send_resp_handler(int err, const struct sip_msg *msg, void *arg)
} }
enum {
ID_UA_STOP_ALL
};
static struct mqueue *mq;
static void mqueue_handler(int id, void *data, void *arg)
{
switch (id) {
case ID_UA_STOP_ALL:
LOGD("calling ua_stop_all with force %u\n", (unsigned)data);
ua_stop_all((bool)data);
}
}
#include <unistd.h> #include <unistd.h>
static int pfd[2]; static int pfd[2];
@@ -408,6 +426,11 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc
(*env)->DeleteLocalRef(env, javaUA); (*env)->DeleteLocalRef(env, javaUA);
} }
LOGI("allocating mqeue\n");
err = mqueue_alloc(&mq, mqueue_handler, NULL);
if (err)
goto out;
LOGI("running main loop ...\n"); LOGI("running main loop ...\n");
err = re_main(signal_handler); err = re_main(signal_handler);
@@ -422,6 +445,7 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc
play = mem_deref(play); play = mem_deref(play);
message = mem_deref(message); message = mem_deref(message);
mq = mem_deref(mq);
LOGD("closing ..."); LOGD("closing ...");
ua_close(); ua_close();
@@ -451,7 +475,7 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_com_tutpro_baresip_BaresipService_baresipStop(JNIEnv *env, jobject thiz, jboolean force) { Java_com_tutpro_baresip_BaresipService_baresipStop(JNIEnv *env, jobject thiz, jboolean force) {
LOGD("ua_stop_all upon baresipStop"); LOGD("ua_stop_all upon baresipStop");
ua_stop_all(force); mqueue_push(mq, ID_UA_STOP_ALL, (void *)force);
return; return;
} }
@@ -115,7 +115,8 @@ class ContactsActivity : AppCompatActivity() {
if (parts.size == 3) { if (parts.size == 3) {
val name = parts[1] val name = parts[1]
val uri = parts[2].trim() val uri = parts[2].trim()
Api.contact_add("\"$name\" $uri") // Currently no need to make baresip aware of the contact
// Api.contact_add("\"$name\" $uri")
Contact.contacts().add(Contact(name, uri)) Contact.contacts().add(Contact(name, uri))
} }
} }
@@ -102,7 +102,7 @@ class MainActivity : AppCompatActivity() {
stopState = "initial" stopState = "initial"
quitTimer = object: CountDownTimer(5000, 1000) { quitTimer = object: CountDownTimer(5000, 1000) {
override fun onTick(millisUntilFinished: Long) { override fun onTick(millisUntilFinished: Long) {
Log.d("Baresip", "seconds remaining: ${millisUntilFinished/1000}") Log.d("Baresip", "Seconds remaining: ${millisUntilFinished/1000}")
} }
override fun onFinish() { override fun onFinish() {
when (stopState) { when (stopState) {
-1
View File
@@ -10,7 +10,6 @@
- peers of calls and messages can be added to contacts by long clicks\n - peers of calls and messages can be added to contacts by long clicks\n
- long clicks can also be used to remove calls, chats, messages, and contacts\n - long clicks can also be used to remove calls, chats, messages, and contacts\n
- call click when callee has not been given can be used for re-dial\n - call click when callee has not been given can be used for re-dial\n
- quit without network connectivity may take up to 10 seconds\n
</string> </string>
<string name="noAccounts">No accounts</string> <string name="noAccounts">No accounts</string>
<string name="dispName">Name (if any) used in From URI of outbound requests.</string> <string name="dispName">Name (if any) used in From URI of outbound requests.</string>