comp.lang.ada
 help / color / mirror / Atom feed
* Calling XtAppAddTimeOut, help
@ 1999-05-30  0:00 John B. Matthews, M.D.
  1999-05-30  0:00 ` Paul Hussein
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: John B. Matthews, M.D. @ 1999-05-30  0:00 UTC (permalink / raw)


Under IRIX 6.5, I'm trying to set up a callback using the X-windows
function Xt.Intrinsic.XtAppAddTimeOut. For some reason, the code raises
Program_Error when the call to XtAppAddTimeOut occurs. Example code
follows. I've tried making my own binding and allocating more space to
Xt.Intrinsic.XtAppStruct. The SGI binding appears to match the declaration
in Intrinsic.h. A call to the obsolete function XtAddTimeOut succeeds, but
the callback never excecutes. Any insights much appreciated; post or email
(sans deleteme) is fine.

Thanks in advance,

John

----- gnatchop here ----
-- gnatmake -g -n32 -mips3 timeout.adb -largs -lXm -lXt -lMrm -lX11
with Ada.Unchecked_Conversion;
with System;
with Text_IO;
with Timer_CB;
with Xt.Intrinsic;

procedure TimeOut is

--- Convert a System.Address to an XtPointer
function To_XtPointer is new Ada.Unchecked_Conversion (
    System.Address, Xt.Intrinsic.XtPointer);

--- Timer static data
App_Context : Xt.Intrinsic.XtAppContext := new Xt.Intrinsic.XtAppStruct;
Timer_Id    : Xt.Intrinsic.XtIntervalId := 0;

begin
    --- Add a timer callback
    Timer_Id := Xt.Intrinsic.XtAppAddTimeOut ( -- dies here!
        App_Context => App_Context,
        Interval    => 200, -- 200 msec
        Proc        => Timer_CB.Timer_Callback'Access,
        Closure     => To_XtPointer (Timer_Id'Address));
    Delay 10.0;
    Text_IO.Put_Line("Main ends.");

end;

package body Timer_CB is

procedure Timer_Callback (
    Closure : Xt.Intrinsic.XtPointer;
    Id      : access Xt.Intrinsic.XtIntervalId) is
begin
    Text_IO.Put_Line("In callback.");
end Timer_Callback;

end;

with Text_IO;
with Xt.Intrinsic;

package Timer_CB is

procedure Timer_Callback (
    Closure : Xt.Intrinsic.XtPointer;
    Id      : access Xt.Intrinsic.XtIntervalId);
pragma Convention (C, Timer_Callback);

end;
----- code ends -----




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Calling XtAppAddTimeOut, help
  1999-05-30  0:00 Calling XtAppAddTimeOut, help John B. Matthews, M.D.
@ 1999-05-30  0:00 ` Paul Hussein
  1999-06-01  0:00 ` dennison
  1999-06-07  0:00 ` John
  2 siblings, 0 replies; 4+ messages in thread
From: Paul Hussein @ 1999-05-30  0:00 UTC (permalink / raw)


Where is you app context coming from. Should it not be the app context for
the main app window ?
I am working on SGI with gnat Ada and C,  and have just implemented a
timeout o.k.

However, I write the Motif code in C and interface to it.

Best approach would be to write it in C and get it working first, then
gradually move to Ada, one part at a time.

John B. Matthews, M.D. <matthewsj@deleteme.saic.com> wrote in message
news:matthewsj-ya023680003005990012190001@news.saic.com...
> Under IRIX 6.5, I'm trying to set up a callback using the X-windows
> function Xt.Intrinsic.XtAppAddTimeOut. For some reason, the code raises
> Program_Error when the call to XtAppAddTimeOut occurs. Example code
> follows. I've tried making my own binding and allocating more space to
> Xt.Intrinsic.XtAppStruct. The SGI binding appears to match the declaration
> in Intrinsic.h. A call to the obsolete function XtAddTimeOut succeeds, but
> the callback never excecutes. Any insights much appreciated; post or email
> (sans deleteme) is fine.
>
> Thanks in advance,
>
> John
>
> ----- gnatchop here ----
> -- gnatmake -g -n32 -mips3 timeout.adb -largs -lXm -lXt -lMrm -lX11
> with Ada.Unchecked_Conversion;
> with System;
> with Text_IO;
> with Timer_CB;
> with Xt.Intrinsic;
>
> procedure TimeOut is
>
> --- Convert a System.Address to an XtPointer
> function To_XtPointer is new Ada.Unchecked_Conversion (
>     System.Address, Xt.Intrinsic.XtPointer);
>
> --- Timer static data
> App_Context : Xt.Intrinsic.XtAppContext := new Xt.Intrinsic.XtAppStruct;
> Timer_Id    : Xt.Intrinsic.XtIntervalId := 0;
>
> begin
>     --- Add a timer callback
>     Timer_Id := Xt.Intrinsic.XtAppAddTimeOut ( -- dies here!
>         App_Context => App_Context,
>         Interval    => 200, -- 200 msec
>         Proc        => Timer_CB.Timer_Callback'Access,
>         Closure     => To_XtPointer (Timer_Id'Address));
>     Delay 10.0;
>     Text_IO.Put_Line("Main ends.");
>
> end;
>
> package body Timer_CB is
>
> procedure Timer_Callback (
>     Closure : Xt.Intrinsic.XtPointer;
>     Id      : access Xt.Intrinsic.XtIntervalId) is
> begin
>     Text_IO.Put_Line("In callback.");
> end Timer_Callback;
>
> end;
>
> with Text_IO;
> with Xt.Intrinsic;
>
> package Timer_CB is
>
> procedure Timer_Callback (
>     Closure : Xt.Intrinsic.XtPointer;
>     Id      : access Xt.Intrinsic.XtIntervalId);
> pragma Convention (C, Timer_Callback);
>
> end;
> ----- code ends -----






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Calling XtAppAddTimeOut, help
  1999-05-30  0:00 Calling XtAppAddTimeOut, help John B. Matthews, M.D.
  1999-05-30  0:00 ` Paul Hussein
@ 1999-06-01  0:00 ` dennison
  1999-06-07  0:00 ` John
  2 siblings, 0 replies; 4+ messages in thread
From: dennison @ 1999-06-01  0:00 UTC (permalink / raw)


In article <matthewsj-ya023680003005990012190001@news.saic.com>,
  matthewsj@deleteme.saic.com (John B. Matthews, M.D.) wrote:
> Under IRIX 6.5, I'm trying to set up a callback using the X-windows
> function Xt.Intrinsic.XtAppAddTimeOut. For some reason, the code
raises
> Program_Error when the call to XtAppAddTimeOut occurs. Example code

>     --- Add a timer callback
>     Timer_Id := Xt.Intrinsic.XtAppAddTimeOut ( -- dies here!
>         App_Context => App_Context,
>         Interval    => 200, -- 200 msec
>         Proc        => Timer_CB.Timer_Callback'Access,
>         Closure     => To_XtPointer (Timer_Id'Address));
>     Delay 10.0;
>     Text_IO.Put_Line("Main ends.");
>
> end;
>
> package body Timer_CB is
>
> procedure Timer_Callback (
>     Closure : Xt.Intrinsic.XtPointer;
>     Id      : access Xt.Intrinsic.XtIntervalId) is
> begin
>     Text_IO.Put_Line("In callback.");
> end Timer_Callback;
>
> end;
>
> with Text_IO;
> with Xt.Intrinsic;
>
> package Timer_CB is
>
> procedure Timer_Callback (
>     Closure : Xt.Intrinsic.XtPointer;
>     Id      : access Xt.Intrinsic.XtIntervalId);
> pragma Convention (C, Timer_Callback);


I've gotten this routine to work correctly before in Ada83, but of
course that doesn't mean much. Looking at your code I do notice a couple
of things (Hopefully deja won't screw up my formatting this time).

   o  You don't have a "pragma export (C, Timer_Callback)". That
might cause a problem.
   o  As written, the callback will never get called. For anything
to happen, you have to allow X to handle its events. This is typically
done by calling XtMainLoop(), or one of its subroutines.
   o  I don't see a call to XtAppInitialize. Without that call, your
App_Context is complete crap, and will probably cause your program to go
off into never-never land. I wouldn't have expected Program_Error to
result, but who knows?

I'd exepect your sample program to have a calling sequence similar to
the following:

XtAppInitialize()
XtAppAddTimeout()
XtMainLoop()

(Note that XtMainLoop will not return, so the program will have to be
killed somehow when you are done).

I highly suggest you get hold of volume 4 of the O'Reilly series of X
manuals. The rest of the series wouldn't be a bad idea either.

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Calling XtAppAddTimeOut, help
  1999-05-30  0:00 Calling XtAppAddTimeOut, help John B. Matthews, M.D.
  1999-05-30  0:00 ` Paul Hussein
  1999-06-01  0:00 ` dennison
@ 1999-06-07  0:00 ` John
  2 siblings, 0 replies; 4+ messages in thread
From: John @ 1999-06-07  0:00 UTC (permalink / raw)


Thanks to everyone who offered insight into this problem. Many pointed
out that XtAppContext wasn't being initialized; others observed that
there was no X event loop. The correct solution was a combination of
both. Specifically, the XtAppContext passed to XtAppAddTimeOut must be
precisely the same one created at initialization time and later used in
the event loop.

John

In article <matthewsj-ya023680003005990012190001@news.saic.com>,
  matthewsj@deleteme.saic.com (John B. Matthews, M.D.) wrote:
> Under IRIX 6.5, I'm trying to set up a callback using the X-windows
> function Xt.Intrinsic.XtAppAddTimeOut. For some reason, the code
raises
> Program_Error when the call to XtAppAddTimeOut occurs. Example code
> follows. I've tried making my own binding and allocating more space to
> Xt.Intrinsic.XtAppStruct. The SGI binding appears to match the
declaration
> in Intrinsic.h. A call to the obsolete function XtAddTimeOut succeeds,
but
> the callback never excecutes. Any insights much appreciated; post or
email
> (sans deleteme) is fine.
>
> Thanks in advance,
>
> John
>
> ----- gnatchop here ----
> -- gnatmake -g -n32 -mips3 timeout.adb -largs -lXm -lXt -lMrm -lX11
> with Ada.Unchecked_Conversion;
> with System;
> with Text_IO;
> with Timer_CB;
> with Xt.Intrinsic;
>
> procedure TimeOut is
>
> --- Convert a System.Address to an XtPointer
> function To_XtPointer is new Ada.Unchecked_Conversion (
>     System.Address, Xt.Intrinsic.XtPointer);
>
> --- Timer static data
> App_Context : Xt.Intrinsic.XtAppContext := new
Xt.Intrinsic.XtAppStruct;
> Timer_Id    : Xt.Intrinsic.XtIntervalId := 0;
>
> begin
>     --- Add a timer callback
>     Timer_Id := Xt.Intrinsic.XtAppAddTimeOut ( -- dies here!
>         App_Context => App_Context,
>         Interval    => 200, -- 200 msec
>         Proc        => Timer_CB.Timer_Callback'Access,
>         Closure     => To_XtPointer (Timer_Id'Address));
>     Delay 10.0;
>     Text_IO.Put_Line("Main ends.");
>
> end;
>
> package body Timer_CB is
>
> procedure Timer_Callback (
>     Closure : Xt.Intrinsic.XtPointer;
>     Id      : access Xt.Intrinsic.XtIntervalId) is
> begin
>     Text_IO.Put_Line("In callback.");
> end Timer_Callback;
>
> end;
>
> with Text_IO;
> with Xt.Intrinsic;
>
> package Timer_CB is
>
> procedure Timer_Callback (
>     Closure : Xt.Intrinsic.XtPointer;
>     Id      : access Xt.Intrinsic.XtIntervalId);
> pragma Convention (C, Timer_Callback);
>
> end;
> ----- code ends -----
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-06-07  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-30  0:00 Calling XtAppAddTimeOut, help John B. Matthews, M.D.
1999-05-30  0:00 ` Paul Hussein
1999-06-01  0:00 ` dennison
1999-06-07  0:00 ` John

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox