Hi all,
I am giving a UI for a library which has been developed in core ANSI C. The library calls a function close to 1000 times and is highly voluminous in terms of space and time. I want to call this function 1000 times from my UI. I have made a dll file out of the C library, and I am using glade for GTK front end. I have written ANSI C code snippets to check if the library functions are working, and they appear to be working very well without any problems. While I told that this function call from the library takes a lot of time, I have a progress bar in my UI, and while runnning this library function, my progress bar keeps updating the fraction of work done by that library[the fraction is actually computed by the C library function, written into a file, and the timeout function keeps reading fraction value from the same file periodically and updates its fraction]. For this I have written a time out function which keeps updating fraction regularly in the progress bar. So, I call this time out function first, and immediately I call this C library function, and then followed by: while (gtk_events_pending ()) { g_print("[.]"); gtk_main_iteration (); } so that the timeout function doesnt have to blocked until this big function is over, and it can keep updating fraction. I am now facing really weird problems here. 1. My time out function is NOT BEING CALLED AT ALL. I am inserting a few g_prints in the time out function, and I see nothing on the console. Moreover, no updates are happening to progress bar fraction. Only after fraction reaches 0.99, progress bar time out function is called. 2. My C library function crashes if I make changes to the timeout function or the callback function. Windows is full of mysteries and I dont even know why it crashed. When I include a g_print somewhere in the callback function or timeout function, it starts working, and then suddenly stops working I am using windows MingGw-Msys-GTK2.0-glade combination for writing my apps in windows. Pseudo code for my call back function [for some button which will initiate action] is as follows: /***************CALL BACK FUNCTION CODE SNIPPET ***********************/ g_timeout_add(1500,progress_timeout,progressbarwidget); f1();//THE BIG FUNCTION WHICH WILL RUN CLOSE TO A FEW HOURS while (gtk_events_pending ()) { g_print("[.]"); gtk_main_iteration (); }//THIS SO THAT THE TIME OUT FUNCTION WILL BE ABLE TO CALL ITSELF /****************END CALL BACK FUNCTION CODE SNIPPET**********************/ /****************TIME OUT FUNCTION *************************************/ static gboolean progress_timeout( gpointer pbar) { /* 1. Open file frac.v in read mode. 2. Read fraction. 3. Convert read fraction into double. 4. Update progress bar with fraction. 5. If fraction >=0.99, then deem that work is complete, so return true to g_timeout_add. */ FILE *fp; gchar *buffer; gdouble fraction = 0.0; //1. Open file frac.v in read mode. fp = fopen("frac.v","r"); if(fp==NULL) { displayError("Unable to update Progress bar.\n"); return FALSE;//Stop updating }//End if fp==NULL /* Buffer will hold the fraction read from file. Fraction is of precision 5, and will be between 0 and 1. So, size = 1[0//1]+1['.']+5[precision 5] +1[EOS] = 8 */ buffer = (gchar *)g_malloc0(8*sizeof(gchar)); //2. Read first line into buffer fgets(buffer,8,fp); fclose(fp); //Buffer contains fraction. //3. Convert read fraction into double[until end of buffer]. fraction = strtod(buffer,NULL); //4. Update progress bar with fraction. gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pbar), fraction); //Free memory g_free(buffer); //5. If fraction >=0.99, then deem that work is complete, so return true to g_timeout_add. if(fraction>=0.99)//If work is complete. { return FALSE;//Stop updating. } else//If work is not complete. { g_print("Time out function called"); return TRUE; } }//End function progress_timeout /******************END TIME OUT FUNCTION *********************************/ 1. Why should my C library function [which otherwise is doing very well] crash just because I made some print changes in callback and time out ? 2. Since my timeout function has file I/O operations, is it that file I/Os are still blocked even if I insert the gtk_main_iteration() call inside while loop as I have indicated ?
************************************************************************************* DISCLAIMER This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any use,distribution,copying or disclosure by any other person is strictly prohibited. If you have received this transmission in error please notify SETS immediately either by replying to this e-mail or by telephone +91-44-28205655 and then delete this e-mail. The sender does not accept any responsibility for any damage which you sustain as a result of software viruses or malicious programs. You should therefore scan attachments (if any) prior to opening them. ************************************************************************************
_______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list