Qtopia library API Documentation

qcopenvelope_qws.cpp

00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #ifndef QT_NO_COP
00022 #include "qcopenvelope_qws.h"
00023 #endif
00024 #include "global.h"
00025 #include <qbuffer.h>
00026 #include <qdatastream.h>
00027 #include <qfile.h>
00028 #include <unistd.h>
00029 #include <errno.h>
00030 #include <sys/file.h>
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #include <time.h>
00034 
00035 #ifndef QT_NO_COP
00036 
00085 QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) :
00086     QDataStream(new QBuffer),
00087     ch(channel), msg(message)
00088 {
00089     device()->open(IO_WriteOnly);
00090 }
00091 
00095 QCopEnvelope::~QCopEnvelope()
00096 {
00097     QByteArray data = ((QBuffer*)device())->buffer();
00098     const int pref=16;
00099     if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) {
00100     QString qcopfn("/tmp/qcop-msg-");
00101     qcopfn += ch.mid(pref);
00102     QFile qcopfile(qcopfn);
00103 
00104     if ( qcopfile.open(IO_WriteOnly | IO_Append) ) {
00105 #ifndef Q_OS_WIN32
00106         if(flock(qcopfile.handle(), LOCK_EX)) {
00107         /* some error occurred */
00108         qWarning(QString("Failed to obtain file lock on %1 (%2)")
00109             .arg(qcopfn).arg( errno ));
00110         }
00111 #endif
00112         {
00113         QDataStream ds(&qcopfile);
00114         ds << ch << msg << data;
00115         qcopfile.flush();
00116 #ifndef Q_OS_WIN32
00117         flock(qcopfile.handle(), LOCK_UN);
00118 #endif
00119         qcopfile.close();
00120         }
00121 
00122         QByteArray b;
00123         QDataStream stream(b, IO_WriteOnly);
00124         stream << QString(ch.mid(pref));
00125         QCopChannel::send("QPE/Server", "processQCop(QString)", b);
00126         delete device();
00127         return;
00128     } else {
00129         qWarning(QString("Failed to open file %1")
00130             .arg(qcopfn));
00131     } // endif open
00132     }
00133     else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) {
00134       // If this is a message that should go along the SOAP channel, we move the
00135       // endpoint URL to the data section.
00136       QString endpoint = ch.mid(9);
00137 
00138       ch = "QPE/SOAP";
00139       // Since byte arrays are explicitly shared, this is appended to the data variable..
00140       *this << endpoint;
00141     }
00142 
00143     QCopChannel::send(ch,msg,data);
00144     delete device();
00145 }
00146 
00147 #endif
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:06 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001