vtkPVSession.cxx 3.91 KB
Newer Older
1 2 3
/*=========================================================================

  Program:   ParaView
Sebastien Jourdain's avatar
Sebastien Jourdain committed
4
  Module:    vtkPVSession.cxx
5 6 7 8 9 10 11 12 13 14 15 16 17

  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkPVSession.h"

#include "vtkObjectFactory.h"
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
18
#include "vtkPVProgressHandler.h"
19
#include "vtkPVServerInformation.h"
20 21 22 23

//----------------------------------------------------------------------------
vtkPVSession::vtkPVSession()
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
24 25 26
  this->ProgressHandler = vtkPVProgressHandler::New();
  this->ProgressHandler->SetSession(this); // not reference counted.
  this->ProgressCount = 0;
27
  this->InCleanupPendingProgress = false;
28 29 30 31 32
}

//----------------------------------------------------------------------------
vtkPVSession::~vtkPVSession()
{
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
33 34 35
  this->ProgressHandler->SetSession(NULL);
  this->ProgressHandler->Delete();
  this->ProgressHandler = NULL;
36 37 38 39 40 41 42 43 44 45 46 47 48 49
}

//----------------------------------------------------------------------------
vtkPVSession::ServerFlags vtkPVSession::GetProcessRoles()
{
  return CLIENT_AND_SERVERS;
}

//----------------------------------------------------------------------------
vtkMultiProcessController* vtkPVSession::GetController(vtkPVSession::ServerFlags)
{
  return NULL;
}

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
50
//----------------------------------------------------------------------------
51 52 53 54 55
bool vtkPVSession::GetPendingProgress()
{
  return (this->InCleanupPendingProgress || this->ProgressCount > 0);
}

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
56 57 58
//----------------------------------------------------------------------------
void vtkPVSession::PrepareProgress()
{
59
  if (this->InCleanupPendingProgress)
Kitware Robot's avatar
Kitware Robot committed
60
  {
61
    return;
Kitware Robot's avatar
Kitware Robot committed
62
  }
63

64
  if (this->ProgressCount++ == 0)
Kitware Robot's avatar
Kitware Robot committed
65
  {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
66
    this->PrepareProgressInternal();
Kitware Robot's avatar
Kitware Robot committed
67
  }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
68 69 70 71 72
}

//----------------------------------------------------------------------------
void vtkPVSession::CleanupPendingProgress()
{
73
  if (this->InCleanupPendingProgress)
Kitware Robot's avatar
Kitware Robot committed
74
  {
75
    return;
Kitware Robot's avatar
Kitware Robot committed
76
  }
77 78

  this->InCleanupPendingProgress = true;
79
  if (--this->ProgressCount == 0)
Kitware Robot's avatar
Kitware Robot committed
80
  {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
81
    this->CleanupPendingProgressInternal();
Kitware Robot's avatar
Kitware Robot committed
82
  }
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
83
  if (this->ProgressCount < 0)
Kitware Robot's avatar
Kitware Robot committed
84
  {
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
85 86
    vtkErrorMacro("PrepareProgress and CleanupPendingProgress mismatch!");
    this->ProgressCount = 0;
Kitware Robot's avatar
Kitware Robot committed
87
  }
88
  this->InCleanupPendingProgress = false;
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102
}

//----------------------------------------------------------------------------
void vtkPVSession::PrepareProgressInternal()
{
  this->ProgressHandler->PrepareProgress();
}

//----------------------------------------------------------------------------
void vtkPVSession::CleanupPendingProgressInternal()
{
  this->ProgressHandler->CleanupPendingProgress();
}

103
//-----------------------------------------------------------------------------
104
bool vtkPVSession::OnWrongTagEvent(vtkObject*, unsigned long, void* calldata)
105 106 107 108 109 110 111 112
{
  int tag = -1;
  int len = -1;
  const char* data = reinterpret_cast<const char*>(calldata);
  const char* ptr = data;
  memcpy(&tag, ptr, sizeof(tag));

  if (tag == vtkPVSession::EXCEPTION_EVENT_TAG)
Kitware Robot's avatar
Kitware Robot committed
113
  {
114 115 116 117 118
    ptr += sizeof(tag);
    memcpy(&len, ptr, sizeof(len));
    ptr += sizeof(len);
    vtkErrorMacro("Encountered Exception: " << ptr);
    // this->OnSocketError();
Kitware Robot's avatar
Kitware Robot committed
119
  }
120
  else
Kitware Robot's avatar
Kitware Robot committed
121
  {
122
    vtkErrorMacro("Internal ParaView Error: "
Kitware Robot's avatar
Kitware Robot committed
123
                  "Socket Communicator received wrong tag: "
124 125 126
      << tag);
    // Treat as a socket error.
    // this->OnSocketError();
Kitware Robot's avatar
Kitware Robot committed
127
  }
128
  return false;
129 130
}

131 132 133 134 135
//----------------------------------------------------------------------------
void vtkPVSession::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}
136 137 138
//----------------------------------------------------------------------------
bool vtkPVSession::IsMultiClients()
{
Sebastien Jourdain's avatar
Sebastien Jourdain committed
139
  return (this->GetServerInformation()->GetMultiClientsEnable() != 0);
140
}