author | zecke <zecke> | 2003-02-10 21:36:08 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-02-10 21:36:08 (UTC) |
commit | eb9be7ada3de060d8c5ce52590bd91120ed5e1bd (patch) (side-by-side diff) | |
tree | 58a5566691737f6f3ee12fa7005b8bdf2d12332b /x11/ipc/client | |
parent | bbb3cdf8f91d567f6c2e786bd144b64bd679ff9a (diff) | |
download | opie-eb9be7ada3de060d8c5ce52590bd91120ed5e1bd.zip opie-eb9be7ada3de060d8c5ce52590bd91120ed5e1bd.tar.gz opie-eb9be7ada3de060d8c5ce52590bd91120ed5e1bd.tar.bz2 |
better commit that...
-rw-r--r-- | x11/ipc/client/ocopclient.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/x11/ipc/client/ocopclient.cpp b/x11/ipc/client/ocopclient.cpp index 91827e7..f59fa41 100644 --- a/x11/ipc/client/ocopclient.cpp +++ b/x11/ipc/client/ocopclient.cpp @@ -1,167 +1,167 @@ #include <errno.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <sys/socket.h> #include <sys/types.h> #include <sys/un.h> #include <qfile.h> #include <qtimer.h> #include "../common/ocoppacket.h" #include "ocopclient.h" OCOPClient* OCOPClient::m_self = 0; OCOPClient* OCOPClient::self() { if (!m_self ) { m_self = new OCOPClient(); } return m_self; } OCOPClient::OCOPClient( const QString& path, QObject* obj ) : QObject( obj ) { m_tries = 0; init(QFile::encodeName(path) ); } OCOPClient::~OCOPClient() { delete m_notify; close( m_socket ); } void OCOPClient::init() { // failed start ther server NOW!!! startUP(); QCString str; init(str ); } void OCOPClient::init( const QCString& ) { m_tries++; struct sockaddr_un unix_adr; if ( (m_socket = socket(PF_UNIX, SOCK_STREAM, 0) ) < 0 ) { qWarning("could not socket"); if ( m_tries < 8 ) QTimer::singleShot(400, this,SLOT(init() ) ); return; } memset(&unix_adr, 0, sizeof(unix_adr ) ); unix_adr.sun_family = AF_UNIX; sprintf(unix_adr.sun_path,"%s/.opie.cop", getenv("HOME") ); int length = sizeof(unix_adr.sun_family) + strlen(unix_adr.sun_path); if ( ::connect(m_socket, (struct sockaddr*)&unix_adr, length ) < 0 ) { qWarning("could not connect %d", errno ); close( m_socket ); if ( m_tries < 8 ) QTimer::singleShot(400, this, SLOT(init() ) ); return; } m_notify = new QSocketNotifier(m_socket, QSocketNotifier::Read, this ); connect( m_notify, SIGNAL(activated(int) ), this, SLOT(newData() ) ); } /** * new data * read the header check magic number * and maybe read body */ void OCOPClient::newData() { OCOPPacket pack = packet(); if ( pack.channel().isEmpty() ) return; switch( pack.type() ) { case OCOPPacket::Register: case OCOPPacket::Unregister: case OCOPPacket::Method: case OCOPPacket::RegisterChannel: case OCOPPacket::UnregisterChannel: case OCOPPacket::Return: case OCOPPacket::Signal: /* is Registered should be handled sync */ case OCOPPacket::IsRegistered: break; /* emit the signal */ case OCOPPacket::Call: emit called( pack.channel(), pack.header(), pack.content() ); break; } } OCOPPacket OCOPClient::packet() const{ QCString chan; QCString func; QByteArray ar; OCOPHead head; memset(&head, 0, sizeof(head) ); read(m_socket, &head, sizeof(head) ); if ( head.magic == 47 ) { - qWarning("Client:Magic Match"); +// qWarning("Client:Magic Match"); chan = QCString( head.chlen+1); func = QCString( head.funclen+1 ); ar = QByteArray( head.datalen); read(m_socket, chan.data(), head.chlen ); read(m_socket, func.data(), head.funclen ); read(m_socket, ar.data(), head.datalen ); - qWarning("Client:%d %s",head.chlen,chan.data() ); +// qWarning("Client:%d %s",head.chlen,chan.data() ); } OCOPPacket pack(head.type, chan, func, ar ); return pack; } /* * we've blocking IO here on these sockets * so we send and go on read * this will be blocked */ bool OCOPClient::isRegistered( const QCString& chan ) const{ - qWarning("OCopClient::isRegistered %s", chan.data() ); +// qWarning("OCopClient::isRegistered %s", chan.data() ); /* should I disconnect the socket notfier? */ OCOPPacket packe(OCOPPacket::IsRegistered, chan ); OCOPHead head = packe.head(); write(m_socket, &head, sizeof(head) ); write(m_socket, chan.data(), chan.size() ); /* block */ OCOPPacket pack = packet(); qWarning("unblock %s %s", pack.channel().data(), chan.data() ); /* connect here again */ if ( pack.channel() == chan ) { QCString func = pack.header(); if (func[0] == 1 ) return true; } return false; }; void OCOPClient::send( const QCString& chan, const QCString& fu, const QByteArray& arr ) { - qWarning("ClientSending %s %s", chan.data(), fu.data() ); +// qWarning("ClientSending %s %s", chan.data(), fu.data() ); OCOPPacket pack(OCOPPacket::Call, chan, fu, arr ); call( pack ); } void OCOPClient::addChannel(const QCString& channel) { OCOPPacket pack(OCOPPacket::RegisterChannel, channel ); call( pack ); } void OCOPClient::delChannel(const QCString& chan ) { OCOPPacket pack(OCOPPacket::UnregisterChannel, chan ); call( pack ); } void OCOPClient::call( const OCOPPacket& pack ) { OCOPHead head = pack.head(); write(m_socket, &head, sizeof(head) ); write(m_socket, pack.channel().data(), pack.channel().size() ); write(m_socket, pack.header().data(), pack.header().size() ); write(m_socket, pack.content().data(), pack.content().size() ); } void OCOPClient::startUP() { qWarning("Start me up"); pid_t pi = fork(); if ( pi == 0 ) { setsid(); execlp("ocopserver", "ocopserver", NULL ); _exit(1); } } |