ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
vtkCommunicationErrorCatcher.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkCommunicationErrorCatcher.cxx
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
16 
17 #include "vtkCommand.h"
18 #include "vtkCommunicator.h"
19 #include "vtkMultiProcessController.h"
20 #include "vtkObjectFactory.h"
21 
22 //----------------------------------------------------------------------------
23 vtkCommunicationErrorCatcher::vtkCommunicationErrorCatcher(vtkMultiProcessController* controller)
24 {
25  this->Controller = controller;
26  if (controller)
27  {
28  this->Communicator = controller->GetCommunicator();
29  }
30  this->Initialize();
31 }
32 
33 //----------------------------------------------------------------------------
35 {
36  this->Communicator = communicator;
37  this->Initialize();
38 }
39 
40 //----------------------------------------------------------------------------
42 {
43  if (this->Communicator && this->CommunicatorObserverId)
44  {
45  this->Communicator->RemoveObserver(this->CommunicatorObserverId);
46  }
47  if (this->Controller && this->ControllerObserverId)
48  {
49  this->Controller->RemoveObserver(this->ControllerObserverId);
50  }
51 }
52 
53 //----------------------------------------------------------------------------
54 void vtkCommunicationErrorCatcher::Initialize()
55 {
56  this->ErrorsRaised = false;
57  this->ControllerObserverId = 0;
58  this->CommunicatorObserverId = 0;
59 
60  if (this->Controller)
61  {
62  this->ControllerObserverId = this->Controller->AddObserver(
63  vtkCommand::ErrorEvent, this, &vtkCommunicationErrorCatcher::OnErrorEvent);
64  }
65  if (this->Communicator)
66  {
67  this->CommunicatorObserverId = this->Communicator->AddObserver(
68  vtkCommand::ErrorEvent, this, &vtkCommunicationErrorCatcher::OnErrorEvent);
69  }
70 }
71 
72 //----------------------------------------------------------------------------
73 void vtkCommunicationErrorCatcher::OnErrorEvent(
74  vtkObject* caller, unsigned long eventid, void* calldata)
75 {
76  if (caller && calldata && eventid == vtkCommand::ErrorEvent)
77  {
78  const char* error_message = reinterpret_cast<const char*>(calldata);
79  if (error_message && error_message[0])
80  {
81  this->ErrorMessages += error_message;
82  }
83  this->ErrorsRaised = true;
84  }
85 }
vtkCommunicationErrorCatcher(vtkMultiProcessController *)