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
|
/*=========================================================================
Program: ParaView
Module: vtkSMMultiServerSourceProxy.cxx
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 "vtkSMMultiServerSourceProxy.h"
#include "vtkObjectFactory.h"
#include "vtkPVMultiServerDataSource.h"
#include "vtkProcessModule.h"
#include "vtkSMMessage.h"
#include "vtkSMProxy.h"
#include "vtkSMProxyLocator.h"
#include "vtkSMSession.h"
#include "vtkSMSourceProxy.h"
#include <assert.h>
//---------------------------------------------------------------------------
vtkStandardNewMacro(vtkSMMultiServerSourceProxy);
//---------------------------------------------------------------------------
vtkSMMultiServerSourceProxy::vtkSMMultiServerSourceProxy()
{
this->RemoteProxySessionID = this->RemoteProxyID = 0;
}
//---------------------------------------------------------------------------
vtkSMMultiServerSourceProxy::~vtkSMMultiServerSourceProxy()
{
}
//---------------------------------------------------------------------------
void vtkSMMultiServerSourceProxy::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//---------------------------------------------------------------------------
void vtkSMMultiServerSourceProxy::MarkDirty(vtkSMProxy* modifiedProxy)
{
// Notify the VTK object as well
vtkPVMultiServerDataSource* clientObj =
vtkPVMultiServerDataSource::SafeDownCast(this->GetClientSideObject());
clientObj->Modified();
// Propagate the dirty flag as regular proxy
this->Superclass::MarkDirty(modifiedProxy);
}
//---------------------------------------------------------------------------
void vtkSMMultiServerSourceProxy::SetExternalProxy(vtkSMSourceProxy* proxyFromAnotherServer, int port)
{
vtkPVMultiServerDataSource* clientObj =
vtkPVMultiServerDataSource::SafeDownCast(this->GetClientSideObject());
clientObj->SetExternalProxy(proxyFromAnotherServer, port);
// Remove previous proxy dependency
vtkSMSourceProxy* previousRemoteProxy = this->GetExternalProxy();
if(previousRemoteProxy != NULL)
{
previousRemoteProxy->RemoveConsumer(this->GetProperty("DependencyLink"), this);
}
// Store data informations
vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
this->RemoteProxySessionID = pm->GetSessionID(proxyFromAnotherServer->GetSession());
this->RemoteProxyID = proxyFromAnotherServer->GetGlobalID();
this->PortToExport = port;
// Create dependency
proxyFromAnotherServer->AddConsumer(this->GetProperty("DependencyLink"), this);
// Push our new state to the session
this->UpdateState();
// Mark dirty
this->MarkDirty(proxyFromAnotherServer);
}
//---------------------------------------------------------------------------
vtkSMSourceProxy* vtkSMMultiServerSourceProxy::GetExternalProxy()
{
vtkSMSourceProxy* bindedProxy = NULL;
vtkSMSession* remoteSession =
vtkSMSession::SafeDownCast(
vtkProcessModule::GetProcessModule()->GetSession(
this->RemoteProxySessionID));
if(remoteSession)
{
bindedProxy =
vtkSMSourceProxy::SafeDownCast(
remoteSession->GetProxyLocator()->LocateProxy(this->RemoteProxyID));
}
return bindedProxy;
}
//---------------------------------------------------------------------------
void vtkSMMultiServerSourceProxy::UpdateState()
{
// ensure that the state is created correctly.
this->CreateVTKObjects();
// Make sure we update our local state with our internal data
// push current state.
this->State->ClearExtension(ProxyState::user_data);
ProxyState_UserData* user_data =
this->State->AddExtension(ProxyState::user_data);
user_data->set_key("RemoteProxyInfo");
Variant* variant = user_data->add_variant();
variant->set_type(Variant::IDTYPE); // type is just arbitrary here.
variant->add_idtype(this->RemoteProxySessionID);
variant->add_idtype(this->RemoteProxyID);
variant->add_integer(this->PortToExport);
// Debug
//this->State->PrintDebugString();
this->PushState(this->State);
}
//---------------------------------------------------------------------------
void vtkSMMultiServerSourceProxy::LoadState( const vtkSMMessage* message, vtkSMProxyLocator* locator)
{
this->Superclass::LoadState(message, locator);
// Extract
if (message->ExtensionSize(ProxyState::user_data) != 1)
{
return;
}
const ProxyState_UserData& user_data =
message->GetExtension(ProxyState::user_data, 0);
if (user_data.key() != "RemoteProxyInfo")
{
//vtkWarningMacro("Unexpected user_data. Expecting RemoteProxyInfo.");
return;
}
const Variant& data = user_data.variant(0);
this->RemoteProxySessionID = data.idtype(0);
this->RemoteProxyID = data.idtype(0);
this->PortToExport = data.integer(0);
// Update associated VTK object
this->SetExternalProxy(this->GetExternalProxy(), this->PortToExport);
}
|