From dc6037d0479e4e22f1aa6cfa2f3475e97fb046cd Mon Sep 17 00:00:00 2001 From: Vojtech Forejt Date: Wed, 19 Oct 2011 14:21:14 +0000 Subject: [PATCH] PrintWarningToMainLog method that gives access to Java printWarning method. git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@4073 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/include/PrismHybridGlob.h | 1 + prism/include/PrismMTBDDGlob.h | 1 + prism/include/PrismSparseGlob.h | 1 + prism/src/hybrid/PrismHybrid.cc | 19 +++++++++++++++++++ prism/src/mtbdd/PrismMTBDD.cc | 19 +++++++++++++++++++ prism/src/sparse/PS_NondetReachReward.cc | 4 ++-- prism/src/sparse/PS_NondetUntil.cc | 4 ++-- prism/src/sparse/PrismSparse.cc | 19 +++++++++++++++++++ 8 files changed, 64 insertions(+), 4 deletions(-) diff --git a/prism/include/PrismHybridGlob.h b/prism/include/PrismHybridGlob.h index 032e47be..b4d27abb 100644 --- a/prism/include/PrismHybridGlob.h +++ b/prism/include/PrismHybridGlob.h @@ -85,6 +85,7 @@ extern double last_unif; #define logtwo(X) log((double)X)/log(2.0) void PH_PrintToMainLog(JNIEnv *env, const char *str, ...); +void PH_PrintWarningToMainLog(JNIEnv *env, const char *str, ...); void PH_PrintToTechLog(JNIEnv *env, const char *str, ...); void PH_PrintMemoryToMainLog(JNIEnv *env, const char *before, double mem, const char *after); void PH_SetErrorMessage(const char *str, ...); diff --git a/prism/include/PrismMTBDDGlob.h b/prism/include/PrismMTBDDGlob.h index 789da200..8b591d67 100644 --- a/prism/include/PrismMTBDDGlob.h +++ b/prism/include/PrismMTBDDGlob.h @@ -80,6 +80,7 @@ extern JNIEnv *export_env; // function prototypes void PM_PrintToMainLog(JNIEnv *env, const char *str, ...); +void PM_PrintWarningToMainLog(JNIEnv *env, const char *str, ...); void PM_PrintToTechLog(JNIEnv *env, const char *str, ...); void PM_SetErrorMessage(const char *str, ...); char *PM_GetErrorMessage(); diff --git a/prism/include/PrismSparseGlob.h b/prism/include/PrismSparseGlob.h index 641101bc..f117ac56 100644 --- a/prism/include/PrismSparseGlob.h +++ b/prism/include/PrismSparseGlob.h @@ -84,6 +84,7 @@ extern JNIEnv *export_env; #define logtwo(X) log((double)X)/log(2.0) void PS_PrintToMainLog(JNIEnv *env, const char *str, ...); +void PS_PrintWarningToMainLog(JNIEnv *env, const char *str, ...); void PS_PrintToTechLog(JNIEnv *env, const char *str, ...); void PS_PrintMemoryToMainLog(JNIEnv *env, const char *before, double mem, const char *after); void PS_SetErrorMessage(const char *str, ...); diff --git a/prism/src/hybrid/PrismHybrid.cc b/prism/src/hybrid/PrismHybrid.cc index 4de33541..aac9eae0 100644 --- a/prism/src/hybrid/PrismHybrid.cc +++ b/prism/src/hybrid/PrismHybrid.cc @@ -54,6 +54,7 @@ static jobject main_log_obj = NULL; static jobject tech_log_obj = NULL; // method ids for print method in logs static jmethodID main_log_mid = NULL; +static jmethodID main_log_warn = NULL; static jmethodID tech_log_mid = NULL; // numerical method stuff @@ -112,6 +113,7 @@ JNIEXPORT void JNICALL Java_hybrid_PrismHybrid_PH_1SetMainLog(JNIEnv *env, jclas main_log_cls = (jclass)env->NewGlobalRef(env->GetObjectClass(main_log_obj)); // get the method id for the print method main_log_mid = env->GetMethodID(main_log_cls, "print", "(Ljava/lang/String;)V"); + main_log_warn = env->GetMethodID(main_log_cls, "printWarning", "(Ljava/lang/String;)V"); } //------------------------------------------------------------------------------ @@ -153,6 +155,23 @@ void PH_PrintToMainLog(JNIEnv *env, const char *str, ...) //------------------------------------------------------------------------------ +void PH_PrintWarningToMainLog(JNIEnv *env, const char *str, ...) +{ + va_list argptr; + char full_string[MAX_LOG_STRING_LEN]; + + va_start(argptr, str); + vsnprintf(full_string, MAX_LOG_STRING_LEN, str, argptr); + va_end(argptr); + + if (env) + env->CallVoidMethod(main_log_obj, main_log_warn, env->NewStringUTF(full_string)); + else + printf("Warning: %s", full_string); +} + +//------------------------------------------------------------------------------ + void PH_PrintToTechLog(JNIEnv *env, const char *str, ...) { va_list argptr; diff --git a/prism/src/mtbdd/PrismMTBDD.cc b/prism/src/mtbdd/PrismMTBDD.cc index 2b339c42..69cc3815 100644 --- a/prism/src/mtbdd/PrismMTBDD.cc +++ b/prism/src/mtbdd/PrismMTBDD.cc @@ -54,6 +54,7 @@ static jobject main_log_obj = NULL; static jobject tech_log_obj = NULL; // method ids for print method in logs static jmethodID main_log_mid = NULL; +static jmethodID main_log_warn = NULL; static jmethodID tech_log_mid = NULL; // numerical method stuff @@ -103,6 +104,7 @@ JNIEXPORT void JNICALL Java_mtbdd_PrismMTBDD_PM_1SetMainLog(JNIEnv *env, jclass main_log_cls = (jclass)env->NewGlobalRef(env->GetObjectClass(main_log_obj)); // get the method id for the print method main_log_mid = env->GetMethodID(main_log_cls, "print", "(Ljava/lang/String;)V"); + main_log_warn = env->GetMethodID(main_log_cls, "printWarning", "(Ljava/lang/String;)V"); } //------------------------------------------------------------------------------ @@ -144,6 +146,23 @@ void PM_PrintToMainLog(JNIEnv *env, const char *str, ...) //------------------------------------------------------------------------------ +void PM_PrintWarningToMainLog(JNIEnv *env, const char *str, ...) +{ + va_list argptr; + char full_string[MAX_LOG_STRING_LEN]; + + va_start(argptr, str); + vsnprintf(full_string, MAX_LOG_STRING_LEN, str, argptr); + va_end(argptr); + + if (env) + env->CallVoidMethod(main_log_obj, main_log_warn, env->NewStringUTF(full_string)); + else + printf("Warning: %s", full_string); +} + +//------------------------------------------------------------------------------ + void PM_PrintToTechLog(JNIEnv *env, const char *str, ...) { va_list argptr; diff --git a/prism/src/sparse/PS_NondetReachReward.cc b/prism/src/sparse/PS_NondetReachReward.cc index 12372b54..62d24768 100644 --- a/prism/src/sparse/PS_NondetReachReward.cc +++ b/prism/src/sparse/PS_NondetReachReward.cc @@ -159,7 +159,7 @@ jboolean min // min or max probabilities (true = min, false = max) // also extract list of action names from 'synchs' get_string_array_from_java(env, synchs, action_names_jstrings, action_names, num_actions); } else { - PS_PrintToMainLog(env, "Warning: Action labels are not available for adversary generation.\n", export_adv_filename); + PS_PrintWarningToMainLog(env, "Action labels are not available for adversary generation.\n", export_adv_filename); } } @@ -234,7 +234,7 @@ jboolean min // min or max probabilities (true = min, false = max) if (fp_adv) { fprintf(fp_adv, "%d ?\n", n); } else { - PS_PrintToMainLog(env, "\nWarning: Adversary generation cancelled (could not open file \"%s\").\n", export_adv_filename); + PS_PrintWarningToMainLog(env, "Adversary generation cancelled (could not open file \"%s\").\n", export_adv_filename); export_adv_enabled = EXPORT_ADV_NONE; } } diff --git a/prism/src/sparse/PS_NondetUntil.cc b/prism/src/sparse/PS_NondetUntil.cc index 986c4233..633e5b51 100644 --- a/prism/src/sparse/PS_NondetUntil.cc +++ b/prism/src/sparse/PS_NondetUntil.cc @@ -155,7 +155,7 @@ jboolean min // min or max probabilities (true = min, false = max) // also extract list of action names from 'synchs' get_string_array_from_java(env, synchs, action_names_jstrings, action_names, num_actions); } else { - PS_PrintToMainLog(env, "Warning: Action labels are not available for adversary generation.\n", export_adv_filename); + PS_PrintWarningToMainLog(env, "Action labels are not available for adversary generation.\n", export_adv_filename); } } @@ -212,7 +212,7 @@ jboolean min // min or max probabilities (true = min, false = max) if (fp_adv) { fprintf(fp_adv, "%d ?\n", n); } else { - PS_PrintToMainLog(env, "\nWarning: Adversary generation cancelled (could not open file \"%s\").\n", export_adv_filename); + PS_PrintWarningToMainLog(env, "Adversary generation cancelled (could not open file \"%s\").\n", export_adv_filename); export_adv_enabled = EXPORT_ADV_NONE; } } diff --git a/prism/src/sparse/PrismSparse.cc b/prism/src/sparse/PrismSparse.cc index b88b5b24..ababe2b1 100644 --- a/prism/src/sparse/PrismSparse.cc +++ b/prism/src/sparse/PrismSparse.cc @@ -53,6 +53,7 @@ static jobject main_log_obj = NULL; static jobject tech_log_obj = NULL; // method ids for print method in logs static jmethodID main_log_mid = NULL; +static jmethodID main_log_warn = NULL; static jmethodID tech_log_mid = NULL; // numerical method stuff @@ -105,6 +106,7 @@ JNIEXPORT void JNICALL Java_sparse_PrismSparse_PS_1SetMainLog(JNIEnv *env, jclas main_log_cls = (jclass)env->NewGlobalRef(env->GetObjectClass(main_log_obj)); // get the method id for the print method main_log_mid = env->GetMethodID(main_log_cls, "print", "(Ljava/lang/String;)V"); + main_log_warn = env->GetMethodID(main_log_cls, "printWarning", "(Ljava/lang/String;)V"); } //------------------------------------------------------------------------------ @@ -146,6 +148,23 @@ void PS_PrintToMainLog(JNIEnv *env, const char *str, ...) //------------------------------------------------------------------------------ +void PS_PrintWarningToMainLog(JNIEnv *env, const char *str, ...) +{ + va_list argptr; + char full_string[MAX_LOG_STRING_LEN]; + + va_start(argptr, str); + vsnprintf(full_string, MAX_LOG_STRING_LEN, str, argptr); + va_end(argptr); + + if (env) + env->CallVoidMethod(main_log_obj, main_log_warn, env->NewStringUTF(full_string)); + else + printf("Warning: %s", full_string); +} + +//------------------------------------------------------------------------------ + void PS_PrintToTechLog(JNIEnv *env, const char *str, ...) { va_list argptr;