WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZblThreadErr.cpp
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2013, 2014 Bob Dinitto
4  *
5  * ZblThreadErr.cpp
6  *
7  * Created on: 04-Feb-2013
8  * Author: Bob Dinitto bob@ninzo.com
9  *
10  * Zuble is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24 */
25 
26 #include "ZblThreadErr.h"
27 #include "ZblException.h"
28 //#include "zglobal.h"
29 #include "ZblLogCategory.h"
30 
31 //ZBL_DEFINE_LOGGED_OBJECT(Zbl::ZblThreadErr)
32 namespace Zbl
33 {
34 ZblLogCategory ZblThreadErr::m_log("Zbl::ZblThreadErr");
35 
36 QThreadStorage<ZblThreadErr*> ZblThreadErr::m_zThreads;
37 
39 {
40  if(m_zThreads.hasLocalData())
41  return;
42 
43  m_zThreads.setLocalData(new ZblThreadErr());
44 }
45 
47 {
48  zInit();
49 
50  return *m_zThreads.localData();
51 }
52 
53 
54 ZblThreadErr::ZblThreadErr(QObject *parent) :
55  QObject(parent), m_aborting(false)
56 {
57  //ZBL_REGISTER_LOGGED_OBJECT
59  // WARNING: don't generate log messages here - Zuble logger uninitialized
60 }
61 
63 {
64  qCCritical(m_log) << "THREAD ERROR: "
65  << m_error.facility()<< ":"
66  << m_error.code() << ":" << m_error.message();
67 }
68 
70 {
71  return m_error;
72 }
73 
75  const QString& facility,
76  const QString& code,
77  const QString& message
78  )
79 {
80  m_error.set(facility, code, message);
81  logError();
82  emit notifyError(m_error);
83 }
84 
86  const char* facility,
87  const char* code,
88  const char* message
89 )
90 {
91  m_error.set(facility, code, message);
92  logError();
93  emit notifyError(m_error);
94 }
95 
96 void ZblThreadErr::raiseError(const QString& message)
97 {
99  logError();
100  emit notifyError(m_error);
101 }
102 
103 void ZblThreadErr::raiseError(const char* message)
104 {
106  logError();
107  emit notifyError(m_error);
108 }
109 
110 
112 {
113  if(m_error.isError())
114  {
115  m_error.clear();
116 
117  emit notifyClearError();
118  }
119 }
120 
122 {
123  return m_error.isError();
124 }
125 
127 {
128  QString msg = QString("%1:%2:%3");
129  return msg.arg(m_error.m_facility).arg( m_error.m_code).arg(m_error.m_message);
130 }
131 
132 
134 {
135  m_aborting = true;
136 
137  emit notifyAbort();
138 }
139 
141 {
142  return m_aborting;
143 }
144 
145 
146 
147 } // Zbl
const ZblError & error() const
Returns a reference to the ZblError instance for the current thread.
void notifyError(const ZblError &error)
Sent when an error condition has been set.
static const QString m_defaultFacility
Definition: ZblError.h:77
void abort()
Sets the current thread&#39;s error status to abort and issues the notifyAbort signal.
A class to manage Zuble&#39;s thread-specific state. This includes error propagation and thread abort han...
Definition: ZblThreadErr.h:87
const QString & code() const
Definition: ZblError.cpp:94
void notifyClearError()
Sent when an error condition has been cleared.
const QString & facility() const
Definition: ZblError.cpp:89
void set(const QString &facility, const QString &code, const QString &message)
Definition: ZblError.cpp:50
void notifyAbort()
Sent when an abort is requested.
Definition: ZAndGate.cpp:6
bool m_aborting
Aborting flag fo this thread.
Definition: ZblThreadErr.h:238
QString m_code
Definition: ZblError.h:74
ZblThreadErr(QObject *parent=0)
Don&#39;t construct this. Call static zInstance() method or use the zThreadErr macro definition instead...
static void zInit()
This method must be called once at the start of each thread that throws or catches ZblException objec...
Data object for thread local error status information.
Definition: ZblError.h:41
QString getErrorMessage()
Obtain a formatted error message.
static QThreadStorage< ZblThreadErr * > m_zThreads
A set of ZblThreadErr object pointers in thread local storage.
Definition: ZblThreadErr.h:226
ZblError m_error
The error object for this thread.
Definition: ZblThreadErr.h:232
const QString & message() const
Definition: ZblError.cpp:99
bool isError() const
Definition: ZblError.cpp:112
bool isError()
Test if an error condition exists.
bool isAborting()
Test if an abort condition exists.
QString m_message
Definition: ZblError.h:75
static ZblThreadErr & zInstance()
Returns a reference to the ZblThreadErr instance for the current thread.
void clearError()
Sets the current thread&#39;s error status to normal and issues the notifyClearError signal.
static ZblLogCategory m_log
Definition: ZblThreadErr.h:211
void raiseError(const QString &facility, const QString &code, const QString &message)
Sets the current thread&#39;s error information and issues the notifyError signal.
void clear()
Definition: ZblError.cpp:80
QString m_facility
Definition: ZblError.h:73