qcopenvelope_qws.cpp
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 "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
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 }
00132 }
00133 else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) {
00134
00135
00136 QString endpoint = ch.mid(9);
00137
00138 ch = "QPE/SOAP";
00139
00140 *this << endpoint;
00141 }
00142
00143 QCopChannel::send(ch,msg,data);
00144 delete device();
00145 }
00146
00147 #endif
This file is part of the documentation for OPIE Version 1.5.5.