Re: Glib::Dispatcher and data transfer into main loop
- From: Andreas Volz <lists brachttal net>
- To: gtkmm-list gnome org
- Subject: Re: Glib::Dispatcher and data transfer into main loop
- Date: Sat, 19 Apr 2008 19:27:41 +0200
Am Sat, 19 Apr 2008 16:55:47 +0100 schrieb Toby Roworth:
> Could you use sigc::bind() ? It annoying to get working at times, but
> the tutorial is vaguely helpful:
> http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-binding-extra-arguments.html
>
> I'm not sure if that's what you want, but good luck either way
I know sigc::bind. But I think it doesn't help here. It's possible to
bind data from the point of connecting to a signal. The signal is
connected inside the gtkmm main loop. But my data that is emited comes
direct from the thread.
regards
Andreas
> Andreas Volz wrote:
> > Hello,
> >
> > I'm using a Glib::Dispatcher to dispatch data from a thread into my
> > main loop. This is my code:
> >
> > Glib::Dispatcher dispatchSignal;
> >
> > ...
> > // cMan is a thread...
> > cMan.signalFinish.connect (sigc::mem_fun (this,
> > &IconBrowser::onFinishWrapper));
> > dispatchSignal.connect(sigc::mem_fun(*this,
> > &IconBrowser::onFinish)); ...
> >
> > void IconBrowser::onFinishWrapper (const CacheManagerFinishEvent
> > &dlFinishEvent) {
> > cout << "IconBrowser:: Download of '" <<
> > dlFinishEvent.getFilename () << "' (" << (float)
> > dlFinishEvent.getMemory ().size () / (1024.0) << " kb ) finished!"
> > << endl; m_addIconMutex.lock ();
> >
> > m_iconData.filename = dlFinishEvent.getFilename ();
> > m_iconData.description = dlFinishEvent.getDescription ();
> > m_iconData.href = dlFinishEvent.getHref ();
> >
> > dispatchSignal ();
> >
> > m_addIconMutex.unlock ();
> > }
> >
> > void IconBrowser::onFinish ()
> > {
> > Global &global = Global::instance ();
> > Gtk::ProgressBar *loadProgressBar = global.getProgressBar ();
> >
> > m_addIconMutex.lock ();
> >
> > addIconEntry (m_iconData.filename,
> > Glib::path_get_basename (m_iconData.description),
> > m_iconData.href, 128, 128);
> >
> > ++iconCount;
> >
> > cout << "progress: " << progressStatus << endl;
> > loadProgressBar->set_fraction (progressStatus);
> > progressStatus += progressStep;
> >
> > if (iconCount >= wpSize)
> > {
> > iconCount = 0;
> > progressStatus = 0;
> > loadProgressBar->set_fraction (iconCount);
> > }
> >
> > m_addIconMutex.unlock ();
> > }
> >
> > This works in most cases. But sometimes The thread calls multiple
> > times onFinishWrapper() before the main loop called each dispatched
> > onFinish(). So the data saved in m_iconData is not correct in some
> > cases.
> >
> > Any ideas how to solve that problem? I've seen no way to give data
> > to the dispatchSignal() call. So I need a member variable to
> > transfer data from the thread called function to the dispatched
> > function. I could think of a queue that saves all the incoming data
> > from the thread for later use in the dispatched function. Do you
> > think that's the best way to do it? Any other ideas?
> >
> > regards
> > Andreas
> > _______________________________________________
> > gtkmm-list mailing list
> > gtkmm-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtkmm-list
> >
> >
> >
>
> --
> ------------------------------------------------------------------------
> Sent by Toby Roworth (webmaster orkyden co uk)
> This message is intended for the named reciepients only, and should
> not be forwarded without permission
> The conents of this message may be ©Toby Roworth
>
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]