1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/*=========================================================================
Program: ParaView
Module: vtkSMRemoteObject.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm 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 "vtkSMRemoteObject.h"
#include "vtkObjectFactory.h"
#include "vtkProcessModule.h"
#include "vtkSMMessage.h"
#include "vtkSMSession.h"
#include <vtksys/SystemTools.hxx>
#include <sstream>
//----------------------------------------------------------------------------
vtkSMRemoteObject::vtkSMRemoteObject()
{
this->GlobalID = 0;
this->GlobalIDString = NULL;
this->Location = 0;
this->Session = NULL;
this->Prototype = false;
this->ClientOnlyLocationFlag = false;
}
//----------------------------------------------------------------------------
vtkSMRemoteObject::~vtkSMRemoteObject()
{
if(this->Session && this->GlobalID != 0)
{
this->Session->UnRegisterRemoteObject(this->GlobalID, this->Location);
}
this->SetSession(0);
delete [] this->GlobalIDString;
this->GlobalIDString = NULL;
}
//----------------------------------------------------------------------------
void vtkSMRemoteObject::SetSession(vtkSMSession* session)
{
this->Superclass::SetSession(session);
// Register object if possible
if(this->Session && this->GlobalID != 0)
{
this->Session->RegisterRemoteObject(this->GlobalID, this->Location, this);
}
}
//----------------------------------------------------------------------------
void vtkSMRemoteObject::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "GlobalID: " << this->GlobalID << endl;
}
//---------------------------------------------------------------------------
bool vtkSMRemoteObject::HasGlobalID()
{
return this->GlobalID != 0;
}
//---------------------------------------------------------------------------
vtkTypeUInt32 vtkSMRemoteObject::GetGlobalID()
{
if (this->Session != NULL && this->GlobalID == 0)
{
this->SetGlobalID(this->GetSession()->GetNextGlobalUniqueIdentifier());
}
return this->GlobalID;
}
//---------------------------------------------------------------------------
const char* vtkSMRemoteObject::GetGlobalIDAsString()
{
if (!this->GlobalIDString)
{
std::ostringstream cname;
cname << this->GetGlobalID();
delete [] this->GlobalIDString;
this->GlobalIDString = vtksys::SystemTools::DuplicateString(
cname.str().c_str());
}
return this->GlobalIDString;
}
//---------------------------------------------------------------------------
void vtkSMRemoteObject::SetGlobalID(vtkTypeUInt32 guid)
{
if(this->GlobalID == guid)
{
return;
}
if(this->GlobalID != 0)
{
vtkErrorMacro("GlobalID must NOT be changed once it has been assigned.\n"
"Try to set " << guid << " to replace the current "
<< this->GlobalID << " value.");
abort();
}
// Keep new ID
this->GlobalID = guid;
// Register object if possible
if(this->Session && this->GlobalID != 0)
{
this->Session->RegisterRemoteObject(this->GlobalID, this->Location, this);
}
}
//---------------------------------------------------------------------------
void vtkSMRemoteObject::PushState(vtkSMMessage* msg)
{
vtkTypeUInt32 filteredLocation = this->GetFilteredLocation();
if(filteredLocation == 0)
{
return; // This object is a prototype and has no location
}
// Check if a GUID has been assigned to that object otherwise assign a new one
vtkTypeUInt32 gid = this->GetGlobalID();
msg->set_global_id(gid);
msg->set_location(filteredLocation);
if (this->GetSession())
{
this->GetSession()->PushState(msg);
}
else
{
// no session, nothing to do.
}
}
//---------------------------------------------------------------------------
bool vtkSMRemoteObject::PullState(vtkSMMessage* msg)
{
if(this->Location == 0)
{
return true; // This object is a prototype and has no location
}
msg->set_global_id(this->GlobalID);
msg->set_location(this->Location);
if(this->GetSession())
{
this->GetSession()->PullState(msg);
}
else
{
vtkErrorMacro("Attempting to PullState() on a " << this->GetClassName()
<< " after the session has been destroyed.");
return false;
}
return true; // Successful call
}
//---------------------------------------------------------------------------
void vtkSMRemoteObject::EnableLocalPushOnly()
{
this->ClientOnlyLocationFlag = true;
}
//---------------------------------------------------------------------------
void vtkSMRemoteObject::DisableLocalPushOnly()
{
this->ClientOnlyLocationFlag = false;
}
//---------------------------------------------------------------------------
vtkTypeUInt32 vtkSMRemoteObject::GetFilteredLocation()
{
if(this->ClientOnlyLocationFlag)
{
return (this->Location & vtkPVSession::CLIENT);
}
else
{
return this->Location;
}
}
//---------------------------------------------------------------------------
vtkClientServerStream& operator<< (vtkClientServerStream& stream,
const SIOBJECT& manipulator)
{
vtkClientServerStream substream;
substream << vtkClientServerStream::Invoke
<< vtkClientServerID(1) // ID for the vtkSMSessionCore helper.
<< "GetSIObject"
<< manipulator.Reference->GetGlobalID()
<< vtkClientServerStream::End;
stream << substream;
return stream;
}
|