00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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 }
00130 }
00131 else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) {
00132
00133
00134 QString endpoint = ch.mid(9);
00135
00136 ch = "QPE/SOAP";
00137
00138 *this << endpoint;
00139 }
00140
00141 QCopChannel::send(ch,msg,data);
00142 delete device();
00143 }
00144
00145 #endif