SUMMARY: XView Problem

From: Rainer Blaes (prime_s!blaes@ernohb.uucp)
Date: Mon Mar 16 1992 - 07:14:51 CST


Two weeks ago I asked:

We have a problem trying to use both the XView and RPC libraries within
one application.
We would like our XView application to have an error message text
subwindow, for displaying error messages received from other applications
on the network. We want to use Broadcast RPC to implement the error message
despatch and receipt mechanism, and so our XView application must also function
as an RPC server process.
The problem comes in trying to combine the error message receipt and display
functions.
The XView application, which will display the error messages, disappears
down a black hole, xv_main_loop (). The RPC server, which will receive the
error messages, disappears however down its own black hole, svc_run ().
It appears then that the RPC server must exist as a separate process from
the XView application.
We tried invoking the RPC server from the XView application as a
forked process, with the error message display procedure being called from the
server. However, it seems that the RPC server cannot display to the text
subwindow created by the XView application.

There appears then to be a conflict in the use of these two high-level libraries.
On the one hand, an XView application is a process which essentially sits there
listening for and responding to X events. On the other hand, an RPC server is a
process which essentially sits there listening for and responding to network events.
Can these two very different kinds of 'listeners' easily be combined into one?
Or do we have to descend to Xlib and the levels below RPC?
===============================================================

Below I summarized all responses and messages, all of them were of great help
for our S/W developers.
Thank you very much again and best regards !

Your's sincerely
Rainer Blaes, MBB/ERNO 2800 Bremen 1 Germany

==============================================================

From: David_Boyd@imd.sterling.com (David Boyd)

        The routine you want to look at is notify_enable_rpc_svc. This
is an Xview function which enables rpc request dispatching in the notifier.
The routine is covered in both Chapter 10 of the O'Reilly RPC book and in
the O'Reilly/Dan Heller Xview book.

Good Luck.

-- 
From: macphed@dvinci.pa.dec.com (Ian MacPhedran)

I don't see an easy way for you to do this at the top level. However, using two "threads" - one for X11, one for RPC, you are able to communicate via several mechanisms. One way would be to have the RPC thread use XSendEvent() to send events to your X11 thread, and have the X11 thread interpret them. To do this, you should probably create the window you want to use for the messages before forking, so that the window id can be passed to the RPC thread.

There was a demo program (xse) posted to alt.sources some time ago (Aug 90) which shows how to use XSendEvent(). -- From: Joe VanAndel Internet:vanandel@ncar.ucar.edu NCAR - ATD/RSF P.O Box 3000 Fax: 303-497-2044

I can't help you with the details, since I don't use XView, but here's the general approach. RPC uses a collection of file descriptors whose identity can be found in the global variable svc_fdset or possibly svc_fds . You need to convince XView's main loop to call your function when data is available on any of these file descriptors. Your function needs to call svc_getreqset(&fds), where &fds is the set of RPC file descriptors that have data ready.

As you can see, svc_run() is quite simple: void svc_run() { #ifdef FD_SETSIZE fd_set readfds; #else int readfds; #endif /* def FD_SETSIZE */ extern int errno;

for (;;) { #ifdef FD_SETSIZE readfds = svc_fdset; #else readfds = svc_fds; #endif /* def FD_SETSIZE */ switch (select(_rpc_dtablesize(), &readfds, (int *)0, (int *)0, (struct timeval *)0)) { case -1: if (errno == EINTR) { continue; } perror("svc_run: - select failed"); return; case 0: continue; default: svc_getreqset(&readfds); } } } As long as you call svc_getreqset() when the RPC sockets have data, everything will work fine. I use this technique with Xt based toolkits, and have no problems.

The trick is registering a "file handler" with XView, so that it eventually calls svc_getreqset().

--------------- From: yih@atom.cs.utah.edu (Benny Yih)

I'm not sure about the state of RPC & XView. In pure X11, you have to unroll the polling loops sometimes to getting things done. At the widget level, X11 supports registrations of callbacks which are invoked during "idle" cycles. This could be a single check of RPC stuff, but must be nonblocking. If you must fork off the RPC "server" from the XView, then the error text should be sent back via pipes to the parent for display.

luck, benny

------------------- From: trdlnk!mike (Michael Sullivan)

There is no need for separate processes, nor do you have to "descend to Xlib or the levels below RPC," but you will have to deal with some lower level functions of the XView and RPC libraries.

The RPC Programming Guide section 4.3, "Other RPC Features," explains how to avoid using svc_run() by instead calling svc_getreqset() when you know there is RPC work to be done. This can be used in conjunction with XView's Notifier, which can be requested to call a function when a certain file descriptor has data to be read with notify_set_input_func().

Alternatively, you can use certain Notifier functions to control of execution in XView in a number of ways, instead of or in addition to calling xv_main_loop(). See the chapter on the Notifier in the XView Programming Manual for details. -------------------

From: sane!genmri!doug (Doug Becker)

The XView application, which will display the error messages, disappears down a black hole, xv_main_loop (). The RPC server, which will receive the error messages, disappears however down its own black hole, svc_run ().

You should be able to use XView and RPCs together by using the notify_enable_rpc_svc(TRUE) call to have the XView notifier do the svc_run().

This routine wasn't documented in OW 2.0, but I believe it is documented in 3.0. It's also covered in the new O'Reilly and Associates "Power Programming with RPC" book by John Bloomer (ISBN 0-937175-77-3).

Doug Becker doug@nmri.ge.com crdgw1!sane!doug

-------------------- From: stpeters@dawn.crd.ge.com (Dick St.Peters)

You can easily combine them into one [see note below about select] ...

______________________________________________________________________ #include <sys/types.h> #include <rpc/rpc.h> extern fd_set svc_fdset ; fd_set your_svc_fdset ; ... set up all the rpc server and XView stuff up to where you would normally call xv_main_loop () or svc_run (). Here is your own main loop: ... notify_do_dispatch () ; size = getdtablesize () ; for (;;) { your_svc_set = svc_fdset ; select (size, &your_svc_fdset, NULL, NULL, NULL) ; svc_getreqset(&your_svc_fdset) ; } } ______________________________________________________________________

Note on select: XView includes its own select, which is what the code above will actually call if linked with XView. The XView select does a syscall on the real select, selecting on all the descriptors the XView Notifier is interested in (notify_do_dispatch () turns on the Notifier) plus the descriptors your masks say you're interested in (in this case, the rpc server descriptors). When a descriptor becomes active, the system select () returns to the XView select (). If the descriptor is one the Notifier deals with, the Notifier does its thing without bothering your loop, but if the descriptor is one you have specified, the XView select () returns so you can deal with it. In this case, that means you pass it to the rpc dispatcher.

In effect, it looks to your loop like the Notifier is running asynchronously.

Of course, the above code is skeletal; you ought to add some error checking etc.

-- Dick St.Peters, GE Corporate R&D, Schenectady, NY stpeters@crd.ge.com uunet!crd.ge.com!stpeters

From: joerg@wp-470-1.fl.bs.dlr.de (J. Theuerkauf) Message-Id: <9203120658.AA02074@wp-470-1.fl.bs.dlr.de> To: ernohb!blaes Subject: Re: XView Problem Status: R

Hi,

all you have to do is to insert the following line before xv_main_loop():

notify_enable_rpc_svc(TRUE);

This will tell the XView-notifier to dispatch RPC-requests too.

--------------------------------------------------------------------- Joerg Theuerkauf /| joerg @ wp-470-1.fl.bs.dlr.de / | FL1A @ DLRVMBS.BITNET / | Tel. (+49) 531 395 22 91 _____/___|_____ Fax (+49) 531 395 25 50 / / / / / / / / /____/____/____/ | / Deutsche Forschungsanstalt | / fuer Luft- und Raumfahrt ___ | / Flughafen (o o) |/ D 3300 Braunschweig ---w--U--w-----------------------------------------------------------



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:06:38 CDT