ToolTalk and pop11 
Author Message
 ToolTalk and pop11

I am trying to intergrate SUNs ToolTalk library into pop11. This should allow
pop11 and other process to talk to each other without having to know too much
about each other.

When you open a ToolTalk conection you get back a file descriptor which is used
for passing messages. This is okay because the library contains all the code
for sending a receiving messages. But the one thing you need to do is setup
an async alerting method so you know when to receive a message. The recomended
version of application using the Xtoolkit is :-

void TT_InputCallback( XtPointer /* closure */, int *source,
                         XtInputId * /* id */ )
{
Tt_message *message;

        message = tt_message_receive();
        ;;;messages handled by callbacks

Quote:
}

main()
{
int TT_fd;
char *procid;

        ...

        procid = tt_open();
        TT_fd = tt_fd();

        ....

        inputID = XtAppAddInput( app, TT_fd,
                                 (XtPointer)(  XtInputReadMask
                                             | XtInputExceptMask ),
                                 TT_InputCallback, 0 );

        ....
        XtAppMainLoop(app);

Quote:
}

The problem is that the pop11 version of XtAppAddInput (XptAppAddInout) expects
a device and not a file descriptor.

So I thought I would use XtAddInput from xt_r2compat as this uses a file descriptor
instead of a device. However when pop11 is sent a message my input handler does
not get called. If I call tt_message_receive by hand then I recieve the message.

What im I doing wrong or is ther another way of calling a pop11 procedure
when data arrives on a file descriptor?

(I know I could write some C code to do this but that would be cheating).


define pop_receive_tt_message(data,dev,id);
lvars data,dev,id,message;

    exacc tt_message_receive() -> message;

    if message.is_null_external_ptr then
        ;;;warning(0,'Null tooltalk mesasge recieved');
        return();
    endif;

    if exacc tt_pointer_error(message) = TT_ERR_NOMP then
        warning(0,'Tooltalk server is down');
        return();
    endif;

    ;;;handle messages via callbacks

enddefine;

include xt_constants;
define handle_tt_messages(app,tt_fd,data);
lvars dev tt_fd app data;
    ;;;make a fake device for tt_fd;
    consdevice('Tooltalk', 'ToolTalk', true, 0,
        {%
            {% erasenum(%3%), identfn, erase %},
            false, false, false
        %}
    ) -> dev;
    XtAddInput(tt_fd, XtInputReadMask || XtInputExceptMask,
        pop_receive_tt_message, data);
enddefine;

handle_tt_messages(false,tt_fd,"handle_tt_messages") -> ptr;
is_null_external_ptr(ptr) =>
** false



Fri, 29 Aug 1997 20:44:14 GMT  
 ToolTalk and pop11

Quote:

> I am trying to intergrate SUNs ToolTalk library into pop11. This should allow
> pop11 and other process to talk to each other without having to know too much
> about each other.

As Julian mentioned in another message.... sockets are coming! Yay!
Everybody give John Gibson a round of applause :-)

Quote:
> When you open a ToolTalk conection you get back a file descriptor which is used
> for passing messages. This is okay because the library contains all the code
> for sending a receiving messages. But the one thing you need to do is setup
> an async alerting method so you know when to receive a message. The recomended
> version of application using the Xtoolkit is :-
[snip]
> The problem is that the pop11 version of XtAppAddInput (XptAppAddInout) expects
> a device and not a file descriptor.

> So I thought I would use XtAddInput from xt_r2compat as this uses a file descriptor
> instead of a device. However when pop11 is sent a message my input handler does
> not get called. If I call tt_message_receive by hand then I recieve the message.

In the next version Poplog we will be able to import file-descriptors as
devices which would solve this (and many other) problems.... but until
then...

Quote:
> What im I doing wrong or is ther another way of calling a pop11 procedure
> when data arrives on a file descriptor?

You're not doing anything wrong..... the events are not getting
processed. All most of the R2 compatability functions do is call the
appropriate modern function with an appcontext. So XtAddInput calls
XtAppAddInput... unfortunately this application context is private to
the Xt libraries, so we cannot get hold of it to make it asyc with
XptAsyncAppContext. So if you use XtAddInput et al you will have to
process the events yourself with XtNextEvent etc.

Another solution would be to call the external XtAppAddInput directly
from Poplog, eg:

    exload 'test' ['-lXt' '-lX11']
        (language C, prefix 'raw_')
        XtAddInput(fd, mask, cbk, data):int;
    endexload;

    vars i = exacc raw_XtAddInput(
        fd,
        XtInputReadMask,
        XptExportInputCached(pop_receive_tt_message, false,data)
    );

The problems with this are:

    1) It's won't work under VMS since XtAppAddInput is fouled up under
    that OS for various reasons. There's no polite way you can fix this
    one (actually... I lie... I suppose you could call the Poplog
    XtAppAddInput with a dummy file descriptor to get them added... but
    this is still messy)

    2) Things won't get added to the various internal lists Poplog uses
    to ensure that the callbacks etc do not become garbage while the
    appcontext is live. You'll have to do this yourself.

Quote:
> (I know I could write some C code to do this but that would be cheating).

Indeed. The above is so much cleaner :-) :-)

Adrian


Phone: +44 (0)1273 678367 URL: http://www.cogs.susx.ac.uk/users/adrianh/



Mon, 01 Sep 1997 06:15:39 GMT  
 ToolTalk and pop11

Quote:

> When you open a ToolTalk conection you get back a file descriptor which is used
> for passing messages. This is okay because the library contains all the code
> for sending a receiving messages. But the one thing you need to do is setup
> an async alerting method so you know when to receive a message. The recomended
> version of application using the Xtoolkit is :-
> ...

> The problem is that the pop11 version of XtAppAddInput (XptAppAddInout) expects
> a device and not a file descriptor.

You can use XptLoadProcedures to get to the C version of
XtAppAddInput. Here is an example:

   XptLoadProcedures tt_procs lvars XtAppAddInput;

   ;;; does no type checking. Discards any result.
   define myXtAppAddInput(app, fd, mask, efc);
        exacc (5) raw_XtAppAddInput(app, fd, mask, efc, 0);
   enddefine;

Note the efc is an external function closure. You can get one
of using make_exfunc_closure. Here is a more worked out example:

 compile_mode :pop11 +strict;

 include xt_constants;

  XptLoadProcedures tt_example lvars XtAppAddInput;

  constant procedure register_tt_input_callback; ;;; forward decl.

  define tt_input_callback(exptr); lvars exptr;
     lvars message = exacc tt_message_receive();

     ... do stuff here

     register_tt_input_callback();
  enddefine;

  constant tt_input_efc = make_exfunc_closure(tt_input_callback,
                            XptCallbackFlags, false);

  define register_tt_input_callback;

     exacc (5) rawXtAppAddInput(XptDefaultAppContext, tt_fd,
            XtInputReadMask || XtInputExceptMask, tt_input_efc, 0);
  enddefine;

Hope this helps. Jon.



Mon, 01 Sep 1997 07:14:57 GMT  
 ToolTalk and pop11


[snip]

Quote:
>    exload 'test' ['-lXt' '-lX11']
>        (language C, prefix 'raw_')
>        XtAddInput(fd, mask, cbk, data):int;
>    endexload;

>    vars i = exacc raw_XtAddInput(
>        fd,
>        XtInputReadMask,
>        XptExportInputCached(pop_receive_tt_message, false,data)
>    );

The above should, of course, be:

     exload 'test' ['-lXt' '-lX11']
         (language C, prefix 'raw_')
         XtAppAddInput(ac, fd, mask, cbk, data):int;
     endexload;

     vars i = exacc raw_XtAppAddInput(
         XptCurrentAppContext,      ;;; or whatever...
         fd,
         XtInputReadMask,
         XptExportInputCached(pop_receive_tt_message, data, true)
     );

Moral: never write code without running it first <sigh>

Adrian



Mon, 01 Sep 1997 19:35:29 GMT  
 ToolTalk and pop11

Quote:
> Moral: never write code without running it first <sigh>

> Adrian

Tricky... I usually find I have to write it *before* I run it ;-)

Andrew



Tue, 02 Sep 1997 01:37:53 GMT  
 ToolTalk and pop11

Quote:

>> Moral: never write code without running it first <sigh>

>> Adrian

>Tricky... I usually find I have to write it *before* I run it ;-)

>Andrew

Nah! Not me. I do both at once because I am a Pop programmer. :-)

BTW - Behrouz, my postgrad student, has just got a program working that converts
CAD drawings in DXF to model-based vision programs. Most of the interfacing is done
in Pop-11. The vision programs are in C, but can be shadowed by a Pop-11 version. Thus
we have an interactive system that generates model-based vision programs within 20
seconds. (I consider this slow.) Meanwhile, in the States people are doing over-night
runs to do the same job with batch compilers ...

P.S. Anthony Worrall had a hand in the development, as did I.

James Anderson



Tue, 02 Sep 1997 18:54:11 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. PROPEL 0.2+ (pop11 for windows) (pop11 4 windows)

2. VW and ToolTalk

3. Is there an Ada language binding for ToolTalk?

4. tooltalk interface?

5. Tcl/Tk and Tooltalk

6. ToolTalk / TclTk Repost Please

7. Tooltalk for Tcl/Tk

8. Tcl and ToolTalk

9. Tcl and ToolTalk

10. Tcl/Tk and ToolTalk

11. Announcing TooCL : Tooltalk for TCL

12. tooltalk.tcl : missing file in Toocl

 

 
Powered by phpBB® Forum Software