lpac-jni: Introduce convenience macros for linked lists
All checks were successful
/ build-debug (push) Successful in 4m41s
All checks were successful
/ build-debug (push) Successful in 4m41s
This commit is contained in:
parent
1c7dc67803
commit
1c0ddefad9
|
@ -1,3 +1,4 @@
|
|||
APP_ABI := all
|
||||
APP_SHORT_COMMANDS := true
|
||||
APP_CFLAGS := -Wno-compound-token-split-by-macro
|
||||
APP_LDFLAGS := -Wl,--build-id=none
|
|
@ -183,29 +183,21 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10cGetProfilesInfo(JNIEnv *env, jobject th
|
|||
jobjectArray ret = NULL;
|
||||
jobject jinfo = NULL;
|
||||
int count = 0;
|
||||
int i = 0;
|
||||
|
||||
if (es10c_get_profiles_info(ctx, &info) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
curr = info;
|
||||
while (curr != NULL) {
|
||||
curr = curr->next;
|
||||
count++;
|
||||
}
|
||||
count = LPAC_JNI_LINKED_LIST_COUNT(info, curr);
|
||||
|
||||
ret = (*env)->NewObjectArray(env, count, local_profile_info_class, NULL);
|
||||
|
||||
// Convert the native info array to Java
|
||||
curr = info;
|
||||
while (curr != NULL) {
|
||||
LPAC_JNI_LINKED_LIST_FOREACH(info, curr, {
|
||||
jinfo = profile_info_native_to_java(env, curr);
|
||||
(*env)->SetObjectArrayElement(env, ret, i, jinfo);
|
||||
(*env)->DeleteLocalRef(env, jinfo);
|
||||
curr = curr->next;
|
||||
i++;
|
||||
}
|
||||
});
|
||||
|
||||
es10c_profile_info_free_all(info);
|
||||
return ret;
|
||||
|
|
|
@ -13,6 +13,21 @@ struct lpac_jni_ctx {
|
|||
JNIEnv *env; \
|
||||
(*jvm)->AttachCurrentThread(jvm, &env, NULL)
|
||||
|
||||
#define __LPAC_JNI_LINKED_LIST_FOREACH(list, curr, body, after) { \
|
||||
int i = 0; \
|
||||
curr = list; \
|
||||
while (curr != NULL) { \
|
||||
body; \
|
||||
curr = curr->next; \
|
||||
i++; \
|
||||
}; \
|
||||
after; \
|
||||
}
|
||||
#define LPAC_JNI_LINKED_LIST_FOREACH(list, curr, body) \
|
||||
__LPAC_JNI_LINKED_LIST_FOREACH(list, curr, body, {})
|
||||
#define LPAC_JNI_LINKED_LIST_COUNT(list, curr) \
|
||||
(__LPAC_JNI_LINKED_LIST_FOREACH(list, curr, {}, i))
|
||||
|
||||
extern JavaVM *jvm;
|
||||
extern jclass string_class;
|
||||
|
||||
|
|
|
@ -39,21 +39,15 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10bListNotification(JNIEnv *env, jobject t
|
|||
jobject operation = NULL;
|
||||
jobjectArray ret = NULL;
|
||||
int count = 0;
|
||||
int i = 0;
|
||||
|
||||
if (es10b_list_notification(ctx, &info) < 0)
|
||||
return NULL;
|
||||
|
||||
curr = info;
|
||||
while (curr != NULL) {
|
||||
curr = curr->next;
|
||||
count++;
|
||||
}
|
||||
count = LPAC_JNI_LINKED_LIST_COUNT(info, curr);
|
||||
|
||||
ret = (*env)->NewObjectArray(env, count, local_profile_notification_class, NULL);
|
||||
|
||||
curr = info;
|
||||
while (curr != NULL) {
|
||||
LPAC_JNI_LINKED_LIST_FOREACH(info, curr, {
|
||||
operation =
|
||||
(*env)->CallStaticObjectMethod(env, local_profile_notification_operation_class,
|
||||
local_profile_notification_operation_from_string,
|
||||
|
@ -69,10 +63,7 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10bListNotification(JNIEnv *env, jobject t
|
|||
|
||||
(*env)->DeleteLocalRef(env, operation);
|
||||
(*env)->DeleteLocalRef(env, notification);
|
||||
|
||||
curr = curr->next;
|
||||
i++;
|
||||
}
|
||||
});
|
||||
|
||||
es10b_notification_metadata_free_all(info);
|
||||
return ret;
|
||||
|
|
Loading…
Reference in a new issue