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