QXRD  0.11.16
qxrdscriptenginethread.cpp
Go to the documentation of this file.
1 #include "qxrddebug.h"
3 
4 #include "qxrdscriptengine.h"
5 #include "qxrdapplication.h"
6 #include "qcepmutexlocker.h"
7 
8 #include <stdio.h>
9 
11  : QxrdThread(NULL),
12  m_ScriptEngine(NULL),
13  m_Application(app),
14  m_Experiment(exp)
15 {
17  printf("QxrdScriptEngineThread::QxrdScriptEngineThread(%p)\n", this);
18  }
19 
20  setObjectName("script");
21 }
22 
24 {
25  shutdown();
26 
28  printf("QxrdScriptEngineThread::~QxrdScriptEngineThread(%p)\n", this);
29  }
30 }
31 
33 {
34  exit();
35 
36  wait(1000);
37 }
38 
40 {
41  while (isRunning()) {
42  {
43  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
44 
45  if (m_ScriptEngine) return m_ScriptEngine;
46  }
47 
48  QThread::msleep(50);
49  }
50 
51  return QxrdScriptEnginePtr();
52 }
53 
55 {
56  if (qcepDebug(DEBUG_THREADS)) {
57  printf("Script Engine Thread Started\n");
58  }
59 
61 
62  int rc = -1;
63 
64  if (p) {
65  p -> initialize();
66 
67  m_Mutex.lock();
68  m_ScriptEngine = p;
69  m_Mutex.unlock();
70 
71  rc = exec();
72  }
73 
74  {
75  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
76 
78  }
79 
80  if (qcepDebug(DEBUG_THREADS)) {
81  printf("Script Engine Thread Terminated with rc %d\n", rc);
82  }
83 }
QxrdApplicationWPtr m_Application
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
QxrdScriptEnginePtr scriptEngine() const
QSharedPointer< QxrdScriptEngine > QxrdScriptEnginePtr
QWeakPointer< QxrdApplication > QxrdApplicationWPtr
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
QxrdScriptEnginePtr m_ScriptEngine
QxrdScriptEngineThread(QxrdApplicationWPtr app, QxrdExperimentWPtr exp)
QMutex m_Mutex
Definition: qcepthread.h:17
QxrdExperimentWPtr m_Experiment