Skip to content

Commit 0ced007

Browse files
authored
Merge pull request #13 from trygvis/master
Minor improvements
2 parents b281de5 + 3fcd3c2 commit 0ced007

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

include/msgflo.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,18 @@ class EngineConfig {
121121
_debugOutput = std::getenv("MSGFLO_CPP_DEBUG") ? true : false;
122122
}
123123

124-
void debugOutput(bool on) {
124+
EngineConfig& debugOutput(bool on) {
125125
_debugOutput = on;
126+
return *this;
126127
};
127128

128129
bool debugOutput() const {
129130
return _debugOutput;
130131
}
131132

132-
void url(const std::string &url) {
133+
EngineConfig& url(const std::string &url) {
133134
_url = url;
135+
return *this;
134136
};
135137

136138
std::string url() const {

src/mqtt_support.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class mqtt_client : public waitable, private mqtt_lib {
207207
const string host;
208208
const int port;
209209
bool connecting_, connected_;
210+
const string client_id;
210211
const int keep_alive;
211212
int unacked_messages_;
212213

@@ -224,7 +225,7 @@ class mqtt_client : public waitable, private mqtt_lib {
224225
mqtt_client(mqtt_event_listener *event_listener, const string &host, const int port, const int keep_alive,
225226
const string &client_id, const bool clean_session) :
226227
event_listener(event_listener), host(host), port(port), connecting_(false), connected_(false),
227-
keep_alive(keep_alive), unacked_messages_(0) {
228+
client_id(client_id), keep_alive(keep_alive), unacked_messages_(0) {
228229
const char *id = nullptr;
229230

230231
if (!client_id.empty()) {
@@ -302,7 +303,7 @@ class mqtt_client : public waitable, private mqtt_lib {
302303
void connect() {
303304
guard lock(this_mutex);
304305

305-
auto msg = "Connecting to " + host + ":" + to_string(port) + ", keep_alive=" + to_string(keep_alive);
306+
auto msg = "Connecting to " + host + ":" + to_string(port) + ", client_id=" + client_id + ", keep_alive=" + to_string(keep_alive);
306307
event_listener->on_msg(msg);
307308

308309
if (connecting_ || connected_) {

src/msgflo.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@ shared_ptr<Engine> createEngine(const EngineConfig config) {
382382
}
383383
}
384384

385+
if (url.empty()) {
386+
throw invalid_argument("Missing msgflo url and MSGFLO_BROKER is not set.");
387+
}
388+
385389
if (string_starts_with(url, "mqtt://")) {
386390
string host, username, password;
387391
int port = 1883;
@@ -394,7 +398,7 @@ shared_ptr<Engine> createEngine(const EngineConfig config) {
394398

395399
if (i_up != string::npos) {
396400
string up = s.substr(0, i_up);
397-
cout << "up: " << up << endl;
401+
// cout << "up: " << up << endl;
398402

399403
auto i_u = up.find(':');
400404

@@ -404,19 +408,19 @@ shared_ptr<Engine> createEngine(const EngineConfig config) {
404408
} else {
405409
username = up;
406410
}
407-
cout << "username: " << username << endl;
408-
cout << "password: " << password << endl;
411+
// cout << "username: " << username << endl;
412+
// cout << "password: " << password << endl;
409413

410414
s = s.substr(i_up + 1);
411-
cout << "s: " << s << endl;
415+
// cout << "s: " << s << endl;
412416
}
413417

414418
auto i_q = s.find('?');
415419

416420
if (i_q != string::npos) {
417421
host = s.substr(0, i_q);
418422
s = s.substr(i_q + 1);
419-
cout << "s: " << s << endl;
423+
// cout << "s: " << s << endl;
420424

421425
while (!s.empty()) {
422426
auto i_amp = s.find('&');
@@ -428,7 +432,7 @@ shared_ptr<Engine> createEngine(const EngineConfig config) {
428432
} else {
429433
kv = s.substr(0, i_amp);
430434
}
431-
cout << "kv: " << kv << endl;
435+
// cout << "kv: " << kv << endl;
432436

433437
auto i_eq = kv.find('=');
434438

@@ -439,6 +443,7 @@ shared_ptr<Engine> createEngine(const EngineConfig config) {
439443
} else {
440444
key = kv;
441445
}
446+
// cout << "key: " << key << endl;
442447

443448
if (key == "keepAlive") {
444449
try {
@@ -464,7 +469,7 @@ shared_ptr<Engine> createEngine(const EngineConfig config) {
464469
break;
465470
}
466471
s = s.substr(i_amp + 1);
467-
cout << "s: " << s << endl;
472+
// cout << "s: " << s << endl;
468473
}
469474
} else {
470475
host = s;

0 commit comments

Comments
 (0)