[Previous] [Contents] [Index] [Next]

PhEventRead()

Provide asynchronous event notification

Synopsis:

int PhEventRead( int rcvid,
                 void *buffer,
                 unsigned size );

Library:

ph

Description:

This function provides an asynchronous event-notification mechanism. You'll find it useful for applications that need to interact with Photon but also need to collect Neutrino pulses or messages from other processes.

For synchronous event notification, see PhEventNext() and PhEventPeek().


Note: The widget library calls PhEventRead() internally; if you call PhEventRead() in an application that uses widgets, you might get unexpected results. Use PtMainLoop() or PtProcessEvent() instead.

Typically, you call this function with the rcvid returned by MsgReceive() (see the QNX 6 Library Reference) to see if the message received was a pulse sent by Photon.

If the message received is the application's event pulse, PhEventRead() retrieves the event and rearms Photon. Otherwise, it returns 0.

Photon may close a region (for example, via the window manager) before you read the pending event. As a result, PhEventRead() may indicate that no event is pending even though you were notified otherwise. In this case, PhEventRead() returns -1 and sets errno to ENOMSG.


Note: You must call PhAttach() and arm the event pulse by calling PhEventArm() before you call PhEventRead() for the first time.

Returns:

Ph_EVENT_MSG
Successful completion.
Ph_RESIZE_MSG
The Ph_DYNAMIC_BUFFER flag was set in PhAttach(), and there's a pending Photon event that's larger than the client's event buffer. This event that indicates how large the client's buffer needs to be to receive the entire event message.
0
A non-Photon message was available.
-1
An error occurred.

Examples:

#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 );
     PhEventArm();
     chid = PhChannelAttach( 0, -1, NULL );
    
     while( 1 ) {
          rcvid = MsgReceive( chid, &msg, sizeof( msg ), NULL );
          switch( PhEventRead( rcvid, event, EVENT_SIZE ) ) {
               case Ph_EVENT_MSG:
                  PtEventHandler( event );
                  break;
               case 0:
                  process_app_msg( &msg );
                  break;
               case -1:
                  perror( "PhEventRead failed" );
                  break;
          }
     }
}

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PhAttach(), PhEvent_t, PhEventArm(), PhEventNext(), PhEventPeek(), PtEventHandler()

"Collecting events" in the Events chapter of the Photon Programmer's Guide

MsgReceive() in the QNX 6 Library Reference


[Previous] [Contents] [Index] [Next]