-
Notifications
You must be signed in to change notification settings - Fork 14
/
Search.cc
43 lines (30 loc) · 993 Bytes
/
Search.cc
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
#include <iostream>
#include <string>
#include "Common.h"
#include "Service.h"
static void onInteraction(Common::RequestHandler);
int main(int argc, char** argv) try {
Common::init();
const auto args = Common::args(argc, argv);
const auto endpoint = args.size() == 2 ? args[1] : "tcp://*:9995";
Service::Requester self{endpoint};
const auto handler = [&self](const Common::Request& req) -> Common::Response {
// query all attached services on interaction
return self.query(req);
};
onInteraction(handler);
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
static void onInteraction(Common::RequestHandler handler) {
std::string request;
do {
if (!request.empty()) {
const auto responses = handler(request);
std::cout << "\nResults>\n";
for (auto&& resp : responses)
std::cout << " * " << resp << '\n';
}
std::cout << "\nSearch>" << std::endl;
} while (std::getline(std::cin, request));
}