File: vtkPVSessionBase.cxx

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (382 lines) | stat: -rw-r--r-- 12,616 bytes parent folder | download | duplicates (2)
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*=========================================================================

  Program:   ParaView
  Module:    vtkPVSessionBase.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 "vtkPVSessionBase.h"

#include "vtkCommand.h"
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkPVServerInformation.h"
#include "vtkPVMultiClientsInformation.h"
#include "vtkProcessModule.h"
#include "vtkSMMessage.h"
#include "vtkPVSessionCore.h"
#include "vtkWeakPointer.h"

#include <sstream>
#include <assert.h>

//----------------------------------------------------------------------------
vtkPVSessionBase::vtkPVSessionBase()
{
  this->InitSessionBase(vtkPVSessionCore::New());
  this->SessionCore->UnRegister(NULL);
}
//----------------------------------------------------------------------------
vtkPVSessionBase::vtkPVSessionBase(vtkPVSessionCore* coreToUse )
{
  this->InitSessionBase(coreToUse);
}
//----------------------------------------------------------------------------
void vtkPVSessionBase::InitSessionBase(vtkPVSessionCore* coreToUse)
{
  this->ProcessingRemoteNotification = false;
  this->SessionCore = coreToUse;
  if(this->SessionCore)
    {
    this->SessionCore->Register(NULL);
    }

  // initialize local process information.
  this->LocalServerInformation = vtkPVServerInformation::New();
  this->LocalServerInformation->CopyFromObject(NULL);

  // This ensure that whenever a message is received on  the parallel
  // controller, this session is marked active. This is essential for
  // satellites when running in parallel.
  vtkMultiProcessController* controller = vtkMultiProcessController::GetGlobalController();
  this->ActivateObserverTag = this->DesactivateObserverTag = 0;

  if(!controller)
    {
    vtkWarningMacro("No vtkMultiProcessController for Session. The session won't work correctly.");
    return;
    }

  this->ActivateObserverTag = controller->AddObserver(vtkCommand::StartEvent,
    this, &vtkPVSessionBase::Activate);
  this->DesactivateObserverTag = controller->AddObserver(vtkCommand::EndEvent,
    this, &vtkPVSessionBase::DeActivate);
}

//----------------------------------------------------------------------------
vtkPVSessionBase::~vtkPVSessionBase()
{
  // Make sure we disable Activate/Desactivate observer
  vtkMultiProcessController* controller = vtkMultiProcessController::GetGlobalController();
  if(controller && this->ActivateObserverTag && this->DesactivateObserverTag)
    {
    controller->RemoveObserver(this->ActivateObserverTag);
    controller->RemoveObserver(this->DesactivateObserverTag);
    }

  if (this->SessionCore)
    {
    this->SessionCore->Delete();
    this->SessionCore = NULL;
    }

  this->LocalServerInformation->Delete();
  this->LocalServerInformation = NULL;
}

//----------------------------------------------------------------------------
vtkSIProxyDefinitionManager* vtkPVSessionBase::GetProxyDefinitionManager()
{
  return this->SessionCore->GetProxyDefinitionManager();
}

//----------------------------------------------------------------------------
vtkPVSessionBase::ServerFlags vtkPVSessionBase::GetProcessRoles()
{
  vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
  assert(pm != NULL);

  int process_id = pm->GetPartitionId();
  switch (pm->GetProcessType())
    {
  case vtkProcessModule::PROCESS_SERVER:
    return vtkPVSession::SERVERS;

  case vtkProcessModule::PROCESS_DATA_SERVER:
    return vtkPVSession::DATA_SERVER;

  case vtkProcessModule::PROCESS_RENDER_SERVER:
    return vtkPVSession::RENDER_SERVER;

  case vtkProcessModule::PROCESS_BATCH:
    return (process_id == 0)?
      vtkPVSession::CLIENT_AND_SERVERS :
      vtkPVSession::SERVERS;

  default:
    break;
    }
  return this->Superclass::GetProcessRoles();
}

//----------------------------------------------------------------------------
vtkPVServerInformation* vtkPVSessionBase::GetServerInformation()
{
  return this->LocalServerInformation;
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::PushState(vtkSMMessage* msg)
{
  this->Activate();

  // This class does not handle remote sessions, so all messages are directly
  // processes locally.
  this->SessionCore->PushState(msg);

  this->DeActivate();
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::PullState(vtkSMMessage* msg)
{
  this->Activate();

  // This class does not handle remote sessions, so all messages are directly
  // processes locally.
  this->SessionCore->PullState(msg);

  this->DeActivate();
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::ExecuteStream(
  vtkTypeUInt32 location, const vtkClientServerStream& stream,
  bool ignore_errors/*=false*/)
{
  this->Activate();

  // This class does not handle remote sessions, so all messages are directly
  // processes locally.
  this->SessionCore->ExecuteStream(location, stream, ignore_errors);

  this->DeActivate();
}

//----------------------------------------------------------------------------
const vtkClientServerStream& vtkPVSessionBase::GetLastResult(
  vtkTypeUInt32 vtkNotUsed(location))
{
  // This class does not handle remote sessions, so all messages are directly
  // processes locally.
  return this->SessionCore->GetLastResult();
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::UnRegisterSIObject(vtkSMMessage* msg)
{
  this->Activate();

  // This class does not handle remote sessions, so all messages are directly
  // processes locally.
  this->SessionCore->UnRegisterSIObject(msg);

  this->DeActivate();
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::RegisterSIObject(vtkSMMessage* msg)
{
  this->Activate();

  // This class does not handle remote sessions, so all messages are directly
  // processes locally.
  this->SessionCore->RegisterSIObject(msg);

  this->DeActivate();
}

//----------------------------------------------------------------------------
vtkSIObject* vtkPVSessionBase::GetSIObject(vtkTypeUInt32 globalid)
{
  return this->SessionCore? this->SessionCore->GetSIObject(globalid) : NULL;
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::PrepareProgressInternal()
{
  vtkClientServerStream substream;
  substream << vtkClientServerStream::Invoke
            << vtkClientServerID(1) // ID for vtkPVSessionCore helper.
            << "GetActiveProgressHandler"
            << vtkClientServerStream::End;
  vtkClientServerStream stream;
  stream << vtkClientServerStream::Invoke
         << substream
         << "PrepareProgress"
         << vtkClientServerStream::End;
  this->ExecuteStream(vtkPVSession::CLIENT_AND_SERVERS, stream, false);
  //this->Superclass::PrepareProgressInternal();
  //FIXME_COLLABORATION - I don't like code that skips superclass implentations.
  //Rethink this.
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::CleanupPendingProgressInternal()
{
  vtkClientServerStream substream;
  substream << vtkClientServerStream::Invoke
            << vtkClientServerID(1) // ID for vtkPVSessionCore helper.
            << "GetActiveProgressHandler"
            << vtkClientServerStream::End;
  vtkClientServerStream stream;
  stream << vtkClientServerStream::Invoke
         << substream
         << "CleanupPendingProgress"
         << vtkClientServerStream::End;
  this->ExecuteStream(vtkPVSession::CLIENT_AND_SERVERS, stream, false);
  //this->Superclass::CleanupPendingProgressInternal();
  //FIXME_COLLABORATION
}

//----------------------------------------------------------------------------
bool vtkPVSessionBase::GatherInformation(vtkTypeUInt32 location,
    vtkPVInformation* information, vtkTypeUInt32 globalid)
{
  return this->SessionCore->GatherInformation(location, information, globalid);
}

//----------------------------------------------------------------------------
vtkObject* vtkPVSessionBase::GetRemoteObject(vtkTypeUInt32 globalid)
{
  return this->SessionCore->GetRemoteObject(globalid);
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::RegisterRemoteObject(vtkTypeUInt32 gid,
                                            vtkTypeUInt32 location, vtkObject* obj)
{
  this->SessionCore->RegisterRemoteObject(gid, obj);

  // Also tell the remote resources that it is used
  vtkSMMessage registerMsg;
  registerMsg.set_global_id(gid);
  registerMsg.set_location(location);
  this->RegisterSIObject(&registerMsg);

  this->InvokeEvent(vtkPVSessionBase::RegisterRemoteObjectEvent, &gid);
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::UnRegisterRemoteObject(vtkTypeUInt32 gid, vtkTypeUInt32 location)
{
  this->SessionCore->UnRegisterRemoteObject(gid);

  // Also delete remote resources as well
  vtkSMMessage deleteMsg;
  deleteMsg.set_global_id(gid);
  deleteMsg.set_location(location);
  this->UnRegisterSIObject(&deleteMsg);

  this->InvokeEvent(vtkPVSessionBase::UnRegisterRemoteObjectEvent, &gid);
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::GetAllRemoteObjects(vtkCollection* collection)
{
  this->SessionCore->GetAllRemoteObjects(collection);
}

//----------------------------------------------------------------------------
vtkMPIMToNSocketConnection* vtkPVSessionBase::GetMPIMToNSocketConnection()
{
  return this->SessionCore->GetMPIMToNSocketConnection();
}

//----------------------------------------------------------------------------
void vtkPVSessionBase::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
vtkTypeUInt32 vtkPVSessionBase::GetNextGlobalUniqueIdentifier()
{
  vtkTypeUInt32 id = this->SessionCore->GetNextGlobalUniqueIdentifier();
  return id;
}

//----------------------------------------------------------------------------
vtkTypeUInt32 vtkPVSessionBase::GetNextChunkGlobalUniqueIdentifier(vtkTypeUInt32 chunkSize)
{
  vtkClientServerStream stream;
  stream << vtkClientServerStream::Invoke
      << vtkClientServerID(1) // ID for the vtkSMSessionCore helper.
      << "GetNextGlobalIdChunk"
      << chunkSize
      << vtkClientServerStream::End;
  this->ExecuteStream(vtkPVSession::DATA_SERVER_ROOT, stream);

  // Extract the first id of the new chunk
  vtkTypeUInt32 id;
  this->GetLastResult(vtkPVSession::DATA_SERVER_ROOT).GetArgument(0,0, &id);
  return id;
}
//----------------------------------------------------------------------------
bool vtkPVSessionBase::StartProcessingRemoteNotification()
{
  bool tmp = this->ProcessingRemoteNotification;
  this->ProcessingRemoteNotification = true;
  return tmp;
}
//----------------------------------------------------------------------------
void vtkPVSessionBase::StopProcessingRemoteNotification(bool previousValue)
{
  this->ProcessingRemoteNotification = previousValue;
  if(!previousValue)
    {
    this->InvokeEvent(vtkPVSessionBase::ProcessingRemoteEnd);
    }
}
//----------------------------------------------------------------------------
bool vtkPVSessionBase::IsProcessingRemoteNotification()
{
  return this->ProcessingRemoteNotification;
}
//----------------------------------------------------------------------------
void vtkPVSessionBase::UseSessionCoreOf(vtkPVSessionBase* other)
{
  if(other)
    {
    this->SetSessionCore(other->GetSessionCore());
    }
  else
    {
    vtkErrorMacro("No vtkPVSessionBase provided");
    }
}

//----------------------------------------------------------------------------
vtkPVSessionCore* vtkPVSessionBase::GetSessionCore() const
{
  return this->SessionCore;
}
//----------------------------------------------------------------------------
void vtkPVSessionBase::SetSessionCore(vtkPVSessionCore* other)
{
  if(this->SessionCore)
    {
    this->SessionCore->Delete();
    }
  this->SessionCore = other;
  if(this->SessionCore)
    {
    this->SessionCore->Register(this);
    }
}