summaryrefslogtreecommitdiff
path: root/library/qcopenvelope_qws.cpp
Unidiff
Diffstat (limited to 'library/qcopenvelope_qws.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qcopenvelope_qws.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/library/qcopenvelope_qws.cpp b/library/qcopenvelope_qws.cpp
index 8f58787..63efb13 100644
--- a/library/qcopenvelope_qws.cpp
+++ b/library/qcopenvelope_qws.cpp
@@ -23,98 +23,98 @@
23#endif 23#endif
24#include <qbuffer.h> 24#include <qbuffer.h>
25#include <qfile.h> 25#include <qfile.h>
26#include <unistd.h> 26#include <unistd.h>
27#include <errno.h> 27#include <errno.h>
28#include <sys/file.h> 28#include <sys/file.h>
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/stat.h> 30#include <sys/stat.h>
31#include <time.h> 31#include <time.h>
32 32
33#ifndef QT_NO_COP 33#ifndef QT_NO_COP
34 34
35/*! 35/*!
36 \class QCopEnvelope qcopenvelope_qws.h 36 \class QCopEnvelope qcopenvelope_qws.h
37 \brief The QCopEnvelope class encapsulates and sends QCop messages 37 \brief The QCopEnvelope class encapsulates and sends QCop messages
38 over QCopChannels. 38 over QCopChannels.
39 39
40 QCop messages allow applications to communicate with each other. 40 QCop messages allow applications to communicate with each other.
41 These messages are sent using QCopEnvelope, and received by connecting 41 These messages are sent using QCopEnvelope, and received by connecting
42 to a QCopChannel. 42 to a QCopChannel.
43 43
44 To send a message, use the following protocol: 44 To send a message, use the following protocol:
45 45
46 \code 46 \code
47 QCopEnvelope e(channelname, messagename); 47 QCopEnvelope e(channelname, messagename);
48 e << parameter1 << parameter2 << ...; 48 e << parameter1 << parameter2 << ...;
49 \endcode 49 \endcode
50 50
51 For messages without parameters, simply use: 51 For messages without parameters, simply use:
52 52
53 \code 53 \code
54 QCopEnvelope e(channelname, messagename); 54 QCopEnvelope e(channelname, messagename);
55 \endcode 55 \endcode
56 56
57 (Do not try to simplify this further as it may confuse some 57 (Do not try to simplify this further as it may confuse some
58 compilers.) 58 compilers.)
59 59
60 The \c{channelname} of channels within Qtopia all start with "QPE/". 60 The \c{channelname} of channels within Qtopia all start with "QPE/".
61 The \c{messagename} is a function identifier followed by a list of types 61 The \c{messagename} is a function identifier followed by a list of types
62 in parentheses. There is no whitespace in the message name. 62 in parentheses. There is no whitespace in the message name.
63 63
64 To receive a message, you will generally just use your application's 64 To receive a message, you will generally just use your application's
65 predefined QPE/Application/\e{appname} channel 65 predefined QPE/Application/\e{appname} channel
66 (see QPEApplication::appMessage()), but you can make another channel 66 (see QPEApplication::appMessage()), but you can make another channel
67 and connect it to a slot like this: 67 and connect it to a slot like this:
68 68
69 \code 69 \code
70 myChannel = new QCopChannel( "QPE/FooBar", this ); 70 myChannel = new QCopChannel( "QPE/FooBar", this );
71 connect( myChannel, SIGNAL(received(const QCString &, const QByteArray &)), 71 connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)),
72 this, SLOT(fooBarMessage( const QCString &, const QByteArray &)) ); 72 this, SLOT(fooBarMessage(const QCString&,const QByteArray&)) );
73 \endcode 73 \endcode
74 74
75 See also, the \link qcop.html list of Qtopia messages\endlink. 75 See also, the \link qcop.html list of Qtopia messages\endlink.
76*/ 76*/
77 77
78/*! 78/*!
79 Constructs a QCopEnvelope that will write \a message to \a channel. 79 Constructs a QCopEnvelope that will write \a message to \a channel.
80 If \a message has parameters, you must then use operator<<() to 80 If \a message has parameters, you must then use operator<<() to
81 add these parameters to the envelope. 81 add these parameters to the envelope.
82*/ 82*/
83QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) : 83QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) :
84 QDataStream(new QBuffer), 84 QDataStream(new QBuffer),
85 ch(channel), msg(message) 85 ch(channel), msg(message)
86{ 86{
87 device()->open(IO_WriteOnly); 87 device()->open(IO_WriteOnly);
88} 88}
89 89
90/*! 90/*!
91 Writes the message and then destroys the QCopEnvelope. 91 Writes the message and then destroys the QCopEnvelope.
92*/ 92*/
93QCopEnvelope::~QCopEnvelope() 93QCopEnvelope::~QCopEnvelope()
94{ 94{
95 QByteArray data = ((QBuffer*)device())->buffer(); 95 QByteArray data = ((QBuffer*)device())->buffer();
96 const int pref=16; 96 const int pref=16;
97 if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) { 97 if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) {
98 QString qcopfn("/tmp/qcop-msg-"); 98 QString qcopfn("/tmp/qcop-msg-");
99 qcopfn += ch.mid(pref); 99 qcopfn += ch.mid(pref);
100 QFile qcopfile(qcopfn); 100 QFile qcopfile(qcopfn);
101 101
102 if ( qcopfile.open(IO_WriteOnly | IO_Append) ) { 102 if ( qcopfile.open(IO_WriteOnly | IO_Append) ) {
103#ifndef Q_OS_WIN32 103#ifndef Q_OS_WIN32
104 if(flock(qcopfile.handle(), LOCK_EX)) { 104 if(flock(qcopfile.handle(), LOCK_EX)) {
105 /* some error occurred */ 105 /* some error occurred */
106 qWarning(QString("Failed to obtain file lock on %1 (%2)") 106 qWarning(QString("Failed to obtain file lock on %1 (%2)")
107 .arg(qcopfn).arg( errno )); 107 .arg(qcopfn).arg( errno ));
108 } 108 }
109#endif 109#endif
110 { 110 {
111 QDataStream ds(&qcopfile); 111 QDataStream ds(&qcopfile);
112 ds << ch << msg << data; 112 ds << ch << msg << data;
113 qcopfile.flush(); 113 qcopfile.flush();
114#ifndef Q_OS_WIN32 114#ifndef Q_OS_WIN32
115 flock(qcopfile.handle(), LOCK_UN); 115 flock(qcopfile.handle(), LOCK_UN);
116#endif 116#endif
117 qcopfile.close(); 117 qcopfile.close();
118 } 118 }
119 119
120 QByteArray b; 120 QByteArray b;