How PtTimer Works??

I’m alittle bit confused. I have piece of simple code as follows:
PtButton_push_Cb is a function for a button’s activate call back,
it runs it when the button is pushed, in there, I invoke a system call to
copy
bunch of times from source folder to destination folder, it takes 1 min to
finish.
Then i have a timer Activate call back, it runs when timer is hit, I put 50
ms for the repeat interval…

Now… the Timer Activate Call back runs Before and After my Copy command,
but not during it… why??? is there something I’m missing?





int PtButton_push_CB ( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t cbinfo )
{ /
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
system ("cp /Source /Destination ");

return( Pt_CONTINUE );
}

int PtTimer_activate_CB( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t cbinfo )
{ /
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
cout << “================= TIMER IS HIT ============”<< endl;
return( Pt_CONTINUE );
}

Hey Ran

The problem is that system doesn’t return until the command is
finished so your app doesn’t have a chance to process the timer
event. You could get around this a couple of ways. You could
put an “&” at the end of your command or you can look up the
PtSpawn* functions and use one of those.

Thanks
Rodney

ran zhang <rzhang@vamcointernational.com> wrote:

I’m alittle bit confused. I have piece of simple code as follows:
PtButton_push_Cb is a function for a button’s activate call back,
it runs it when the button is pushed, in there, I invoke a system call to
copy
bunch of times from source folder to destination folder, it takes 1 min to
finish.
Then i have a timer Activate call back, it runs when timer is hit, I put 50
ms for the repeat interval…

Now… the Timer Activate Call back runs Before and After my Copy command,
but not during it… why??? is there something I’m missing?



int PtButton_push_CB ( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t cbinfo )
{ /
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
system ("cp /Source /Destination ");

return( Pt_CONTINUE );
}

int PtTimer_activate_CB( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t cbinfo )
{ /
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
cout << “================= TIMER IS HIT ============”<< endl;
return( Pt_CONTINUE );
}

I wouldn’t want to use & to run in the background, since i can’t get the
result of the system call for copy,I need that result to determine if my
copy was successfully, unless there is anyother way…

I need to use spawn right? not PtSpawn. Can u supple me an example of how to
use Spawn? i looked help, it’s confusing.

Gui Group <gui@qnx.com> wrote in message news:9q6rfb$1ir$1@nntp.qnx.com

Hey Ran

The problem is that system doesn’t return until the command is
finished so your app doesn’t have a chance to process the timer
event. You could get around this a couple of ways. You could
put an “&” at the end of your command or you can look up the
PtSpawn* functions and use one of those.

Thanks
Rodney

ran zhang <> rzhang@vamcointernational.com> > wrote:
I’m alittle bit confused. I have piece of simple code as follows:
PtButton_push_Cb is a function for a button’s activate call back,
it runs it when the button is pushed, in there, I invoke a system call
to
copy
bunch of times from source folder to destination folder, it takes 1 min
to
finish.
Then i have a timer Activate call back, it runs when timer is hit, I
put 50
ms for the repeat interval…

Now… the Timer Activate Call back runs Before and After my Copy
command,
but not during it… why??? is there something I’m missing?





int PtButton_push_CB ( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t cbinfo )
{ /
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
system ("cp /Source /Destination ");

return( Pt_CONTINUE );
}

int PtTimer_activate_CB( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t cbinfo )
{ /
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
cout << “================= TIMER IS HIT ============”<< endl;
return( Pt_CONTINUE );
}
\

No you can use PtSpawn ( in fact it is recommended ). It’s not really that
hard and you can install a callback that gets called when the process that
you spawned terminates, so you can check your status at that point.

PtSpawCbF_t ProcessFinished;

void ProcessFinished ( void *data, int status )
{
// WIFEXITED and WEXITSTATUS can be found in the
// waitpid function documentation

if ( WIFEXITED ( status ) )
if ( WEXITSTATUS (status ) == EXIT_SUCCESS )
printf (“Command was successful\n”);
}

// Somewhere in code
{
static const char cmd[] = “cp”;
static const char *args[]={ cmd, “/source”, “/dest”, NULL};



if ( PtSpawn ( cmd, args, NULL, NULL, ProcessFinished, NULL, NULL ) < 0 )
printf (“There was an error starting the command\n”);



}


Thanks
Rodney


ran zhang <rzhang@vamcointernational.com> wrote:

I wouldn’t want to use & to run in the background, since i can’t get the
result of the system call for copy,I need that result to determine if my
copy was successfully, unless there is anyother way…

I need to use spawn right? not PtSpawn. Can u supple me an example of how to
use Spawn? i looked help, it’s confusing.

Gui Group <> gui@qnx.com> > wrote in message news:9q6rfb$1ir$> 1@nntp.qnx.com> …
Hey Ran

The problem is that system doesn’t return until the command is
finished so your app doesn’t have a chance to process the timer
event. You could get around this a couple of ways. You could
put an “&” at the end of your command or you can look up the
PtSpawn* functions and use one of those.

Thanks
Rodney

ran zhang <> rzhang@vamcointernational.com> > wrote:
I’m alittle bit confused. I have piece of simple code as follows:
PtButton_push_Cb is a function for a button’s activate call back,
it runs it when the button is pushed, in there, I invoke a system call
to
copy
bunch of times from source folder to destination folder, it takes 1 min
to
finish.
Then i have a timer Activate call back, it runs when timer is hit, I
put 50
ms for the repeat interval…

Now… the Timer Activate Call back runs Before and After my Copy
command,
but not during it… why??? is there something I’m missing?





int PtButton_push_CB ( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t cbinfo )
{ /
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
system ("cp /Source /Destination ");

return( Pt_CONTINUE );
}

int PtTimer_activate_CB( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t cbinfo )
{ /
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
cout << “================= TIMER IS HIT ============”<< endl;
return( Pt_CONTINUE );
}
\