summaryrefslogtreecommitdiff
path: root/library/qcopmessage_qws.h
Unidiff
Diffstat (limited to 'library/qcopmessage_qws.h') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qcopmessage_qws.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/library/qcopmessage_qws.h b/library/qcopmessage_qws.h
new file mode 100644
index 0000000..c19f57d
--- a/dev/null
+++ b/library/qcopmessage_qws.h
@@ -0,0 +1,99 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef QCOP_MESSAGE_H
22#define QCOP_MESSAGE_H
23
24#include <qdatastream.h>
25#include <qbuffer.h>
26
27class QCopMessage : public QDataStream {
28 public:
29 QCopMessage();
30 QCopMessage(const QCString& channel, const QCString& message);
31 QCopMessage(const QCopMessage& orig);
32 ~QCopMessage();
33
34 void setChannel(QCString& channel) { m_Channel = channel; }
35 QCString channel() const { return m_Channel; }
36 void setMessage(QCString& message) { m_Message = message; }
37 QCString message() const { return m_Message; }
38 const QByteArray data() const;
39
40 QCopMessage& operator=(const QCopMessage& orig);
41
42 private:
43 QCString m_Channel;
44 QCString m_Message;
45};
46
47// ### No need to inline, just maintaining binary compatability
48inline QCopMessage::QCopMessage() : QDataStream(new QBuffer()) {
49 device()->open(IO_WriteOnly);
50}
51
52inline QCopMessage::QCopMessage(const QCString& channel, const QCString& message)
53 : QDataStream(new QBuffer()), m_Channel(channel), m_Message(message) {
54 device()->open(IO_WriteOnly);
55}
56
57inline QCopMessage::QCopMessage(const QCopMessage& orig) : QDataStream() {
58 // The QBuffer is going to share the byte array, so it will keep the
59 // data pointer even when this one goes out of scope.
60 QByteArray array(((QBuffer*)orig.device())->buffer());
61 array.detach();
62 setDevice(new QBuffer(array));
63 device()->open(IO_Append);
64
65 m_Channel = orig.channel();
66 m_Message = orig.message();
67}
68
69inline QCopMessage& QCopMessage::operator=(const QCopMessage& orig) {
70 if (device()) {
71 delete device();
72 unsetDevice();
73 }
74
75 // The QBuffer is going to share the byte array, so it will keep the
76 // data pointer even when this one goes out of scope.
77 QByteArray array(((QBuffer*)orig.device())->buffer());
78 array.detach();
79 setDevice(new QBuffer(array));
80 device()->open(IO_Append);
81
82 m_Channel = orig.channel();
83 m_Message = orig.message();
84
85 return *this;
86}
87
88inline const QByteArray QCopMessage::data() const {
89 return ((QBuffer*)device())->buffer();
90}
91
92inline QCopMessage::~QCopMessage() {
93 // If we still have our QBuffer, clean it up...
94 if (device())
95 delete device();
96 unsetDevice();
97}
98
99#endif