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


Add an input processing function


PtInputId_t *PtAppAddInput( 
                 PtAppContext_t app_context,
                 pid_t pid,
                 PtInputCallbackProc_t input_func,
                 void *data );


This routine adds a function to a PtMainLoop() input-event processing chain.

The app argument is the address of the application context, a structure that manages all the data associated with this application. For Photon 1.1x, this must be specified as NULL, so that the default context is used.

The input function is executed whenever the application receives a message from process pid. If pid is negative, it's the ID of a Photon pulse.

If you specify a pid of 0, the input function will be called for every non-Photon event message that's received, but only if there's no input function that catches messages from the sending pid specifically.

The rcvid argument that the input function will get may have a different value:

The input_func argument points to the input function to be invoked. The function takes this form:

int (*input_func)(void *data, pid_t rcvid, 
               void *message, size_t size);

You can declare the function to be of type PtInputCallbackProcF_t to take advantage of the compiler's type-checking.

The data argument points to user data that's passed to the input entry function.

  • If the input function changes the display, it should call PtFlush() to make sure the display is updated.
  • If the input function returns a value other than Pt_CONTINUE, the function is removed from the input entry chain.


A pointer to a PtInputId_t structure that uniquely identifies the specified input function for the given application context. If an error occurs, the function returns NULL.


// From /qnx4/phtk/apps/msgpass register_name.c
msg_handler( void *data, pid_t rcvid, 
             void *message, ushort_t size)
    struct msg_s 
        unsigned type;
        unsigned color;
    } *msg;

    msg = ( struct msg_s * ) message;
    Reply( rcvid, "OK!", 4);
        case 10:
            printf("got:: type = %d, color = %d, 
                size = %d\n",msg->type,
                msg->color, size);
            color = msg->color;
            color_chg( ABW_PtRegBut, NULL, NULL );
    return( Pt_CONTINUE );

/*** The following function would normally        ***/
/*** be placed in an AppBuilder Init function.    ***/
/*** See Application menu, Startup Info. The      ***/
/*** function is set up here as a button callback ***/
/*** to clarify the sample's operation.           ***/
register_name( PtWidget_t *widget, void *data, 
               PtCallbackInfo_t *cbinfo )
    PtArg_t args[5];
    PtInputId_t *ipid;
    static nid_t name = -1;
    if ( -1 == name )
        name = qnx_name_attach( 0, "Photon_App" );
        if( name == -1 )
            return( Pt_CONTINUE );
    PtSetArg( &args[0], Pt_ARG_TEXT_STRING, 
              "Registered!", 0);
    PtSetResources( ABW_PtRegBut, 1, &args );

    ipid = PtAppAddInput( NULL, 0, msg_handler, NULL );
    return( Pt_CONTINUE );
    //added to illustrate removal of input routine....
    PtAppRemoveInput( NULL, ipid );



Interrupt handler No
Signal handler No
Thread No

See also:

PtMainLoop(), PtAppRemoveInput(), PtSetParentWidget(), PtResizeEventMsg()

"Receiving QNX messages" in the Interprocess Communication and Lengthy Operations chapter of the Programmer's Guide

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