Diffstat (limited to 'x11/libqpe-x11/qt/qcopchannel_qws.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | x11/libqpe-x11/qt/qcopchannel_qws.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
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 | |||
@@ -1,39 +1,51 @@ | |||
1 | 1 | ||
2 | #include "../../ipc/client/ocopclient.h" | 2 | #include "../../ipc/client/ocopclient.h" |
3 | 3 | ||
4 | #include <qcopchannel_qws.h> | 4 | #include <qcopchannel_qws.h> |
5 | 5 | ||
6 | QList<QCopChannel>* QCopChannel::m_list = 0; | 6 | QList<QCopChannel>* QCopChannel::m_list = 0; |
7 | QMap<QCString, int> QCopChannel::m_refCount; | ||
7 | 8 | ||
8 | QCopChannel::QCopChannel( const QCString& channel, QObject* parent, | 9 | QCopChannel::QCopChannel( const QCString& channel, QObject* parent, |
9 | const char* name ) | 10 | const char* name ) |
10 | : QObject( parent, name ),m_chan(channel) { | 11 | : QObject( parent, name ),m_chan(channel) { |
11 | init(); | ||
12 | if (!m_list ) { | 12 | if (!m_list ) { |
13 | m_list = new QList<QCopChannel>; | 13 | m_list = new QList<QCopChannel>; |
14 | /* only connect once */ | ||
15 | connect(OCOPClient::self(), SIGNAL(called(const QCString&, const QCString&, const QByteArray& ) ), | ||
16 | this, SLOT(rev(const QCString&, const QCString&, const QByteArray&) ) ); | ||
14 | } | 17 | } |
18 | /* first registration or ref count is 0 for m_chan*/ | ||
19 | if (!m_refCount.contains( m_chan ) || !m_refCount[m_chan] ) { | ||
20 | m_refCount[m_chan] = 1; | ||
21 | OCOPClient::self()->addChannel( m_chan ); | ||
22 | }else | ||
23 | m_refCount[m_chan]++; | ||
24 | |||
15 | m_list->append(this); | 25 | m_list->append(this); |
16 | } | 26 | } |
17 | void QCopChannel::receive( const QCString& msg, const QByteArray& ar ) { | 27 | void QCopChannel::receive( const QCString& msg, const QByteArray& ar ) { |
18 | emit received( msg, ar ); | 28 | emit received( msg, ar ); |
19 | } | 29 | } |
20 | QCopChannel::~QCopChannel() { | 30 | QCopChannel::~QCopChannel() { |
31 | if (m_refCount[m_chan] == 1 ) { | ||
32 | OCOPClient::self()->delChannel( m_chan ); | ||
33 | m_refCount[m_chan] = 0; | ||
34 | }else | ||
35 | m_refCount[m_chan]--; | ||
36 | |||
37 | |||
21 | m_list->remove(this); | 38 | m_list->remove(this); |
22 | if (m_list->count() == 0 ) { | 39 | if (m_list->count() == 0 ) { |
23 | delete m_list; | 40 | delete m_list; |
24 | m_list = 0; | 41 | m_list = 0; |
25 | } | 42 | } |
26 | OCOPClient::self()->delChannel( m_chan ); | 43 | |
27 | } | ||
28 | void QCopChannel::init() { | ||
29 | OCOPClient::self()->addChannel( m_chan ); | ||
30 | connect(OCOPClient::self(), SIGNAL(called(const QCString&, const QCString&, const QByteArray& ) ), | ||
31 | this, SLOT(rev(const QCString&, const QCString&, const QByteArray&) ) ); | ||
32 | } | 44 | } |
33 | QCString QCopChannel::channel()const { | 45 | QCString QCopChannel::channel()const { |
34 | return m_chan; | 46 | return m_chan; |
35 | } | 47 | } |
36 | bool QCopChannel::isRegistered( const QCString& chan) {; | 48 | bool QCopChannel::isRegistered( const QCString& chan) {; |
37 | return OCOPClient::self()->isRegistered( chan ); | 49 | return OCOPClient::self()->isRegistered( chan ); |
38 | } | 50 | } |
39 | bool QCopChannel::send( const QCString& chan, const QCString& msg ) { | 51 | bool QCopChannel::send( const QCString& chan, const QCString& msg ) { |
@@ -42,22 +54,23 @@ bool QCopChannel::send( const QCString& chan, const QCString& msg ) { | |||
42 | } | 54 | } |
43 | bool QCopChannel::send( const QCString& chan, const QCString& msg, | 55 | bool QCopChannel::send( const QCString& chan, const QCString& msg, |
44 | const QByteArray& ar ) { | 56 | const QByteArray& ar ) { |
45 | OCOPClient::self()->send( chan, msg, ar ); | 57 | OCOPClient::self()->send( chan, msg, ar ); |
46 | return true; | 58 | return true; |
47 | } | 59 | } |
48 | bool QCopChannel::sendLocally( const QCString& chann, const QCString& msg, | 60 | bool QCopChannel::sendLocally( const QCString& chann, const QCString& msg, |
49 | const QByteArray& ar ) { | 61 | const QByteArray& ar ) { |
62 | qWarning("Client:sendLocally %s %s", chann.data(), msg.data() ); | ||
50 | if (!m_list ) | 63 | if (!m_list ) |
51 | return true; | 64 | return true; |
52 | QCopChannel* chan; | 65 | QCopChannel* chan; |
66 | |||
53 | for ( chan = m_list->first(); chan; chan = m_list->next() ) { | 67 | for ( chan = m_list->first(); chan; chan = m_list->next() ) { |
54 | if ( chan->channel() == chann ) | 68 | if ( chan->channel() == chann ) |
55 | chan->receive( msg, ar ); | 69 | chan->receive( msg, ar ); |
56 | } | 70 | } |
57 | 71 | ||
58 | return true; | 72 | return true; |
59 | } | 73 | } |
60 | void QCopChannel::rev( const QCString& chan, const QCString& msg, const QByteArray& ar ) { | 74 | void QCopChannel::rev( const QCString& chan, const QCString& msg, const QByteArray& ar ) { |
61 | if (chan == m_chan ) | 75 | sendLocally( chan, msg, ar ); |
62 | emit received(msg, ar ); | ||
63 | } | 76 | } |