vtkPVProcessModule.cxx 11.5 KB
Newer Older
1
2
3
4
5
/*=========================================================================

  Program:   ParaView
  Module:    vtkPVProcessModule.cxx

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

10
11
12
     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.
13
14
15
16

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

17
#include "vtkCallbackCommand.h"
18
#include "vtkCharArray.h"
19
20
#include "vtkDataSet.h"
#include "vtkDoubleArray.h"
21
22
#include "vtkDummyController.h"
#include "vtkFloatArray.h"
23
24
#include "vtkLongArray.h"
#include "vtkMapper.h"
25
26
27
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkPVConfig.h"
28
#include "vtkPolyData.h"
29
30
#include "vtkShortArray.h"
#include "vtkSource.h"
31
#include "vtkString.h"
32
#include "vtkStringList.h"
33
34
35
36
#include "vtkToolkits.h"
#include "vtkUnsignedIntArray.h"
#include "vtkUnsignedLongArray.h"
#include "vtkUnsignedShortArray.h"
37
38
#include "vtkClientServerStream.h"
#include "vtkClientServerInterpreter.h"
39
40
41
42
43
44
#include "vtkTimerLog.h"
#include "vtkProcessModuleGUIHelper.h"

// initialze the class variables
int vtkPVProcessModule::GlobalLODFlag = 0;

45
46
47

//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPVProcessModule);
Bill Hoffman's avatar
Bill Hoffman committed
48
vtkCxxRevisionMacro(vtkPVProcessModule, "1.3");
49
50
51
52

//----------------------------------------------------------------------------
vtkPVProcessModule::vtkPVProcessModule()
{
53
54
  this->ProgressRequests = 0;
  this->GUIHelper = 0;
55
  this->MPIMToNSocketConnectionID.ID = 0;
56
  this->ProgressEnabled = 0;
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  this->LogThreshold = 0.01;
  this->ClientMode = 0;
  this->ServerMode = 0;
  this->RenderServerMode = 0;
  this->HostName = NULL;
  this->RenderServerHostName = NULL;
  this->SetRenderServerHostName("localhost");
  this->SetHostName("localhost");
  this->Port = 11111;
  this->RenderServerPort = 22221;
  this->RenderNodePort = 0;
  this->ReverseConnection = 0;
  this->Username = 0;
  this->MachinesFileName =0;
  this->DemoPath = 0;
72
73
74
75
}

//----------------------------------------------------------------------------
vtkPVProcessModule::~vtkPVProcessModule()
76
{ 
Bill Hoffman's avatar
Bill Hoffman committed
77
78
79
80
  if(this->GUIHelper)
    {
    this->GUIHelper->Delete();
    }
81
  this->FinalizeInterpreter();
82
83
}

84
85
86
//----------------------------------------------------------------------------
int vtkPVProcessModule::Start(int argc, char **argv)
{
87
88
89
90
91
92
  if(!this->GUIHelper)
    {
    vtkErrorMacro("GUIHelper must be set, for vtkPVProcessModule to be able to run a gui.");
    return -1;
    }
  
93
94
95
  if (this->Controller == NULL)
    {
    this->Controller = vtkDummyController::New();
Charles Law's avatar
Charles Law committed
96
    vtkMultiProcessController::SetGlobalController(this->Controller);
97
    }
98
  return this->GUIHelper->RunGUIStart(argc, argv, 1, 0);
99
100
101
102
103
104
105
}

//----------------------------------------------------------------------------
void vtkPVProcessModule::Exit()
{
}

106
//----------------------------------------------------------------------------
107
108
109
int vtkPVProcessModule::GetDirectoryListing(const char* dir,
                                            vtkStringList* dirs,
                                            vtkStringList* files,
110
                                            int save)
111
{
112
113
114
115
116
  // Get the listing from the server.
  vtkClientServerID lid = this->NewStreamObject("vtkPVServerFileListing");
  this->GetStream() << vtkClientServerStream::Invoke
                    << lid << "GetFileListing" << dir << save
                    << vtkClientServerStream::End;
117
  this->SendStream(vtkProcessModule::DATA_SERVER_ROOT);
118
119
120
121
122
  vtkClientServerStream result;
  if(!this->GetLastServerResult().GetArgument(0, 0, &result))
    {
    vtkErrorMacro("Error getting file list result from server.");
    this->DeleteStreamObject(lid);
123
    this->SendStream(vtkProcessModule::DATA_SERVER_ROOT);
124
125
126
    return 0;
    }
  this->DeleteStreamObject(lid);
127
  this->SendStream(vtkProcessModule::DATA_SERVER_ROOT);
128
129

  // Parse the listing.
130
131
132
133
134
135
136
137
  if ( dirs )
    {
    dirs->RemoveAllItems();
    }
  if ( files )
    {
    files->RemoveAllItems();
    }
138
139
140
141
  if(result.GetNumberOfMessages() == 2)
    {
    int i;
    // The first message lists directories.
142
    if ( dirs )
143
      {
144
      for(i=0; i < result.GetNumberOfArguments(0); ++i)
145
        {
146
147
148
149
150
151
152
153
154
        const char* d;
        if(result.GetArgument(0, i, &d))
          {
          dirs->AddString(d);
          }
        else
          {
          vtkErrorMacro("Error getting directory name from listing.");
          }
155
156
157
158
        }
      }

    // The second message lists files.
159
    if ( files )
160
      {
161
      for(i=0; i < result.GetNumberOfArguments(1); ++i)
162
        {
163
164
165
166
167
168
169
170
171
        const char* f;
        if(result.GetArgument(1, i, &f))
          {
          files->AddString(f);
          }
        else
          {
          vtkErrorMacro("Error getting file name from listing.");
          }
172
173
174
175
176
        }
      }
    return 1;
    }
  else
177
178
179
    {
    return 0;
    }
180
}
181

182
//----------------------------------------------------------------------------
183
184
vtkObjectBase* vtkPVProcessModule::GetObjectFromID(vtkClientServerID id)
{
185
  return this->Interpreter->GetObjectFromID(id);
186
187
}

188
//----------------------------------------------------------------------------
189
190
191
192
193
194
vtkObjectBase* vtkPVProcessModule::GetObjectFromIntID(unsigned int idin)
{
  vtkClientServerID id;
  id.ID = idin;
  return this->GetObjectFromID(id);
}
195

196

197
198
199
200
//----------------------------------------------------------------------------
void vtkPVProcessModule::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
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
  os << indent << "LogThreshold: " << this->LogThreshold << endl;
  os << indent << "MachinesFileName: " 
     << (this->MachinesFileName?this->MachinesFileName:"(null)") << endl;
  if (this->ClientMode)
    {
    os << indent << "Running as a client\n";
    os << indent << "Port: " << this->Port << endl;
    os << indent << "RenderNodePort: " << this->RenderNodePort << endl;
    os << indent << "RenderServerPort: " << this->RenderServerPort << endl;
    os << indent << "Host: " << (this->HostName?this->HostName:"(none)") << endl;
    os << indent << "Render Host: " << (this->RenderServerHostName?this->RenderServerHostName:"(none)") << endl;
    os << indent << "Username: " 
       << (this->Username?this->Username:"(none)") << endl;
    os << indent << "AlwaysSSH: " << this->AlwaysSSH << endl;
    os << indent << "ReverseConnection: " << this->ReverseConnection << endl;
    }
  if (this->ServerMode)
    {
    os << indent << "Running as a server\n";
    os << indent << "Port: " << this->Port << endl;
    os << indent << "RenderServerPort: " << this->RenderServerPort << endl;
    os << indent << "ReverseConnection: " << this->ReverseConnection << endl;
    }
  if (this->RenderServerMode)
    {
    if(this->ClientMode)
      {
      os << indent << "Running as a client connectd to a render server\n";
      }
    else
      {
      os << indent << "Running as a render server\n";
      os << indent << "RenderServerPort: " << this->RenderServerPort << endl;
      os << indent << "Port: " << this->Port << endl;
      os << indent << "ReverseConnection: " << this->ReverseConnection << endl;
      }
    } 
Bill Hoffman's avatar
Bill Hoffman committed
238
  os << indent << "ProgressEnabled: " << this->ProgressEnabled << endl;
239
  os << indent << "DemoPath: " << (this->DemoPath?this->DemoPath:"(none)") << endl;
240
}
241

242
//----------------------------------------------------------------------------
243
void vtkPVProcessModule::InitializeInterpreter()
244
{
245
246
247
248
249
  if(this->Interpreter)
    {
    return;
    }

250
  this->Superclass::InitializeInterpreter();
251

252
253
254
255
256
257
258
259
260
261
}

//----------------------------------------------------------------------------
void vtkPVProcessModule::FinalizeInterpreter()
{
  if(!this->Interpreter)
    {
    return;
    }

262
  this->Superclass::FinalizeInterpreter();
263
264
}

265
//----------------------------------------------------------------------------
266
int vtkPVProcessModule::LoadModule(const char* name, const char* directory)
267
268
269
{
  this->GetStream()
    << vtkClientServerStream::Invoke
270
271
    << this->GetProcessModuleID()
    << "LoadModuleInternal" << name << directory
272
    << vtkClientServerStream::End;
273
  this->SendStream(vtkProcessModule::DATA_SERVER);
274
  int result = 0;
Brad King's avatar
Brad King committed
275
276
277
278
279
  if(!this->GetLastServerResult().GetArgument(0, 0, &result))
    {
    vtkErrorMacro("LoadModule could not get result from server.");
    return 0;
    }
280
281
282
283
  return result;
}

//----------------------------------------------------------------------------
284
285
int vtkPVProcessModule::LoadModuleInternal(const char* name,
                                           const char* directory)
286
{
287
288
  const char* paths[] = {directory, 0};
  return this->Interpreter->Load(name, paths);
289
}
290
291
292

//----------------------------------------------------------------------------
void vtkPVProcessModule::SendPrepareProgress()
293
294
{ 
  if(!this->GUIHelper)
295
    {
296
297
    vtkErrorMacro("GUIHelper must be set, for SendPrepareProgress.");
    return;
298
    }
299
  this->GUIHelper->SendPrepareProgress();
300
301
302
303
304
305
306
307
308
309
310
  this->Superclass::SendPrepareProgress();
}

//----------------------------------------------------------------------------
void vtkPVProcessModule::SendCleanupPendingProgress()
{
  this->Superclass::SendCleanupPendingProgress();
  if ( this->ProgressRequests > 0 )
    {
    return;
    }
311
312
313
314
315
316
 if(!this->GUIHelper)
    {
    vtkErrorMacro("GUIHelper must be set, for SendCleanupPendingProgress.");
    return;
    }
  this->GUIHelper->SendCleanupPendingProgress();
317
318
319
320
321
}

//----------------------------------------------------------------------------
void vtkPVProcessModule::SetLocalProgress(const char* filter, int progress)
{
322
 if(!this->GUIHelper)
323
    {
324
    vtkErrorMacro("GUIHelper must be set, for SetLocalProgress.");
325
326
    return;
    }
327
328
329
330
331
332
333
334
335
336
337
338
339
340
 this->GUIHelper->SetLocalProgress(filter, progress);
}


//----------------------------------------------------------------------------
void vtkPVProcessModule::LogStartEvent(char* str)
{
  vtkTimerLog::MarkStartEvent(str);
}

//----------------------------------------------------------------------------
void vtkPVProcessModule::LogEndEvent(char* str)
{
  vtkTimerLog::MarkEndEvent(str);
341
342
343
}

//----------------------------------------------------------------------------
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
void vtkPVProcessModule::SetLogBufferLength(int length)
{
  vtkTimerLog::SetMaxEntries(length);
}

//----------------------------------------------------------------------------
void vtkPVProcessModule::ResetLog()
{
  vtkTimerLog::ResetLog();
}
//----------------------------------------------------------------------------
void vtkPVProcessModule::SetEnableLog(int flag)
{
  vtkTimerLog::SetLogging(flag);
}
//----------------------------------------------------------------------------
void vtkPVProcessModule::SetGlobalLODFlag(int val)
361
{
362
  if (vtkPVProcessModule::GlobalLODFlag == val)
363
    {
364
    return;
365
    }
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
  this->GetStream() << vtkClientServerStream::Invoke
                  << this->GetProcessModuleID()
                  << "SetGlobalLODFlagInternal"
                  << val
                  << vtkClientServerStream::End;
  this->SendStream(vtkProcessModule::CLIENT|vtkProcessModule::DATA_SERVER);
}

 
//----------------------------------------------------------------------------
void vtkPVProcessModule::SetGlobalLODFlagInternal(int val)
{
  vtkPVProcessModule::GlobalLODFlag = val;
}



//----------------------------------------------------------------------------
int vtkPVProcessModule::GetGlobalLODFlag()
{
  return vtkPVProcessModule::GlobalLODFlag;
}


const char* vtkPVProcessModule::GetDemoPath()
{
  return this->DemoPath;
}

void vtkPVProcessModule::SetGUIHelper(vtkProcessModuleGUIHelper* h)
{
  this->GUIHelper = h;
  h->Register(this);
399
400
}