docs: adjust designing
This commit is contained in:
@ -11,6 +11,7 @@ class BookStoreBackEndClass {
|
||||
BlockingStringStream *output_ptr;
|
||||
BookStoreEngineClass *engine_ptr;
|
||||
std::unordered_map<std::string, SessionClass> session_map;
|
||||
std::unordered_map<std::string, std::thread> worker_theads;
|
||||
|
||||
public:
|
||||
BookStoreBackEndClass() = delete;
|
||||
|
@ -4,57 +4,9 @@
|
||||
#include "bs-utility.h"
|
||||
#include "builtin-cli.h"
|
||||
#include "clipp/clipp.h"
|
||||
ReadWriteLock rwLock;
|
||||
std::mutex mtx;
|
||||
void readerFunc(int id) {
|
||||
while (true) {
|
||||
rwLock.startRead();
|
||||
debugPrint("Reader ", id, " is reading.");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(498));
|
||||
debugPrint("Reader ", id, " end reading.");
|
||||
rwLock.endRead();
|
||||
|
||||
// 模拟一些其他操作
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(502));
|
||||
}
|
||||
}
|
||||
|
||||
void writerFunc(int id) {
|
||||
while (true) {
|
||||
rwLock.startWrite();
|
||||
debugPrint("Writer ", id, " is writing.");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1005));
|
||||
debugPrint("Writer ", id, " end writing.");
|
||||
rwLock.endWrite();
|
||||
|
||||
// 模拟一些其他操作
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1013));
|
||||
}
|
||||
}
|
||||
void test() {
|
||||
std::thread readers[3];
|
||||
std::thread writers[2];
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
readers[i] = std::thread(readerFunc, i + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
writers[i] = std::thread(writerFunc, i + 1);
|
||||
}
|
||||
|
||||
// 等待所有线程结束
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
readers[i].join();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
writers[i].join();
|
||||
}
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
test();
|
||||
return 0;
|
||||
// test();
|
||||
// return 0;
|
||||
bool is_server = false;
|
||||
std::string config_dir = "";
|
||||
bool custom_config_dir = false;
|
||||
|
@ -73,43 +73,43 @@ memoryriver类维护一个缓存,简单地缓存高频访问和连续访问;
|
||||
实际上是一个页面,不同模式下动态绘制。
|
||||
|
||||
# 用户交互设计
|
||||
## 内置命令
|
||||
- `# OpenSession <TempChannelID>`:向调度模块申请一个新会话
|
||||
- `# CloseSession <SessionToken> <OuthenticationKey>`:显示地告知调度模块停止某个会话
|
||||
- `# ReRequest <SessionToken> <OperationToken> <OuthenticationKey>`:向服务端重新请求调取某次操作响应的缓存
|
||||
- `# Request <SessionToken> <OuthenticationKey> # <UserCommand>`:向后端发送一个请求
|
||||
## 内部命令
|
||||
- `# OpenSession`:向调度模块申请一个新会话
|
||||
- `# CloseSession [SessionToken] [OuthenticationKey]`:显示地告知调度模块停止某个会话
|
||||
- `# ReRequest [SessionToken] [OperationToken] [OuthenticationKey]`:向服务端重新请求调取某次操作响应的缓存
|
||||
- `# Request [SessionToken] [OuthenticationKey] # [UserCommand]`:向后端发送一个请求
|
||||
- `# ShutDownSystem`:关闭整个系统
|
||||
|
||||
## 向用户提供的命令
|
||||
- `SU <UserName> <Password>`:登录某个用户(登录栈+1)
|
||||
- `LOGOUT`:退出当前用户(登录栈-1)
|
||||
- `EXIT`:退出当前会话
|
||||
- `$SHUTDOWN`:关闭整个系统(需要最高权限)
|
||||
- `$REBOOT`:重启整个系统(需要最高权限)
|
||||
- `REGISTER <UserName> <Password> <NickName>`:注册用户
|
||||
- `ADDUSER <UserName> <Password> <NickName> [Power]`:添加用户(至少需要销售员权限),权限缺省为客户,且不可超过当前用户的权限
|
||||
- `QUERY ( [-ISBN=<isbn>] | [-AuthorName=<author>] | [-BookName=<bookname>] | [-KeyWords=<keywordslists>] )`:查询图书
|
||||
- `BUY <ISBN> [Number]`:购买图书,默认数量是1
|
||||
- `IMPORT <ISBN> <Number> <Cost>`:进货(至少需要销售员权限)
|
||||
- `ADDBOOK <ISBN> <BookName> <Author> <KeyWordList>`:添加图书信息(至少需要销售员权限)
|
||||
- `MODIFY <ISBN> [ [-NewISBN=<newisbn>] | [-BookName=<newname>] | [-Author=<newauthor>] | [-KeyWordList=<newkeylists>] ]`:修改图书信息(至少需要销售员权限)
|
||||
- `$QUERYIMPORT [-from=<begintime>] [-till=<endtime>]`:查看采购情况(需要最高权限)
|
||||
- `$QUERYSELL [-from=<begintime>] [-till=<endtime>]`:查看销售情况(需要最高权限)
|
||||
- `$QUERYBENEFIT [-from=<begintime>] [-till=<endtime>]`:查看盈利情况(需要最高权限)
|
||||
- `$QUERYOPT [-from=<begintime>] [-till=<endtime>] [-operator=<operatorname>]`:查看操作情况(需要最高权限)
|
||||
- `$QUERYLOG [-from=<begintime>] [-till=<endtime>]`:查看日志情况(需要最高权限)
|
||||
- `quit`和`exit`:正常退出系统
|
||||
- `su [UserID] ([Password])?`:登录
|
||||
- `logout`:退出上一个登录
|
||||
- `register [UserID] [Password] [Username]`:注册用户
|
||||
- `passwd [UserID] ([CurrentPassword])? [NewPassword]`:修改密码
|
||||
- `useradd [UserID] [Password] [Privilege] [Username]`:店员修改密码
|
||||
- `delete [UserID]`:删除用户
|
||||
- `show (-ISBN=[ISBN] | -name="[BookName]" | -author="[Author]" | -keyword="[Keyword]")?`:查找图书
|
||||
- `buy [ISBN] [Quantity]`:购买图书
|
||||
- `select [ISBN]`:选中图书
|
||||
- `modify (-ISBN=[ISBN] | -name="[BookName]" | -author="[Author]" | -keyword="[Keyword]" | -price=[Price])+`:修改图书信息
|
||||
- `import [Quantity] [TotalCost]`:进货
|
||||
- `show finance ([Count])?`:查询交易总账
|
||||
- `report finance`:查询财务报表
|
||||
- `report employee`:查询员工工作报告
|
||||
- `log`:查询系统操作日志
|
||||
|
||||
# 底层数据接口约定(类、结构体设计)
|
||||
## 请求
|
||||
- 引擎接受:内部数据`struct RequestType { RequestKindType requestkind; std::any content; };`
|
||||
- 调度模块接受:`! <SessionToken> <OperationToken> <AuthenticationKey> ! <RequestContent>`
|
||||
- 内置交互模块(interactive模式)接受:字符串,`<RequestContent>`
|
||||
- 云命令行接受:字符串,`<RequestContent>`
|
||||
- 引擎接受:内部数据,数据传进函数参数列表
|
||||
- 调度模块接受:内部命令
|
||||
- 内置交互模块(interactive模式)接受:字符串,`[UserCommand]`
|
||||
- 云命令行接受:字符串,`[UserCommand]`
|
||||
- WebUI:图形界面
|
||||
|
||||
## 响应
|
||||
注意,对于申请Session时,响应用`<TempChannelID>`替代`<SessionToken`,返回信息内容是`SessionToken`和`AuthenticationKey`。
|
||||
- 引擎返回:内部数据,`struct ResponseType { int code; std::any content; };`
|
||||
- 调度模块返回:字符串,`! <SessionToken> <OperationToken> <Code> ! <ResponseContent>`
|
||||
- 内置交互模块(interactive模式)返回:字符串,`<ResponseContent>`
|
||||
- 云命令行返回:字符串,`<ResponseContent>`
|
||||
注意,对于申请Session时,响应用`[TempChannelID]`替代`[SessionToken]`,返回信息内容是`[SessionToken]`和`[AuthenticationKey]`。
|
||||
- 引擎返回:`std::string`
|
||||
- 调度模块返回:字符串,`[SessionToken] [OperationToken] [LineCounter]\n[ResponseContent]`,其中,`[ResponseContent]`恰有`[LineCounter]`行,每行行末有且仅有一个`\n`。输出为空通过把`[LineCounter]`设置为0来实现。
|
||||
- 内置交互模块(interactive模式)返回:字符串,`[ResponseContent]`
|
||||
- 云命令行返回:字符串,`[ResponseContent]`
|
||||
- WebUI:图形界面
|
Reference in New Issue
Block a user