diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-05-06 17:09:32 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-05-06 18:54:24 +0200 |
commit | 25a1ba71e3cf4250489291f688423963aa603498 (patch) | |
tree | fb1e23060b810237316f4cde6524c0b1a66d5d0e /src/main.cpp | |
parent | 07f61b1ad6363cd471b7dab3f94c3160636fd6a0 (diff) |
Server and services configuration using separate objects
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
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<bool> confirmPairing(string prefix, const Peer & peer, string confirm, fu void startServer(const vector<string> &) { - vector<unique_ptr<Service>> services; - using namespace std::placeholders; - auto atts = make_unique<AttachService>(); - 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<ContactService>(); - 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<AttachService>() + .onRequest(bind(confirmPairing, "attach-request", _1, _2, _3)) + .onResponse(bind(confirmPairing, "attach-response", _1, _2, _3)) + ; - auto dms = make_unique<DirectMessageService>(); - dms->onUpdate([](const DirectMessageThread & thread, ssize_t, ssize_t) { - ostringstream ss; + config.service<ContactService>() + .onRequest(bind(confirmPairing, "contact-request", _1, _2, _3)) + .onResponse(bind(confirmPairing, "contact-response", _1, _2, _3)) + ; - string name = "<unnamed>"; - if (auto opt = thread.peer().name()) - name = *opt; + config.service<DirectMessageService>() + .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 = "<unnamed>"; + 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<SyncService>()); + config.service<SyncService>(); - server.emplace(*h, move(services)); + server.emplace(*h, move(config)); server->peerList().onUpdate([](size_t idx, const Peer * peer) { size_t i = 0; |