Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qcopenvelope_qws.cpp

Go to the documentation of this file.
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 <qbuffer.h>
00025 #include <qfile.h>
00026 #include <unistd.h>
00027 #include <errno.h>
00028 #include <sys/file.h>
00029 #include <sys/types.h>
00030 #include <sys/stat.h>
00031 #include <time.h>
00032 
00033 #ifndef QT_NO_COP
00034 
00083 QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) :
00084     QDataStream(new QBuffer),
00085     ch(channel), msg(message)
00086 {
00087     device()->open(IO_WriteOnly);
00088 }
00089 
00093 QCopEnvelope::~QCopEnvelope()
00094 {
00095     QByteArray data = ((QBuffer*)device())->buffer();
00096     const int pref=16;
00097     if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) {
00098         QString qcopfn("/tmp/qcop-msg-");
00099         qcopfn += ch.mid(pref);
00100         QFile qcopfile(qcopfn);
00101 
00102         if ( qcopfile.open(IO_WriteOnly | IO_Append) ) {
00103 #ifndef Q_OS_WIN32
00104             if(flock(qcopfile.handle(), LOCK_EX)) {
00105                 /* some error occurred */
00106                 qWarning(QString("Failed to obtain file lock on %1 (%2)")
00107                         .arg(qcopfn).arg( errno ));
00108             }
00109 #endif
00110             {
00111                 QDataStream ds(&qcopfile);
00112                 ds << ch << msg << data;
00113                 qcopfile.flush();
00114 #ifndef Q_OS_WIN32
00115                 flock(qcopfile.handle(), LOCK_UN);
00116 #endif
00117                 qcopfile.close();
00118             }
00119 
00120             QByteArray b;
00121             QDataStream stream(b, IO_WriteOnly);
00122             stream << QString(ch.mid(pref));
00123             QCopChannel::send("QPE/Server", "processQCop(QString)", b);
00124             delete device();
00125             return;
00126         } else {
00127             qWarning(QString("Failed to open file %1")
00128                         .arg(qcopfn));
00129         } // endif open
00130     }
00131     else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) {
00132       // If this is a message that should go along the SOAP channel, we move the
00133       // endpoint URL to the data section.
00134       QString endpoint = ch.mid(9);
00135 
00136       ch = "QPE/SOAP";
00137       // Since byte arrays are explicitly shared, this is appended to the data variable..
00138       *this << endpoint;
00139     }
00140 
00141     QCopChannel::send(ch,msg,data);
00142     delete device();
00143 }
00144 
00145 #endif

Generated on Sat Nov 5 16:16:38 2005 for OPIE by  doxygen 1.4.2