From bbb3690f12191763a407e6a0edd521113b3c25ac Mon Sep 17 00:00:00 2001 From: zecke Date: Wed, 05 Feb 2003 08:54:58 +0000 Subject: Fix the IPC server and client registering channel is done locally with refcounts if the channel is already registered globally Fix some sizes to allow proper communication.. --- (limited to 'x11/libqpe-x11/qt') diff --git a/x11/libqpe-x11/qt/qcopchannel_qws.cpp b/x11/libqpe-x11/qt/qcopchannel_qws.cpp index e90f056..1cea80c 100644 --- a/x11/libqpe-x11/qt/qcopchannel_qws.cpp +++ b/x11/libqpe-x11/qt/qcopchannel_qws.cpp @@ -4,31 +4,43 @@ #include QList* QCopChannel::m_list = 0; +QMap QCopChannel::m_refCount; QCopChannel::QCopChannel( const QCString& channel, QObject* parent, const char* name ) : QObject( parent, name ),m_chan(channel) { - init(); if (!m_list ) { m_list = new QList; + /* only connect once */ + connect(OCOPClient::self(), SIGNAL(called(const QCString&, const QCString&, const QByteArray& ) ), + this, SLOT(rev(const QCString&, const QCString&, const QByteArray&) ) ); } + /* first registration or ref count is 0 for m_chan*/ + if (!m_refCount.contains( m_chan ) || !m_refCount[m_chan] ) { + m_refCount[m_chan] = 1; + OCOPClient::self()->addChannel( m_chan ); + }else + m_refCount[m_chan]++; + m_list->append(this); } void QCopChannel::receive( const QCString& msg, const QByteArray& ar ) { emit received( msg, ar ); } QCopChannel::~QCopChannel() { + if (m_refCount[m_chan] == 1 ) { + OCOPClient::self()->delChannel( m_chan ); + m_refCount[m_chan] = 0; + }else + m_refCount[m_chan]--; + + m_list->remove(this); if (m_list->count() == 0 ) { delete m_list; m_list = 0; } - OCOPClient::self()->delChannel( m_chan ); -} -void QCopChannel::init() { - OCOPClient::self()->addChannel( m_chan ); - connect(OCOPClient::self(), SIGNAL(called(const QCString&, const QCString&, const QByteArray& ) ), - this, SLOT(rev(const QCString&, const QCString&, const QByteArray&) ) ); + } QCString QCopChannel::channel()const { return m_chan; @@ -47,9 +59,11 @@ bool QCopChannel::send( const QCString& chan, const QCString& msg, } bool QCopChannel::sendLocally( const QCString& chann, const QCString& msg, const QByteArray& ar ) { + qWarning("Client:sendLocally %s %s", chann.data(), msg.data() ); if (!m_list ) return true; QCopChannel* chan; + for ( chan = m_list->first(); chan; chan = m_list->next() ) { if ( chan->channel() == chann ) chan->receive( msg, ar ); @@ -58,6 +72,5 @@ bool QCopChannel::sendLocally( const QCString& chann, const QCString& msg, return true; } void QCopChannel::rev( const QCString& chan, const QCString& msg, const QByteArray& ar ) { - if (chan == m_chan ) - emit received(msg, ar ); + sendLocally( chan, msg, ar ); } diff --git a/x11/libqpe-x11/qt/qcopchannel_qws.h b/x11/libqpe-x11/qt/qcopchannel_qws.h index 94b199e..c1220cb 100644 --- a/x11/libqpe-x11/qt/qcopchannel_qws.h +++ b/x11/libqpe-x11/qt/qcopchannel_qws.h @@ -4,6 +4,7 @@ #include #include #include +#include class OCOPClient; class QCopChannel : public QObject { @@ -30,8 +31,9 @@ private slots: void rev( const QCString& chan, const QCString&, const QByteArray& ); private: - void init(); + bool isRegisteredLocally( const QCString& str); static QList *m_list; + static QMap m_refCount; /* the channel */ QCString m_chan; class Private; -- cgit v0.9.0.2