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_ABI := all
|
||||||
APP_SHORT_COMMANDS := true
|
APP_SHORT_COMMANDS := true
|
||||||
|
APP_CFLAGS := -Wno-compound-token-split-by-macro
|
||||||
APP_LDFLAGS := -Wl,--build-id=none
|
APP_LDFLAGS := -Wl,--build-id=none
|
|
@ -183,29 +183,21 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10cGetProfilesInfo(JNIEnv *env, jobject th
|
||||||
jobjectArray ret = NULL;
|
jobjectArray ret = NULL;
|
||||||
jobject jinfo = NULL;
|
jobject jinfo = NULL;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (es10c_get_profiles_info(ctx, &info) < 0) {
|
if (es10c_get_profiles_info(ctx, &info) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
curr = info;
|
count = LPAC_JNI_LINKED_LIST_COUNT(info, curr);
|
||||||
while (curr != NULL) {
|
|
||||||
curr = curr->next;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = (*env)->NewObjectArray(env, count, local_profile_info_class, NULL);
|
ret = (*env)->NewObjectArray(env, count, local_profile_info_class, NULL);
|
||||||
|
|
||||||
// Convert the native info array to Java
|
// Convert the native info array to Java
|
||||||
curr = info;
|
LPAC_JNI_LINKED_LIST_FOREACH(info, curr, {
|
||||||
while (curr != NULL) {
|
|
||||||
jinfo = profile_info_native_to_java(env, curr);
|
jinfo = profile_info_native_to_java(env, curr);
|
||||||
(*env)->SetObjectArrayElement(env, ret, i, jinfo);
|
(*env)->SetObjectArrayElement(env, ret, i, jinfo);
|
||||||
(*env)->DeleteLocalRef(env, jinfo);
|
(*env)->DeleteLocalRef(env, jinfo);
|
||||||
curr = curr->next;
|
});
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
es10c_profile_info_free_all(info);
|
es10c_profile_info_free_all(info);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -13,6 +13,21 @@ struct lpac_jni_ctx {
|
||||||
JNIEnv *env; \
|
JNIEnv *env; \
|
||||||
(*jvm)->AttachCurrentThread(jvm, &env, NULL)
|
(*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 JavaVM *jvm;
|
||||||
extern jclass string_class;
|
extern jclass string_class;
|
||||||
|
|
||||||
|
|
|
@ -39,21 +39,15 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10bListNotification(JNIEnv *env, jobject t
|
||||||
jobject operation = NULL;
|
jobject operation = NULL;
|
||||||
jobjectArray ret = NULL;
|
jobjectArray ret = NULL;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (es10b_list_notification(ctx, &info) < 0)
|
if (es10b_list_notification(ctx, &info) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
curr = info;
|
count = LPAC_JNI_LINKED_LIST_COUNT(info, curr);
|
||||||
while (curr != NULL) {
|
|
||||||
curr = curr->next;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = (*env)->NewObjectArray(env, count, local_profile_notification_class, NULL);
|
ret = (*env)->NewObjectArray(env, count, local_profile_notification_class, NULL);
|
||||||
|
|
||||||
curr = info;
|
LPAC_JNI_LINKED_LIST_FOREACH(info, curr, {
|
||||||
while (curr != NULL) {
|
|
||||||
operation =
|
operation =
|
||||||
(*env)->CallStaticObjectMethod(env, local_profile_notification_operation_class,
|
(*env)->CallStaticObjectMethod(env, local_profile_notification_operation_class,
|
||||||
local_profile_notification_operation_from_string,
|
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, operation);
|
||||||
(*env)->DeleteLocalRef(env, notification);
|
(*env)->DeleteLocalRef(env, notification);
|
||||||
|
});
|
||||||
curr = curr->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
es10b_notification_metadata_free_all(info);
|
es10b_notification_metadata_free_all(info);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue