set_qnx_callback()

Set/Unset a user callback which will be called by library.

Synopsis:

#include <curses.h>
void set_qnx_callback( void (*user_callback)(pid_t pid),
                 bool on );

Description:

The set_qnx_callback() function will setup a user defined callback which will be called by ncurses library during inputing. The ncurses library do a Receive() while calling getch(), wgetch()... If an unknown pid is coming, the user callback iovoked and the pid is pass down. The on argument is either TRUE (to set the callback), or FALSE (to unset the callback).

Returns:

The function do not return any value

Examples:


#include <curses.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/proxy.h>
#include <time.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>

static void my_callback(pid_t pid);
static pid_t timer_proxy;
static time_t now;

static void my_callback(pid_t pid)
{
	char *p;

	now = time (NULL);
	p = ctime(&now);
	p[strlen(p)-1] = '\0';

	if (pid != timer_proxy)
		printw("%s: Unknown pid (%d)\n", p, pid);
	else
		printw("%s: timer proxy has been triggled !\n", p);

	refresh();
}

void main( int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
{
	int c;
	int tmout = -1;
	timer_t timer;
	struct sigevent ev;
	struct itimerspec t;
	MEVENT  event;
	char *p;

	while ((c = getopt(argc, argv, "t:")) != EOF) {
		switch (c) {
		case 't':
			tmout = atoi(optarg);
			break;
		}
	}

	/* set up a 5 second timer */
	if ((timer_proxy = qnx_proxy_attach(0, 0, 0, -1)) == -1) {
		perror("qnx_proxy_attach");
		exit(-1);
	}
	ev.sigev_signo = -1 * timer_proxy;

	if ((timer = timer_create(CLOCK_REALTIME, &ev)) == -1) {
		perror("timer_create");
		exit(-1);
	}

	t.it_value.tv_sec  = 5L;
	t.it_value.tv_nsec = 0L;
	t.it_interval.tv_sec  = 5L;
	t.it_interval.tv_nsec = 0L;

	timer_settime(timer, 0, &t, NULL);

    initscr();
	raw();
	noecho();
	mousemask(ALL_MOUSE_EVENTS, (mmask_t *)0);
	keypad(stdscr, TRUE);
	scrollok(stdscr, TRUE);

	if (tmout != -1)
		timeout(tmout * 1000);

	set_qnx_callback(my_callback, TRUE);
	
	for (;;) {
		c = getch();
		now = time(NULL);
		p = ctime(&now);
		p[strlen(p)-1] = '\0';
		switch(c)
		{
			case ERR:
				printw("%s: input timed out\n", p);
				break;
			case('q'):
			case('Q'):
	    		noraw();
				nl();
	    		endwin();
				exit(EXIT_SUCCESS);
				break;
			case KEY_MOUSE:
				getmouse(&event);
				printw("%s: mouse event arrived\n", p);
				break;
			default:
				printw("%s: key event. key = %x\n", p, c);
				break;
		}	
    }
}