Re: Sending slots to main thread (implemented)



On Sat, 2007-09-01 at 15:52 +0200, joaquinduran adtelecom es wrote:
> On Sat Sep  1 14:38 , Chris Vine  sent:
> >
> >You can however use the unwrapped g_idle_add() for passing your
> >callbacks to the thread in which the default programme GMainContext is
> >running, if you want.
> >
> 
> Thanks but I think that my proposed class is working fine.

I have replied separately on the part of your e-mail about disconnecting
and connecting slots in Glib::Dispatcher objects, and I wanted to delay
replying on this other point until I had produced some code which I had
checked.

Obviously your approach works fine.  However, it can be reduced down to
just this:

------
extern "C" gboolean slot_wrapper(void*);
inline gboolean slot_wrapper(void* data) {
  try {(*static_cast<sigc::slot<void>*>(data))();}
  // we can't propagate exceptions in functions with C linkage
  catch (...) {std::cerr << "Exception thrown in ...\n";}
  delete static_cast<sigc::slot<void>*>(data);
  return false;
}

inline void dispatch_slot(const sigc::slot<void>& callback) {
  g_idle_add(slot_wrapper, new sigc::slot<void>(callback));
}
------

You would need to include glib/gmain.h for this to compile.  The
"public" function to call is dispatch_slot(), the other is just a C
callback wrapping the slot.

This would form an alternative to the Glib::SignalIdle::connect_once()
proposal, and I could provide it as a patch in Glib namespace if the
glibmm maintainers think it useful (but a name other than
Glib::dispatch_slot() would probably have to be chosen).

Chris





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