Debian Codegraph @

src/serviceframework/qremoteserviceregister.h

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 #ifndef QREMOTESERVICEREGISTER_H
41 #define QREMOTESERVICEREGISTER_H
42
43 #include "qserviceframeworkglobal.h"
44 #include <QObject>
45 #include <QQueue>
46 #include <QHash>
47 #include <QDebug>
48 #include <QExplicitlySharedDataPointer>
49
50 #include "qserviceclientcredentials.h"
51 #include "qservice.h"
52
53 QT_BEGIN_NAMESPACE
54
55 class QRemoteServiceRegisterPrivate;
56 class QRemoteServiceRegisterEntryPrivate;
57 class QServiceClientCredentialsPrivate;
58 class QServiceClientCredentials;
59
60 class Q_SERVICEFW_EXPORT QRemoteServiceRegister : public QObject
61 {
62 Q_OBJECT
63 Q_PROPERTY(bool quitOnLastInstanceClosed READ quitOnLastInstanceClosed WRITE setQuitOnLastInstanceClosed)
64 Q_FLAGS(SocketAccessOption SecurityAccessOptions)
65 public:
66
67 enum InstanceType {
68 GlobalInstance = 0,
69 PrivateInstance
70 };
71
72 enum SecurityAccessOption {
73 NoOptions = 0x0,
74 UserAccessOption = 0x01,
75 GroupAccessOption = 0x02,
76 OtherAccessOption = 0x04,
77 WorldAccessOption = 0x07
78 };
79 Q_DECLARE_FLAGS(SecurityAccessOptions, SecurityAccessOption)
80
81 typedef QObject *(*CreateServiceFunc)();
82
83 class Q_SERVICEFW_EXPORT Entry {
84 public:
85 Entry();
86 Entry(const Entry &);
87 Entry &operator=(const Entry &);
88
89 ~Entry();
90
91 bool operator==(const Entry &) const;
92 bool operator!=(const Entry &) const;
93
94 bool isValid() const;
95
96 QString interfaceName() const;
97 QString serviceName() const;
98 QString version() const;
99
100 void setInstantiationType(QRemoteServiceRegister::InstanceType type);
101 QRemoteServiceRegister::InstanceType instantiationType() const;
102
103 private:
104 QExplicitlySharedDataPointer<QRemoteServiceRegisterEntryPrivate> d;
105
106 const QMetaObject* metaObject() const;
107
108 friend class QRemoteServiceRegisterPrivate;
109 friend class QRemoteServiceRegister;
110 friend class InstanceManager;
111 friend class QServiceManager;
112 #ifndef QT_NO_DATASTREAM
113 friend Q_SERVICEFW_EXPORT QDataStream &operator<<(QDataStream &, const QRemoteServiceRegister::Entry &);
114 friend Q_SERVICEFW_EXPORT QDataStream &operator>>(QDataStream &, QRemoteServiceRegister::Entry &);
115 #endif
116 };
117
118 explicit QRemoteServiceRegister(QObject* parent = Q_NULLPTR);
119 ~QRemoteServiceRegister();
120
121 template <typename T>
122 Entry createEntry(const QString& serviceName,
123 const QString& interfaceName, const QString& version);
124
125 void publishEntries(const QString& ident );
126
127 bool quitOnLastInstanceClosed() const;
128 void setQuitOnLastInstanceClosed(const bool quit);
129
130 typedef void (*SecurityFilter)(QServiceClientCredentials *creds);
131 SecurityFilter setSecurityFilter(SecurityFilter filter);
132
133 SecurityAccessOptions securityAccessOptions() const;
134 void setSecurityAccessOptions(SecurityAccessOptions options);
135
136 qintptr getBaseUserIdentifier() const;
137 void setBaseUserIdentifier(qintptr uid);
138
139 qintptr getBaseGroupIdentifier() const;
140 void setBaseGroupIdentifier(qintptr gid);
141
142 Q_SIGNALS:
143 void allInstancesClosed();
144 void instanceClosed(const QRemoteServiceRegister::Entry& entry);
145
146 private:
147
148 Entry createEntry(const QString& serviceName,
149 const QString& interfaceName, const QString& version,
150 CreateServiceFunc cptr, const QMetaObject* meta);
151
152 void init();
153 bool event(QEvent *e);
154
155 QRemoteServiceRegisterPrivate* d;
156 };
157
158 inline uint qHash(const QRemoteServiceRegister::Entry& e) {
159 //Only consider version, iface and service name -> needs to sync with operator==
160 return ( qHash(e.serviceName()) + qHash(e.interfaceName()) + qHash(e.version()) );
161 }
162
163 #ifndef QT_NO_DATASTREAM
164 Q_SERVICEFW_EXPORT QDataStream& operator>>(QDataStream& s, QRemoteServiceRegister::Entry& entry);
165 Q_SERVICEFW_EXPORT QDataStream& operator<<(QDataStream& s, const QRemoteServiceRegister::Entry& entry);
166 #endif
167
168 #ifndef QT_NO_DEBUG_STREAM
169 QDebug operator<<(QDebug dbg, const QRemoteServiceRegister::Entry& entry);
170 #endif
171
172 template <typename T>
173 QObject* qServiceTypeConstructHelper()
174 {
175 return new T;
176 }
177
178 template <typename T>
179 QRemoteServiceRegister::Entry QRemoteServiceRegister::createEntry(const QString& serviceName,
180 const QString& interfaceName, const QString& version)
181 {
182
183 QRemoteServiceRegister::CreateServiceFunc cptr = qServiceTypeConstructHelper<T>;
184 return createEntry(serviceName, interfaceName, version, cptr, &T::staticMetaObject);
185 }
186
187
188 QT_END_NAMESPACE
189 #endif //QREMOTESERVICEREGISTER_H