Skip to content

Commit f588c62

Browse files
committed
discovery: Automatically set .id based on .role
1 parent 02b5051 commit f588c62

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/msgflo.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ using namespace trygvis::mqtt_support;
1111

1212
namespace msgflo {
1313

14+
std::string random_string( size_t length )
15+
{
16+
auto randchar = []() -> char
17+
{
18+
const char charset[] =
19+
"0123456789"
20+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
21+
"abcdefghijklmnopqrstuvwxyz";
22+
const size_t max_index = (sizeof(charset) - 1);
23+
return charset[ rand() % max_index ];
24+
};
25+
std::string str(length,0);
26+
std::generate_n( str.begin(), length, randchar );
27+
return str;
28+
}
29+
1430
std::string string_to_upper_copy(const std::string &str) {
1531
std::string ret;
1632
ret.resize(str.size());
@@ -145,6 +161,11 @@ class AbstractEngine {
145161

146162
Definition validateDefinitionFromUser(const Definition &definition) {
147163
Definition d(definition);
164+
165+
if (d.id.size() == 0) {
166+
d.id = d.role + "-" + random_string(8);
167+
}
168+
148169
for (auto &port : d.inports) {
149170
if (port.queue.empty()) {
150171
port.queue = generateQueueName(definition, port);

0 commit comments

Comments
 (0)