qavrg 0.0.28
|
#include <qavrgscriptingengine.h>
Public Slots | |
void | evaluateAppCommand (QString cmd) |
void | evaluateServerCommand (QString cmd) |
void | evaluateSpecCommand (QString cmd) |
Signals | |
void | serverResultAvailable (QScriptValue cmd) |
void | specResultAvailable (QScriptValue cmd) |
void | appResultAvailable (QScriptValue res) |
void | printMessage (QString msg) |
Public Member Functions | |
QavrgScriptingEngine (QavrgApplication *app, QavrgWindow *win, QavrgAcquisition *acq) | |
void | initialize () |
bool | hasUncaughtException () const |
int | uncaughtExceptionLineNumber () const |
QString | uncaughtExceptionString () const |
void | cancelCommand () |
Private Slots | |
void | evaluate (int src, QString cmd) |
Static Private Member Functions | |
static QScriptValue | printFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | newFileFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | closeFileFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | newScanFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | acquireDataFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | acquireReferenceFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | acquireDarkFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | acquireScopeFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | acquireOnceFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | acquireCancelFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | statusFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | saveDataFunc (QScriptContext *context, QScriptEngine *engine) |
static QScriptValue | fitterFunc (QScriptContext *context, QScriptEngine *engine) |
Private Attributes | |
QMutex | m_Mutex |
QScriptEngine * | m_ScriptEngine |
QavrgApplication * | m_Application |
QavrgWindow * | m_Window |
QavrgAcquisition * | m_Acquisition |
Definition at line 12 of file qavrgscriptingengine.h.
QavrgScriptingEngine::QavrgScriptingEngine | ( | QavrgApplication * | app, |
QavrgWindow * | win, | ||
QavrgAcquisition * | acq | ||
) |
Definition at line 15 of file qavrgscriptingengine.cpp.
: QObject(), m_Mutex(QMutex::Recursive), m_ScriptEngine(NULL), m_Application(app), m_Window(win), m_Acquisition(acq) { g_ScriptingEngine = this; g_Acquisition = acq; g_Application = app; }
QScriptValue QavrgScriptingEngine::acquireCancelFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 392 of file qavrgscriptingengine.cpp.
References printMessage().
Referenced by initialize().
{ if (context->argumentCount() == 0) { g_ScriptingEngine -> emit printMessage("acquireCancel()"); g_Acquisition -> acquireCancel(); } else { return context -> throwError("acquireCancel() takes no arguments"); } return QScriptValue(engine,0); }
QScriptValue QavrgScriptingEngine::acquireDarkFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 302 of file qavrgscriptingengine.cpp.
References printMessage().
Referenced by initialize().
{ if (g_Acquisition -> getAcquisitionLock() == 0) { return context -> throwError("Attempt to start new acquire operation before previous acquire has completed"); } switch (context->argumentCount()) { case 2: g_ScriptingEngine -> emit printMessage(tr("acquireDark(%1,%2)") .arg(context->argument(0).toNumber()) .arg(context->argument(1).toInteger())); g_Acquisition -> set_DarkNRepeats(context->argument(1).toInteger()); g_Acquisition -> set_IntegrationTime(context->argument(0).toNumber()); break; case 1: g_ScriptingEngine -> emit printMessage(tr("acquireDark(%1)") .arg(context->argument(0).toNumber())); g_Acquisition -> set_IntegrationTime(context->argument(0).toNumber()); break; case 0: g_ScriptingEngine -> emit printMessage("acquireDark()"); break; default: return context -> throwError("acquireDark() takes zero, one or two arguments"); } QMetaObject::invokeMethod(g_Acquisition, "acquireDark"); return QScriptValue(engine,0); }
QScriptValue QavrgScriptingEngine::acquireDataFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 229 of file qavrgscriptingengine.cpp.
References printMessage().
Referenced by initialize().
{ if (g_Acquisition -> getAcquisitionLock() == 0) { return context -> throwError("Attempt to start new acquire operation before previous acquire has completed"); } switch (context->argumentCount()) { case 2: g_ScriptingEngine -> emit printMessage(tr("acquireData(%1,%2)") .arg(context->argument(0).toNumber()) .arg(context->argument(1).toInteger())); g_Acquisition -> set_NRepeats(context->argument(1).toInteger()); g_Acquisition -> set_IntegrationTime(context->argument(0).toNumber()); break; case 1: g_ScriptingEngine -> emit printMessage(tr("acquireData(%1)") .arg(context->argument(0).toNumber())); g_ScriptingEngine -> emit printMessage("acquireData()"); g_Acquisition -> set_IntegrationTime(context->argument(0).toNumber()); break; case 0: g_ScriptingEngine -> emit printMessage("acquireData()"); break; default: return context -> throwError("acquireData() takes zero, one or two arguments"); } QMetaObject::invokeMethod(g_Acquisition, "acquireData"); return QScriptValue(engine,0); }
QScriptValue QavrgScriptingEngine::acquireOnceFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 365 of file qavrgscriptingengine.cpp.
References printMessage().
Referenced by initialize().
{ if (g_Acquisition -> getAcquisitionLock() == 0) { return context -> throwError("Attempt to start new acquire operation before previous acquire has completed"); } switch (context->argumentCount()) { case 1: g_ScriptingEngine -> emit printMessage(tr("acquireOnce(%1)") .arg(context->argument(0).toNumber())); g_Acquisition -> set_IntegrationTime(context->argument(0).toNumber()); break; case 0: g_ScriptingEngine -> emit printMessage("acquireOnce()"); break; default: return context -> throwError("acquireOnce() takes zero or one arguments"); } QMetaObject::invokeMethod(g_Acquisition, "acquireOnce"); return QScriptValue(engine,0); }
QScriptValue QavrgScriptingEngine::acquireReferenceFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 266 of file qavrgscriptingengine.cpp.
References printMessage().
Referenced by initialize().
{ if (g_Acquisition -> getAcquisitionLock() == 0) { return context -> throwError("Attempt to start new acquire operation before previous acquire has completed"); } switch (context->argumentCount()) { case 2: g_ScriptingEngine -> emit printMessage(tr("acquireReference(%1,%2)") .arg(context->argument(0).toNumber()) .arg(context->argument(1).toInteger())); g_Acquisition -> set_ReferenceNRepeats(context->argument(1).toInteger()); g_Acquisition -> set_IntegrationTime(context->argument(0).toNumber()); break; case 1: g_ScriptingEngine -> emit printMessage(tr("acquireReference(%1)") .arg(context->argument(0).toNumber())); g_Acquisition -> set_IntegrationTime(context->argument(0).toNumber()); break; case 0: g_ScriptingEngine -> emit printMessage("acquireReference()"); break; default: return context -> throwError("acquireReference() takes zero, one or two arguments"); } QMetaObject::invokeMethod(g_Acquisition, "acquireReference"); return QScriptValue(engine,0); }
QScriptValue QavrgScriptingEngine::acquireScopeFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 338 of file qavrgscriptingengine.cpp.
References printMessage().
Referenced by initialize().
{ if (g_Acquisition -> getAcquisitionLock() == 0) { return context -> throwError("Attempt to start new acquire operation before previous acquire has completed"); } switch (context->argumentCount()) { case 1: g_ScriptingEngine -> emit printMessage(tr("acquireScope(%1)") .arg(context->argument(0).toNumber())); g_Acquisition -> set_ScopeIntegrationTime(context->argument(0).toNumber()); break; case 0: g_ScriptingEngine -> emit printMessage("acquireScope()"); break; default: return context -> throwError("acquireScope() takes zero or one arguments"); } QMetaObject::invokeMethod(g_Acquisition, "acquireScope"); return QScriptValue(engine,0); }
void QavrgScriptingEngine::appResultAvailable | ( | QScriptValue | res | ) | [signal] |
Referenced by evaluate().
void QavrgScriptingEngine::cancelCommand | ( | ) |
Definition at line 113 of file qavrgscriptingengine.cpp.
References m_ScriptEngine.
{ m_ScriptEngine -> abortEvaluation(); }
QScriptValue QavrgScriptingEngine::closeFileFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 180 of file qavrgscriptingengine.cpp.
References printMessage().
Referenced by initialize().
{ int nargs = context->argumentCount(); if (nargs == 0) { g_ScriptingEngine -> emit printMessage("closeFile()"); QMetaObject::invokeMethod(g_Acquisition, "closeSaveFile"); } else { return context -> throwError("closeFile() takes no arguments"); } return QScriptValue(engine, nargs); }
void QavrgScriptingEngine::evaluate | ( | int | src, |
QString | cmd | ||
) | [private, slot] |
Definition at line 92 of file qavrgscriptingengine.cpp.
References appResultAvailable(), m_ScriptEngine, serverResultAvailable(), and specResultAvailable().
{ THREAD_CHECK; // printf("QavrgScriptingEngine::evaluate(%s)\n", qPrintable(expr)); QScriptValue result = m_ScriptEngine -> evaluate(expr); switch (src) { case 0: emit appResultAvailable(result); break; case 1: emit serverResultAvailable(result); break; case 2: emit specResultAvailable(result); break; } }
void QavrgScriptingEngine::evaluateAppCommand | ( | QString | cmd | ) | [slot] |
Definition at line 65 of file qavrgscriptingengine.cpp.
References m_Mutex.
{ QMutexLocker lock(&m_Mutex); // printf("QavrgScriptingEngine::evaluateAppCommand(%s)\n", qPrintable(expr)); QMetaObject::invokeMethod(this, "evaluate", Qt::QueuedConnection, Q_ARG(int, 0), Q_ARG(QString, expr)); }
void QavrgScriptingEngine::evaluateServerCommand | ( | QString | cmd | ) | [slot] |
Definition at line 74 of file qavrgscriptingengine.cpp.
References m_Mutex.
{ QMutexLocker lock(&m_Mutex); // printf("QavrgScriptingEngine::evaluateServerCommand(%s)\n", qPrintable(expr)); QMetaObject::invokeMethod(this, "evaluate", Qt::QueuedConnection, Q_ARG(int, 1), Q_ARG(QString, expr)); }
void QavrgScriptingEngine::evaluateSpecCommand | ( | QString | cmd | ) | [slot] |
Definition at line 83 of file qavrgscriptingengine.cpp.
References m_Mutex.
{ QMutexLocker lock(&m_Mutex); // printf("QavrgScriptingEngine::evaluateSpecCommand(%s)\n", qPrintable(expr)); QMetaObject::invokeMethod(this, "evaluate", Qt::QueuedConnection, Q_ARG(int, 2), Q_ARG(QString, expr)); }
QScriptValue QavrgScriptingEngine::fitterFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 492 of file qavrgscriptingengine.cpp.
Referenced by initialize().
{ QavrgFitter *f = NULL; int nargs = context->argumentCount(); if (nargs == 1) { int n = context->argument(0).toInteger(); f = g_Acquisition -> fitter(n); } return engine->newQObject(f); }
bool QavrgScriptingEngine::hasUncaughtException | ( | ) | const |
Definition at line 118 of file qavrgscriptingengine.cpp.
References m_Mutex, and m_ScriptEngine.
{ QMutexLocker lock(&m_Mutex); return m_ScriptEngine -> hasUncaughtException(); }
void QavrgScriptingEngine::initialize | ( | ) |
Definition at line 28 of file qavrgscriptingengine.cpp.
References acquireCancelFunc(), acquireDarkFunc(), acquireDataFunc(), acquireOnceFunc(), acquireReferenceFunc(), acquireScopeFunc(), closeFileFunc(), fitterFunc(), m_Acquisition, m_Application, m_ScriptEngine, m_Window, newFileFunc(), newScanFunc(), printFunc(), saveDataFunc(), and statusFunc().
{ // printf("enter QavrgScriptingEngine::initialize\n"); m_ScriptEngine = new QScriptEngine(this); qScriptRegisterSequenceMetaType< QList<int> >(m_ScriptEngine); qScriptRegisterSequenceMetaType< QList<bool> >(m_ScriptEngine); qScriptRegisterSequenceMetaType< QList<double> >(m_ScriptEngine); qScriptRegisterSequenceMetaType< QList<QString> >(m_ScriptEngine); qScriptRegisterSequenceMetaType< QVector<int> >(m_ScriptEngine); qScriptRegisterSequenceMetaType< QVector<bool> >(m_ScriptEngine); qScriptRegisterSequenceMetaType< QVector<double> >(m_ScriptEngine); qScriptRegisterSequenceMetaType< QVector<QString> >(m_ScriptEngine); m_ScriptEngine -> globalObject().setProperty("acquireData",m_ScriptEngine -> newFunction(acquireDataFunc)); m_ScriptEngine -> globalObject().setProperty("acquireReference",m_ScriptEngine -> newFunction(acquireReferenceFunc)); m_ScriptEngine -> globalObject().setProperty("acquireDark",m_ScriptEngine -> newFunction(acquireDarkFunc)); m_ScriptEngine -> globalObject().setProperty("acquireScope",m_ScriptEngine -> newFunction(acquireScopeFunc)); m_ScriptEngine -> globalObject().setProperty("acquireOnce",m_ScriptEngine -> newFunction(acquireOnceFunc)); m_ScriptEngine -> globalObject().setProperty("acquireCancel",m_ScriptEngine -> newFunction(acquireCancelFunc)); m_ScriptEngine -> globalObject().setProperty("status",m_ScriptEngine -> newFunction(statusFunc)); m_ScriptEngine -> globalObject().setProperty("newFile",m_ScriptEngine -> newFunction(newFileFunc)); m_ScriptEngine -> globalObject().setProperty("closeFile",m_ScriptEngine -> newFunction(closeFileFunc)); m_ScriptEngine -> globalObject().setProperty("newScan",m_ScriptEngine -> newFunction(newScanFunc)); m_ScriptEngine -> globalObject().setProperty("saveData",m_ScriptEngine -> newFunction(saveDataFunc)); // m_ScriptEngine -> globalObject().setProperty("readData",m_ScriptEngine -> newFunction(readDataFunc)); m_ScriptEngine -> globalObject().setProperty("channel",m_ScriptEngine -> newFunction(fitterFunc)); m_ScriptEngine -> globalObject().setProperty("print",m_ScriptEngine -> newFunction(printFunc)); m_ScriptEngine -> globalObject().setProperty("application",m_ScriptEngine -> newQObject(m_Application)); m_ScriptEngine -> globalObject().setProperty("acquisition",m_ScriptEngine -> newQObject(m_Acquisition)); m_ScriptEngine -> globalObject().setProperty("window",m_ScriptEngine -> newQObject(m_Window)); // printf("leave QavrgScriptingEngine::initialize\n"); }
QScriptValue QavrgScriptingEngine::newFileFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 157 of file qavrgscriptingengine.cpp.
References printMessage().
Referenced by initialize().
{ int nargs = context->argumentCount(); int nscan = 0; QString name; switch (nargs) { case 2: nscan = context->argument(1).toInteger(); case 1: name = context->argument(0).toString(); g_ScriptingEngine -> emit printMessage(tr("newFile(\"%1\".%2)").arg(name).arg(nscan)); QMetaObject::invokeMethod(g_Acquisition, "newSaveFile", Q_ARG(QString, name), Q_ARG(int, nscan)); break; default: return context -> throwError("newFile(QString,int=0) takes one or two arguments"); } return QScriptValue(engine, nargs); }
QScriptValue QavrgScriptingEngine::newScanFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 197 of file qavrgscriptingengine.cpp.
References printMessage(), and s_ScanNArgs.
Referenced by initialize().
{ QString cmd = "newScan("; QVector<QString> hdr; int nargs = context->argumentCount(); s_ScanNArgs = nargs; for (int i = 0; i<nargs; i++) { if (i != 0) { cmd += ", "; } cmd += "\""+context->argument(i).toString()+"\""; hdr.append(context->argument(i).toString()); } cmd += ")"; g_ScriptingEngine -> emit printMessage(cmd); bool ok = QMetaObject::invokeMethod(g_Acquisition, "startNewScan", Q_ARG(QcepStringVector, hdr)); if (!ok) { printf("Problem with QMetaObject::invokeMethod startNewScan\n"); } return QScriptValue(engine, nargs); }
QScriptValue QavrgScriptingEngine::printFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 139 of file qavrgscriptingengine.cpp.
References printMessage().
Referenced by initialize().
{ int nargs = context->argumentCount(); QString result; for (int i=0; i<nargs; i++) { if (i>0) { result += " "; } result += context->argument(i).toString(); } g_ScriptingEngine -> emit printMessage(result); return QScriptValue(engine, 0); }
void QavrgScriptingEngine::printMessage | ( | QString | msg | ) | [signal] |
QScriptValue QavrgScriptingEngine::saveDataFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 425 of file qavrgscriptingengine.cpp.
References printMessage(), and s_ScanNArgs.
Referenced by initialize().
{ int nargs = context->argumentCount(); if (nargs != s_ScanNArgs) { return context -> throwError(tr("saveData() called with %1 arguments, newScan() was called with %2") .arg(nargs).arg(s_ScanNArgs)); } QString cmd = "saveData("; QVector<double> vals; for (int i = 0; i<nargs; i++) { if (i != 0) { cmd += ", "; } cmd += tr("%1").arg(context->argument(i).toNumber()); vals.append(context->argument(i).toNumber()); } cmd += ")"; g_ScriptingEngine -> emit printMessage(cmd); bool ok = QMetaObject::invokeMethod(g_Acquisition, "saveAcquisitionResult", Q_ARG(QcepDoubleVector, vals)); if (!ok) { printf("Problem with QMetaObject::invokeMethod\n"); } return QScriptValue(engine, nargs); }
void QavrgScriptingEngine::serverResultAvailable | ( | QScriptValue | cmd | ) | [signal] |
Referenced by evaluate().
void QavrgScriptingEngine::specResultAvailable | ( | QScriptValue | cmd | ) | [signal] |
Referenced by evaluate().
QScriptValue QavrgScriptingEngine::statusFunc | ( | QScriptContext * | context, |
QScriptEngine * | engine | ||
) | [static, private] |
Definition at line 405 of file qavrgscriptingengine.cpp.
Referenced by initialize().
{ int status = 0; switch (context->argumentCount()) { case 1: status = g_Acquisition -> acquireWait(context->argument(0).toNumber()); break; case 0: status = g_Acquisition -> get_Status(); break; default: return context -> throwError("status() takes zero or one arguments"); } return QScriptValue(engine, status); }
int QavrgScriptingEngine::uncaughtExceptionLineNumber | ( | ) | const |
Definition at line 125 of file qavrgscriptingengine.cpp.
References m_Mutex, and m_ScriptEngine.
{ QMutexLocker lock(&m_Mutex); return m_ScriptEngine -> uncaughtExceptionLineNumber(); }
QString QavrgScriptingEngine::uncaughtExceptionString | ( | ) | const |
Definition at line 132 of file qavrgscriptingengine.cpp.
References m_Mutex, and m_ScriptEngine.
{ QMutexLocker lock(&m_Mutex); return m_ScriptEngine -> uncaughtException().toString(); }
Definition at line 61 of file qavrgscriptingengine.h.
Referenced by initialize().
Definition at line 59 of file qavrgscriptingengine.h.
Referenced by initialize().
QMutex QavrgScriptingEngine::m_Mutex [mutable, private] |
Definition at line 57 of file qavrgscriptingengine.h.
Referenced by evaluateAppCommand(), evaluateServerCommand(), evaluateSpecCommand(), hasUncaughtException(), uncaughtExceptionLineNumber(), and uncaughtExceptionString().
QScriptEngine* QavrgScriptingEngine::m_ScriptEngine [private] |
Definition at line 58 of file qavrgscriptingengine.h.
Referenced by cancelCommand(), evaluate(), hasUncaughtException(), initialize(), uncaughtExceptionLineNumber(), and uncaughtExceptionString().
QavrgWindow* QavrgScriptingEngine::m_Window [private] |
Definition at line 60 of file qavrgscriptingengine.h.
Referenced by initialize().