Hi,
My form contains two input text fields "output directory" and "kitversion Number" an scroll window with two label's to display error and status message and two buttons i.e, "Generate" and "Cancel".
Whenever i am giving required parameter to the form and click on "Generate" buttons I have to get a status message saying "the generate process is in Progress" and when the process is complete display a message in same status label saying "Generate is complete" and return from the event. This whole process is happening in a single event. The issue is application is giving the last message in the status label before the return from the event . No intermediate messages are being displayed.
Below is the code snippet for "Generate" Buttons.
Code Snippet:
Logical CreateDbKit::Generate( const FormEvent& event )
{
bool status = true;
Stringz error;
_dboutput.copy_to( _output_directory );
_output_directory.truncate( );
if( _output_directory.is_empty() )
{
_output_directory = "\"\"";
Stringz tmp_path = _input_directory + "kitbuild";
_dboutput.draw( tmp_path );
}
else
{
struct stat script_stats;
if ( stat( _output_directory, &script_stats ) != 0 )
{
_dboutput.assert_error( format_msg( InvDirName ) );
message( format_msg( InvOutputPath ) );
status = false;
return (Logical)status;
}
else
{
status = true;
message( format_msg( KitInProgress ) ); //is not printed at all
}
}
Stringz tmp_name = _db_name + ZoneExtension;
struct stat script_stats;
if ( stat( tmp_name, &script_stats ) != 0 )
{
_db_zoned = false;
stat_msg( MODULE_NAME, STAT_INFO, "database is unzoned" );
}
else
{
_db_zoned = true;
stat_msg( MODULE_NAME, STAT_INFO, "database is zoned" );
}
_kitversion.copy_to( _kitverno );
_kitverno.truncate( );
if( _kitverno.is_empty() )
{
_kitverno = "\"\"";
}
AttList att;
att.protect( );
AttList attr;
attr.accessible( );
_generate.set_attributes( att );
_kitcancel.set_attributes( att );
if( status )
{
status = produce_and_execute_createdbkit_script( );
char filename[200];
char cmd_str[200];
char buffer[2000];
Stringz GenkitErrMsg = "";
sprintf( filename,"%serror.txt",getenv( "SCRIPTS" ) );
ifstream errFile( filename, ios::in );
if ( errFile != NULL )
{
while ( !errFile.eof( ) )
{
errFile.getline( buffer, 2000 );
GenkitErrMsg += buffer;
}
sprintf( cmd_str, "rm -rf %s", filename );
system( cmd_str );
_errormsg = GenkitErrMsg;
}
if( status )
{
message( format_msg( KitGenerated, _errormsg.c_str( ) ) ); // is printed in the form
}
else
{
message( format_msg( KitGenFailed, _errormsg.c_str( ) ) );
}
}
_generate.set_attributes( attr );
_kitcancel.set_attributes( attr );
unlock( );
return ( status );
}
End of Code Snippet.
Request help.
Your message cannot be drawn because the your callback function CreateDbKit::Generate() doesn't return control to Xt main loop and so draw event cannot be processed. You may familiarize with event handling in Motif Programming Manual (6A) - http://oreilly.com/catalog/motifref2/vol6a/Vol6a_html/ch02.html#3_3_6
Thanks Yuriy for your suggestion.
If a call a function just after the first message then, the first message is getting printed and the final message as well. Below is the code snippet.
Code Snippet:
Code Snippet:
bool create_ICU_resource_bundle( const char*db_file_name, bool zonedDb );
Logical CreateDbKit::Generate( const FormEvent& event )
{
bool status = true;
Stringz error;
_dboutput.copy_to( _output_directory );
_output_directory.truncate( );
if( _output_directory.is_empty() )
{
_output_directory = "\"\"";
Stringz tmp_path = _input_directory + "kitbuild";
_dboutput.draw( tmp_path );
}
else
{
struct stat script_stats;
if ( stat( _output_directory, &script_stats ) != 0 )
{
_dboutput.assert_error( format_msg( InvDirName ) );
message( format_msg( InvOutputPath ) );
status = false;
return (Logical)status;
}
else
{
status = true;
message( format_msg( KitInProgress ) ); //1. printing, If i call this below function "create_ICU_resource_bundle"
}
}
status = create_ICU_resource_bundle( _db_name.c_str( ), zoned ); //This is the function is defined in main.C file
Stringz tmp_name = _db_name + ZoneExtension;
struct stat script_stats;
if ( stat( tmp_name, &script_stats ) != 0 )
{
_db_zoned = false;
stat_msg( MODULE_NAME, STAT_INFO, "database is unzoned" );
}
else
{
_db_zoned = true;
stat_msg( MODULE_NAME, STAT_INFO, "database is zoned" );
}
_kitversion.copy_to( _kitverno );
_kitverno.truncate( );
if( _kitverno.is_empty() )
{
_kitverno = "\"\"";
}
AttList att;
att.protect( );
AttList attr;
attr.accessible( );
_generate.set_attributes( att );
_kitcancel.set_attributes( att );
if( status )
{
status = produce_and_execute_createdbkit_script( );
char filename[200];
char cmd_str[200];
char buffer[2000];
Stringz GenkitErrMsg = "";
sprintf( filename,"%serror.txt",getenv( "SCRIPTS" ) );
ifstream errFile( filename, ios::in );
if ( errFile != NULL )
{
while ( !errFile.eof( ) )
{
errFile.getline( buffer, 2000 );
GenkitErrMsg += buffer;
}
sprintf( cmd_str, "rm -rf %s", filename );
system( cmd_str );
_errormsg = GenkitErrMsg;
}
if( status )
{
message( format_msg( KitGenerated, _errormsg.c_str( ) ) ); //2. Clearing 1st message and then printed final msg the form
}
else
{
message( format_msg( KitGenFailed, _errormsg.c_str( ) ) );
}
}
_generate.set_attributes( attr );
_kitcancel.set_attributes( attr );
unlock( );
return ( status );
}
Defination of the caller function:
bool create_ICU_resource_bundle( const char *db_file_name, bool zonedDb )
{
bool status = true;
Stringz screen_path;
Stringz tmp_path( getenv( "RESBUNDLESCRCONFIGPATH" ) );
if( ! tmp_path.is_empty( ) )
{
screen_path = getenv( "RESBUNDLESCRCONFIGPATH" );
}
else
{
screen_path = getenv( "SCRCONFIGPATH" );
}
screen_path.truncate( );
if ( screen_path.is_empty( ) )
{
stat_msg( MODULE_NAME, STAT_WARNING,
"The SCRCONFIGPATH environment variable is not set, the "
"ICU Resource Bundle may be incomplete\n" );
}
screen_path += '/';
// get a list of the screen files
ScreenFileList screens;
read_screen_files( screen_path, screens );
ConfigFileList configs;
read_config_files( screen_path, configs );
ConfigFileList configs;
read_config_files( screen_path, configs );
update_related = 0;
update_resource_keys = 0;
Sct_Db *db = NULL;
// create an Sct_Db object used to output the ICU data.
if( zonedDb )
{
Stringz dbname( db_file_name );
Stringz comments( "Generate of ICU Resource Bundle" );
Stringz user( getenv( "USER" ) );
Logical new_database, template_database, user_load, load_sections;
new_database = template_database = lFalse;
user_load = load_sections = lTrue;
unsigned char zone = 1; // set zone = 1 since zero indicates no zones
db = new Sct_Db( dbname, user, comments, new_database,
template_database, user_load, load_sections,
zone );
}
if ( db == 0 )
{
status = 0;
return status;
}
return status;
}
End Of Code Snippet:
Thanks in Advance.