From 02767aae047338f60cc3744e105e7dfcf0435780 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Tue, 12 Dec 2023 06:27:48 +0000 Subject: [PATCH] docs: adjust designing --- backend/include/schedule.h | 1 + backend/src/main.cpp | 52 ++---------------------------- docs/develop/总体设计文档.md | 62 ++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 81 deletions(-) diff --git a/backend/include/schedule.h b/backend/include/schedule.h index d092084..5c18994 100644 --- a/backend/include/schedule.h +++ b/backend/include/schedule.h @@ -11,6 +11,7 @@ class BookStoreBackEndClass { BlockingStringStream *output_ptr; BookStoreEngineClass *engine_ptr; std::unordered_map session_map; + std::unordered_map worker_theads; public: BookStoreBackEndClass() = delete; diff --git a/backend/src/main.cpp b/backend/src/main.cpp index 58301ae..cb932d9 100644 --- a/backend/src/main.cpp +++ b/backend/src/main.cpp @@ -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; diff --git a/docs/develop/总体设计文档.md b/docs/develop/总体设计文档.md index 10ae6de..ebee4c4 100644 --- a/docs/develop/总体设计文档.md +++ b/docs/develop/总体设计文档.md @@ -73,43 +73,43 @@ memoryriver类维护一个缓存,简单地缓存高频访问和连续访问; 实际上是一个页面,不同模式下动态绘制。 # 用户交互设计 -## 内置命令 -- `# OpenSession `:向调度模块申请一个新会话 -- `# CloseSession `:显示地告知调度模块停止某个会话 -- `# ReRequest `:向服务端重新请求调取某次操作响应的缓存 -- `# Request # `:向后端发送一个请求 +## 内部命令 +- `# OpenSession`:向调度模块申请一个新会话 +- `# CloseSession [SessionToken] [OuthenticationKey]`:显示地告知调度模块停止某个会话 +- `# ReRequest [SessionToken] [OperationToken] [OuthenticationKey]`:向服务端重新请求调取某次操作响应的缓存 +- `# Request [SessionToken] [OuthenticationKey] # [UserCommand]`:向后端发送一个请求 +- `# ShutDownSystem`:关闭整个系统 ## 向用户提供的命令 -- `SU `:登录某个用户(登录栈+1) -- `LOGOUT`:退出当前用户(登录栈-1) -- `EXIT`:退出当前会话 -- `$SHUTDOWN`:关闭整个系统(需要最高权限) -- `$REBOOT`:重启整个系统(需要最高权限) -- `REGISTER `:注册用户 -- `ADDUSER [Power]`:添加用户(至少需要销售员权限),权限缺省为客户,且不可超过当前用户的权限 -- `QUERY ( [-ISBN=] | [-AuthorName=] | [-BookName=] | [-KeyWords=] )`:查询图书 -- `BUY [Number]`:购买图书,默认数量是1 -- `IMPORT `:进货(至少需要销售员权限) -- `ADDBOOK `:添加图书信息(至少需要销售员权限) -- `MODIFY [ [-NewISBN=] | [-BookName=] | [-Author=] | [-KeyWordList=] ]`:修改图书信息(至少需要销售员权限) -- `$QUERYIMPORT [-from=] [-till=]`:查看采购情况(需要最高权限) -- `$QUERYSELL [-from=] [-till=]`:查看销售情况(需要最高权限) -- `$QUERYBENEFIT [-from=] [-till=]`:查看盈利情况(需要最高权限) -- `$QUERYOPT [-from=] [-till=] [-operator=]`:查看操作情况(需要最高权限) -- `$QUERYLOG [-from=] [-till=]`:查看日志情况(需要最高权限) +- `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; };` -- 调度模块接受:`! ! ` -- 内置交互模块(interactive模式)接受:字符串,`` -- 云命令行接受:字符串,`` +- 引擎接受:内部数据,数据传进函数参数列表 +- 调度模块接受:内部命令 +- 内置交互模块(interactive模式)接受:字符串,`[UserCommand]` +- 云命令行接受:字符串,`[UserCommand]` - WebUI:图形界面 ## 响应 -注意,对于申请Session时,响应用``替代` ! ` -- 内置交互模块(interactive模式)返回:字符串,`` -- 云命令行返回:字符串,`` +注意,对于申请Session时,响应用`[TempChannelID]`替代`[SessionToken]`,返回信息内容是`[SessionToken]`和`[AuthenticationKey]`。 +- 引擎返回:`std::string` +- 调度模块返回:字符串,`[SessionToken] [OperationToken] [LineCounter]\n[ResponseContent]`,其中,`[ResponseContent]`恰有`[LineCounter]`行,每行行末有且仅有一个`\n`。输出为空通过把`[LineCounter]`设置为0来实现。 +- 内置交互模块(interactive模式)返回:字符串,`[ResponseContent]` +- 云命令行返回:字符串,`[ResponseContent]` - WebUI:图形界面 \ No newline at end of file