Debian Codegraph @

src/serviceframework/ipc/qservicepackage.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 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:LGPL$
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 https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #include "qservicepackage_p.h"
41 #include <QDataStream>
42 #include <QDebug>
43
44 QT_BEGIN_NAMESPACE
45
46 QServicePackage::QServicePackage()
47 : d(0)
48 {
49
50 }
51
52 QServicePackage::QServicePackage(const QServicePackage& other)
53 : d(other.d)
54 {
55 }
56
57 QServicePackage& QServicePackage::operator=(const QServicePackage& other)
58 {
59 d = other.d;
60 return *this;
61 }
62
63 QServicePackage::~QServicePackage()
64 {
65 }
66
67 bool QServicePackage::isValid() const
68 {
69 return d;
70 }
71
72 QServicePackage QServicePackage::createResponse() const
73 {
74 Q_ASSERT(d->responseType == QServicePackage::NotAResponse);
75 QServicePackage response;
76 response.d = new QServicePackagePrivate();
77 response.d->packageType = d->packageType;
78 response.d->messageId = d->messageId;
79 response.d->instanceId = d->instanceId;
80 response.d->responseType = QServicePackage::Failed;
81
82 return response;
83 }
84
85 #ifndef QT_NO_DATASTREAM
86 QDataStream &operator<<(QDataStream &out, const QServicePackage& package)
87 {
88 const quint32 magicNumber = 0x78AFAFB;
89 out.setVersion(QDataStream::Qt_4_6);
90 out << magicNumber;
91
92 const qint8 valid = package.d ? 1 : 0;
93 out << (qint8) valid;
94 if (valid) {
95 out << (qint8) package.d->packageType;
96 out << (qint8) package.d->responseType;
97 out << package.d->messageId;
98 out << package.d->instanceId;
99 out << package.d->entry;
100 out << package.d->payload;
101 }
102
103 return out;
104 }
105
106 QDataStream &operator>>(QDataStream &in, QServicePackage& package)
107 {
108 const quint32 magicNumber = 0x78AFAFB;
109 in.setVersion(QDataStream::Qt_4_6);
110
111 quint32 storedMagicNumber;
112 in >> storedMagicNumber;
113 if (storedMagicNumber != magicNumber) {
114 qWarning() << Q_FUNC_INFO << "Datastream doesn't provide serialized QServiceFilter";
115 return in;
116 }
117
118 qint8 valid;
119 in >> valid;
120 if (valid) {
121 if (!package.d) {
122 QServicePackagePrivate* priv = new QServicePackagePrivate();
123 package.d = priv;
124 } else {
125 package.d.detach();
126 package.d->clean();
127 }
128 qint8 data;
129 in >> data;
130 package.d->packageType = (QServicePackage::Type) data;
131 in >> data;
132 package.d->responseType = (QServicePackage::ResponseType) data;
133 in >> package.d->messageId;
134 in >> package.d->instanceId;
135 in >> package.d->entry;
136 in >> package.d->payload;
137 } else {
138 if (package.d)
139 package.d.reset();
140 }
141
142 return in;
143 }
144 #endif
145
146
147 #ifndef QT_NO_DEBUG_STREAM
148 QDebug operator<<(QDebug dbg, const QServicePackage& p)
149 {
150 if (p.isValid()) {
151 QString type;
152 switch (p.d->packageType) {
153 case QServicePackage::ObjectCreation:
154 type = QLatin1String("ObjectCreation");
155 break;
156 case QServicePackage::MethodCall:
157 type = QLatin1String("MethodCall");
158 break;
159 case QServicePackage::PropertyCall:
160 type = QLatin1String("PropertyCall");
161 break;
162 default:
163 break;
164 }
165 dbg.nospace() << "QServicePackage ";
166 dbg.nospace() << type << ' ' << p.d->responseType ; dbg.space();
167 dbg.nospace() << p.d->messageId.toString(); dbg.space();
168 dbg.nospace() << p.d->entry;dbg.space();
169 } else {
170 dbg.nospace() << "QServicePackage(invalid)";
171 }
172 return dbg.space();
173 }
174 #endif
175
176
177
178 QT_END_NAMESPACE