summaryrefslogtreecommitdiff
path: root/adapters
diff options
context:
space:
mode:
authorPietro Cerutti <gahr@gahr.ch>2014-06-17 17:04:44 +0200
committerJan-Erik Rediger <janerik@fnordig.de>2015-07-27 23:17:41 +0200
commit1984b309b82f1dd07f0ee04bb618e4b4ff41a3fe (patch)
tree2d27a3312c5c1cdf3243852ee6d4b7e77a5b0574 /adapters
parent8ef7d595acd9f4263aa9720dfc57712bbf2cdb33 (diff)
Add hooks for read/write/cleanup
Diffstat (limited to 'adapters')
-rw-r--r--adapters/qt.h72
1 files changed, 68 insertions, 4 deletions
diff --git a/adapters/qt.h b/adapters/qt.h
index 54c0b91..9c801db 100644
--- a/adapters/qt.h
+++ b/adapters/qt.h
@@ -28,10 +28,46 @@
#include <QSocketNotifier>
#include "../async.h"
+static void RedisQtAddRead(void *);
+static void RedisQtDelRead(void *);
+static void RedisQtAddWrite(void *);
+static void RedisQtDelWrite(void *);
+static void RedisQtCleanup(void *);
+
class RedisQtAdapter : public QObject {
Q_OBJECT
+ friend
+ void RedisQtAddRead(void * adapter) {
+ RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
+ a->addRead();
+ }
+
+ friend
+ void RedisQtDelRead(void * adapter) {
+ RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
+ a->delRead();
+ }
+
+ friend
+ void RedisQtAddWrite(void * adapter) {
+ RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
+ a->addWrite();
+ }
+
+ friend
+ void RedisQtDelWrite(void * adapter) {
+ RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
+ a->delWrite();
+ }
+
+ friend
+ void RedisQtCleanup(void * adapter) {
+ RedisQtAdapter * a = static_cast<RedisQtAdapter *>(adapter);
+ a->cleanup();
+ }
+
public:
RedisQtAdapter(QObject * parent = 0)
: QObject(parent), m_ctx(0), m_read(0), m_write(0) { }
@@ -40,16 +76,44 @@ class RedisQtAdapter : public QObject {
void setContext(redisAsyncContext * ac) {
m_ctx = ac;
+ m_ctx->ev.data = this;
+ m_ctx->ev.addRead = RedisQtAddRead;
+ m_ctx->ev.delRead = RedisQtDelRead;
+ m_ctx->ev.addWrite = RedisQtAddWrite;
+ m_ctx->ev.delWrite = RedisQtDelWrite;
+ m_ctx->ev.cleanup = RedisQtCleanup;
+ }
- delete m_read;
- m_read = new QSocketNotifier(ac->c.fd, QSocketNotifier::Read, this),
+ private:
+ void addRead() {
+ if (m_read) return;
+ m_read = new QSocketNotifier(m_ctx->c.fd, QSocketNotifier::Read, 0),
connect(m_read, SIGNAL(activated(int)), this, SLOT(read()));
+ }
- delete m_write;
- m_write = new QSocketNotifier(ac->c.fd, QSocketNotifier::Write, this);
+ void delRead() {
+ if (!m_read) return;
+ delete m_read;
+ m_read = 0;
+ }
+
+ void addWrite() {
+ if (m_write) return;
+ m_write = new QSocketNotifier(m_ctx->c.fd, QSocketNotifier::Write, 0);
connect(m_write, SIGNAL(activated(int)), this, SLOT(write()));
}
+ void delWrite() {
+ if (!m_write) return;
+ delete m_write;
+ m_write = 0;
+ }
+
+ void cleanup() {
+ delRead();
+ delWrite();
+ }
+
private slots:
void read() { redisAsyncHandleRead(m_ctx); }
void write() { redisAsyncHandleWrite(m_ctx); }