Hi,
I am trying to use the Free Widget Foundation PcBar progress indicator
widget, in a motif message dialog box, to indicate the progress of a
potentially lengthy operation, run as a child process of my main
application.
The attached source code shows how i have tried to implement this and
works to a point. The dialog box is realised and the process
successfully forks and execs, however the required update to the
percentage bar widget does not happen until the child process
terminates, at which point the indicator leaps from 0% to 100%.
The actual child process takes in excess of one minute to execute and so
i think i can rule out delays in window mapping. Also if i place an
XFlush() command after each update percentage widget call, there is
still no improvement.
The code is very much a first attempt and consequently there is no error
checking for child/parent UNIX signals, etc.
Any suggestions would be deeply appreciated.
Cheers.....
William
[
PcBarM.c 3K ]
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/MessageB.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "/users/wrc1/FWF/src/PcBar/PcBar.h"
#define REQ_COLOUR (Pixel)3
#define MAX_FILE_VALUE 94.0
static int pcval;
static Widget PcBar;
Widget CreatePCDoneDialog(Widget);
void PcBarCB ( Widget, XtPointer,XtPointer);
int main ( int argc, char **argv )
{
Widget shell, button;
XtAppContext app;
char *prgname={"/users/wrc1/rp/sarhp"};
shell = XtAppInitialize ( &app, "Askquestion", NULL, 0,
&argc, argv, NULL, NULL, 0 );
button = XtCreateManagedWidget ( "Quit",
xmPushButtonWidgetClass,
shell, NULL, 0 );
XtAddCallback(button, XmNactivateCallback, PcBarCB, (XtPointer)prgname);
XtRealizeWidget ( shell );
XtAppMainLoop ( app );
return(0);
{
static Widget retw=NULL;
Widget form;
if (retw==NULL)
{
retw = XmCreateMessageDialog ( w, "PcBarM", NULL, 0 );
XtVaSetValues ( retw,
XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
NULL );
form = XtCreateManagedWidget("form",xmFormWidgetClass,retw,NULL,0);
PcBar = XtVaCreateManagedWidget("testpc", xfwfPcBarWidgetClass, form,
XtNshowzero, True,
XtNforeground, REQ_COLOUR,
XtNdisplaypc,True,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_FORM,
NULL);
}
return(retw);
XtPointer clientData,
XtPointer callData )
{
Widget dialog;
int i;
int fd[2],result,cnt=0;
pid_t pid;
char line[51],c;
char *prgname=(char*)clientData;
dialog = CreatePCDoneDialog(w);
XtManageChild ( dialog );
if (pipe(fd) < 0) { fprintf(stderr,"Duff pipe formation\n"); exit(-1); }
if ( (pid = fork()) < 0)
{
fprintf(stderr,"Fork error\n");
}
else if (pid > 0) /* PARENT code */
{
close(fd[1]); /* close parent write pipe */
while (read(fd[0],&c,1) != NULL)
{
switch(c)
{
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
line[cnt] = c;
cnt++;
break;
default:
if (cnt)
{
line[cnt] = 0;
cnt=0;
sscanf(line,"%d",&result);
result = (result/MAX_FILE_VALUE)*100;
XfwfPcBarSetPercentage(PcBar, result);
}
else cnt = 0;
break;
}
}
}
else /* CHILD code */
{
close(fd[0]); /* close childs read pipe */
if (fd[1] != STDOUT_FILENO)
{
if (dup2(fd[1],STDOUT_FILENO) != STDOUT_FILENO) fprintf(stderr,"Duplication Error\n");
close(fd[1]); /* Not needed after dup */
}
if (execl(prgname,"sarhp",(char*)0) < 0) fprintf(stderr,"DUFF EXEC\n");
}