Skip to content

Commit

Permalink
Setter funcs return bool, add missing CHK_JVM_EXCEPTIONs
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankiesz committed Apr 23, 2024
1 parent 8f7b248 commit 5a3e503
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
27 changes: 20 additions & 7 deletions src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) {
kvsRetryStrategy = (jobject) env->CallObjectMethod(clientInfo, methodId);
CHK_JVM_EXCEPTION(env);
}
setKvsRetryStrategy(env, kvsRetryStrategy, &pClientInfo->kvsRetryStrategy);
if (!setKvsRetryStrategy(env, kvsRetryStrategy, &pClientInfo->kvsRetryStrategy)) {
DLOGW("Failed getting/setting KvsRetryStrategy.");
}

methodId = env->GetMethodID(cls, "getKvsRetryStrategyCallbacks", "()Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;");
if (methodId == NULL) {
Expand All @@ -285,14 +287,17 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) {
kvsRetryStrategyCallbacks = (jobject) env->CallObjectMethod(clientInfo, methodId);
CHK_JVM_EXCEPTION(env);
}
setKvsRetryStrategyCallbacks(env, kvsRetryStrategyCallbacks, &pClientInfo->kvsRetryStrategyCallbacks);
if (!setKvsRetryStrategyCallbacks(env, kvsRetryStrategyCallbacks, &pClientInfo->kvsRetryStrategyCallbacks)) {
DLOGW("Failed getting/setting KvsRetryStrategyCallbacks.");
}

CleanUp:
return STATUS_FAILED(retStatus) ? FALSE : TRUE;
}

VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrategy pKvsRetryStrategy)
BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrategy pKvsRetryStrategy)
{
STATUS retStatus = STATUS_SUCCESS;
jmethodID methodId = NULL;
jclass cls = NULL;
BOOL nullKvsRetryStrategy = FALSE;
Expand All @@ -306,8 +311,9 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg

cls = env->GetObjectClass(kvsRetryStrategy);
if (cls == NULL) {
DLOGW("Failed to create Java kvsRetryStrategy class.");
nullKvsRetryStrategy = TRUE;
DLOGW("Failed to create Java kvsRetryStrategy class.");
CHK(FALSE, STATUS_INVALID_OPERATION);
goto CleanUp;
}

Expand All @@ -322,9 +328,10 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg
// TODO: Implement once we have support for this in Java, setting to null for safety.
pKvsRetryStrategy->pRetryStrategy = NULL;
}
CHK_JVM_EXCEPTION(env);
}

methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyConfig");
methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()J");
if (methodId == NULL) {
DLOGW("Couldn't find method id getRetryStrategyConfig, setting pRetryStrategyConfig to null.");
pKvsRetryStrategy->pRetryStrategyConfig = NULL;
Expand All @@ -335,6 +342,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg
// TODO: Implement once we have support for this in Java, setting to null for safety.
pKvsRetryStrategy->pRetryStrategyConfig = NULL;
}
CHK_JVM_EXCEPTION(env);
}

methodId = env->GetMethodID(cls, "getRetryStrategyType", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyType");
Expand All @@ -343,6 +351,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg
pKvsRetryStrategy->retryStrategyType = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT;
} else {
pKvsRetryStrategy->retryStrategyType = (KVS_RETRY_STRATEGY_TYPE) env->CallIntMethod(kvsRetryStrategy, methodId);
CHK_JVM_EXCEPTION(env);
}


Expand All @@ -353,10 +362,12 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg
pKvsRetryStrategy->pRetryStrategyConfig = NULL;
pKvsRetryStrategy->retryStrategyType = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT;
}
return STATUS_FAILED(retStatus) ? FALSE : TRUE;
}

VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks)
BOOL setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks)
{
STATUS retStatus = STATUS_SUCCESS;
jmethodID methodId = NULL;
jclass cls = NULL;
BOOL nullSetCallbacks = FALSE;
Expand All @@ -370,8 +381,9 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks

cls = env->GetObjectClass(kvsRetryStrategyCallbacks);
if (cls == NULL) {
DLOGW("Failed to create Java kvsRetryStrategyCallbacks class.");
nullSetCallbacks = TRUE;
DLOGW("Failed to create Java kvsRetryStrategyCallbacks class.");
CHK(FALSE, STATUS_INVALID_OPERATION);
goto CleanUp;
}

Expand Down Expand Up @@ -438,6 +450,7 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks
pKvsRetryStrategyCallbacks->freeRetryStrategyFn = NULL;
pKvsRetryStrategyCallbacks->executeRetryStrategyFn = NULL;
}
return STATUS_FAILED(retStatus) ? FALSE : TRUE;
}

BOOL setTags(JNIEnv *env, jobjectArray tagArray, PTag* ppTags, PUINT32 pTagCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BOOL setStreamDataBuffer(JNIEnv* env, jobject dataBuffer, UINT32 offset, PBYTE*
BOOL releaseStreamDataBuffer(JNIEnv* env, jobject dataBuffer, UINT32 offset, PBYTE pBuffer);
BOOL setTags(JNIEnv *env, jobjectArray tagArray, PTag* ppTags, PUINT32 pTagCount);
VOID releaseTags(PTag tags);
VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks);
VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategy pKvsRetryStrategy);
BOOL setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks);
BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategy pKvsRetryStrategy);

#endif // __KINESIS_VIDEO_PARAMETERS_CONVERSION_H__

0 comments on commit 5a3e503

Please sign in to comment.