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
@@ -1,145 +1,145 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef QT_NO_COP 21#ifndef QT_NO_COP
22#include "qcopenvelope_qws.h" 22#include "qcopenvelope_qws.h"
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;
121 QDataStream stream(b, IO_WriteOnly); 121 QDataStream stream(b, IO_WriteOnly);
122 stream << QString(ch.mid(pref)); 122 stream << QString(ch.mid(pref));
123 QCopChannel::send("QPE/Server", "processQCop(QString)", b); 123 QCopChannel::send("QPE/Server", "processQCop(QString)", b);
124 delete device(); 124 delete device();
125 return; 125 return;
126 } else { 126 } else {
127 qWarning(QString("Failed to open file %1") 127 qWarning(QString("Failed to open file %1")
128 .arg(qcopfn)); 128 .arg(qcopfn));
129 } // endif open 129 } // endif open
130 } 130 }
131 else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) { 131 else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) {
132 // If this is a message that should go along the SOAP channel, we move the 132 // If this is a message that should go along the SOAP channel, we move the
133 // endpoint URL to the data section. 133 // endpoint URL to the data section.
134 QString endpoint = ch.mid(9); 134 QString endpoint = ch.mid(9);
135 135
136 ch = "QPE/SOAP"; 136 ch = "QPE/SOAP";
137 // Since byte arrays are explicitly shared, this is appended to the data variable.. 137 // Since byte arrays are explicitly shared, this is appended to the data variable..
138 *this << endpoint; 138 *this << endpoint;
139 } 139 }
140 140
141 QCopChannel::send(ch,msg,data); 141 QCopChannel::send(ch,msg,data);
142 delete device(); 142 delete device();
143} 143}
144 144
145#endif 145#endif