1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#include "../../ipc/client/ocopclient.h"
#include <qcopchannel_qws.h>
QList<QCopChannel>* QCopChannel::m_list = 0;
QMap<QCString, int> QCopChannel::m_refCount;
QCopChannel::QCopChannel( const QCString& channel, QObject* parent,
const char* name )
: QObject( parent, name ),m_chan(channel) {
if (!m_list ) {
m_list = new QList<QCopChannel>;
/* 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] ) {
qWarning("adding channel %s", m_chan.data() );
m_refCount[m_chan] = 1;
OCOPClient::self()->addChannel( m_chan );
}else{
qWarning("reffing up for %s %d", m_chan.data(), m_refCount[m_chan] );
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;
}
}
QCString QCopChannel::channel()const {
return m_chan;
}
bool QCopChannel::isRegistered( const QCString& chan) {
if (m_refCount.contains(chan) ) {
qDebug("Client:locally contains");
return true;
}
return OCOPClient::self()->isRegistered( chan );
}
bool QCopChannel::send( const QCString& chan, const QCString& msg ) {
QByteArray ar;
return send(chan, msg, ar );
}
bool QCopChannel::send( const QCString& chan, const QCString& msg,
const QByteArray& ar ) {
OCOPClient::self()->send( chan, msg, ar );
return true;
}
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 );
}
return true;
}
void QCopChannel::rev( const QCString& chan, const QCString& msg, const QByteArray& ar ) {
sendLocally( chan, msg, ar );
}
|