/* g++ -o gsrc gsrc.cc `pkg-config --cflags --libs glibmm-2.4` */
#include <iostream>
#include <cstdlib>
#include <glibmm/main.h>

using namespace Glib;
using namespace std;

Glib::RefPtr<MainLoop> mainloop;

bool
show_me (IOCondition ioc)
{
	static IOCondition last_ioc = IOCondition (0);

	if (ioc != last_ioc) {
		cerr << "IO condition is now " << ioc << endl;
		last_ioc = ioc;
	}

	if (ioc & ~IO_IN) {
		cerr << "Hang up!\n";
		mainloop->quit ();
		return false;
	}

	return true;
}

int
main (int argc, char* argv[])
{
	mainloop = MainLoop::create (MainContext::create());

	Glib::RefPtr<IOSource> iosource = IOSource::create (0, IOCondition (IO_IN|IO_ERR|IO_HUP));

	iosource->connect (sigc::ptr_fun (&show_me));
	iosource->attach (mainloop->get_context());
	
	mainloop->run ();

	iosource->destroy ();

	cerr << "Back from main loop - expect to see source finalized next ...\n";
}
