author | zecke <zecke> | 2002-10-16 15:34:05 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-16 15:34:05 (UTC) |
commit | 321cea04e34658fde3de47c104682b5cefce6eeb (patch) (side-by-side diff) | |
tree | abdf45ae54d24dedfd20e4e40371df5f39687139 /x11/ipc | |
parent | 61f2f6ef32685002710f197dc8990fd9e99d83a5 (diff) | |
download | opie-321cea04e34658fde3de47c104682b5cefce6eeb.zip opie-321cea04e34658fde3de47c104682b5cefce6eeb.tar.gz opie-321cea04e34658fde3de47c104682b5cefce6eeb.tar.bz2 |
more implementation!!
OCOPClient now tries to start the server
-rw-r--r-- | x11/ipc/client/ocopclient.cpp | 25 | ||||
-rw-r--r-- | x11/ipc/client/ocopclient.h | 4 |
2 files changed, 26 insertions, 3 deletions
diff --git a/x11/ipc/client/ocopclient.cpp b/x11/ipc/client/ocopclient.cpp index 43e426c..ac6e4a3 100644 --- a/x11/ipc/client/ocopclient.cpp +++ b/x11/ipc/client/ocopclient.cpp @@ -1,63 +1,75 @@ #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( 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"); - QTimer::singleShot(400, this,SLOT(init() ) ); + 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 ); - QTimer::singleShot(400, this, SLOT(init() ) ); + 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: @@ -106,24 +118,33 @@ bool OCOPClient::isRegistered( const QCString& chan ) const{ return true; } return false; }; void OCOPClient::send( const QCString& chan, const QCString& fu, const QByteArray& arr ) { 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("opie-ipc", "opie-ipc", NULL ); + _exit(1); + } +} diff --git a/x11/ipc/client/ocopclient.h b/x11/ipc/client/ocopclient.h index e9544b9..53018a5 100644 --- a/x11/ipc/client/ocopclient.h +++ b/x11/ipc/client/ocopclient.h @@ -23,37 +23,39 @@ public: /** * Occasionally I decide to start a Server from here */ OCOPClient(const QString& pathToServer = QString::null, QObject* obj = 0l); ~OCOPClient(); bool isRegistered( const QCString& )const; void send( const QCString& chan, const QCString&, const QByteArray& msg ); /** * add a channel and does connect to a signal * callback is the object * slot is the SLOT() */ void addChannel( const QCString& channel ); void delChannel( const QCString& channel ); /* make it singleton? */ //static OCOPClient* self(); /* no direct signals due the design */ signals: void called(const QCString&, const QCString&, const QByteArray& ); private slots: + void init(); void init(const QCString& pa); void newData(); private: + void startUP(); OCOPPacket packet()const; void call( const OCOPPacket& ); QSocketNotifier* m_notify; int m_socket; -private slots: + int m_tries; }; #endif |