+
+bool SignalProxy::methodsMatch(const QMetaMethod &signal, const QMetaMethod &slot) const {
+ // if we don't even have the same basename it's a sure NO
+ if(methodBaseName(signal) != methodBaseName(slot))
+ return false;
+
+ // are the signatures compatible?
+ if(!QObject::staticMetaObject.checkConnectArgs(signal.signature(), slot.signature()))
+ return false;
+
+ // we take an educated guess if the signals and slots match
+ QString signalsuffix = ::methodName(signal).mid(QString(::methodName(signal)).lastIndexOf(QRegExp("[A-Z]"))).toLower();
+ QString slotprefix = ::methodName(slot).left(QString(::methodName(slot)).indexOf(QRegExp("[A-Z]"))).toLower();
+
+ uint sizediff = qAbs(slotprefix.size() - signalsuffix.size());
+ int ratio = editingDistance(slotprefix, signalsuffix) - sizediff;
+ return (ratio < 2);
+}
+
+QString SignalProxy::methodBaseName(const QMetaMethod &method) {
+ QString methodname = QString(method.signature()).section("(", 0, 0);
+
+ // determine where we have to chop:
+ if(method.methodType() == QMetaMethod::Slot) {
+ // we take evertyhing from the first uppercase char if it's slot
+ methodname = methodname.mid(methodname.indexOf(QRegExp("[A-Z]")));
+ } else {
+ // and if it's a signal we discard everything from the last uppercase char
+ methodname = methodname.left(methodname.lastIndexOf(QRegExp("[A-Z]")));
+ }
+
+ methodname[0] = methodname[0].toUpper();
+
+ return methodname;
+}
+
+QVariantMap SignalProxy::initData(QObject *obj) const {
+ QVariantMap properties;
+
+ const QMetaObject* meta = obj->metaObject();
+
+ // we collect data from properties
+ for(int i = 0; i < meta->propertyCount(); i++) {
+ QMetaProperty prop = meta->property(i);
+ properties[QString(prop.name())] = prop.read(obj);
+ }
+
+ // ...as well as methods, which have names starting with "init"
+ for(int i = 0; i < meta->methodCount(); i++) {
+ QMetaMethod method = meta->method(i);
+ QString methodname(::methodName(method));
+ if(!methodname.startsWith("init") || methodname.startsWith("initSet"))
+ continue;
+
+ QVariant value = QVariant(QVariant::nameToType(method.typeName()));
+ QGenericReturnArgument genericvalue = QGenericReturnArgument(method.typeName(), &value);
+ QMetaObject::invokeMethod(obj, methodname.toAscii(), genericvalue);
+
+ properties[methodBaseName(method)] = value;
+ // qDebug() << ">>> SYNC:" << methodBaseName(method) << value;
+ }
+
+ // properties["Payload"] = QByteArray(10000000, 'a'); // for testing purposes
+ return properties;
+}
+
+void SignalProxy::setInitData(QObject *obj, const QVariantMap &properties) {
+ if(initialized(obj))
+ return;
+
+ const QMetaObject *meta = obj->metaObject();
+
+ QVariantMap::const_iterator iterator = properties.constBegin();
+ while(iterator != properties.constEnd()) {
+ QString name = iterator.key();
+ int propertyIndex = meta->indexOfProperty(name.toAscii());
+
+ if(propertyIndex == -1 || !meta->property(propertyIndex).isWritable())
+ setInitValue(obj, name, iterator.value());
+ else
+ obj->setProperty(name.toAscii(), iterator.value());
+ // qDebug() << "<<< SYNC:" << name << iterator.value();
+ iterator++;
+ }
+ setInitialized(obj);
+}
+
+bool SignalProxy::setInitValue(QObject *obj, const QString &property, const QVariant &value) {
+ QString handlername = QString("initSet") + property;
+ handlername[7] = handlername[7].toUpper();
+ QGenericArgument param(value.typeName(), value.constData());
+ return QMetaObject::invokeMethod(obj, handlername.toAscii(), param);
+}
+
+void SignalProxy::dumpProxyStats() {
+ QString mode;
+ if(proxyMode() == Server)
+ mode = "Server";
+ else
+ mode = "Client";
+
+ int sigCount = 0;
+ foreach(SignalRelay *relay, _relayHash.values())
+ sigCount += relay->sigCount();
+
+ int slaveCount = 0;
+ foreach(ObjectId oid, _syncSlave.values())
+ slaveCount += oid.count();
+
+ qDebug() << this;
+ qDebug() << " Proxy Mode:" << mode;
+ qDebug() << "attached sending Objects:" << _relayHash.count();
+ qDebug() << " number of Signals:" << sigCount;
+ qDebug() << " attached Slots:" << _attachedSlots.count();
+ qDebug() << " number of synced Slaves:" << slaveCount;
+ qDebug() << "number of Classes cached:" << _classInfo.count();
+}
+
+void SignalProxy::dumpSyncMap(QObject *object) {
+ const QMetaObject *meta = object->metaObject();
+ qDebug() << "SignalProxy: SyncMap for Class" << meta->className();
+
+ QHash<int, int> syncMap_ = syncMap(object);
+ QHash<int, int>::const_iterator iter = syncMap_.constBegin();
+ while(iter != syncMap_.constEnd()) {
+ qDebug() << iter.key() << meta->method(iter.key()).signature() << "-->" << iter.value() << meta->method(iter.value()).signature();
+ iter++;
+ }
+}