From 180ee063b701d07271894122d58d02ee9e81afc1 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Fri, 13 May 2022 19:22:43 +0300 Subject: [PATCH] Use new UA_EVENT_CREATE to create UserAgents --- app/src/main/cpp/baresip.c | 15 ++------- .../com/tutpro/baresip/BaresipService.kt | 31 ++++++++----------- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c index e3cf78e7..dee9a1fd 100644 --- a/app/src/main/cpp/baresip.c +++ b/app/src/main/cpp/baresip.c @@ -173,6 +173,9 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev, LOGD("ua event (%s) %s\n", uag_event_str(ev), prm); switch (ev) { + case UA_EVENT_CREATE: + len = re_snprintf(event_buf, sizeof event_buf, "create"); + break; case UA_EVENT_REGISTERING: case UA_EVENT_UNREGISTERING: case UA_EVENT_REGISTER_OK: @@ -526,15 +529,6 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc goto out; } - char ua_buf[32]; - struct ua *ua; - for (le = list_head(uag_list()); le != NULL; le = le->next) { - ua = le->data; - LOGD("adding UA for AoR %s/%ld\n", account_aor(ua_account(ua)), (long)ua); - jmethodID uaAddId = (*env)->GetMethodID(env, g_ctx.mainActivityClz, "uaAdd", "(J)V"); - (*env)->CallVoidMethod(env, g_ctx.mainActivityObj, uaAddId, (long)ua); - } - err = mqueue_alloc(&mq, mqueue_handler, NULL); if (err) { LOGW("mqueue_alloc failed (%d)\n", err); @@ -542,9 +536,6 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc goto out; } - for (le = list_head(uag_list()); le != NULL; le = le->next) - ua_print_status_log(le->data); - jmethodID startedId = (*env)->GetMethodID(env, g_ctx.mainActivityClz, "started", "()V"); (*env)->CallVoidMethod(env, g_ctx.mainActivityObj, startedId); diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index b4b84637..5f628b74 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -527,36 +527,31 @@ class BaresipService: Service() { } } - @Keep - fun uaAdd(uap: Long) { - val ua = UserAgent(uap) - ua.status = if (Api.ua_isregistered(uap)) { - Log.d(TAG, "Ua ${ua.account.aor} is registered") - R.drawable.dot_green - } else { - Log.d(TAG, "Ua ${ua.account.aor} is NOT registered") - if (ua.account.regint == 0) - R.drawable.dot_white - else - R.drawable.dot_yellow - } - Log.d(TAG, "uaAdd ${ua.account.aor} at BaresipService") - uas.add(ua) - } - @SuppressLint("UnspecifiedImmutableFlag") @Keep fun uaEvent(event: String, uap: Long, callp: Long) { if (!isServiceRunning) return + val ev = event.split(",") + + if (ev[0] == "create") { + val ua = UserAgent(uap) + ua.status = if (ua.account.regint == 0) + R.drawable.dot_white + else + R.drawable.dot_yellow + uas.add(UserAgent(uap)) + return; + } + val ua = UserAgent.ofUap(uap) if (ua == null) { Log.w(TAG, "uaEvent $event did not find ua $uap") return } - val ev = event.split(",") + val aor = ua.account.aor Log.d(TAG, "got uaEvent $event/$aor/$callp")