| 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 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 |
|
| 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 |