Torc  0.1
torcqthread.cpp
Go to the documentation of this file.
1 /* Class TorcQThread
2 *
3 * Copyright (C) Mark Kendall 2013-18
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 // Torc
21 #include "torclocalcontext.h"
22 #include "torcloggingimp.cpp"
23 #include "torcqthread.h"
24 
43 static QThread *gMainThread = nullptr;
44 
46 {
47  gMainThread = QThread::currentThread();
48  InitRand();
49  QThread::currentThread()->setObjectName(QStringLiteral("MainLoop"));
50 }
51 
53 {
54  if (gMainThread)
55  return QThread::currentThread() == gMainThread;
56  return QThread::currentThread()->objectName() == TORC_MAIN_THREAD;
57 }
58 
60 {
61  qsrand(QDateTime::currentDateTimeUtc().toTime_t() ^ QTime::currentTime().msec());
62 }
63 
64 TorcQThread::TorcQThread(const QString &Name)
65  : QThread()
66 {
67  // this ensures database access is allowed if needed
68  setObjectName(Name);
69 }
70 
71 void TorcQThread::run(void)
72 {
73  Initialise();
74  QThread::run();
75  Deinitialise();
76 }
77 
80 {
82  InitRand();
83 
84  Start();
85 
86  emit Started();
87 }
88 
91 {
92  Finish();
93 
94  emit Finished();
95 
96  // ensure database connections are released
99 }
static bool IsMainThread(void)
Definition: torcqthread.cpp:52
void Initialise(void)
Performs Torc specific thread initialisation.
Definition: torcqthread.cpp:79
TorcLocalContext * gLocalContext
virtual void run(void)
Definition: torcqthread.cpp:71
virtual void Finish(void)=0
static QThread * gMainThread
Definition: torcqthread.cpp:43
TorcQThread(const QString &Name)
Definition: torcqthread.cpp:64
void Finished(void)
static void SetMainThread(void)
Definition: torcqthread.cpp:45
void CloseDatabaseConnections(void)
void RegisterLoggingThread(void)
void Deinitialise(void)
Performs Torc specific thread cleanup.
Definition: torcqthread.cpp:90
static void InitRand(void)
Definition: torcqthread.cpp:59
#define TORC_MAIN_THREAD
Definition: torclocaldefs.h:10
virtual void Start(void)=0
void Started(void)
void DeregisterLoggingThread(void)