Migration of QtMvvm from github
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.2 KiB

7 years ago
#ifndef QTMVVM_SERVICEREGISTRY_P_H
#define QTMVVM_SERVICEREGISTRY_P_H
7 years ago
#include <QtCore/QMutex>
#include <QtCore/QSharedPointer>
7 years ago
7 years ago
#include "qtmvvmcore_global.h"
#include "serviceregistry.h"
namespace QtMvvm {
class ServiceRegistryPrivate
{
public:
7 years ago
class ServiceInfo {
Q_DISABLE_COPY(ServiceInfo)
7 years ago
public:
ServiceInfo(bool weak, ServiceRegistry::DestructionScope scope);
7 years ago
virtual ~ServiceInfo();
bool replaceable() const;
bool needsDestroy(ServiceRegistry::DestructionScope scope) const;
QObject *instance(ServiceRegistryPrivate *d, const QByteArray &iid);
7 years ago
protected:
virtual QObject *construct(ServiceRegistryPrivate *d) const = 0;
private:
const bool _weak;
const ServiceRegistry::DestructionScope _scope;
QObject *_instance = nullptr;
mutable bool _closingDown = false;
7 years ago
};
class FnServiceInfo : public ServiceInfo {
public:
FnServiceInfo(std::function<QObject*(QObjectList)> &&creator, QByteArrayList &&injectables, bool weak, ServiceRegistry::DestructionScope scope);
7 years ago
protected:
QObject *construct(ServiceRegistryPrivate *d) const final;
private:
std::function<QObject*(QObjectList)> _creator;
QByteArrayList _injectables;
7 years ago
};
class MetaServiceInfo : public ServiceInfo {
public:
MetaServiceInfo(const QMetaObject *metaObject, bool weak, ServiceRegistry::DestructionScope scope);
7 years ago
protected:
QObject *construct(ServiceRegistryPrivate *d) const final;
private:
const QMetaObject *_metaObject;
};
class PluginServiceInfo : public ServiceInfo {
public:
PluginServiceInfo(QString &&type,
QString &&key,
QByteArray &&iid,
bool weak,
ServiceRegistry::DestructionScope scope);
const QByteArray &iid() const;
protected:
QObject *construct(ServiceRegistryPrivate *d) const final;
private:
QString _type;
QString _key;
QByteArray _iid;
7 years ago
};
QMutex serviceMutex{QMutex::Recursive};
7 years ago
QHash<QByteArray, QSharedPointer<ServiceInfo>> services;
bool serviceBlocked(const QByteArray &iid) const;
QObject *constructInjectedLocked(const QMetaObject *metaObject, QObject *parent);
void injectLocked(QObject *object);
void destroyServices(ServiceRegistry::DestructionScope scope);
static void appDestroyedHook();
7 years ago
};
}
#endif // QTMVVM_SERVICEREGISTRY_P_H