Evita  0.16
evProgressReporter.h
Go to the documentation of this file.
1 /*
2  *
3  * EVITA: Efficient Visualization of Terascale Datasets
4  * Copyright (C) 2000-2016 Team Evita
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
19  * MA 02139, USA.
20  *
21  */
22 
23 
24 #ifndef __evProgressReporter_h
25 #define __evProgressReporter_h
26 
27 
28 #include "evCommon.h"
30 
31 
33 {
34 public:
35  evProgressReporter(void);
36  virtual ~evProgressReporter(void);
37 
38  virtual const evString GetClassName(void) const
39  {
40  return(evString("evProgressReporter"));
41  }
42 
43  void SetController(const int report_to_thread,
44  evMultiProcessController *controller);
45 
46  void ReportProgress(const double progress);
47  void ReportProgress(const unsigned int count,
48  const unsigned int max_count);
49  void ReportProcess(evString process);
50 
51 protected:
52 
53 private:
54 
55  unsigned int PreviousProgress;
57  int Thread;
58 
59 };
60 
61 
63 {
64  this->Controller = NULL;
65  this->PreviousProgress = 0;
66 }
67 
68 
70 {
71 }
72 
73 
74 inline void evProgressReporter::SetController(const int
75  report_to_thread,
77  *controller)
78 {
79  this->Thread = report_to_thread;
80  this->Controller = controller;
81 }
82 
83 
84 inline void evProgressReporter::ReportProgress(const double progress)
85 {
86  this->ReportProgress((unsigned int)(progress * 100),
87  (unsigned int)100);
88 }
89 
90 
91 inline void evProgressReporter::ReportProgress(const unsigned int count,
92  const unsigned int max_count)
93 {
94  unsigned int progress;
95 
96  if (this->Controller != NULL)
97  {
98  if (count == max_count)
99  progress = 100;
100  else
101  if (max_count > 100)
102  progress = count / (max_count / 100);
103  else
104  if (!max_count)
105  progress = 0;
106  else
107  progress = (int)((double)count / max_count * 100);
108 
109  if (progress != this->PreviousProgress)
110  {
111  this->PreviousProgress = progress;
112  this->Controller->Send((char *)&progress,
113  sizeof(unsigned int),
114  this->Thread,
116  }
117  }
118 }
119 
120 
122 {
123  if (this->Controller != NULL)
124  {
125  this->Controller->Send(process.GetString(),
126  EVSTRINGLEN,
127  this->Thread,
129  this->ReportProgress(0);
130  }
131 }
132 
133 
134 #endif
char * GetString(void)
Definition: evString.h:110
evProgressReporter(void)
Definition: evProgressReporter.h:62
Definition: evProgressReporter.h:32
unsigned int PreviousProgress
Definition: evProgressReporter.h:55
evMultiProcessController * Controller
Definition: evProgressReporter.h:56
int Thread
Definition: evProgressReporter.h:57
void ReportProgress(const double progress)
Definition: evProgressReporter.h:84
virtual ~evProgressReporter(void)
Definition: evProgressReporter.h:69
virtual const evString GetClassName(void) const
Definition: evProgressReporter.h:38
#define EVMESSAGE_PROGRESS
Definition: evDefinitions.h:49
#define EVSTRINGLEN
Definition: evString.h:28
Definition: evMultiProcessController.h:122
#define EVMESSAGE_PROCESS
Definition: evDefinitions.h:50
virtual int Send(vtkDataObject *data, int remoteProcessId, int tag)
void ReportProcess(evString process)
Definition: evProgressReporter.h:121
void SetController(const int report_to_thread, evMultiProcessController *controller)
Definition: evProgressReporter.h:74
Definition: evString.h:30