NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxErrorObserver.h
Go to the documentation of this file.
1 #ifndef CXERROROBSERVER_H
2 #define CXERROROBSERVER_H
3 
4 #include "cxResourceExport.h"
5 
6 #include "boost/shared_ptr.hpp"
7 #include <vtkCommand.h>
8 #include <vtkSmartPointer.h>
9 #include <vtkAlgorithm.h>
10 #include <QString>
11 #include "cxLogger.h"
12 #include <QMutex>
13 
14 namespace cx {
15 
28 class cxResource_EXPORT StaticMutexVtkLocker
29 {
30 public:
33 private:
34  static boost::shared_ptr<QMutex> mMutex;
35 };
36 
37 
38 //---------------------------------------------------------
44 class cxResource_EXPORT ErrorObserver: public vtkCommand
45 {
46 public:
48  {
49  }
50  static ErrorObserver* New()
51  {
52  return new ErrorObserver;
53  }
54  virtual void Execute(vtkObject* caller, unsigned long, void* text)
55  {
56  mMessage = QString(reinterpret_cast<char*> (text));
57  }
58  QString mMessage;
59 
60  static bool checkedRead(vtkSmartPointer<vtkAlgorithm> reader, QString filename)
61  {
62  vtkSmartPointer<ErrorObserver> errorObserver = vtkSmartPointer<ErrorObserver>::New();
63  reader->AddObserver("ErrorEvent", errorObserver);
64 
65  {
67  reader->Update();
68  }
69 // ErrorObserver::threadSafeUpdate(reader);
70 
71  if (!errorObserver->mMessage.isEmpty())
72  {
73  reportError("Load of data [" + filename + "] failed with message:\n"
74  + errorObserver->mMessage);
75  return false;
76  }
77  return true;
78  }
79 };
80 
81 }
82 
83 #endif // CXERROROBSERVER_H
cx::ErrorObserver::ErrorObserver
ErrorObserver()
Definition: cxErrorObserver.h:47
cxLogger.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::ErrorObserver
Definition: cxErrorObserver.h:44
cx::ErrorObserver::New
static ErrorObserver * New()
Definition: cxErrorObserver.h:50
cx::ErrorObserver::mMessage
QString mMessage
Definition: cxErrorObserver.h:58
cx::ErrorObserver::Execute
virtual void Execute(vtkObject *caller, unsigned long, void *text)
Definition: cxErrorObserver.h:54
cx::StaticMutexVtkLocker
Definition: cxErrorObserver.h:28
cx::ErrorObserver::checkedRead
static bool checkedRead(vtkSmartPointer< vtkAlgorithm > reader, QString filename)
Definition: cxErrorObserver.h:60
cx::reportError
void reportError(QString msg)
Definition: cxLogger.cpp:71