Fraxinus  17.12-rc3
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
void reportError(QString msg)
Definition: cxLogger.cpp:92
static ErrorObserver * New()
virtual void Execute(vtkObject *caller, unsigned long, void *text)
static bool checkedRead(vtkSmartPointer< vtkAlgorithm > reader, QString filename)
Namespace for all CustusX production code.