#include "validationserver.h" XRValidationServer::XRValidationServer( Q_UINT16 port, int backlog, QObject * parent, const char * name) : XRServer(port,backlog,parent,name) { /* * This looks horrific, but it is really simple (just long). * This wires up ALL slots to the methodCall signal. */ connect(this, SIGNAL(methodCall(int, const QString&, const QValueList&, bool&)), this, SLOT(arrayOfStructsTest(int, const QString&, const QValueList&, bool&))); connect(this, SIGNAL(methodCall(int, const QString&, const QValueList&, bool&)), this, SLOT(countTheEntities(int, const QString&, const QValueList&, bool&))); connect(this, SIGNAL(methodCall(int, const QString&, const QValueList&, bool&)), SLOT(easyStructTest(int, const QString&, const QValueList&, bool&))); connect(this, SIGNAL(methodCall(int, const QString&, const QValueList&, bool&)), SLOT(echoStructTest(int, const QString&, const QValueList&, bool&))); connect(this, SIGNAL(methodCall(int, const QString&, const QValueList&, bool&)), SLOT(manyTypesTest(int, const QString&, const QValueList&, bool&))); connect(this, SIGNAL(methodCall(int, const QString&, const QValueList&, bool&)), SLOT(moderateSizeArrayCheck(int, const QString&, const QValueList&, bool&))); connect(this, SIGNAL(methodCall(int, const QString&, const QValueList&, bool&)), SLOT(nestedStructTest(int, const QString&, const QValueList&, bool&))); connect(this, SIGNAL(methodCall(int, const QString&, const QValueList&, bool&)), SLOT(simpleStructReturnTest(int, const QString&, const QValueList&, bool&))); connect(this, SIGNAL(methodCall( int, const QString&, const QValueList&, bool&)), SLOT(sumAndDifference( int, const QString&, const QValueList&, bool&)) ); } void XRValidationServer::arrayOfStructsTest( int req, const QString& methodname, const QValueList& params, bool& handled ) { if( (handled == false) && (methodname == "validator1.arrayOfStructsTest") ) { handled = true; //Here we through caution to the wind, assume all the params are okay QValueList array = params[0].toList(); QMap map; QValueList::iterator it; int result = 0; for(it = array.begin(); it != array.end(); it++) { map = (*it).toMap(); if( map.contains("curly") ) { result += map["curly"].toInt(); } } sendMethodResponse(req,QVariant(result)); } } void XRValidationServer::countTheEntities( int req, const QString& methodname, const QValueList& params, bool& handled) { if( (handled == false) && (methodname == "validator1.countTheEntities") ) { handled = true; QMap result; QString input = params[0].toString(); result["ctLeftAngleBrackets"] = input.contains('<'); result["ctRightAngleBrackets"] = input.contains('>'); result["ctAmpersands"] = input.contains('&'); result["ctApostrophes"] = input.contains('\''); result["ctQuotes"] = input.contains('"'); sendMethodResponse(req,QVariant(result)); } } void XRValidationServer::easyStructTest( int req, const QString& methodname, const QValueList& params, bool& handled) { if( (handled == false) && (methodname == "validator1.easyStructTest") ) { handled = true; int result = 0; QMap map = params[0].toMap(); result += map["larry"].toInt(); result += map["moe"].toInt(); result += map["curly"].toInt(); sendMethodResponse(req,QVariant(result)); } } void XRValidationServer::echoStructTest( int req, const QString& methodname, const QValueList& params, bool& handled) { if( (handled == false) && (methodname == "validator1.echoStructTest") ) { handled = true; sendMethodResponse(req, QVariant( params[0].toMap() ) ); } } void XRValidationServer::manyTypesTest( int req, const QString& methodname, const QValueList& params, bool& handled) { if( (handled == false) && (methodname == "validator1.manyTypesTest") ) { handled = true; sendMethodResponse(req, QVariant( params ) ); } } void XRValidationServer::moderateSizeArrayCheck( int req, const QString& methodname, const QValueList& params, bool& handled) { if( (handled == false) && (methodname == "validator1.moderateSizeArrayCheck") ) { handled = true; QValueList array = params[0].toList(); QString result = array.front().toString() + array.back().toString(); sendMethodResponse(req, QVariant( result ) ); } } void XRValidationServer::nestedStructTest( int req, const QString& methodname, const QValueList& params, bool& handled) { if( (handled == false) && (methodname == "validator1.nestedStructTest") ) { handled = true; QMap years,months,days,day; years = params[0].toMap(); months = years["2000"].toMap(); days = months["04"].toMap(); day = days["01"].toMap(); int result = 0; result += day["larry"].toInt(); result += day["moe"].toInt(); result += day["curly"].toInt(); sendMethodResponse(req, QVariant( result ) ); } } void XRValidationServer::simpleStructReturnTest( int req, const QString& methodname, const QValueList& params, bool& handled) { if( (handled == false) && (methodname == "validator1.simpleStructReturnTest") ) { handled = true; QMap map; map["times10"] = params[0].toInt() * 10; map["times100"] = params[0].toInt() * 100; map["times1000"] = params[0].toInt() * 1000; sendMethodResponse(req, QVariant( map ) ); } } void XRValidationServer::sumAndDifference( int req, const QString& methodname, const QValueList& params, bool& handled) { if( (handled == false) && (methodname == "sample.sumAndDifference") ) { handled = true; int a,b; a = params[0].toInt(); b = params[1].toInt(); QMap result; result["difference"] = a - b; result["sum"] = a+b; sendMethodResponse(req, QVariant( result ) ); } }