コード例 #1
0
ファイル: xstream.c プロジェクト: SWI-Prolog/packages-xpce
static void
ws_handle_stream_data(XtPointer xp, int *source, XtInputId *id)
{ Stream s = (Stream)xp;

  pceMTLock(LOCK_PCE);
  assert(isProperObject(s));
  DEBUG(NAME_stream, Cprintf("handleInputStream(%s)\n", pp(s)));
  handleInputStream(s);
  pceMTUnlock(LOCK_PCE);
}
コード例 #2
0
ファイル: mstimer.c プロジェクト: brayc0/nlfetdb
VOID CALLBACK
timer_proc(HWND hwnd, UINT msg, UINT id, DWORD now)
{ DEBUG(NAME_timer, Cprintf("Firing timer %d\n", id));

  if ( TimerTable )
  { Timer tm;

    pceMTLock(LOCK_PCE);
    if ( (tm = getMemberHashTable(TimerTable, toInt(id))) )
    { if ( tm->service == ON )
      { ServiceMode(PCE_EXEC_SERVICE, do_timer_proc(tm, id));
      } else
	do_timer_proc(tm, id);

      pceMTUnlock(LOCK_PCE);

      return;
    }
    pceMTUnlock(LOCK_PCE);
  }

  KillTimer(NULL, id);			/* Unexpected timer.  Get rid of it */
}
コード例 #3
0
ファイル: xwindow.c プロジェクト: SWI-Prolog/packages-xpce
static void
event_window(Widget w, XtPointer xsw, XtPointer xevent)
{ PceWindow sw = (PceWindow) xsw;
  XEvent *event = (XEvent *)xevent;

  pceMTLock(LOCK_PCE);
  DEBUG(NAME_event, Cprintf("event_window(): X-event %d on %s\n",
			    event->xany.type, pp(sw)));

  if ( isFreeingObj(sw) || isFreedObj(sw) || sw->sensitive == OFF )
  { pceMTUnlock(LOCK_PCE);
    return;
  }

  ServiceMode(is_service_window(sw),
	      { AnswerMark mark;
		markAnswerStack(mark);

		x_event_window(sw, event);

		rewindAnswerStack(mark, NIL);
	      });
コード例 #4
0
ファイル: xevent.c プロジェクト: SWI-Prolog/packages-xpce
status
ws_dispatch(Int FD, Any timeout)
{ XtIntervalId tid = 0;
  XtInputId iid = 0;
  status rval = SUCCEED;
  int ofd = dispatch_fd;
  int fd = (isDefault(FD) ? dispatch_fd :
	    isNil(FD)	  ? -1
			  : valInt(FD));

					/* No context: wait for input */
					/* timeout */
  if ( ThePceXtAppContext == NULL )
  { int ready;
#ifdef HAVE_POLL
    int to;
    struct pollfd fds[1];

    if ( isNil(timeout) )
    { to = -1;
    } else if ( isDefault(timeout) )
    { to = 250;
    } else if ( isInteger(timeout) )
    { to = valInt(timeout);
    } else if ( instanceOfObject(timeout, ClassReal) )
    { to = (int)(valReal(timeout)*1000.0);
    } else
      to = 256;

    fds[0].fd = fd;
    fds[0].events = POLLIN;

    ready = poll(fds, 1, to);
#else
    struct timeval to;
    struct timeval *tp = &to;
    fd_set readfds;
    int setmax = 0;

    if ( isNil(timeout) )
    { tp = NULL;
    } else if ( isDefault(timeout) )
    { to.tv_sec = 0;
      to.tv_usec = 250000;
    } else
    { double v;

      if ( isInteger(timeout) )
	v = (double)valInt(timeout)/1000.0;
      else if ( instanceOfObject(timeout, ClassReal) )
	v = valReal(timeout);
      else
	v = 0.25;

      to.tv_sec  = (long)v;
      to.tv_usec = (long)(v * 1000000.0) % 1000000;
    }

    FD_ZERO(&readfds);
    if ( fd >= 0 )
    { FD_SET(fd, &readfds);
      setmax = max(setmax, fd);
      dispatch_fd = fd;
    }

    ready = select(setmax+1, &readfds, NULL, NULL, tp);
#endif
    dispatch_fd = ofd;

    return (ready > 0 ? SUCCEED : FAIL);
  }					/* A display: dispatch until there */
					/* is input or a timeout */

  if ( fd >= 0 )
  { iid = XtAppAddInput(ThePceXtAppContext, fd,
			(XtPointer) XtInputReadMask, is_pending, NULL);
    dispatch_fd = fd;
  }

  if ( notNil(timeout) )
  { long to = -1;

    if ( isInteger(timeout) )
      to = valInt(timeout);
    else if ( instanceOfObject(timeout, ClassReal) )
      to = (long)(valReal(timeout)*1000.0);

    if ( to > 0 )
      tid = XtAppAddTimeOut(ThePceXtAppContext, to, is_timeout,
			    (XtPointer) &rval);
  }

  DEBUG(NAME_dispatch, Cprintf("Dispatch: timeout = %s, tid = %p\n",
			       pp(timeout), (void*)tid));

  if ( pceMTTryLock(LOCK_PCE) )
  { RedrawDisplayManager(TheDisplayManager());
    pceMTUnlock(LOCK_PCE);
  }
					/* All callbacks must be locked! */
  XtAppProcessEvent(ThePceXtAppContext,
		    XtIMXEvent|XtIMTimer|XtIMAlternateInput);

  if ( tid && rval )			/* if rval = FAIL, we had a timeout */
    XtRemoveTimeOut(tid);
  if ( iid )
    XtRemoveInput(iid);
  dispatch_fd = ofd;

  considerLocStillEvent();

  return rval;
}