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);
|
||||
|
@ -5,8 +5,6 @@
|
||||
#include "builtin-cli.h"
|
||||
#include "clipp/clipp.h"
|
||||
int main(int argc, char **argv) {
|
||||
// test();
|
||||
// return 0;
|
||||
bool is_server = false;
|
||||
std::string config_dir = "";
|
||||
bool custom_config_dir = false;
|
||||
|
@ -1,13 +1,34 @@
|
||||
#include "schedule.h"
|
||||
#include "engine.h"
|
||||
|
||||
void BookStoreBackEndClass::Run()
|
||||
{
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
|
||||
#include "engine.h"
|
||||
void BookStoreBackEndClass::Run() {
|
||||
std::string request_data;
|
||||
while(true)
|
||||
{
|
||||
const unsigned int RndSeed = std::random_device{}();
|
||||
std::mt19937 rnd(RndSeed);
|
||||
while (true) {
|
||||
input_ptr->getline(request_data, '\n');
|
||||
// std::string response_data = Engine::Process(request_data);
|
||||
// output_ptr << response_data << '\n';
|
||||
debugPrint("request_data=", request_data);
|
||||
if (request_data[1] == 'O') // #OpenSession [TempChannelID]
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << request_data;
|
||||
ss >> request_data;
|
||||
std::string TempChannelID;
|
||||
ss >> TempChannelID;
|
||||
SessionClass new_session;
|
||||
std::string new_SessionToken;
|
||||
std::string new_AuthenticationKey;
|
||||
for (int i = 0; i < 16; i++) new_SessionToken.push_back(rnd() % 26 + 'A');
|
||||
for (int i = 0; i < 16; i++)
|
||||
new_AuthenticationKey.push_back(rnd() % 26 + 'A');
|
||||
new_session.SessionToken = new_SessionToken;
|
||||
new_session.OuthorizationKey = new_AuthenticationKey;
|
||||
session_map[new_SessionToken] = new_session;
|
||||
(*output_ptr) << TempChannelID << " IinitialOpt 1\n"
|
||||
<< new_SessionToken << ' ' << new_AuthenticationKey << '\n';
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user