1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtSystems module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#include "qservicepackage_p.h"
35#include <QDataStream>
36#include <QDebug>
37
38QT_BEGIN_NAMESPACE
39
40QServicePackage::QServicePackage()
41 : d(0)
42{
43
44}
45
46QServicePackage::QServicePackage(const QServicePackage& other)
47 : d(other.d)
48{
49}
50
51QServicePackage& QServicePackage::operator=(const QServicePackage& other)
52{
53 d = other.d;
54 return *this;
55}
56
57QServicePackage::~QServicePackage()
58{
59}
60
61bool QServicePackage::isValid() const
62{
63 return d;
64}
65
66QServicePackage QServicePackage::createResponse() const
67{
68 Q_ASSERT(d->responseType == QServicePackage::NotAResponse);
69 QServicePackage response;
70 response.d = new QServicePackagePrivate();
71 response.d->packageType = d->packageType;
72 response.d->messageId = d->messageId;
73 response.d->instanceId = d->instanceId;
74 response.d->responseType = QServicePackage::Failed;
75
76 return response;
77}
78
79#ifndef QT_NO_DATASTREAM
80QDataStream &operator<<(QDataStream &out, const QServicePackage& package)
81{
82 const quint32 magicNumber = 0x78AFAFB;
83 out.setVersion(QDataStream::Qt_4_6);
84 out << magicNumber;
85
86 const qint8 valid = package.d ? 1 : 0;
87 out << (qint8) valid;
88 if (valid) {
89 out << (qint8) package.d->packageType;
90 out << (qint8) package.d->responseType;
91 out << package.d->messageId;
92 out << package.d->instanceId;
93 out << package.d->entry;
94 out << package.d->payload;
95 }
96
97 return out;
98}
99
100QDataStream &operator>>(QDataStream &in, QServicePackage& package)
101{
102 const quint32 magicNumber = 0x78AFAFB;
103 in.setVersion(QDataStream::Qt_4_6);
104
105 quint32 storedMagicNumber;
106 in >> storedMagicNumber;
107 if (storedMagicNumber != magicNumber) {
108 qWarning() << Q_FUNC_INFO << "Datastream doesn't provide serialized QServiceFilter";
109 return in;
110 }
111
112 qint8 valid;
113 in >> valid;
114 if (valid) {
115 if (!package.d) {
116 QServicePackagePrivate* priv = new QServicePackagePrivate();
117 package.d = priv;
118 } else {
119 package.d.detach();
120 package.d->clean();
121 }
122 qint8 data;
123 in >> data;
124 package.d->packageType = (QServicePackage::Type) data;
125 in >> data;
126 package.d->responseType = (QServicePackage::ResponseType) data;
127 in >> package.d->messageId;
128 in >> package.d->instanceId;
129 in >> package.d->entry;
130 in >> package.d->payload;
131 } else {
132 if (package.d)
133 package.d.reset();
134 }
135
136 return in;
137}
138#endif
139
140
141#ifndef QT_NO_DEBUG_STREAM
142QDebug operator<<(QDebug dbg, const QServicePackage& p)
143{
144 if (p.isValid()) {
145 QString type;
146 switch (p.d->packageType) {
147 case QServicePackage::ObjectCreation:
148 type = QLatin1String("ObjectCreation");
149 break;
150 case QServicePackage::MethodCall:
151 type = QLatin1String("MethodCall");
152 break;
153 case QServicePackage::PropertyCall:
154 type = QLatin1String("PropertyCall");
155 break;
156 default:
157 break;
158 }
159 dbg.nospace() << "QServicePackage ";
160 dbg.nospace() << type << ' ' << p.d->responseType ; dbg.space();
161 dbg.nospace() << p.d->messageId.toString(); dbg.space();
162 dbg.nospace() << p.d->entry;dbg.space();
163 } else {
164 dbg.nospace() << "QServicePackage(invalid)";
165 }
166 return dbg.space();
167}
168#endif
169
170
171
172QT_END_NAMESPACE
173

source code of qtsystems/src/serviceframework/ipc/qservicepackage.cpp