From: dgm@cronus.colorado.edu (Dom Maddalone)
Subject: Re: Waiting simultaneously on X event & VMS event flag?
Date: 19 Jul 94 15:58:04 MST [thread overview]
Message-ID: <1994Jul19.155807.1669@buckie.hsc.colorado.edu> (raw)
In-Reply-To: youngn-1807941655410001@158.234.17.99
In article <youngn-1807941655410001@158.234.17.99>, youngn@logica.co.uk (Nicholas Young) writes:
>I have an Xt-based program running on OpenVMS/Alpha that needs to wait
>simultaneously on X events and VMS event flags. [Don't ask why :-)] Is
>there an easy way to do this? Possibilities seem to be:
>
>1) Use XtAppAddInput (best, because portable). Can the alternative input
>source be made to wait on event flags?
>
>2) Go below the X level and use something else [...]
>
>3) [Last resort] Write a separate app/thread that sits there [...]
Your first possibilty is my choice. Here's an example: it creates
a push button; activate it or wait for a timed AST to off 5 times and the
application ends.
Pay attention to the IOSB argument. Beware of the code too, very
fast and loose.
#include <descrip.h>
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/PushB.h>
#define DOMs_EFN 21
#define DOMs_EXPIRATION "0 00:00:05"
struct io_status_block {
unsigned short condition;
unsigned short unused;
unsigned long also_unused;
} iosb;
/*
* Globals
*/
char *btn_text;
int daytim[2];
unsigned long reqidt;
XtInputId inputCallbackId;
/*
* Forward declarations
*/
void set_timer (void);
void set_efn (void);
void activateCB (Widget, caddr_t, caddr_t);
void timerInputCB(caddr_t, int *, XtInputId *);
main(int argc, char **argv)
{
Widget toplevel;
Widget button;
XtAppContext app_ctx;
Arg args[10];
int n;
register status;
$DESCRIPTOR(timbuf,DOMs_EXPIRATION);
toplevel = XtAppInitialize(&app_ctx,"Dom",NULL,0,&argc,argv,NULL,NULL,
0);
btn_text = XmStringCreateLtoR("Push Here\n\tor\nWait for timer",
XmSTRING_DEFAULT_CHARSET);
n = 0;
XtSetArg(args[n],XmNlabelString,btn_text); n++;
XtSetArg(args[n],XmNwidth,250); n++;
XtSetArg(args[n],XmNheight,150); n++;
button = XtCreateManagedWidget("button",xmPushButtonWidgetClass,toplevel,
args,n);
XtAddCallback(button,XmNactivateCallback,activateCB,NULL);
if (((status = SYS$BINTIM(&timbuf,&daytim)) &1) != 1)
LIB$SIGNAL(status);
(void) set_timer();
inputCallbackId = XtAppAddInput(app_ctx,DOMs_EFN,&iosb,timerInputCB,NULL);
XtRealizeWidget(toplevel);
XtAppMainLoop(app_ctx);
}
void set_timer(void)
{
register status;
/*
* The condition enables/disables the input callback:
* zero - disabled
* non zero - enabled
*
* Important: Do NOT disable the input callback AND set the event flag;
* it will put the application into a compute bound loop.
*/
SYS$CLREF(DOMs_EFN);
iosb.condition = 1;
/*
* Have an AST execute after a few seconds to set the event flag,
* which will kick off the input callback routine.
*/
if (((status = SYS$SETIMR(0,&daytim,set_efn,reqidt,0)) &1) != 1)
LIB$SIGNAL(status);
}
void set_efn(void)
{
SYS$SETEF(DOMs_EFN);
}
void activateCB(Widget w, caddr_t client_data, caddr_t call_data)
{
printf("PushButton selected.\n");
/*
* The button has been pushed so we don't want anything more to do with
* the input callback routine:
* unregister the input source callback
* cancel the outstanding timer
*/
XtRemoveInput(inputCallbackId);
SYS$CANTIM(reqidt,0);
XmStringFree(btn_text);
printf("Exiting\n");
exit(0);
}
void timerInputCB(caddr_t client_data, int *source, XtInputId *id)
{
static int count = 0;
count++;
printf("Timer expired %d\n",count);
/*
* For politeness' sake, disable the input callback
*/
SYS$CLREF(DOMs_EFN);
iosb.condition = 0;
if (count > 4) {
XmStringFree(btn_text);
printf("Exiting\n");
exit(0);
} else {
(void) set_timer();
}
}
Dom Maddalone, dgm@cronus.colorado.edu
System Administrator, University Physicians, Inc., Denver
next prev parent reply other threads:[~1994-07-19 22:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-07-18 16:55 Waiting simultaneously on X event & VMS event flag? Nicholas Young
1994-07-19 22:58 ` Dom Maddalone [this message]
1994-07-20 13:00 ` Tim Llewellyn
1994-07-21 13:35 ` Art Stine
1994-07-22 13:21 ` fisher
1994-07-27 9:57 ` dominique dierick
-- strict thread matches above, loose matches on Subject: below --
1994-07-20 21:07 Dom Maddalone
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox