+2002-07-31 John Levon <levon@movementarian.org>
+
+ * io_callback.h: make a more proper class
+
+ * lyx_gui.C: implement removal of I/O callbacks
+
2002-07-30 John Levon <levon@movementarian.org>
* qlkey.h:
#include <config.h>
#include "lyxserver.h"
+#include "debug.h"
#include <qsocketnotifier.h>
+#include <boost/scoped_ptr.hpp>
+
/**
* io_callback - a simple wrapper for asynchronous pipe notification
*
/// connect a read ready notification for fd to the LyXComm
io_callback(int fd, LyXComm * comm)
: comm_(comm) {
- QSocketNotifier * sn = new QSocketNotifier(fd,
- QSocketNotifier::Read, this);
- connect(sn, SIGNAL(activated(int)), this, SLOT(data_received()));
+ sn_.reset(new QSocketNotifier(fd, QSocketNotifier::Read, this));
+ connect(sn_.get(), SIGNAL(activated(int)), this, SLOT(data_received()));
}
-
+
public slots:
void data_received() {
comm_->read_ready();
}
private:
+ /// our notifier
+ boost::scoped_ptr<QSocketNotifier> sn_;
+
LyXComm * comm_;
};
#endif
using std::vector;
-using std::hex;
+using std::map;
using std::endl;
extern BufferList bufferlist;
return fontloader.available(font);
}
+
+namespace {
+ map<int, io_callback *> io_callbacks;
+}
+
void lyx_gui::set_read_callback(int fd, LyXComm * comm)
{
- // FIXME: "leak"
- new io_callback(fd, comm);
+ io_callbacks[fd] = new io_callback(fd, comm);
+}
+
+
+void lyx_gui::remove_read_callback(int fd)
+{
+ map<int, io_callback *>::iterator it = io_callbacks.find(fd);
+ if (it != io_callbacks.end()) {
+ delete it->second;
+ io_callbacks.erase(it);
+ }
}