[Previous]
[Contents]
[Next]

mouse_read()

read mouse events from a mouse server

Synopsis:

#include <sys/mouse.h>
int mouse_read( struct _mouse_ctrl *mc,
                struct mouse_event *buf,
                int n,
                pid_t proxy,
                int *armed );

Description:

The mouse_read() function reads up to n mouse events from the mouse server associated with mc into the buffer pointed to by buf.

If proxy is nonzero, and either no data is available now (mouse_read() returns zero), or this call has completely drained the mouse queue, the system arms this proxy to be triggered when data becomes available.

If the proxy is armed by the system, and the argument armed is nonzero, mouse_read() sets the variable pointed to by armed.

If proxy is a signal number, that signal is generated on the calling process when data becomes available rather than triggering a proxy. See <signal.h> for the list of signals.

Returns:

The number of mouse events read. If an error occurs, then mouse_read() returns -1, and errno is set. If proxy is nonzero, then armed is nonzero if that proxy was armed as a result of the call.

Errors:

EBADF
The file descriptor in the mouse control structure is invalid.
EINTR
The mouse_read() call was interrupted when the process was signalled.

Examples:

#include <stdio.h>
#include <sys/types.h>
#include <sys/mouse.h>
#include <sys/dev.h>
#include <sys/proxy.h>
#include <sys/kernel.h>

#define N 10
struct mouse_event buf[N];
char kbuf[N];

void main()
  {
    pid_t mproxy, kproxy, pid;
    struct _mouse_ctrl *mc;
    int armed, n;

    mc = mouse_open( ( nid_t ) 0, 0, 0 );

    /*
     * The following example uses proxies to
     * kick us when data is available, allowing
     * the process to accept input from other tasks
     * ( via messages ) as well as data from either
     * the keyboard ( stdin ) or the mouse
     * WITHOUT requiring polling.
     */

    mproxy = qnx_proxy_attach( 0, 0, 0, -1 );
    kproxy = qnx_proxy_attach( 0, 0, 0, -1 );

    /*
     * Flush any pending events
     */
    mouse_flush( mc );

    /*
     * Arm the proxies by reading zero bytes
     */
    n = mouse_read( mc, &buf, 0, mproxy, NULL );
    dev_read( 0, &buf, 0, 1, 0, 0, kproxy, NULL );

    for( ;; ) {
      /*
       * wait for a proxy from either keyboard or mouse
       */
      pid = Receive( 0, &buf, sizeof( buf ) );
      if( pid == mproxy ) {
        armed = 0;
        while( !armed ) {
          n = mouse_read( mc, &buf, N, mproxy, &armed );
          /* process 'n' mouse_events in 'buf' */
          printf( "Got %d event( s ) from mouse\n", n );
        }
      }
      else if( pid == kproxy ) {
        armed = 0;
        while( !armed ) {
          n = dev_read( 0, &kbuf, N, 1, 0, 0,
                kproxy, &armed );
          /* process 'n' keyboard chars in 'kbuf' */
          printf( "Got %d char( s ) from keyboard\n", n );
        }
      }
      else {
        /*
         * process other proxy or message from a task
         */
      }
    }
    mouse_close( mc );
  }

Classification:

QNX

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

errno, mouse_close(), mouse_flush(), mouse_open(), mouse_param()


[Previous]
[Contents]
[Next]