From 25a1ba71e3cf4250489291f688423963aa603498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 6 May 2023 17:09:32 +0200 Subject: Server and services configuration using separate objects --- src/main.cpp | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index aa70c48..0052c8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -257,39 +257,39 @@ future confirmPairing(string prefix, const Peer & peer, string confirm, fu void startServer(const vector &) { - vector> services; - using namespace std::placeholders; - auto atts = make_unique(); - atts->onRequest(bind(confirmPairing, "attach-request", _1, _2, _3)); - atts->onResponse(bind(confirmPairing, "attach-response", _1, _2, _3)); - services.push_back(move(atts)); + ServerConfig config; - auto conts = make_unique(); - conts->onRequest(bind(confirmPairing, "contact-request", _1, _2, _3)); - conts->onResponse(bind(confirmPairing, "contact-response", _1, _2, _3)); - services.push_back(move(conts)); + config.service() + .onRequest(bind(confirmPairing, "attach-request", _1, _2, _3)) + .onResponse(bind(confirmPairing, "attach-response", _1, _2, _3)) + ; - auto dms = make_unique(); - dms->onUpdate([](const DirectMessageThread & thread, ssize_t, ssize_t) { - ostringstream ss; + config.service() + .onRequest(bind(confirmPairing, "contact-request", _1, _2, _3)) + .onResponse(bind(confirmPairing, "contact-response", _1, _2, _3)) + ; - string name = ""; - if (auto opt = thread.peer().name()) - name = *opt; + config.service() + .onUpdate([](const DirectMessageThread & thread, ssize_t, ssize_t) { + ostringstream ss; - ss << "dm-received" - << " from " << name - << " text " << thread.at(0).text() - ; - printLine(ss.str()); - }); - services.push_back(move(dms)); + string name = ""; + if (auto opt = thread.peer().name()) + name = *opt; + + ss << "dm-received" + << " from " << name + << " text " << thread.at(0).text() + ; + printLine(ss.str()); + }) + ; - services.push_back(make_unique()); + config.service(); - server.emplace(*h, move(services)); + server.emplace(*h, move(config)); server->peerList().onUpdate([](size_t idx, const Peer * peer) { size_t i = 0; -- cgit v1.2.3