home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / windows / x / motif / 8761 < prev    next >
Encoding:
Internet Message Format  |  1993-01-22  |  5.8 KB

  1. Xref: sparky comp.windows.x.motif:8761 comp.os.vms:21739 comp.windows.x:21476
  2. Path: sparky!uunet!usc!sdd.hp.com!ux1.cso.uiuc.edu!moe.ksu.ksu.edu!mccall!mccall!tp
  3. Newsgroups: comp.windows.x.motif,comp.os.vms,comp.windows.x
  4. Subject: Re: event flags in X/Motif
  5. Message-ID: <1993Jan22.091001@mccall.com>
  6. From: tp@mccall.com (Terry Poot)
  7. Date: Fri, 22 Jan 1993 09:10:01 CST
  8. Reply-To: tp@mccall.com (Terry Poot)
  9. References: <1993Jan22.000239.1435@mprgate.mpr.ca>
  10. Organization: The McCall Pattern Co., Manhattan, KS, USA
  11. Nntp-Posting-Host: mis1
  12. Nntp-Posting-User: tp
  13. Lines: 103
  14.  
  15.  
  16. In article <1993Jan22.000239.1435@mprgate.mpr.ca>, vli@mpr.ca (Vincent Li)
  17. writes:
  18. >   I'm running on VMS 5.5-1, Motif 1.0 (I think).
  19.  
  20. Assuming you are correct...
  21.  
  22. >   Got 3 questions I can't find in the FAQ's
  23. >
  24. >1) Could my X/Motif application exe generated in this environment be able to
  25. >   run under VMS5.5-1 with DECwindows with XUI? If not, what should I look
  26. >   out for? I've seen some discussions concerning DECwindows & Motif already,
  27. >   but couldn't figure out a clear yes/no on this issue.
  28.  
  29. A clear no. Your Motif application will be linked against shareable images that
  30. do not exist unless the system has Motif. You can go the other way, however. XUI
  31. applications will run on Motif. DEC was careful to provide look-alike shareable
  32. images for XUI.
  33.  
  34. >2) A real easy one, how do I ghost out a button (pushbutton widget/gadget) to
  35. >   prevent unprivileged user from selecting an option?
  36.  
  37. XtSetSensitive. Look it up.
  38.  
  39. >3) Can I have my Motif application be notified when a VMS event flag is set?
  40. >   (ie. one you get with sys$getef.) I've seen codes to work with VMS
  41. >mailboxes
  42. >   before, but I would like, and have, all those $QIO code hidden well away.
  43. >   All my application does is make a call to connect and pass an event flag
  44. >   as the parameter. When something is in the mailbox, for example, the event
  45. >   flag get set. Currently, I simply wait for the event flags in the main
  46. >line.
  47. >   (For some uses, I have an AST set the event flag which I wait for in the
  48. >   mainline.) Is there a way I can tell the X server the event flag set is an
  49. >   X event and add a callback of some kine to process it, or am I stuck with
  50. >   the processing in AST (which I can do now)?
  51.  
  52. Four things I can think of: 
  53.  
  54. 1) Use XtAppAddInput. This is complicated. Look at the examples in the manual
  55. (don't remember _which_ manual) VERY carefully. I've done this. It works. It
  56. isn't simple, and it isn't portable (the concept is, but not the
  57. implementation), but then, neither are event flags.
  58.  
  59. 2) Instead of calling XtAppMainLoop, you can write your application's main loop
  60. something like:
  61.  
  62.    for(;;){
  63.       if(XtAppPending(app_context))XtAppProcessEvent(app_context, XtIMAll);
  64.       <code here to check your event flag and handle it>
  65.       }
  66.  
  67. This has the disadvantage that it implements a CPU busy loop. You can't wait on
  68. either type of event without potentially causing the other type to stack up
  69. waiting to be serviced. This loop never waits.
  70.  
  71. 3) In your AST routine, call XSendEvent, or queue a timeout event with a time of
  72. 0, or otherwise tickle the Xt event loop into dispatching your event for you.
  73. This is not guaranteed to work, because Xt and Motif aren't reentrant. If the
  74. AST hits at the wrong time, you could corrupt things. One way to solve this is
  75. to do all your X processing at AST level. Bob Gezelter has mentioned that he
  76. does this. I haven't done it, so I won't speculate about how it is accomplished.
  77. (Pretty easy, if I recall). If one AST is running, another will be queued. If X
  78. runs at AST level, it can't be interrupted by an AST, and the reentrancy problem
  79. is solved.
  80.  
  81. 4) If it is acceptable in your application for there to be a slight delay
  82. servicing the event signaled by the event flag, you can use XtAppAddTimer to add
  83. a timer event, which can then check to see if the event flag has been set.
  84.  
  85. Option 1 is "best", but a pain to do well in any kind of open-ended manner. You
  86. need one event flag for each event stream (i.e. each mailbox or other class of
  87. event). You have to hard code the value of the event flag, so you are
  88. susceptible to conflicts with other software (you can't use lib$get_ef, because
  89. it returns event flags in a range unacceptable to XtAppAddInput(). If you need
  90. an example besides the one in the book, get a copy of the VMS port of Ghostview,
  91. which does precisely what you are asking about (connecting mailbox I/O to the Xt
  92. event dispatcher) using XtAppAddInput. It uses one event flag just for
  93. signalling Xt and then the callback has to figure out which event triggered.
  94.  
  95. The one in the manual is an extremely general example that will work for almost
  96. every conceivable use (kudos to whoever at DEC wrote that code!), but it has
  97. some overhead, so I didn't use it directly (I did use it to learn the technique,
  98. of course).
  99.  
  100. Option 4 is easy, if it's acceptable to your application. Option 2 stinks, it
  101. keeps your machine nailed at 100% cpu. If you put a time delay in it, your
  102. application gets real sluggish when there are events. (If you must do that, put
  103. the XtAppProcessEvent in a while(XtAppPending(app_context)) loop so you do _all_
  104. the pending X events, then yours, and then wait.
  105.  
  106. Option 3 is dangerous, unless you use Bob Gezelter's trick, or some other way of
  107. synchronizing. I won't tell you it won't work, it might most of the time, but
  108. nobody will guarantee it unless it is synchronized. (As someone else recently
  109. quiped, if you have any questions call or write to Bob Gezelter :-) Maybe he'll
  110. follow up here and describe how to make all X event handling run at AST level).
  111. If properly syncronized, this may be the simplest solution to your problem.
  112.  
  113. Bet you didn't think that question would be such a can of worms, eh?
  114. --
  115. Terry Poot <tp@mccall.com>                   The McCall Pattern Company
  116. (uucp: ...!rutgers!depot!mccall!tp)          615 McCall Road
  117. (800)255-2762, in KS (913)776-4041           Manhattan, KS 66502, USA
  118.