Diffstat (limited to 'library/qcopenvelope_qws.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | library/qcopenvelope_qws.cpp | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/library/qcopenvelope_qws.cpp b/library/qcopenvelope_qws.cpp index 10d1567..81bb0f5 100644 --- a/library/qcopenvelope_qws.cpp +++ b/library/qcopenvelope_qws.cpp | |||
@@ -1,8 +1,8 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of 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 |
@@ -17,9 +17,11 @@ | |||
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #ifndef QT_NO_COP | ||
21 | #include "qcopenvelope_qws.h" | 22 | #include "qcopenvelope_qws.h" |
23 | #endif | ||
22 | #include "global.h" | 24 | #include "global.h" |
23 | #include <qbuffer.h> | 25 | #include <qbuffer.h> |
24 | #include <qdatastream.h> | 26 | #include <qdatastream.h> |
25 | #include <qfile.h> | 27 | #include <qfile.h> |
@@ -33,12 +35,13 @@ | |||
33 | #ifndef QT_NO_COP | 35 | #ifndef QT_NO_COP |
34 | 36 | ||
35 | /*! | 37 | /*! |
36 | \class QCopEnvelope qcopenvelope_qws.h | 38 | \class QCopEnvelope qcopenvelope_qws.h |
37 | \brief The QCopEnvelope class encapsulates QCop message sending. | 39 | \brief The QCopEnvelope class encapsulates and sends QCop messages |
40 | over QCopChannels. | ||
38 | 41 | ||
39 | QCop messages allow applications to communicate with each other. | 42 | QCop messages allow applications to communicate with each other. |
40 | These messages are send using QCopEnvelope, and received by connecting | 43 | These messages are sent using QCopEnvelope, and received by connecting |
41 | to a QCopChannel. | 44 | to a QCopChannel. |
42 | 45 | ||
43 | To send a message, use the following protocol: | 46 | To send a message, use the following protocol: |
44 | 47 | ||
@@ -46,25 +49,25 @@ | |||
46 | QCopEnvelope e(channelname, messagename); | 49 | QCopEnvelope e(channelname, messagename); |
47 | e << parameter1 << parameter2 << ...; | 50 | e << parameter1 << parameter2 << ...; |
48 | \endcode | 51 | \endcode |
49 | 52 | ||
50 | For messages without parameters, you can simply use: | 53 | For messages without parameters, simply use: |
51 | 54 | ||
52 | \code | 55 | \code |
53 | QCopEnvelope (channelname, messagename); | 56 | QCopEnvelope e(channelname, messagename); |
54 | \endcode | 57 | \endcode |
55 | 58 | ||
56 | Do not try to simplify further as some compilers may not do | 59 | (Do not try to simplify this further as it may confuse some |
57 | as you expect. | 60 | compilers.) |
58 | 61 | ||
59 | The <tt>channelname</tt> of channels within Qtopia all start with "QPE/". | 62 | The \c{channelname} of channels within Qtopia all start with "QPE/". |
60 | The <tt>messagename</tt> is a function identifier followed by a list of types | 63 | The \c{messagename} is a function identifier followed by a list of types |
61 | in parentheses. There are no spaces in the message name. | 64 | in parentheses. There is no whitespace in the message name. |
62 | 65 | ||
63 | To receive a message, you will generally just use your applications | 66 | To receive a message, you will generally just use your application's |
64 | predefined QPE/Application/<i>appname</i> channel | 67 | predefined QPE/Application/\e{appname} channel |
65 | (see QPEApplication::appMessage()), but you can make another channel | 68 | (see QPEApplication::appMessage()), but you can make another channel |
66 | and connect it to a slot with: | 69 | and connect it to a slot like this: |
67 | 70 | ||
68 | \code | 71 | \code |
69 | myChannel = new QCopChannel( "QPE/FooBar", this ); | 72 | myChannel = new QCopChannel( "QPE/FooBar", this ); |
70 | connect( myChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 73 | connect( myChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
@@ -75,10 +78,10 @@ | |||
75 | */ | 78 | */ |
76 | 79 | ||
77 | /*! | 80 | /*! |
78 | Constructs a QCopEnvelope that will write \a message to \a channel. | 81 | Constructs a QCopEnvelope that will write \a message to \a channel. |
79 | If \a message has parameters, you must then user operator<<() to | 82 | If \a message has parameters, you must then use operator<<() to |
80 | write the parameters. | 83 | add these parameters to the envelope. |
81 | */ | 84 | */ |
82 | QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) : | 85 | QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) : |
83 | QDataStream(new QBuffer), | 86 | QDataStream(new QBuffer), |
84 | ch(channel), msg(message) | 87 | ch(channel), msg(message) |
@@ -86,9 +89,9 @@ QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) : | |||
86 | device()->open(IO_WriteOnly); | 89 | device()->open(IO_WriteOnly); |
87 | } | 90 | } |
88 | 91 | ||
89 | /*! | 92 | /*! |
90 | Writes the completed message and destroys the QCopEnvelope. | 93 | Writes the message and then destroys the QCopEnvelope. |
91 | */ | 94 | */ |
92 | QCopEnvelope::~QCopEnvelope() | 95 | QCopEnvelope::~QCopEnvelope() |
93 | { | 96 | { |
94 | QByteArray data = ((QBuffer*)device())->buffer(); | 97 | QByteArray data = ((QBuffer*)device())->buffer(); |
@@ -110,9 +113,9 @@ QCopEnvelope::~QCopEnvelope() | |||
110 | struct stat buf; | 113 | struct stat buf; |
111 | time_t t; | 114 | time_t t; |
112 | if (!fstat(qcopfile.handle(), &buf) && (time(&t) != (time_t)-1) ) { | 115 | if (!fstat(qcopfile.handle(), &buf) && (time(&t) != (time_t)-1) ) { |
113 | // success on fstat, lets compare times | 116 | // success on fstat, lets compare times |
114 | if (buf.st_mtime + 60 < t) { | 117 | if (buf.st_ctime + 60 < t) { |
115 | qWarning("stale file " + qcopfn + " found. Truncating"); | 118 | qWarning("stale file " + qcopfn + " found. Truncating"); |
116 | ftruncate(qcopfile.handle(), 0); | 119 | ftruncate(qcopfile.handle(), 0); |
117 | qcopfile.reset(); | 120 | qcopfile.reset(); |
118 | } | 121 | } |
@@ -128,10 +131,9 @@ QCopEnvelope::~QCopEnvelope() | |||
128 | } | 131 | } |
129 | 132 | ||
130 | if (fsize == 0) { | 133 | if (fsize == 0) { |
131 | QString cmd = ch.mid(pref); | 134 | QString cmd = ch.mid(pref); |
132 | cmd += " -qcop " + qcopfn; | 135 | Global::execute(cmd); |
133 | Global::invoke(cmd); | ||
134 | } | 136 | } |
135 | 137 | ||
136 | char c; | 138 | char c; |
137 | for (int i=0; (c=msg[i]); i++) { | 139 | for (int i=0; (c=msg[i]); i++) { |
@@ -153,8 +155,17 @@ QCopEnvelope::~QCopEnvelope() | |||
153 | qWarning(QString("Failed to obtain file lock on %1") | 155 | qWarning(QString("Failed to obtain file lock on %1") |
154 | .arg(qcopfn)); | 156 | .arg(qcopfn)); |
155 | } // endif open | 157 | } // endif open |
156 | } | 158 | } |
159 | else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) { | ||
160 | // If this is a message that should go along the SOAP channel, we move the | ||
161 | // endpoint URL to the data section. | ||
162 | QString endpoint = ch.mid(9); | ||
163 | |||
164 | ch = "QPE/SOAP"; | ||
165 | // Since byte arrays are explicitly shared, this is appended to the data variable.. | ||
166 | *this << endpoint; | ||
167 | } | ||
157 | QCopChannel::send(ch,msg,data); | 168 | QCopChannel::send(ch,msg,data); |
158 | end: | 169 | end: |
159 | delete device(); | 170 | delete device(); |
160 | } | 171 | } |