Previously, Steve Reid wrote in qdn.public.qnxrtp.photon:
I don’t know if this will help, but here’s how the example currently
looks:
I think this example is incomplete:
#define EVENT_SIZE sizeof( PhEvent_t ) + 1000
main( int argc, char *argv[] )
{
int rcvid, chid;
PhEvent_t *event;
struct app_msg msg;
if( initialize() == -1 )
exit( EXIT_FAILURE );
if( NULL == ( event = malloc( EVENT_SIZE ) ) )
exit( EXIT_FAILURE );
You need to call at least PhAttach(NULL, NULL) before the PhEventArm().
PhEventArm();
chid = PhChannelAttach( 0, -1, NULL );
The order of these is very important. In your example, the PhEventArm
comes before the PhChannelAttach because the call to PhChannelAttach
is really just querying the channel that PhEventArm created.
In my case, I have to call:
PhChannelAttach (mychid, mycoid, NULL);
PhEventArm();
in that order, because I want PhEventArm to use the channel that I
passed to PhChannelAttach. Obviously the example cannot do both, but
the docs don’t appear to contain this interesting relationship.
while( 1 ) {
rcvid = MsgReceive( chid, &msg, sizeof( msg ), NULL );
switch( PhEventRead( rcvid, event, EVENT_SIZE ) ) {
case Ph_EVENT_MSG:
PtEventHandler( event );
break;
Wojtek pointed out that there is a case missing for
case Ph_RESIZE_MSG:
msg = realloc (msg, PhGetMsgSize(msg));
break;
Which means that in your example, you must change the declaration of
msg from
struct app_msg msg;
to:
struct app_msg msg;
and add:
msg = (struct app_msg) malloc (sizeof (struct app_msg));
case 0:
process_app_msg( &msg );
break;
case -1:
perror( “PhEventRead failed” );
break;
}
}
}
As a general note about examples, it would be really nice if they were
to compile as presented, if possible. The calls to initialize() and
to process_app_msg() are just fluff whose sole apparent purpose is to
act as comments. Replace them with comments, and add the one
#include <Ph.h> at the top, and this would compile and run. It would
let you at least figure out whether your example was sane, and provide
some means of regression testing as the API is modified.
Regards,
Andrew