Re: Gtkmm thread example



Argh, forgot to reply to all, copypaste occurs:

Hi -

On Thu, Jun 5, 2008 at 8:43 PM, Damon Register <damonregister bellsouth net> wrote:
What I really want to do (I think) is have the main gtkmm app and a separate
thread that reads the hardware and signals the main app when there is data.
I have been searching for info and examples.  Perhaps I have found something
quite close to what I need.
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__Threads.html
shows a link to this dispatcher example.
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/thread_2dispatcher_8cc-example.html#a17

You've found the correct classes to use here.

This might be just what I need but the example is glibmm and I don't know how
to adapt to a gtkmm. 

The example you found is a bit confusing as it does not show how it fits in with gtkmm, and it's a bit long to be a simple example, but that's probably because there's not a lot to using a dispatcher.

Here's a breakdown:
- from your main thread (the UI thread), connect your dispatcher to a callback function via connect()
- start your second thread (the hardware polling thread), and in that, use the emit() or simply <dispatcher_name>() on the dispatcher instance to cause the dispatcher to fire, which means your main thread will run the signal handler you connected in step one.

However, this does not solve everything.  Presumably you want your hardware thread to provide some data to the UI thread, which the dispatcher does not provide.  You have to use some data structure that is common between them, and protect that data structure with a mutex, locking before access and unlocking after.

Hopefully that is enough to get you going..

dave


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]