#include "p4commandrunner.h" class HClientUser : public ClientUser { public: HClientUser(P4CommandRunner* runner) { m_Runner = runner; } virtual void OutputInfo( char /*level*/, const char * data ) { QVariantMap entry; entry.insert(data, ""); m_TaggedOutput.append(entry); } virtual void OutputStat(StrDict *varList) { StrRef var, val; QVariantMap entry; for( int i = 0; varList->GetVar( i, var, val ); i++ ) { if( var == "func" || var == P4Tag::v_specFormatted ) continue; entry.insert(var.Text(),val.Text()); } m_TaggedOutput.append(entry); } virtual void OutputError( const char * errBuf) { QString errmsg = QString("OutputError: " + QString(errBuf)); m_Runner->errorList()->append(errmsg); } virtual void InputData( StrBuf *strbuf, Error *e ) { QString inputData = m_Runner->getInputData(); if (inputData.isEmpty()) { e->Set( E_FAILED, "No user-input supplied." ); m_Runner->errorList()->append("Error: No input data. Did you forget to call .setInput()?"); } if (m_Runner) strbuf->Set(inputData.toLocal8Bit()); // todo: refactor into constructor } virtual int Help( char *const *help ) { QString errmsg = QString("Help: " + QString(*help)); m_Runner->errorList()->append(errmsg); return 0; } void clearOutputMap() {m_TaggedOutput.clear();} QVariantList getOutput() {return m_TaggedOutput;} private: QVariantList m_TaggedOutput; P4CommandRunner* m_Runner; }; P4CommandRunner::P4CommandRunner(P4Connection* caller, QVariantList args) { m_Caller = caller; m_Command = args.takeFirst().toString(); m_Args = args; m_Future = new QFuture<QVariant>; m_Watcher = new QFutureWatcher<void>; connect(m_Watcher, SIGNAL(finished()), this, SLOT(deliverRunResponse())); } QVariant P4CommandRunner::exec() { Error e; HClientUser ui(this); ClientApi client; client.SetPort(m_Caller->getPort().toLatin1()); client.SetUser(m_Caller->getUser().toLatin1()); client.SetClient(m_Caller->getClient().toLatin1()); client.SetCharset(m_Caller->getCharset().toLatin1()); client.SetProtocol("tag", ""); client.Init( &e ); client.SetVar("enableStreams"); int numArgs = m_Args.count(); QByteArray ba0; QByteArray ba1; QByteArray ba2; QByteArray ba3; QByteArray ba4; QByteArray ba5; char* arg0; char* arg1; char* arg2; char* arg3; char* arg4; char* arg5; if (numArgs > 0) //todo: process more than 6 args { ba0 = m_Args[0].toString().toLatin1(); arg0 = ba0.data(); if (numArgs > 1) { ba1 = m_Args[1].toString().toLatin1(); arg1 = ba1.data(); if (numArgs > 2) { ba2 = m_Args[2].toString().toLatin1(); arg2 = ba2.data(); if (numArgs > 3) { ba3 = m_Args[3].toString().toLatin1(); arg3 = ba3.data(); if (numArgs > 4) { ba4 = m_Args[4].toString().toLatin1(); arg4 = ba4.data(); if (numArgs > 5) { ba5 = m_Args[5].toString().toLatin1(); arg5 = ba5.data(); if (numArgs > 6) { throw e; // mErrorList += "Warning: Exceeded maximum number of processed arguments"; } } } } } } } char *argv[] = { arg0, arg1, arg2, arg3, arg4, arg5 }; int argc = numArgs; client.SetArgv( argc, argv ); ui.clearOutputMap(); client.Run( m_Command.toLocal8Bit(), &ui ); client.Final( &e ); QVariantList infoList = ui.getOutput(); QVariantMap returnMap; if (infoList.count()>0) { returnMap.insert("size", infoList.count()); returnMap.insert("data", infoList); } if (m_ErrorList.count() > 0) { returnMap.insert("error", m_ErrorList); } return returnMap; } void P4CommandRunner::execBG() { *m_Future = QtConcurrent::run(this, &P4CommandRunner::exec); m_Watcher->setFuture(*m_Future); } void P4CommandRunner::deliverRunResponse() { QVariant result = m_Future->result(); this->runCompleted(result); } void P4CommandRunner::destroy() { delete this; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 8119 | David George |
fixing setInput for -i commands, and fixing connectionObject.run() to take a form as its second argument. (if the second argument is a form, it will check the third argument for a callback function) |
||
#1 | 8101 | David George |
beginning of _massive_ re-factoring your current build settings will fail create a new project from newly added .pro file (but change its p4api paths to match your old one) look for updated README as soon as Dave agrees that changes are _indeed_ for the best (Changes by Jaimen) |