| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 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 |
|
| 155 |
|
| 156 |
|
| 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 |