upd: writing cli
This commit is contained in:
@ -82,6 +82,7 @@ class ReadWriteLock {
|
|||||||
void endWrite();
|
void endWrite();
|
||||||
};
|
};
|
||||||
class SessionClass {
|
class SessionClass {
|
||||||
|
public:
|
||||||
std::stack<int> login_stack;
|
std::stack<int> login_stack;
|
||||||
std::string SessionToken;
|
std::string SessionToken;
|
||||||
std::string OuthorizationKey;
|
std::string OuthorizationKey;
|
||||||
|
@ -7,7 +7,35 @@
|
|||||||
void BookStoreMain(bool is_server, std::string config_dir) {
|
void BookStoreMain(bool is_server, std::string config_dir) {
|
||||||
std::ios::sync_with_stdio(false);
|
std::ios::sync_with_stdio(false);
|
||||||
if (!is_server) {
|
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 {
|
} else {
|
||||||
std::cin.tie(nullptr);
|
std::cin.tie(nullptr);
|
||||||
std::cout.rdbuf(nullptr);
|
std::cout.rdbuf(nullptr);
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
#include "builtin-cli.h"
|
#include "builtin-cli.h"
|
||||||
#include "clipp/clipp.h"
|
#include "clipp/clipp.h"
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// test();
|
|
||||||
// return 0;
|
|
||||||
bool is_server = false;
|
bool is_server = false;
|
||||||
std::string config_dir = "";
|
std::string config_dir = "";
|
||||||
bool custom_config_dir = false;
|
bool custom_config_dir = false;
|
||||||
|
@ -1,13 +1,34 @@
|
|||||||
#include "schedule.h"
|
#include "schedule.h"
|
||||||
#include "engine.h"
|
|
||||||
|
|
||||||
void BookStoreBackEndClass::Run()
|
#include <random>
|
||||||
{
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "engine.h"
|
||||||
|
void BookStoreBackEndClass::Run() {
|
||||||
std::string request_data;
|
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');
|
input_ptr->getline(request_data, '\n');
|
||||||
// std::string response_data = Engine::Process(request_data);
|
debugPrint("request_data=", request_data);
|
||||||
// output_ptr << response_data << '\n';
|
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';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -74,11 +74,11 @@ memoryriver类维护一个缓存,简单地缓存高频访问和连续访问;
|
|||||||
|
|
||||||
# 用户交互设计
|
# 用户交互设计
|
||||||
## 内部命令
|
## 内部命令
|
||||||
- `# OpenSession`:向调度模块申请一个新会话
|
- `#OpenSession [TempChannelID]`:向调度模块申请一个新会话
|
||||||
- `# CloseSession [SessionToken] [OuthenticationKey]`:显示地告知调度模块停止某个会话
|
- `#CloseSession [SessionToken] [OuthenticationKey]`:显示地告知调度模块停止某个会话
|
||||||
- `# ReRequest [SessionToken] [OperationToken] [OuthenticationKey]`:向服务端重新请求调取某次操作响应的缓存
|
- `#_Request [SessionToken] [OperationToken] [OuthenticationKey]`:向服务端重新请求调取某次操作响应的缓存
|
||||||
- `# Request [SessionToken] [OuthenticationKey] # [UserCommand]`:向后端发送一个请求
|
- `#Request [SessionToken] [OperationToken] [OuthenticationKey] [UserCommand]`:向后端发送一个请求
|
||||||
- `# ShutDownSystem`:关闭整个系统
|
- `#ShutDownSystem`:关闭整个系统
|
||||||
|
|
||||||
## 向用户提供的命令
|
## 向用户提供的命令
|
||||||
- `quit`和`exit`:正常退出系统
|
- `quit`和`exit`:正常退出系统
|
||||||
@ -107,7 +107,7 @@ memoryriver类维护一个缓存,简单地缓存高频访问和连续访问;
|
|||||||
- WebUI:图形界面
|
- WebUI:图形界面
|
||||||
|
|
||||||
## 响应
|
## 响应
|
||||||
注意,对于申请Session时,响应用`[TempChannelID]`替代`[SessionToken]`,返回信息内容是`[SessionToken]`和`[AuthenticationKey]`。
|
注意,对于申请Session时,响应用`[TempChannelID]`替代`[SessionToken]`,仅用于保证信息投递正确,返回信息内容是`[SessionToken]`和`[AuthenticationKey]`。
|
||||||
- 引擎返回:`std::string`
|
- 引擎返回:`std::string`
|
||||||
- 调度模块返回:字符串,`[SessionToken] [OperationToken] [LineCounter]\n[ResponseContent]`,其中,`[ResponseContent]`恰有`[LineCounter]`行,每行行末有且仅有一个`\n`。输出为空通过把`[LineCounter]`设置为0来实现。
|
- 调度模块返回:字符串,`[SessionToken] [OperationToken] [LineCounter]\n[ResponseContent]`,其中,`[ResponseContent]`恰有`[LineCounter]`行,每行行末有且仅有一个`\n`。输出为空通过把`[LineCounter]`设置为0来实现。
|
||||||
- 内置交互模块(interactive模式)返回:字符串,`[ResponseContent]`
|
- 内置交互模块(interactive模式)返回:字符串,`[ResponseContent]`
|
||||||
|
Reference in New Issue
Block a user