Debian Codegraph @

src/serviceframework/qservicemanager.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 QSERVICEMANAGER_H
41 #define QSERVICEMANAGER_H
42
43 #include "qserviceframeworkglobal.h"
44
45 #include "qservice.h"
46 #include "qserviceinterfacedescriptor.h"
47 #include "qservicefilter.h"
48
49 #include <QObject>
50 #include <QList>
51 #include <QStringList>
52 #include <QDebug>
53
54 QT_BEGIN_NAMESPACE
55
56 class QServiceContext;
57 class QServiceFilter;
58 class QServiceManagerPrivate;
59 class QServiceReply;
60 class Q_SERVICEFW_EXPORT QServiceManager : public QObject
61 {
62 Q_OBJECT
63
64 public:
65
66 enum Error {
67 NoError,
68 StorageAccessError,
69 InvalidServiceLocation,
70 InvalidServiceXml,
71 InvalidServiceInterfaceDescriptor,
72 ServiceAlreadyExists,
73 ImplementationAlreadyExists,
74 PluginLoadingFailed,
75 ComponentNotFound,
76 ServiceCapabilityDenied,
77 UnknownError = 100
78 };
79
80 explicit QServiceManager(QObject *parent = Q_NULLPTR);
81 explicit QServiceManager(QService::Scope scope, QObject *parent = Q_NULLPTR);
82 ~QServiceManager();
83
84 QService::Scope scope() const;
85
86 QStringList findServices(const QString& interfaceName = QString()) const;
87 QList<QServiceInterfaceDescriptor> findInterfaces(const QServiceFilter& filter = QServiceFilter()) const;
88 QList<QServiceInterfaceDescriptor> findInterfaces(const QString& serviceName) const;
89
90 QObject* loadInterface(const QString& interfaceName);
91 QObject* loadInterface(const QServiceInterfaceDescriptor& descriptor);
92
93 bool isInterfaceRunning(const QString& interfaceName);
94 bool isInterfaceRunning(const QServiceInterfaceDescriptor& descriptor);
95
96 template <class T>
97 T* loadLocalTypedInterface(const QString& interfaceName);
98
99 template <class T>
100 T* loadLocalTypedInterface(const QServiceInterfaceDescriptor& descriptor);
101
102 QServiceReply *loadInterfaceRequest(const QString& interfaceName);
103 QServiceReply *loadInterfaceRequest(const QServiceInterfaceDescriptor& descriptor);
104
105 bool addService(const QString& xmlFilePath);
106 bool addService(QIODevice* xmlDevice);
107 bool removeService(const QString& serviceName);
108
109 bool setInterfaceDefault(const QString &service, const QString &interfaceName);
110 bool setInterfaceDefault(const QServiceInterfaceDescriptor& descriptor);
111
112 QServiceInterfaceDescriptor interfaceDefault(const QString& interfaceName) const;
113
114 QServiceManager::Error error() const;
115
116 bool event(QEvent *);
117
118 protected:
119 void connectNotify(const QMetaMethod &signal);
120 void disconnectNotify(const QMetaMethod &signal);
121
122 Q_SIGNALS:
123 void serviceAdded(const QString& serviceName, QService::Scope scope);
124 void serviceRemoved(const QString& serviceName, QService::Scope scope);
125 void errorChanged();
126
127 private:
128 QObject *loadInterProcessService(const QServiceInterfaceDescriptor &descriptor,
129 const QString &location) const;
130 QObject *loadInProcessService(const QServiceInterfaceDescriptor &descriptor,
131 const QString &serviceFilePath) const;
132
133 static QString resolveLibraryPath(const QString &libNameOrPath);
134
135 friend class QServiceManagerPrivate;
136 friend class QServiceOperationProcessor;
137 QServiceManagerPrivate* d;
138 };
139
140 template <class T>
141 Q_INLINE_TEMPLATE T* QServiceManager::loadLocalTypedInterface(const QString& interfaceName)
142 {
143 return loadLocalTypedInterface<T>(interfaceDefault(interfaceName));
144 }
145
146 template <class T>
147 Q_OUTOFLINE_TEMPLATE T* QServiceManager::loadLocalTypedInterface(const QServiceInterfaceDescriptor& descriptor)
148 {
149 T* instance = Q_NULLPTR;
150 if (descriptor.isValid()) {
151 QObject* obj = loadInterface(descriptor);
152 if (!obj) return Q_NULLPTR;
153
154 //TODO this should really be
155 //instance = qobject_cast<T *>(loadInterface(descriptor, context, session));
156 //check why qobject_cast fails
157 const char* templateClassName = T::staticMetaObject.className();
158 const QMetaObject* source = obj->metaObject();
159 do {
160 if (strcmp(templateClassName,source->className())==0) {
161 instance = static_cast<T *>(obj);
162 break;
163 }
164 source = source->superClass();
165 } while (source);
166 if (!instance)
167 delete obj;
168 }
169 return instance;
170 }
171
172 QT_END_NAMESPACE
173
174 #endif