From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10f8a1,5309f6184b0934b9 X-Google-Attributes: gid10f8a1,public X-Google-Thread: f7cd1,5309f6184b0934b9 X-Google-Attributes: gidf7cd1,public X-Google-Thread: 103734,5309f6184b0934b9 X-Google-Attributes: gid103734,public X-Google-Thread: 1164f8,5309f6184b0934b9 X-Google-Attributes: gid1164f8,public X-Google-Thread: 13f27d,5309f6184b0934b9 X-Google-Attributes: gid13f27d,public X-Google-ArrivalTime: 1994-07-19 15:06:20 PST Path: nntp.gmd.de!xlink.net!howland.reston.ans.net!swrinde!news.dell.com!tadpole.com!uunet!CS.Arizona.EDU!buckie.ucha!cronus.colorado.edu!DGM Newsgroups: comp.sys.dec,vmsnet.misc,vmsnet.alpha,comp.windows.x,comp.windows.x.xt Subject: Re: Waiting simultaneously on X event & VMS event flag? Message-ID: <1994Jul19.155807.1669@buckie.hsc.colorado.edu> From: dgm@cronus.colorado.edu (Dom Maddalone) Date: 19 Jul 94 15:58:04 MST Reply-To: dgm@cronus.colorado.edu References: Organization: University Physicians, Inc., Denver, Colorado Nntp-Posting-Host: athena.hsc.colorado.edu Xref: nntp.gmd.de comp.sys.dec:16798 vmsnet.misc:2482 vmsnet.alpha:2180 comp.windows.x:37992 In article , 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 #include #include #include #include #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