* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
// ==================================================
// SignalRelay
// ==================================================
class SignalProxy::SignalRelay : public QObject
{
// ==================================================
// SignalRelay
// ==================================================
class SignalProxy::SignalRelay : public QObject
{
-/* Q_OBJECT is not necessary or even allowed, because we implement
- qt_metacall ourselves (and don't use any other features of the meta
- object system)
-*/
+ /* Q_OBJECT is not necessary or even allowed, because we implement
+ qt_metacall ourselves (and don't use any other features of the meta
+ object system)
+ */
- SignalRelay(SignalProxy *parent) : QObject(parent), _proxy(parent) {}
- inline SignalProxy *proxy() const { return _proxy; }
+ SignalRelay(SignalProxy* parent)
+ : QObject(parent)
+ , _proxy(parent)
+ {}
+ inline SignalProxy* proxy() const { return _proxy; }
- void attachSignal(QObject *sender, int signalId, const QByteArray &funcName);
- void detachSignal(QObject *sender, int signalId = -1);
+ void attachSignal(QObject* sender, int signalId, const QByteArray& funcName);
+ void detachSignal(QObject* sender, int signalId = -1);
- Signal(QObject *sender, int sigId, const QByteArray &signature) : sender(sender), signalId(sigId), signature(signature) {}
- Signal() : sender(0), signalId(-1) {}
+ Signal(QObject* sender, int sigId, QByteArray signature)
+ : sender(sender)
+ , signalId(sigId)
+ , signature(std::move(signature))
+ {}
+ Signal() = default;
-
-void SignalProxy::SignalRelay::attachSignal(QObject *sender, int signalId, const QByteArray &funcName)
+void SignalProxy::SignalRelay::attachSignal(QObject* sender, int signalId, const QByteArray& funcName)
{
// we ride without safetybelts here... all checking for valid method etc pp has to be done by the caller
// all connected methodIds are offset by the standard methodCount of QObject
{
// we ride without safetybelts here... all checking for valid method etc pp has to be done by the caller
// all connected methodIds are offset by the standard methodCount of QObject
QMetaObject::connect(sender, signalId, this, QObject::staticMetaObject.methodCount() + slotId);
}
QMetaObject::connect(sender, signalId, this, QObject::staticMetaObject.methodCount() + slotId);
}
{
QHash<int, Signal>::iterator slotIter = _slots.begin();
while (slotIter != _slots.end()) {
{
QHash<int, Signal>::iterator slotIter = _slots.begin();
while (slotIter != _slots.end()) {
- qWarning() << "SignalRelay::qt_metacall(): received invalid data for argument number" << i << "of signal" << QString("%1::%2").arg(caller->metaObject()->className()).arg(caller->metaObject()->method(signal.signalId).methodSignature().constData());
+ qWarning() << "SignalRelay::qt_metacall(): received invalid data for argument number" << i << "of signal"
+ << QString("%1::%2")
+ .arg(caller->metaObject()->className())
+ .arg(caller->metaObject()->method(signal.signalId).methodSignature().constData());
// ==================================================
// SignalProxy
// ==================================================
// ==================================================
// SignalProxy
// ==================================================
SignalProxy::~SignalProxy()
{
QHash<QByteArray, ObjectId>::iterator classIter = _syncSlave.begin();
while (classIter != _syncSlave.end()) {
ObjectId::iterator objIter = classIter->begin();
while (objIter != classIter->end()) {
SignalProxy::~SignalProxy()
{
QHash<QByteArray, ObjectId>::iterator classIter = _syncSlave.begin();
while (classIter != _syncSlave.end()) {
ObjectId::iterator objIter = classIter->begin();
while (objIter != classIter->end()) {
- attachSlot("__objectRenamed__", this, SLOT(objectRenamed(QByteArray,QString,QString)));
+ attachSlot("__objectRenamed__", this, SLOT(objectRenamed(QByteArray, QString, QString)));
- connect(peer, SIGNAL(lagUpdated(int)), SIGNAL(lagUpdated(int)));
+ connect(peer, &Peer::lagUpdated, this, &SignalProxy::lagUpdated);
- connect(peer, SIGNAL(disconnected()), SLOT(removePeerBySender()));
- connect(peer, SIGNAL(secureStateChanged(bool)), SLOT(updateSecureState()));
+ connect(peer, &Peer::disconnected, this, &SignalProxy::removePeerBySender);
+ connect(peer, &Peer::secureStateChanged, this, &SignalProxy::updateSecureState);
void SignalProxy::removeAllPeers()
{
Q_ASSERT(proxyMode() == Server || peerCount() <= 1);
// wee need to copy that list since we modify it in the loop
void SignalProxy::removeAllPeers()
{
Q_ASSERT(proxyMode() == Server || peerCount() <= 1);
// wee need to copy that list since we modify it in the loop
- disconnect(peer, 0, this, 0);
- peer->setSignalProxy(0);
+ disconnect(peer, nullptr, this, nullptr);
+ peer->setSignalProxy(nullptr);
-
-void SignalProxy::renameObject(const SyncableObject *obj, const QString &newname, const QString &oldname)
+void SignalProxy::renameObject(const SyncableObject* obj, const QString& newname, const QString& oldname)
const QByteArray className(meta->className());
objectRenamed(className, newname, oldname);
dispatch(RpcCall("__objectRenamed__", QVariantList() << className << newname << oldname));
}
const QByteArray className(meta->className());
objectRenamed(className, newname, oldname);
dispatch(RpcCall("__objectRenamed__", QVariantList() << className << newname << oldname));
}
-
-void SignalProxy::objectRenamed(const QByteArray &classname, const QString &newname, const QString &oldname)
+void SignalProxy::objectRenamed(const QByteArray& classname, const QString& newname, const QString& oldname)
{
if (!_extendedMetaObjects.contains(meta)) {
_extendedMetaObjects[meta] = new ExtendedMetaObject(meta, checkConflicts);
{
if (!_extendedMetaObjects.contains(meta)) {
_extendedMetaObjects[meta] = new ExtendedMetaObject(meta, checkConflicts);
QByteArray sig(meta->normalizedSignature(signal).mid(1));
int methodId = meta->indexOfMethod(sig.constData());
if (methodId == -1 || meta->method(methodId).methodType() != QMetaMethod::Signal) {
QByteArray sig(meta->normalizedSignature(signal).mid(1));
int methodId = meta->indexOfMethod(sig.constData());
if (methodId == -1 || meta->method(methodId).methodType() != QMetaMethod::Signal) {
createExtendedMetaObject(meta);
_signalRelay->attachSignal(sender, methodId, sigName);
createExtendedMetaObject(meta);
_signalRelay->attachSignal(sender, methodId, sigName);
- disconnect(sender, SIGNAL(destroyed(QObject *)), this, SLOT(detachObject(QObject *)));
- connect(sender, SIGNAL(destroyed(QObject *)), this, SLOT(detachObject(QObject *)));
+ disconnect(sender, &QObject::destroyed, this, &SignalProxy::detachObject);
+ connect(sender, &QObject::destroyed, this, &SignalProxy::detachObject);
int methodId = meta->indexOfMethod(meta->normalizedSignature(slot).mid(1));
if (methodId == -1 || meta->method(methodId).methodType() == QMetaMethod::Method) {
qWarning() << "SignalProxy::attachSlot(): No such slot" << slot;
int methodId = meta->indexOfMethod(meta->normalizedSignature(slot).mid(1));
if (methodId == -1 || meta->method(methodId).methodType() == QMetaMethod::Method) {
qWarning() << "SignalProxy::attachSlot(): No such slot" << slot;
QByteArray funcName = QMetaObject::normalizedSignature(sigName.constData());
_attachedSlots.insert(funcName, qMakePair(recv, methodId));
QByteArray funcName = QMetaObject::normalizedSignature(sigName.constData());
_attachedSlots.insert(funcName, qMakePair(recv, methodId));
- disconnect(recv, SIGNAL(destroyed(QObject *)), this, SLOT(detachObject(QObject *)));
- connect(recv, SIGNAL(destroyed(QObject *)), this, SLOT(detachObject(QObject *)));
+ disconnect(recv, &QObject::destroyed, this, &SignalProxy::detachObject);
+ connect(recv, &QObject::destroyed, this, &SignalProxy::detachObject);
{
// we can't use a className here, since it might be effed up, if we receive the call as a result of a decon
// gladly the objectName() is still valid. So we have only to iterate over the classes not each instance! *sigh*
{
// we can't use a className here, since it might be effed up, if we receive the call as a result of a decon
// gladly the objectName() is still valid. So we have only to iterate over the classes not each instance! *sigh*
{
for (auto&& peer : _peerMap.values()) {
dispatch(peer, protoMessage);
}
}
{
for (auto&& peer : _peerMap.values()) {
dispatch(peer, protoMessage);
}
}
- qWarning() << QString("no registered receiver for sync call: %1::%2 (objectName=\"%3\"). Params are:").arg(syncMessage.className, syncMessage.slotName, syncMessage.objectName)
+ qWarning() << QString("no registered receiver for sync call: %1::%2 (objectName=\"%3\"). Params are:")
+ .arg(syncMessage.className, syncMessage.slotName, syncMessage.objectName)
- SyncableObject *receiver = _syncSlave[syncMessage.className][syncMessage.objectName];
- ExtendedMetaObject *eMeta = extendedMetaObject(receiver);
+ SyncableObject* receiver = _syncSlave[syncMessage.className][syncMessage.objectName];
+ ExtendedMetaObject* eMeta = extendedMetaObject(receiver);
- qWarning() << QString("no matching slot for sync call: %1::%2 (objectName=\"%3\"). Params are:").arg(syncMessage.className, syncMessage.slotName, syncMessage.objectName)
+ qWarning() << QString("no matching slot for sync call: %1::%2 (objectName=\"%3\"). Params are:")
+ .arg(syncMessage.className, syncMessage.slotName, syncMessage.objectName)
- if (!_syncSlave.contains(initRequest.className)) {
- qWarning() << "SignalProxy::handleInitRequest() received initRequest for unregistered Class:"
- << initRequest.className;
+ if (!_syncSlave.contains(initRequest.className)) {
+ qWarning() << "SignalProxy::handleInitRequest() received initRequest for unregistered Class:" << initRequest.className;
- qWarning() << "SignalProxy::handleInitRequest() received initRequest for unregistered Object:"
- << initRequest.className << initRequest.objectName;
+ qWarning() << "SignalProxy::handleInitRequest() received initRequest for unregistered Object:" << initRequest.className
+ << initRequest.objectName;
int methodId;
SlotHash::const_iterator slot = _attachedSlots.constFind(rpcCall.slotName);
while (slot != _attachedSlots.constEnd() && slot.key() == rpcCall.slotName) {
receiver = (*slot).first;
methodId = (*slot).second;
if (!invokeSlot(receiver, methodId, rpcCall.params, peer)) {
int methodId;
SlotHash::const_iterator slot = _attachedSlots.constFind(rpcCall.slotName);
while (slot != _attachedSlots.constEnd() && slot.key() == rpcCall.slotName) {
receiver = (*slot).first;
methodId = (*slot).second;
if (!invokeSlot(receiver, methodId, rpcCall.params, peer)) {
-
-bool SignalProxy::invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms, QVariant &returnValue, Peer *peer)
+bool SignalProxy::invokeSlot(QObject* receiver, int methodId, const QVariantList& params, QVariant& returnValue, Peer* peer)
if (eMeta->minArgCount(methodId) > params.count()) {
qWarning() << "SignalProxy::invokeSlot(): not enough params to invoke" << eMeta->methodName(methodId);
return false;
}
if (eMeta->minArgCount(methodId) > params.count()) {
qWarning() << "SignalProxy::invokeSlot(): not enough params to invoke" << eMeta->methodName(methodId);
return false;
}
- void *_a[] = { 0, // return type...
- 0, 0, 0, 0, 0, // and 10 args - that's the max size qt can handle with signals and slots
- 0, 0, 0, 0, 0 };
+ void* _a[] = {nullptr, // return type...
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr, // and 10 args - that's the max size qt can handle with signals and slots
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr};
// check for argument compatibility and build params array
for (int i = 0; i < numArgs; i++) {
if (!params[i].isValid()) {
// check for argument compatibility and build params array
for (int i = 0; i < numArgs; i++) {
if (!params[i].isValid()) {
- qWarning() << "SignalProxy::invokeSlot(): received invalid data for argument number" << i << "of method" << QString("%1::%2()").arg(receiver->metaObject()->className()).arg(receiver->metaObject()->method(methodId).methodSignature().constData());
+ qWarning() << "SignalProxy::invokeSlot(): received invalid data for argument number" << i << "of method"
+ << QString("%1::%2()")
+ .arg(receiver->metaObject()->className())
+ .arg(receiver->metaObject()->method(methodId).methodSignature().constData());
if (type == Qt::DirectConnection) {
_sourcePeer = peer;
auto result = receiver->qt_metacall(QMetaObject::InvokeMetaMethod, methodId, _a) < 0;
_sourcePeer = nullptr;
return result;
if (type == Qt::DirectConnection) {
_sourcePeer = peer;
auto result = receiver->qt_metacall(QMetaObject::InvokeMetaMethod, methodId, _a) < 0;
_sourcePeer = nullptr;
return result;
-
-bool SignalProxy::invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms, Peer *peer)
+bool SignalProxy::invokeSlot(QObject* receiver, int methodId, const QVariantList& params, Peer* peer)
{
QVariant ret;
return invokeSlot(receiver, methodId, params, ret, peer);
}
{
QVariant ret;
return invokeSlot(receiver, methodId, params, ret, peer);
}
-
-void SignalProxy::sync_call__(const SyncableObject *obj, SignalProxy::ProxyMode modeType, const char *funcname, va_list ap)
+void SignalProxy::sync_call__(const SyncableObject* obj, SignalProxy::ProxyMode modeType, const char* funcname, va_list ap)
if (peer != nullptr)
dispatch(peer, SyncMessage(eMeta->metaObject()->className(), obj->objectName(), QByteArray(funcname), params));
}
if (peer != nullptr)
dispatch(peer, SyncMessage(eMeta->metaObject()->className(), obj->objectName(), QByteArray(funcname), params));
}
dispatch(SyncMessage(eMeta->metaObject()->className(), obj->objectName(), QByteArray(funcname), params));
}
dispatch(SyncMessage(eMeta->metaObject()->className(), obj->objectName(), QByteArray(funcname), params));
}
- foreach(ObjectId oid, _syncSlave.values())
- slaveCount += oid.count();
+ foreach (ObjectId oid, _syncSlave.values())
+ slaveCount += oid.count();
void SignalProxy::updateSecureState()
{
bool wasSecure = _secure;
_secure = !_peerMap.isEmpty();
void SignalProxy::updateSecureState()
{
bool wasSecure = _secure;
_secure = !_peerMap.isEmpty();
// We use ::value() here instead of the [] operator because the latter has the side-effect
// of automatically inserting a null value with the passed key into the map. See
// https://doc.qt.io/qt-5/qhash.html#operator-5b-5d and https://doc.qt.io/qt-5/qhash.html#value.
// We use ::value() here instead of the [] operator because the latter has the side-effect
// of automatically inserting a null value with the passed key into the map. See
// https://doc.qt.io/qt-5/qhash.html#operator-5b-5d and https://doc.qt.io/qt-5/qhash.html#value.
_targetPeer = targetPeer;
}
// ==================================================
// ExtendedMetaObject
// ==================================================
_targetPeer = targetPeer;
}
// ==================================================
// ExtendedMetaObject
// ==================================================
-SignalProxy::ExtendedMetaObject::ExtendedMetaObject(const QMetaObject *meta, bool checkConflicts)
- : _meta(meta),
- _updatedRemotelyId(_meta->indexOfSignal("updatedRemotely()"))
+SignalProxy::ExtendedMetaObject::ExtendedMetaObject(const QMetaObject* meta, bool checkConflicts)
+ : _meta(meta)
+ , _updatedRemotelyId(_meta->indexOfSignal("updatedRemotely()"))
{
for (int i = 0; i < _meta->methodCount(); i++) {
if (_meta->method(i).methodType() != QMetaMethod::Slot)
{
for (int i = 0; i < _meta->methodCount(); i++) {
if (_meta->method(i).methodType() != QMetaMethod::Slot)
/* funny... moc creates for methods containing default parameters multiple metaMethod with separate methodIds.
we don't care... we just need the full fledged version
*/
/* funny... moc creates for methods containing default parameters multiple metaMethod with separate methodIds.
we don't care... we just need the full fledged version
*/
- const QMetaMethod ¤t = _meta->method(_methodIds[method]);
- const QMetaMethod &candidate = _meta->method(i);
+ const QMetaMethod& current = _meta->method(_methodIds[method]);
+ const QMetaMethod& candidate = _meta->method(i);
if (current.parameterTypes().count() > candidate.parameterTypes().count()) {
int minCount = candidate.parameterTypes().count();
QList<QByteArray> commonParams = current.parameterTypes().mid(0, minCount);
if (current.parameterTypes().count() > candidate.parameterTypes().count()) {
int minCount = candidate.parameterTypes().count();
QList<QByteArray> commonParams = current.parameterTypes().mid(0, minCount);
int minCount = current.parameterTypes().count();
QList<QByteArray> commonParams = candidate.parameterTypes().mid(0, minCount);
if (commonParams == current.parameterTypes()) {
int minCount = current.parameterTypes().count();
QList<QByteArray> commonParams = candidate.parameterTypes().mid(0, minCount);
if (commonParams == current.parameterTypes()) {
{
if (_receiveMap.isEmpty()) {
QHash<int, int> receiveMap;
{
if (_receiveMap.isEmpty()) {
QHash<int, int> receiveMap;
-
-SignalProxy::ExtendedMetaObject::MethodDescriptor::MethodDescriptor(const QMetaMethod &method)
- : _methodName(SignalProxy::ExtendedMetaObject::methodName(method)),
- _returnType(QMetaType::type(method.typeName()))
+SignalProxy::ExtendedMetaObject::MethodDescriptor::MethodDescriptor(const QMetaMethod& method)
+ : _methodName(SignalProxy::ExtendedMetaObject::methodName(method))
+ , _returnType(QMetaType::type(method.typeName()))
QString signature(method.methodSignature());
_minArgCount = method.parameterTypes().count() - signature.count("=");
QString signature(method.methodSignature());
_minArgCount = method.parameterTypes().count() - signature.count("=");