Newer
Older
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
#include <cstdlib>
#include "RandomChaining.h"
#include <thread>
#include <chrono>
namespace armarx::skills::provider
{
namespace util
{
int randomgen(int max, int min) //Pass in range
{
srand(time(NULL)); //Changed from rand(). srand() seeds rand for you.
int random = rand() % max + min;
return random;
}
}
RandomChainingSkill::RandomChainingSkill() : SimpleSkill(GetSkillDescription())
{
}
SkillDescription
RandomChainingSkill::GetSkillDescription()
{
return SkillDescription{.skillId = armarx::skills::SkillID{.skillName = "RandomChainingSkill"},
.description =
"This skill calls 100 random subskills from the skillProviderExample excluding the segfault skill.",
.timeout = armarx::core::time::Duration::MilliSeconds(50000)};
}
Skill::MainResult
RandomChainingSkill::main(const MainInput& in)
{
std::vector<std::string> subskillNames = {"Timeout", "ChainingSkill", "Foo", "HelloWorld", "IncompleteSkill", "ShowMeCallbacks"};
ARMARX_CHECK(subskillNames.size() > 0);
for (unsigned int i = 0; i < 100; ++i)
{
this->throwIfSkillShouldTerminate();
auto index = util::randomgen(subskillNames.size() -1, 0);
auto subskillName = subskillNames[index];
SkillProxy prx(
manager,
skills::SkillID{.providerId = *getSkillId().providerId, .skillName = subskillName});
if (util::randomgen(10, 0) < 2)
{
callSubskill(prx);
}
else
{
callSubskillAsync(prx);
auto sleep_milliseconds = util::randomgen(1000, 0);
ARMARX_INFO << "SLEEP FOR " << sleep_milliseconds << "ms";
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_milliseconds));
}
}
return {TerminatedSkillStatus::Succeeded, nullptr};
}
} // namespace armarx::skills::provider