QXRD  0.11.16
qxrdexperimentthread.cpp
Go to the documentation of this file.
1 #include "qxrddebug.h"
2 #include "qxrdexperimentthread.h"
3 #include "qxrdapplication.h"
4 #include "qxrdexperiment.h"
5 //#include "qxrdexperimentperkinelmeranalysis.h"
6 //#include "qxrdexperimentpilatusacquisition.h"
7 //#include "qxrdexperimentpilatusanalysis.h"
8 //#include "qxrdexperimentsimulatedacquisition.h"
9 //#include "qxrdexperimentgenericanalysis.h"
10 #include "qcepmutexlocker.h"
11 
12 #include <stdio.h>
13 
14 QxrdExperimentThread::QxrdExperimentThread(QString path, QxrdApplicationWPtr app, QSettings *settings) :
15  QxrdThread(),
16  m_ExperimentPath(path),
17  m_Application(app),
18  m_Settings(settings)
19 {
21  printf("QxrdExperimentThread::QxrdExperimentThread(%p)\n", this);
22  }
23 
24  setObjectName("experiment");
25 }
26 
28 {
29  if (qcepDebug(DEBUG_APP)) {
31 
32  if (app) {
33  app->printMessage("QxrdExperimentThread::~QxrdExperimentThread");
34  }
35  }
36 
38  printf("QxrdExperimentThread::~QxrdExperimentThread(%p)\n", this);
39  }
40 
41  ::fflush(stdout);
42 
43  shutdown();
44 }
45 
47 {
48  m_ExperimentThread = expThread;
49 }
50 
52 {
54 
55  res->start();
56 
57  return res;
58 }
59 
61 {
62  while (isRunning()) {
63  {
64  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
65 
66  if (m_Experiment) return m_Experiment;
67  }
68 
69  msleep(100);
70  }
71 
72  return QxrdExperimentPtr();
73 }
74 
76 {
77  if (qcepDebug(DEBUG_THREADS)) {
78  printf("Experiment Thread Started\n");
79  }
80 
81  {
83 
84  doc = QxrdExperimentPtr(
85  new QxrdExperiment(sharedFromThis(), m_ExperimentPath, m_Application));
86 
87  if (doc) {
88  doc -> initialize(m_Settings);
89 
90  m_Mutex.lock();
91  m_Experiment = doc;
92  m_Mutex.unlock();
93  }
94  }
95 
96  int rc = -1;
97 
98  rc = exec();
99 
100  {
101  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
102 
104  }
105 
106  if (qcepDebug(DEBUG_THREADS)) {
107  printf("Experiment Thread Terminated with rc %d\n", rc);
108  }
109 }
110 
112 {
113 // INVOKE_CHECK(QMetaObject::invokeMethod(m_Experiment, "shutdown", Qt::QueuedConnection));
114  exit();
115 
116  wait();
117 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
static QxrdExperimentThreadPtr newExperiment(QString path, QxrdApplicationWPtr app, QSettings *settings)
QxrdApplicationWPtr m_Application
QxrdExperimentThread(QString path, QxrdApplicationWPtr app, QSettings *settings)
QWeakPointer< QxrdApplication > QxrdApplicationWPtr
static void msleep(long unsigned int)
Definition: qcepthread.cpp:10
QSharedPointer< QxrdExperimentThread > QxrdExperimentThreadPtr
QxrdExperimentPtr experiment()
QWeakPointer< QxrdExperimentThread > QxrdExperimentThreadWPtr
QMutex m_Mutex
Definition: qcepthread.h:17
QxrdExperimentPtr m_Experiment
QxrdExperimentThreadWPtr m_ExperimentThread
QSharedPointer< QxrdApplication > QxrdApplicationPtr
void init(QxrdExperimentThreadWPtr expThread)