openModeller
Version 1.4.0
|
00001 00027 #include <om_cmd_utils.hh> 00028 #include <time.h> 00029 00030 using std::ios_base; 00031 00032 // get Log Level 00033 Log::Level getLogLevel( std::string level ) { 00034 00035 if ( level == "debug" ) { 00036 00037 return Log::Debug; 00038 } 00039 else if ( level == "info" ) { 00040 00041 return Log::Info; 00042 } 00043 else if ( level == "warn" ) { 00044 00045 return Log::Warn; 00046 } 00047 else if ( level == "error" ) { 00048 00049 return Log::Error; 00050 } 00051 else { 00052 00053 printf( "Unrecognized log level (%s). Using default value.\n", level.c_str() ); 00054 return Log::Default; 00055 } 00056 } 00057 00058 // Display progress on screen 00059 void progressDisplayCallback( float progress, void *extraParam ) 00060 { 00061 char buffer[9]; 00062 00063 sprintf( buffer, "%07.4f", 100 * progress ); 00064 00065 std::cout << "Progress: " << buffer << "% \r" << flush; 00066 } 00067 00068 // Progress callback 00069 void progressFileCallback( float progress, void *progressData ) 00070 { 00071 if ( ! progressData ) { 00072 00073 return; 00074 } 00075 00076 progress_data * prog_data = (progress_data *)progressData; 00077 00078 time_t current_time; 00079 time( ¤t_time ); 00080 00081 int my_progress = static_cast<int>(100*progress); 00082 00083 if ( my_progress < 0 ) { 00084 00085 my_progress /= 100; 00086 } 00087 00088 if ( my_progress == -1 || my_progress == -2 || 00089 my_progress == 0 || my_progress == 100 || 00090 ( progress != prog_data->progress && 00091 difftime( current_time, prog_data->timestamp ) > MIN_PROGRESS_INTERVAL ) ) { 00092 00093 FILE *p_file = NULL; 00094 p_file = fopen( prog_data->file_name.c_str(), "w" ); 00095 00096 if ( p_file == NULL ) { 00097 00098 // Could not open file 00099 // todo: send message to cerr but avoid doing this every time the callback is called 00100 //cerr << "Could not open progress file" << endl; 00101 } 00102 else { 00103 00104 char buffer[4]; 00105 sprintf( buffer, "%d", my_progress ); 00106 fputs( buffer, p_file ); 00107 fclose( p_file ); 00108 prog_data->progress = progress; 00109 prog_data->timestamp = current_time; 00110 } 00111 } 00112 }