-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathstepfile_rw_progress.cc
More file actions
111 lines (94 loc) · 2.98 KB
/
stepfile_rw_progress.cc
File metadata and controls
111 lines (94 loc) · 2.98 KB
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
#include "cleditor/STEPfile.h"
#include "clstepcore/sdai.h"
#include "clstepcore/STEPattribute.h"
#include "clstepcore/ExpDict.h"
#include "clstepcore/Registry.h"
#include "clutils/errordesc.h"
#include <algorithm>
#include <string>
#ifdef HAVE_STD_THREAD
# include <thread>
#else
# error Need std::thread for this test!
#endif
#ifdef HAVE_STD_CHRONO
# include <chrono>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "SdaiAUTOMOTIVE_DESIGN.h"
//macro for N ms sleep
//currently used for 5ms sleep (could be more for a larger file, may need reduced for a fast processor)
//TODO: rework this test to not be timing-sensitive
#ifdef HAVE_STD_CHRONO
# define DELAY(t) std::this_thread::sleep_for(std::chrono::milliseconds(t));
#else
# ifndef _WIN32
# define DELAY(t) usleep( t * 100 )
# else
# include <WinBase.h>
# define DELAY(t) Sleep( t )
# endif
#endif
// NOTE this test requires std::thread, part of C++11. It will fail to compile otherwise.
void readProgressParallel( STEPfile & f, float & maxProgress ) {
while( 1 ) {
float p = f.GetReadProgress();
if( p > maxProgress ) {
maxProgress = p;
}
DELAY( 5 );
}
}
void writeProgressParallel( STEPfile & f, float & maxProgress ) {
while( 1 ) {
float p = f.GetWriteProgress();
if( p > maxProgress ) {
maxProgress = p;
}
DELAY( 5 );
}
}
int main( int argc, char * argv[] ) {
float progress = 0.0;
if( argc != 2 ) {
cerr << "Wrong number of args. Use: " << argv[0] << " file.stp" << endl;
exit( EXIT_FAILURE );
}
Registry registry( SchemaInit );
InstMgr instance_list;
STEPfile sfile( registry, instance_list, "", false );
// read the file
std::thread r( readProgressParallel, std::ref( sfile ), std::ref( progress ) );
sfile.ReadExchangeFile( argv[1] );
r.detach();
Severity readSev = sfile.Error().severity();
if( readSev != SEVERITY_NULL ) {
sfile.Error().PrintContents( cout );
exit( EXIT_FAILURE );
}
if( progress < 55 ) { //55 is arbitrary. should be >50 due to how GetReadProgress() works.
cerr << "Error: Read progress (" << progress << ") never exceeded the threshold (55). Exiting." << endl;
exit( EXIT_FAILURE );
} else {
cout << "Read progress reached " << progress << "% - success." << endl;
}
progress = 0;
// write the file
std::thread w( writeProgressParallel, std::ref( sfile ), std::ref( progress ) );
sfile.WriteExchangeFile( "out.stp" );
w.detach();
readSev = sfile.Error().severity();
if( readSev != SEVERITY_NULL ) {
sfile.Error().PrintContents( cout );
exit( EXIT_FAILURE );
}
if( progress < 55 ) {
cerr << "Error: Write progress (" << progress << ") never exceeded the threshold (55). Exiting." << endl;
exit( EXIT_FAILURE );
} else {
cout << "Write progress reached " << progress << "% - success." << endl;
}
exit( EXIT_SUCCESS );
}