From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: hreba Newsgroups: comp.lang.ada Subject: Re: Pass a serial port as user data in a GTK callback handler? Date: Sun, 16 Feb 2014 13:57:42 -0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net LmoqDmtcRUfH2420X6q2yQuoUJ8FyEOX/yN8rAcd/5nSabgLZ7 Cancel-Lock: sha1:TTPL22sWK3FybG16OTtYmgB0v+U= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: X-Original-Bytes: 2571 Xref: number.nntp.dca.giganews.com comp.lang.ada:184918 Date: 2014-02-16T13:57:42-03:00 List-Id: On 02/16/2014 06:20 AM, Dmitry A. Kazakov wrote: > On Sat, 15 Feb 2014 21:32:58 -0200, hreba wrote: > >> My actual programming exercise has a GTK GUI, and I want a callback >> handler to communicate through a serial port, so I need to pass the port >> in my user data, which must be of > > Additionally to other responses. > > There cannot be any reason to pass a stream object to GTK signal handler. > It is most certainly wrong to do any I/O from a signal handler, as it would > block the UI. So far I am only trying to open/close the port when the window opens/closes, or check the availability of /dev/ttyUSB0 upon a button press. > In some cases the UI may indeed be aware of I/O objects, like a COM port > configuration dialog or cancel button. In these cases there is a larger > object that contains the I/O object usually as a private member. I think this is what I am trying right now. > Specifically to GTK, you should better use smart pointers rather than raw > access types when dealing with callbacks and pass them around. The point > that UI and I/O will run in independent tasks. It is difficult to prevent > dangling pointers otherwise. [I don't consider global variables, of course] So I will be back when I have to fight with task programming in Ada, as soon as I begin with the real communication part. I did a fast search without finding a data structure "smart pointer" in GObject, GLib or GTK (devhelp), only as part of the C++ language (which I don't know). But I am using Ada. Could you give a hint/reference/link to that? -- Frank Hrebabetzky +55 / 48 / 3235 1106 Florianopolis, Brazil