-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseEngine.hpp
123 lines (107 loc) · 4.25 KB
/
BaseEngine.hpp
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
#ifndef ___FCF__PARALLEL__BASE_ENGINE_HPP___
#define ___FCF__PARALLEL__BASE_ENGINE_HPP___
#include <string>
#include "macro.hpp"
#include "include.hpp"
#include "Details/Distributor.hpp"
#include "Call.hpp"
#include "Arg.hpp"
#include "Unit.hpp"
#include "Registrator.hpp"
namespace fcf {
namespace Parallel {
class FCF_PARALLEL_DECL_EXPORT BaseEngine {
public:
BaseEngine();
virtual ~BaseEngine();
virtual Union& property(std::string a_name);
virtual void property(std::string a_name, const Union& a_value);
virtual void initialize(size_t a_index, Details::Distributor* a_distributor);
virtual void prepare(const Call& a_call, Details::Distributor::Call& a_distributorCall, BaseArg** a_args, size_t a_argsc);
virtual void applyArgs(bool a_first, const Call& a_call, BaseArg** a_args, size_t a_argsc);
virtual void execute(const fcf::Parallel::Details::Distributor::SubTask& a_subtask, BaseArg** a_args, size_t a_argsc);
protected:
Union _properties;
};
#ifdef FCF_PARALLEL_IMPLEMENTATION
BaseEngine::BaseEngine()
: _properties(fcf::UT_MAP)
{
_properties["enable"] = true;
_properties["minDuration"] = 200 * 1000;
}
#endif
#ifdef FCF_PARALLEL_IMPLEMENTATION
BaseEngine::~BaseEngine(){
}
#endif
#ifdef FCF_PARALLEL_IMPLEMENTATION
Union& BaseEngine::property(std::string a_name) {
return _properties[a_name];
}
#endif
#ifdef FCF_PARALLEL_IMPLEMENTATION
void BaseEngine::property(std::string a_name, const Union& a_value) {
_properties[a_name] = a_value;
}
#endif
#ifdef FCF_PARALLEL_IMPLEMENTATION
void BaseEngine::initialize(size_t a_index, Details::Distributor* a_distributor) {
}
#endif
#ifdef FCF_PARALLEL_IMPLEMENTATION
void BaseEngine::applyArgs(bool a_first, const Call& a_call, BaseArg** a_args, size_t a_argsc){
}
#endif
#ifdef FCF_PARALLEL_IMPLEMENTATION
void BaseEngine::execute(const fcf::Parallel::Details::Distributor::SubTask& a_subtask, BaseArg** a_args, size_t a_argsc) {
}
#endif
#ifdef FCF_PARALLEL_IMPLEMENTATION
void BaseEngine::prepare(const Call& a_call, Details::Distributor::Call& a_distributorCall, BaseArg** a_args, size_t a_argsc) {
PUnit punit = Registrator().get(a_call.name);
if (punit->args.size() != a_argsc) {
throw std::runtime_error("The number of arguments does not match the required number");
}
if ((a_argsc + 1) > FCF_PARALLEL_MAX_FUNCTION_ARGS) {
throw std::runtime_error("The number of arguments exceeds the maximum value");
}
for(size_t i = 0; i < a_argsc; ++i) {
if (!a_distributorCall.split) {
if (a_args[i]->split == PS_PACKAGE) {
throw std::runtime_error(std::string() +
"Argument " +
std::to_string(i+1) +
" has split parameter equal to PS_PACKAGE. Call::split property must be set to true");
}
}
bool found = false;
const char* types1[FCF_PARALLEL_MAX_TYPE_COMPATIBLE];
size_t typesc1;
const char* types2[FCF_PARALLEL_MAX_TYPE_COMPATIBLE];
size_t typesc2;
a_args[i]->types(types1, typesc1);
punit->args[i]->types(types2, typesc2);
for(size_t ti1 = 0; !found && ti1 < typesc1; ++ti1){
for(size_t ti2 = 0; ti2 < typesc2; ++ti2){
if (ti1 == 2) {
a_args[i]->types(types1, typesc1);
punit->args[i]->types(types2, typesc2);
}
if (strcmp(types1[ti1], types2[ti2]) == 0) {
found = true;
break;
}
}
}
if (!found){
throw std::runtime_error(std::string("Type does not match for argument ") +
std::to_string(i+1) +
". Expected type " + types2[0] + ", but received " + types1[0]);
}
}
}
#endif // #ifdef FCF_PARALLEL_IMPLEMENTATION
} // Parallel namespace
} // fcf namespace
#endif