upd: writing cli
This commit is contained in:
@ -7,7 +7,35 @@
|
||||
void BookStoreMain(bool is_server, std::string config_dir) {
|
||||
std::ios::sync_with_stdio(false);
|
||||
if (!is_server) {
|
||||
; // TODO: run as client
|
||||
BlockingStringStream input;
|
||||
BlockingStringStream output;
|
||||
BookStoreBackEndClass backend(config_dir, &input, &output);
|
||||
std::thread backend_thread([&backend]() { backend.Run(); });
|
||||
input << "#OpenSession INNERCLI\n";
|
||||
std::string SessionToken, AuthenticationKey, tmp;
|
||||
output.getline(tmp);
|
||||
output >> SessionToken >> AuthenticationKey;
|
||||
debugPrint("SessionToken=", SessionToken,
|
||||
" AuthenticationKey=", AuthenticationKey);
|
||||
std::string cmd;
|
||||
while (getline(std::cin, cmd)) {
|
||||
if (cmd == "quit" || cmd == "exit") {
|
||||
input << "#CloseSession " << SessionToken << ' ' << AuthenticationKey
|
||||
<< '\n';
|
||||
input << "#ShutDownSystem\n";
|
||||
backend_thread.join();
|
||||
return;
|
||||
}
|
||||
input << "#Request " << SessionToken << " I-T-D " << AuthenticationKey
|
||||
<< ' ' << cmd << '\n';
|
||||
output.getline(tmp);
|
||||
std::cout << tmp << std::endl;
|
||||
}
|
||||
input << "#CloseSession " << SessionToken << ' ' << AuthenticationKey
|
||||
<< '\n';
|
||||
input << "#ShutDownSystem\n";
|
||||
backend_thread.join();
|
||||
return;
|
||||
} else {
|
||||
std::cin.tie(nullptr);
|
||||
std::cout.rdbuf(nullptr);
|
||||
|
Reference in New Issue
Block a user