├── LICENSE
├── OS.pro
├── OS.pro.user
├── README.md
├── disk
├── confilespacedetail.cpp
├── confilespacedetail.h
├── confilespacedetail.ui
├── disk.cpp
├── disk.h
├── disk.ui
├── fatfilespacedetail.cpp
├── fatfilespacedetail.h
├── fatfilespacedetail.ui
├── freeblocktable.cpp
├── freeblocktable.h
├── freeblocktable.ui
├── indexfilespacedetail.cpp
├── indexfilespacedetail.h
├── indexfilespacedetail.ui
├── showfileseekoder.cpp
├── showfileseekoder.h
└── showfileseekoder.ui
├── equipment
├── dequip.cpp
├── dequip.h
├── dequip.ui
├── myprocess.cpp
├── myprocess.h
├── myprocess.ui
├── request.cpp
├── request.h
├── request.ui
├── widget.cpp
├── widget.h
└── widget.ui
├── file
├── file.cpp
├── file.h
├── file.ui
├── filecontext.cpp
├── filecontext.h
├── filecontext.ui
├── filecreate.cpp
├── filecreate.h
├── filecreate.ui
├── fileproperty.cpp
├── fileproperty.h
├── fileproperty.ui
├── foldercreate.cpp
├── foldercreate.h
├── foldercreate.ui
├── myPhotos
│ ├── dirIcon.png
│ └── file.png
├── myfilepro.cpp
├── myfilepro.h
├── spaceexband.cpp
├── spaceexband.h
└── spaceexband.ui
├── icon.qrc
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── memory
├── memory.cpp
├── memory.h
└── memory.ui
├── pics.qrc
├── pics
└── tubiao.jpg
├── process
├── pcb.cpp
├── pcb.h
├── processdialog.cpp
├── processdialog.h
├── processdialog.ui
├── processtab.cpp
├── processtab.h
└── processtab.ui
└── 操作系统课程设计.docx
/LICENSE:
--------------------------------------------------------------------------------
1 | 木兰宽松许可证, 第2版
2 |
3 | 木兰宽松许可证, 第2版
4 | 2020年1月 http://license.coscl.org.cn/MulanPSL2
5 |
6 |
7 | 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
8 |
9 | 0. 定义
10 |
11 | “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
12 |
13 | “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
14 |
15 | “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
16 |
17 | “法人实体”是指提交贡献的机构及其“关联实体”。
18 |
19 | “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
20 |
21 | 1. 授予版权许可
22 |
23 | 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
24 |
25 | 2. 授予专利许可
26 |
27 | 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
28 |
29 | 3. 无商标许可
30 |
31 | “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。
32 |
33 | 4. 分发限制
34 |
35 | 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
36 |
37 | 5. 免责声明与责任限制
38 |
39 | “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
40 |
41 | 6. 语言
42 | “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
43 |
44 | 条款结束
45 |
46 | 如何将木兰宽松许可证,第2版,应用到您的软件
47 |
48 | 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
49 |
50 | 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
51 |
52 | 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中;
53 |
54 | 3, 请将如下声明文本放入每个源文件的头部注释中。
55 |
56 | Copyright (c) [Year] [name of copyright holder]
57 | [Software Name] is licensed under Mulan PSL v2.
58 | You can use this software according to the terms and conditions of the Mulan PSL v2.
59 | You may obtain a copy of Mulan PSL v2 at:
60 | http://license.coscl.org.cn/MulanPSL2
61 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
62 | See the Mulan PSL v2 for more details.
63 |
64 |
65 | Mulan Permissive Software License,Version 2
66 |
67 | Mulan Permissive Software License,Version 2 (Mulan PSL v2)
68 | January 2020 http://license.coscl.org.cn/MulanPSL2
69 |
70 | Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
71 |
72 | 0. Definition
73 |
74 | Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
75 |
76 | Contribution means the copyrightable work licensed by a particular Contributor under this License.
77 |
78 | Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
79 |
80 | Legal Entity means the entity making a Contribution and all its Affiliates.
81 |
82 | Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
83 |
84 | 1. Grant of Copyright License
85 |
86 | Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
87 |
88 | 2. Grant of Patent License
89 |
90 | Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
91 |
92 | 3. No Trademark License
93 |
94 | No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4.
95 |
96 | 4. Distribution Restriction
97 |
98 | You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
99 |
100 | 5. Disclaimer of Warranty and Limitation of Liability
101 |
102 | THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
103 |
104 | 6. Language
105 |
106 | THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
107 |
108 | END OF THE TERMS AND CONDITIONS
109 |
110 | How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
111 |
112 | To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
113 |
114 | i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
115 |
116 | ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package;
117 |
118 | iii Attach the statement to the appropriate annotated syntax at the beginning of each source file.
119 |
120 |
121 | Copyright (c) [Year] [name of copyright holder]
122 | [Software Name] is licensed under Mulan PSL v2.
123 | You can use this software according to the terms and conditions of the Mulan PSL v2.
124 | You may obtain a copy of Mulan PSL v2 at:
125 | http://license.coscl.org.cn/MulanPSL2
126 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
127 | See the Mulan PSL v2 for more details.
128 |
--------------------------------------------------------------------------------
/OS.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2023-02-05T15:04:23
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui
8 | QT += widgets
9 |
10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
11 |
12 | TARGET = OS
13 | TEMPLATE = app
14 |
15 | # The following define makes your compiler emit warnings if you use
16 | # any feature of Qt which has been marked as deprecated (the exact warnings
17 | # depend on your compiler). Please consult the documentation of the
18 | # deprecated API in order to know how to port your code away from it.
19 | DEFINES += QT_DEPRECATED_WARNINGS
20 |
21 | # You can also make your code fail to compile if you use deprecated APIs.
22 | # In order to do so, uncomment the following line.
23 | # You can also select to disable deprecated APIs only up to a certain version of Qt.
24 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
25 |
26 | CONFIG += c++11
27 |
28 | SOURCES += \
29 | memory/memory.cpp \
30 | process/pcb.cpp \
31 | process/processdialog.cpp \
32 | process/processtab.cpp \
33 | main.cpp \
34 | mainwindow.cpp \
35 | file/file.cpp \
36 | file/filecontext.cpp \
37 | file/filecreate.cpp \
38 | file/fileproperty.cpp \
39 | file/foldercreate.cpp \
40 | file/myfilepro.cpp \
41 | file/spaceexband.cpp \
42 | disk/confilespacedetail.cpp \
43 | disk/disk.cpp \
44 | disk/fatfilespacedetail.cpp \
45 | disk/freeblocktable.cpp \
46 | disk/indexfilespacedetail.cpp \
47 | disk/showfileseekoder.cpp \
48 | equipment/dequip.cpp \
49 | equipment/myprocess.cpp \
50 | equipment/request.cpp \
51 | equipment/widget.cpp
52 |
53 |
54 | HEADERS += \
55 | disk/disk.h \
56 | file/file.h \
57 | memory/memory.h \
58 | process/pcb.h \
59 | process/processdialog.h \
60 | process/processtab.h \
61 | mainwindow.h \
62 | file/file.h \
63 | file/filecontext.h \
64 | file/filecreate.h \
65 | file/fileproperty.h \
66 | file/foldercreate.h \
67 | file/myfilepro.h \
68 | file/spaceexband.h \
69 | disk/confilespacedetail.h \
70 | disk/disk.h \
71 | disk/fatfilespacedetail.h \
72 | disk/freeblocktable.h \
73 | disk/indexfilespacedetail.h \
74 | disk/showfileseekoder.h \
75 | equipment/dequip.h \
76 | equipment/myprocess.h \
77 | equipment/request.h \
78 | equipment/widget.h
79 |
80 |
81 |
82 | FORMS += \
83 | disk/disk.ui \
84 | file/file.ui \
85 | memory/memory.ui \
86 | process/processdialog.ui \
87 | process/processtab.ui \
88 | mainwindow.ui \
89 | file/file.ui \
90 | file/filecontext.ui \
91 | file/filecreate.ui \
92 | file/fileproperty.ui \
93 | file/foldercreate.ui \
94 | file/spaceexband.ui \
95 | disk/confilespacedetail.ui \
96 | disk/disk.ui \
97 | disk/fatfilespacedetail.ui \
98 | disk/freeblocktable.ui \
99 | disk/indexfilespacedetail.ui \
100 | disk/showfileseekoder.ui \
101 | equipment/dequip.ui \
102 | equipment/myprocess.ui \
103 | equipment/request.ui \
104 | equipment/widget.ui
105 |
106 |
107 |
108 | # Default rules for deployment.
109 | qnx: target.path = /tmp/$${TARGET}/bin
110 | else: unix:!android: target.path = /opt/$${TARGET}/bin
111 | !isEmpty(target.path): INSTALLS += target
112 |
113 | RESOURCES += \
114 | icon.qrc \
115 | pics.qrc \
116 | pics.qrc
117 |
118 | SUBDIRS += \
119 | OS.pro
120 |
121 | DISTFILES += \
122 | pics/tubiao.jpg \
123 | README.md \
124 | LICENSE
125 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 操作系统课设
2 |
3 |
4 |
5 | > 详情请看课设报告
6 |
7 |
8 |
9 | ## (一)课设板块
10 |
11 | 模块划分:
12 | (1)、进程管理模块
13 | (2)、内存管理模块
14 | (3)、文件管理模块
15 | (4)、设备管理模块
16 | (5)、界面管理模块
17 |
18 |
19 |
20 | ### 1. **进程管理:** 考虑进程的创建、状态转换(就绪、执行、阻塞)、调度、撤销等,设计PCB结构,设计进程调度算法。
21 |
22 | **选做:使用信号量机制模拟多任务系统中的进程同步。**
23 |
24 |
25 |
26 | ### 2. **内存管理** :考虑内存的动态分配与回收,采取何种数据结构,采用何内存分配算法等。
27 |
28 | **选做:内存的离散分配(分页式、分段式或段页式管理),以及基于此种机制下的虚拟内存管理,页面置换算法。**
29 |
30 |
31 |
32 | ### 3. **文件管理:** 考虑文件及文件目录的创建、查询、删除等操作的实现,考虑磁盘空间分配采用的数据结构及算法(连续分配、显式链接、索引分配),考虑磁盘空闲区管理采用的数据结构及算法(空闲盘块表、空闲盘块链、位示图、成组链接法)和算法。
33 |
34 | **选做:磁盘调度算法。**
35 |
36 |
37 |
38 | ### 4. 设备管理:考虑设备的分配和回收,采取何种数据结构,采用何种分配算法,使用银行家算法避免死锁。
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | ## (二)项目文件
48 |
49 | 主窗口
50 |
51 | mainwindow.h
52 |
53 | mainwindow.cpp
54 |
55 | mainwindow.ui
56 |
57 |
58 |
59 | OS.pro 项目配置文件
60 |
61 | pics文件夹 存放图标
62 |
63 |
64 |
65 |
66 | 1. 进程管理
67 |
68 | * process文件夹
69 |
70 | 2. 内存管理
71 |
72 | * memory文件夹
73 |
74 | 3. 文件管理
75 |
76 | * file文件夹
77 |
78 | 4. 设备管理
79 |
80 | * equipment文件夹
81 |
82 | 5. 磁盘管理
83 |
84 | * disk文件夹
85 |
86 |
87 |
88 |
89 |
90 | ## (三)模块间数据共享
91 |
92 | ### 关于数据共享
93 |
94 | 不同的类之间共享数据,通常可以考虑;
95 |
96 | * 某变量设置为全局变量,然后extern声明
97 |
98 | 如下,通过全局变量w, 共享readyQueue队列
99 |
100 | ```cpp
101 | //根据优先级排序,放入就绪队列
102 | extern MainWindow *w;
103 | w->processTab->readyQueue.push_back(process);
104 | sort(w->processTab->readyQueue.begin(),w->processTab->readyQueue.end(), ProcessTab::compare);
105 |
106 | ```
107 |
108 | * 包含某个类的文件,然后使用其函数
109 |
110 | * 利用信号与槽
111 |
112 | 如下,在对话框更改了另一个process的界面
113 |
114 | ```cpp
115 | //更新表格
116 | connect(this,SIGNAL(sendToShowProcess()),w->processTab,SLOT(showProcess()));
117 | emit this->sendToShowProcess();
118 | ```
119 |
120 |
121 |
122 |
123 |
124 | ## (四)流程图
125 |
126 | **进程管理**
127 |
128 | **内存管理**
129 |
130 | 
131 |
132 |
133 |
134 | **文件管理**
135 |
136 | 
137 |
138 |
139 |
140 | **设备管理**
141 |
142 |
143 |
144 | 
145 |
146 |
147 |
148 | ## (五)UML
149 |
150 | **进程管理**
151 |
152 | 
153 |
154 |
155 |
156 | 
157 |
158 |
159 |
160 | 
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 | **内存管理**
169 |
170 | 
171 |
172 | **文件管理**
173 |
174 | 
175 |
176 |
177 |
178 | **设备管理**
179 |
180 | 
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 | ## (六)效果展示
193 |
194 | #### 1.进程模块
195 |
196 | 创建进程时,所有进程就绪
197 |
198 | 
199 |
200 | 开始调度,由下图可见,进程“获取键值”在“键盘输入”未运行完,只执行了一部分时调入运行队列后阻塞。同时“键盘输入”在运行自己的第三个时间片(一个时间片2s,图上显示第6秒)时,请求调入第19号页面。 且运行完的进程所占用的内存块释放。
201 |
202 | 
203 |
204 |
205 |
206 | 磁盘调度时显示磁盘调度信息
207 |
208 |
209 |
210 | 访问磁道号2,磁盘模块第三行正在被访问,变为红色
211 |
212 | 
213 |
214 |
215 |
216 | #### 2.内存模块
217 |
218 | 内存初始化状态
219 |
220 | 
221 |
222 |
223 |
224 | 虚拟内存初始化状态:
225 |
226 | 
227 |
228 |
229 |
230 | 运行时:
231 |
232 | 
233 |
234 |
235 |
236 | 
237 |
238 |
239 |
240 |
241 |
242 | #### 3.文件模块
243 |
244 | 文件初始创建时
245 |
246 | 
247 |
248 |
249 |
250 | 
251 |
252 |
253 |
254 | **扩展各个文件后**
255 |
256 | 
257 |
258 | 操作删除文件
259 |
260 | 
261 |
262 |
263 |
264 | 操作后
265 |
266 | 
267 |
268 |
269 |
270 |
271 |
272 | #### 4. 设备管理模块
273 |
274 | **4.1 进程队列的生成**
275 |
276 | 点击生成按钮,产生一个进程个数为24的进程队列。
277 |
278 | 
279 |
280 | 点击每个进程可以查看该进程详情
281 |
282 | 
283 |
284 |
285 |
286 | **4.2 进程资源矩阵展示**
287 |
288 | 点击开始,展示资源的分配以及进程请求的详细情况
289 |
290 | 
291 |
292 |
293 |
294 | **4.3 发送请求**
295 |
296 | 点击发送请求按钮,开始发出请求。
297 |
298 | 
299 |
300 | 若请求资源大于need向量,则拒绝请求。
301 |
302 | 
303 |
304 | 
305 |
306 |
307 |
308 | 请求合理则执行安全性算法检测
309 |
310 | 
311 |
312 |
313 |
314 | **4.4 安全性算法**
315 |
316 | 执行安全性算法,
317 |
318 | 
319 |
320 |
321 |
322 | **4.5 资源分配**
323 |
324 | 通过则分配资源,进程的need减少,allocati增加,available减少。
325 |
326 | 例如:
327 |
328 | 
329 |
330 | 请求后(request = (1,1,1,1))
331 |
332 | )
333 |
334 |
335 |
336 | 
337 |
338 |
339 |
340 |
341 |
342 | **4.资源回收**
343 |
344 | 资源占有时间到后,则回收,该进程allocation和need置零,available=available+allocationi
345 |
346 | 
347 |
348 |
349 |
350 | 
351 |
352 |
353 |
354 |
355 |
--------------------------------------------------------------------------------
/disk/confilespacedetail.cpp:
--------------------------------------------------------------------------------
1 | #include "confilespacedetail.h"
2 | #include "ui_confilespacedetail.h"
3 |
4 | conFileSpaceDetail::conFileSpaceDetail(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::conFileSpaceDetail)
7 | {
8 | ui->setupUi(this);
9 | this->setWindowTitle("连续文件空间详情");
10 | ui->dir_tab->verticalHeader()->setVisible(false);
11 | ui->fileblock_tab->verticalHeader()->setVisible(false);
12 | }
13 |
14 | conFileSpaceDetail::~conFileSpaceDetail()
15 | {
16 | delete ui;
17 | }
18 |
19 | QTableWidget *conFileSpaceDetail::getconfTableWidget()
20 | {
21 | return ui->fileblock_tab;
22 | }
23 |
24 | QTableWidget *conFileSpaceDetail::getconfDirTableWidget()
25 | {
26 | return ui->dir_tab;
27 | }
28 |
--------------------------------------------------------------------------------
/disk/confilespacedetail.h:
--------------------------------------------------------------------------------
1 | #ifndef CONFILESPACEDETAIL_H
2 | #define CONFILESPACEDETAIL_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 |
9 | namespace Ui {
10 | class conFileSpaceDetail;
11 | }
12 |
13 | class conFileSpaceDetail : public QWidget
14 | {
15 | Q_OBJECT
16 |
17 | public:
18 | explicit conFileSpaceDetail(QWidget *parent = nullptr);
19 | ~conFileSpaceDetail();
20 | QTableWidget *getconfTableWidget();
21 | QTableWidget *getconfDirTableWidget();
22 |
23 | private:
24 | Ui::conFileSpaceDetail *ui;
25 | };
26 |
27 | #endif // CONFILESPACEDETAIL_H
28 |
--------------------------------------------------------------------------------
/disk/confilespacedetail.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | conFileSpaceDetail
4 |
5 |
6 |
7 | 0
8 | 0
9 | 666
10 | 512
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 10
20 | 20
21 | 101
22 | 18
23 |
24 |
25 |
26 | 目录结构 :
27 |
28 |
29 |
30 |
31 |
32 | 10
33 | 40
34 | 641
35 | 81
36 |
37 |
38 |
39 |
40 |
41 |
42 | 10
43 | 150
44 | 81
45 | 18
46 |
47 |
48 |
49 | 文件块 :
50 |
51 |
52 |
53 |
54 |
55 | 10
56 | 170
57 | 641
58 | 341
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/disk/disk.h:
--------------------------------------------------------------------------------
1 | #ifndef DISK_H
2 | #define DISK_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include"confilespacedetail.h"
14 | #include"fatfilespacedetail.h"
15 | #include"indexfilespacedetail.h"
16 | #include"showfileseekoder.h"
17 | #include"freeblocktable.h"
18 | #include"process/processtab.h"
19 | #include"file/myfilepro.h"
20 |
21 | #include
22 | #include
23 | #include "QTabWidget"
24 | #include "vector"
25 | #include"cstring"
26 | #include "algorithm"
27 |
28 | using namespace std;
29 |
30 | namespace Ui {
31 | class Disk;
32 | }
33 |
34 | struct virtualMemory{
35 | QString pid;
36 | int startIndex;
37 | int ranking;
38 | virtualMemory * nextBlock;
39 | };
40 |
41 |
42 | //文件策略表
43 | struct FilePolicy{
44 | int fileId;
45 | QString filename;
46 | QString policy;
47 | };
48 | // **************** 连续分配 *********
49 | //文件目录
50 | struct conFileDir{
51 | int fileId;
52 | QString filename;
53 | int size;
54 | int first_block;//首块号
55 | };
56 | //文件块结构
57 | struct FileBlock{
58 | int firstBlockId;//连续块起始地址
59 | int blockNum;//块数
60 | int nextBlockId;//下一连续块起始地址
61 | };
62 | // **************** 连续分配 *********
63 |
64 |
65 | // **************** FAT *********
66 | //FAT 文件目录
67 | struct Dir_fat{
68 | int fileId;
69 | QString filename;
70 | int size;
71 | int first_block;//首块号
72 | };
73 | //FAT表
74 | struct FAT{
75 | int blockId;
76 | int value;
77 | };
78 | // **************** FAT *********
79 |
80 | // **************** 索引分配 *********
81 | //文件目录结构
82 | struct IndexDir{
83 | int fileId;//文件 id
84 | QString filename;//文件名
85 | int size;//文件大小
86 | int indexBlockId;//起始索引块位置
87 | };
88 | //索引块 :包含文件信息、3 个磁盘块地址、下一索引块地址
89 | struct IndexBlock{
90 | int diskblockId;//索引块所在磁盘块号
91 | int fileId;//文件 id
92 | QString filename;//文件名
93 | int *blocksID;
94 | int nextIndexBlockId;//下一索引块地址 -1 结束
95 | };
96 | // **************** 索引分配 *********
97 |
98 | //磁盘块
99 | struct Block{
100 | int blockId;//块号
101 | int cyId=0;//块所在磁道号
102 | int fileId;//被分配文件 id
103 | QString filename;//目标文件名
104 | int size;//目标文件大小
105 | };
106 |
107 | //空闲空间管理 :计数法
108 | struct FreeBlockTable{
109 | int blockId;//磁盘地址
110 | int con_num;//紧跟空闲数量
111 | };
112 |
113 |
114 |
115 | class Disk : public QWidget
116 | {
117 | Q_OBJECT
118 |
119 | public:
120 | explicit Disk(QWidget *parent = nullptr);
121 | virtualMemory * virtualMemoryBlock = nullptr;
122 | bool isUsed[20];
123 | void createVirtualMemoryBlock(QString pid,int ranking);
124 | void initvirtualMemory();
125 | void replacePage(QString pid,int page);
126 | void freeMemory(QString pid);
127 |
128 | int* disk_sheduling(QVector disk_visit_Queue);
129 | void ShowDiskTrack(int track_num);
130 | ~Disk();
131 |
132 |
133 |
134 | //文件扩充
135 | void fileExband(QString policy,QString filename,QString exbandType,QString exbanSize);
136 | //文件扩大
137 | void fileToMore(QString policy,QString filename,QString exbanSize);
138 | //文件缩小
139 | void fileToFew(QString policy,QString filename,QString exbanSize);
140 |
141 | //磁盘分配文件内存
142 | void distrcFileSpace(int id,QString name,int size,QString);
143 |
144 | //************************* 新加
145 | //连续分配
146 | void conFileDistrc(int id,QString name,int size,QString);
147 | //显示链接
148 | void fatFileDistrc(int id,QString name,int size,QString);
149 | //索引分配
150 | void indexFileDistrc(int id,QString name,int size,QString);
151 | //************************* 新加
152 |
153 | //获取文件磁盘块序列
154 |
155 | //生成磁盘调度窗口
156 | void geentFileSeekWind(QString filename,QString policy);
157 | //释放磁盘空间
158 | void releaseSpace(QString filename,QString policy);
159 | //在空闲表中分配磁盘块 nextId
160 | void disrtSpaceInFreeTable(int nextId);
161 |
162 | //************************* 新加
163 | //______________________________
164 | //设置占用块
165 | void setBlockBeFull(int start,int end);
166 | //给文件夹分配空间
167 | void getSpaceToFolder();
168 | //返回磁盘块表
169 | QTableWidget *getBlockTable();
170 | //占用磁盘块颜色
171 | void getBlockColor(int j);
172 | //释放磁盘块颜色
173 | void releaseTabBlockColor(int j);
174 | //初始化空闲空间表数据
175 | void flushFreeBlockTab();
176 | //显示磁盘块信息
177 | void showBlockInfo();
178 | //显示空闲空间数据
179 | void showFreeData();
180 | //************************* 新加
181 |
182 |
183 |
184 |
185 | QString diskID;
186 |
187 | QVectordiskBlock;//磁盘块列表
188 |
189 | //文件策略表
190 | QVector fpol;
191 | // **************** 连续分配 *********
192 | //文件目录
193 | QVectorconfiledir;
194 | QVectorfileBlocks;
195 | // **************** 连续分配 *********
196 |
197 | QVectorfreeblockTab;//空闲空间列表
198 |
199 | // **************** FAT *********
200 | //FAT 目录列表
201 | QVectorfatDir;
202 | QVectorFat;
203 | // **************** FAT *********
204 |
205 | // **************** 索引分配 *********
206 | QVectorindexFileDir;//索引文件目录
207 | QVectorindexFiles;//虚拟磁盘映射
208 | // **************** 索引分配 *********
209 |
210 | //窗口
211 | conFileSpaceDetail *confDetailWind;
212 | fatFileSpaceDetail *fatDetailWind;
213 | indexFileSpaceDetail *indexfDetailWind;
214 | showFileSeekOder *showFileSeekWind;//磁盘调度窗口
215 | freeBlockTable *freeblobktab;//空闲空间列表窗口
216 |
217 | public slots:
218 |
219 | //查看某一文件的磁盘分配情况
220 | void LookFileSpace(int id,QString name,QString type,QString pos,int size,QString time);
221 |
222 |
223 | private:
224 | Ui::Disk *ui;
225 | };
226 |
227 | #endif // DISK_H
228 |
--------------------------------------------------------------------------------
/disk/disk.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Disk
4 |
5 |
6 |
7 | 0
8 | 0
9 | 710
10 | 240
11 |
12 |
13 |
14 |
15 | 710
16 | 240
17 |
18 |
19 |
20 | Form
21 |
22 |
23 |
24 |
25 | 160
26 | 10
27 | 72
28 | 15
29 |
30 |
31 |
32 | 磁盘状态
33 |
34 |
35 |
36 |
37 |
38 | 425
39 | 31
40 | 291
41 | 211
42 |
43 |
44 |
45 |
46 |
47 |
48 | 550
49 | 10
50 | 69
51 | 20
52 |
53 |
54 |
55 | 虚拟内存
56 |
57 |
58 |
59 |
60 |
61 | 0
62 | 30
63 | 421
64 | 221
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/disk/fatfilespacedetail.cpp:
--------------------------------------------------------------------------------
1 | #include "fatfilespacedetail.h"
2 | #include "ui_fatfilespacedetail.h"
3 |
4 | fatFileSpaceDetail::fatFileSpaceDetail(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::fatFileSpaceDetail)
7 | {
8 | ui->setupUi(this);
9 | this->setWindowTitle("显式链接分配详情");
10 | ui->fat_tab->verticalHeader()->setVisible(false);
11 | ui->fat_dir_tab->verticalHeader()->setVisible(false);
12 | }
13 |
14 | fatFileSpaceDetail::~fatFileSpaceDetail()
15 | {
16 | delete ui;
17 | }
18 |
19 | QTableWidget *fatFileSpaceDetail::getFatTableWidget()
20 | {
21 | return ui->fat_tab;
22 | }
23 |
24 | QTableWidget *fatFileSpaceDetail::getFatDirTableWidget()
25 | {
26 | return ui->fat_dir_tab;
27 | }
28 |
--------------------------------------------------------------------------------
/disk/fatfilespacedetail.h:
--------------------------------------------------------------------------------
1 | #ifndef FATFILESPACEDETAIL_H
2 | #define FATFILESPACEDETAIL_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | namespace Ui {
9 | class fatFileSpaceDetail;
10 | }
11 |
12 | class fatFileSpaceDetail : public QWidget
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | explicit fatFileSpaceDetail(QWidget *parent = nullptr);
18 | ~fatFileSpaceDetail();
19 | QTableWidget *getFatTableWidget();
20 | QTableWidget *getFatDirTableWidget();
21 | private:
22 | Ui::fatFileSpaceDetail *ui;
23 | };
24 |
25 | #endif // FATFILESPACEDETAIL_H
26 |
--------------------------------------------------------------------------------
/disk/fatfilespacedetail.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | fatFileSpaceDetail
4 |
5 |
6 |
7 | 0
8 | 0
9 | 670
10 | 673
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 10
20 | 20
21 | 121
22 | 18
23 |
24 |
25 |
26 | 目录结构 :
27 |
28 |
29 |
30 |
31 |
32 | 10
33 | 50
34 | 651
35 | 101
36 |
37 |
38 |
39 |
40 |
41 |
42 | 10
43 | 168
44 | 131
45 | 20
46 |
47 |
48 |
49 | FAT 表 :
50 |
51 |
52 |
53 |
54 |
55 | 10
56 | 190
57 | 651
58 | 471
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/disk/freeblocktable.cpp:
--------------------------------------------------------------------------------
1 | #include "freeblocktable.h"
2 | #include "ui_freeblocktable.h"
3 |
4 | freeBlockTable::freeBlockTable(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::freeBlockTable)
7 | {
8 | ui->setupUi(this);
9 | //***************** 空闲空间列表
10 | QTableWidget *tbd=ui->freeblock_tab;
11 | tbd->verticalHeader()->setVisible(false);
12 | tbd->setColumnCount(2);
13 | tbd->setRowCount(200);
14 | //设置表头
15 | QTableWidgetItem *h11=new QTableWidgetItem("连续块起始");
16 | QFont fontt=h11->font();//获取原有字体设置
17 | fontt.setBold(true);//设置为粗体
18 | fontt.setPointSize(8);//字体大小
19 | h11->setBackground(Qt::blue);//字体颜色
20 | // h11->setBackground(Qt::blue);
21 | h11->setFont(fontt);//设置字体
22 | tbd->setHorizontalHeaderItem(0,h11);
23 | QTableWidgetItem *h22=new QTableWidgetItem("块数");
24 | h22->setBackground(Qt::blue);;//字体颜色
25 | h22->setFont(fontt);//设置字体
26 | tbd->setHorizontalHeaderItem(1,h22);
27 | }
28 |
29 | freeBlockTable::~freeBlockTable()
30 | {
31 | delete ui;
32 | }
33 |
34 | QTableWidget *freeBlockTable::getFreeBlockTable()
35 | {
36 | return ui->freeblock_tab;
37 | }
38 |
--------------------------------------------------------------------------------
/disk/freeblocktable.h:
--------------------------------------------------------------------------------
1 | #ifndef FREEBLOCKTABLE_H
2 | #define FREEBLOCKTABLE_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | namespace Ui {
9 | class freeBlockTable;
10 | }
11 |
12 | class freeBlockTable : public QWidget
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | explicit freeBlockTable(QWidget *parent = nullptr);
18 | ~freeBlockTable();
19 | QTableWidget *getFreeBlockTable();
20 | private:
21 | Ui::freeBlockTable *ui;
22 | };
23 |
24 | #endif // FREEBLOCKTABLE_H
25 |
--------------------------------------------------------------------------------
/disk/freeblocktable.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | freeBlockTable
4 |
5 |
6 |
7 | 0
8 | 0
9 | 462
10 | 626
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 10
20 | 10
21 | 151
22 | 18
23 |
24 |
25 |
26 | 空闲空间列表 :
27 |
28 |
29 |
30 |
31 |
32 | 10
33 | 30
34 | 441
35 | 591
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/disk/indexfilespacedetail.cpp:
--------------------------------------------------------------------------------
1 | #include "indexfilespacedetail.h"
2 | #include "ui_indexfilespacedetail.h"
3 |
4 | indexFileSpaceDetail::indexFileSpaceDetail(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::indexFileSpaceDetail)
7 | {
8 | ui->setupUi(this);
9 | this->setWindowTitle("索引分配详情");
10 | ui->indexf_dir_tab->verticalHeader()->setVisible(false);
11 | ui->indexblock_tab->verticalHeader()->setVisible(false);
12 | }
13 |
14 | indexFileSpaceDetail::~indexFileSpaceDetail()
15 | {
16 | delete ui;
17 | }
18 |
19 | QTableWidget *indexFileSpaceDetail::getindexFileTable()
20 | {
21 | return ui->indexblock_tab;
22 | }
23 |
24 | QTableWidget *indexFileSpaceDetail::getindexFileDirTable()
25 | {
26 | return ui->indexf_dir_tab;
27 | }
28 |
--------------------------------------------------------------------------------
/disk/indexfilespacedetail.h:
--------------------------------------------------------------------------------
1 | #ifndef INDEXFILESPACEDETAIL_H
2 | #define INDEXFILESPACEDETAIL_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | namespace Ui {
9 | class indexFileSpaceDetail;
10 | }
11 |
12 | class indexFileSpaceDetail : public QWidget
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | explicit indexFileSpaceDetail(QWidget *parent = nullptr);
18 | ~indexFileSpaceDetail();
19 | QTableWidget *getindexFileTable();
20 | QTableWidget *getindexFileDirTable();
21 | private:
22 | Ui::indexFileSpaceDetail *ui;
23 | };
24 |
25 | #endif // INDEXFILESPACEDETAIL_H
26 |
--------------------------------------------------------------------------------
/disk/indexfilespacedetail.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | indexFileSpaceDetail
4 |
5 |
6 |
7 | 0
8 | 0
9 | 624
10 | 587
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 10
20 | 20
21 | 131
22 | 18
23 |
24 |
25 |
26 | 目录结构 :
27 |
28 |
29 |
30 |
31 |
32 | 10
33 | 40
34 | 611
35 | 91
36 |
37 |
38 |
39 |
40 |
41 |
42 | 10
43 | 160
44 | 141
45 | 18
46 |
47 |
48 |
49 | 索引块结构 :
50 |
51 |
52 |
53 |
54 |
55 | 10
56 | 180
57 | 611
58 | 401
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/disk/showfileseekoder.cpp:
--------------------------------------------------------------------------------
1 | #include "showfileseekoder.h"
2 | #include "ui_showfileseekoder.h"
3 |
4 | showFileSeekOder::showFileSeekOder(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::showFileSeekOder)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | showFileSeekOder::~showFileSeekOder()
12 | {
13 | delete ui;
14 | }
15 |
16 | void showFileSeekOder::fileDispatch(QVector blockCyIdOrder)
17 | {
18 | // blockCyIdOrder 相当于数组,里面的元素为 int 行,依次为 磁道 号序列
19 | // 访问方式 blockCyIdOrder[下标]
20 | // 例如:输出每个元素
21 | qDebug()<<"连续文件 磁道号 ";
22 | for (int i=0;i
5 | #include
6 | #include
7 | namespace Ui {
8 | class showFileSeekOder;
9 | }
10 |
11 | class showFileSeekOder : public QWidget
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit showFileSeekOder(QWidget *parent = nullptr);
17 | ~showFileSeekOder();
18 | void fileDispatch(QVector blockCyIdOrder);
19 | private:
20 | Ui::showFileSeekOder *ui;
21 | };
22 |
23 | #endif // SHOWFILESEEKODER_H
24 |
--------------------------------------------------------------------------------
/disk/showfileseekoder.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | showFileSeekOder
4 |
5 |
6 |
7 | 0
8 | 0
9 | 460
10 | 526
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 190
20 | 50
21 | 112
22 | 34
23 |
24 |
25 |
26 | PushButton
27 |
28 |
29 |
30 |
31 |
32 | 70
33 | 130
34 | 321
35 | 25
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/equipment/dequip.cpp:
--------------------------------------------------------------------------------
1 | #include "dequip.h"
2 | #include "ui_dequip.h"
3 |
4 | Dequip::Dequip(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::Dequip)
7 | {
8 | peCount = 0;
9 | ui->setupUi(this);
10 | for (int i = 0; i < 24; i++){
11 | Finished[i] = false;
12 | newFinished[i] = false;
13 | }
14 | ui->tableWidget->setColumnCount(17);
15 | ui->tableWidget->setRowCount(24);
16 | ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"进程id"<<"蓝牙需求数"<<"键盘需求数"<<"鼠标需求数"<<"打印机需求数"<<"蓝牙已得数"<<"键盘已得数"<<"鼠标已得数"<<"打印机已得数"<<"蓝牙仍需数"<<"键盘仍需数"<<"鼠标仍需数"<<"打印机仍需数"<<"蓝牙剩余数"<<"键盘剩余数"<<"鼠标剩余数"<<"打印机剩余数");
17 | ui->tableWidget->setAlternatingRowColors(true);
18 | ui->tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{background:skyblue;}");
19 | for (int i = 0; i < 24; i++){
20 | for (int j = 0; j < 17; j++){
21 | ui->tableWidget->setItem(i,j,new QTableWidgetItem(" "));
22 | }
23 | }
24 | for (int j = 1; j < 5; j++){
25 | for (int i = 0; i < 24; i++){
26 | ui->tableWidget->item(i,j)->setBackgroundColor(Qt::gray);
27 | }
28 | }
29 | for (int j = 5; j < 9; j++){
30 | for (int i = 0; i < 24; i++){
31 | ui->tableWidget->item(i,j)->setBackgroundColor(Qt::white);
32 | }
33 | }
34 | for (int j = 9; j < 13; j++){
35 | for (int i = 0; i < 24; i++){
36 | ui->tableWidget->item(i,j)->setBackgroundColor(Qt::gray);
37 | }
38 | }
39 | for (int j = 13; j < 17; j++){
40 | for (int i = 0; i < 24; i++){
41 | ui->tableWidget->item(i,j)->setBackgroundColor(Qt::white);
42 | }
43 | }
44 |
45 | }
46 |
47 | Dequip::~Dequip()
48 | {
49 | delete ui;
50 | }
51 | void Dequip::compareSlot(int requestData[], int pId, int time){
52 | if (requestData[0] <= ui->tableWidget->item(pId,9)->text().toInt() && requestData[1] <= ui->tableWidget->item(pId,10)->text().toInt() && requestData[2] <= ui->tableWidget->item(pId,11)->text().toInt() && requestData[3] <= ui->tableWidget->item(pId,12)->text().toInt()){
53 | if (requestData[0] <= ui->tableWidget->item(0,13)->text().toInt() && requestData[1] <= ui->tableWidget->item(0,14)->text().toInt() && requestData[2] <= ui->tableWidget->item(0,15)->text().toInt() && requestData[3] <= ui->tableWidget->item(0,16)->text().toInt()){
54 | //执行安全性算法
55 | for (int i = 0; i < 4; i ++){
56 | ui->tableWidget->setItem(0, i+13, new QTableWidgetItem(QString::number(ui->tableWidget->item(0, i+13)->text().toInt()-requestData[i])));
57 | }
58 | if (security(pId)){
59 | QMessageBox::information(this, "提示", "安全性算法检测通过!");
60 | Finished[pId] = true;
61 | //更新剩余资源数
62 | for (int i = 0; i < 4; i++){
63 | ui->tableWidget->setItem(pId, i+5, new QTableWidgetItem(QString::number(ui->tableWidget->item(pId, i+5)->text().toInt() + requestData[i])));
64 | ui->tableWidget->setItem(pId, i+9, new QTableWidgetItem(QString::number(ui->tableWidget->item(pId, i+9)->text().toInt() - requestData[i])));
65 | }
66 | myTimerId = this->startTimer(time);
67 | pe[peCount].timeId = myTimerId;
68 | pe[peCount].pId = pId;
69 | peCount++;
70 | QMessageBox::information(this,"提示","请求占用资源成功,该进程占用资源"+QString::number(time)+"毫秒");
71 | }
72 | else{
73 | for (int i = 0; i < 4; i ++){
74 | ui->tableWidget->setItem(0, i+13, new QTableWidgetItem(QString::number(ui->tableWidget->item(0, i+13)->text().toInt()+requestData[i])));
75 | }
76 | QMessageBox::warning(this, "警告", "安全性算法不通过,拒绝分配!");
77 | return;
78 | }
79 | }
80 | else{
81 | QMessageBox::warning(this,"警告","系统剩余资源数不足,进程阻塞!");
82 | emit sendWaitToWidget(pId);
83 | }
84 | }
85 | else{
86 | QMessageBox::warning(this,"警告","请求资源数大于所需资源数,拒绝请求!");
87 | }
88 | }
89 |
90 | void Dequip::on_requestButton_clicked()
91 | {
92 | request *re = new request;
93 | re->show();
94 | connect(re, &request::sendToDequip, this,&Dequip::compareSlot);
95 | }
96 |
97 | void Dequip::timerEvent(QTimerEvent *event){
98 | for (int i = 0; i < 500; i++){
99 | if (event->timerId() == pe[i].timeId){
100 | for (int j = 0; j < 4; j++){
101 | ui->tableWidget->setItem(0, j+13, new QTableWidgetItem(QString::number(ui->tableWidget->item(0, j+13)->text().toInt()+ui->tableWidget->item(pe[i].pId, j+5)->text().toInt())));
102 | ui->tableWidget->setItem(pe[i].pId, j+5, new QTableWidgetItem("0"));
103 | ui->tableWidget->setItem(pe[i].pId, j+9, new QTableWidgetItem("0"));
104 | }
105 | QMessageBox::information(this, "提示", "进程占用资源结束,该进程占有的所有资源已归还");
106 | this->killTimer(pe[i].timeId);
107 | }
108 | }
109 |
110 | }
111 | //安全性算法
112 | bool Dequip::security(int pId){
113 | int oldData[4];
114 | for (int i = 0; i < 4; i++){
115 | oldData[i] = ui->tableWidget->item(0, i + 13)->text().toInt();
116 | }
117 | while(true){
118 | bool isSame = true;
119 | for (int i = 0; i < 24; i++){
120 | bool isOk = true;
121 | if (i == pId)continue;
122 | if (Finished[i] == true) continue; //如果当前进程已分配,则继续循环
123 | for (int j = 0; j < 4; j++){
124 | if (ui->tableWidget->item(i, j + 9)->text().toInt() > ui->tableWidget->item(0, j + 13)->text().toInt()){
125 | isOk = false;
126 | }
127 | }
128 | if (isOk == true){
129 | newFinished[i] = true;
130 | for (int j = 0; j < 4; j++){
131 | ui->tableWidget->setItem(0, j+13, new QTableWidgetItem(QString::number(ui->tableWidget->item(i, j + 5)->text().toInt() + ui->tableWidget->item(0, j + 13)->text().toInt())));
132 | }
133 | }
134 | }
135 | for (int i = 0; i < 24; i++){
136 | if (Finished[i] != newFinished[i]){
137 | isSame = false;
138 | for (int j = 0; j < 24; j++){
139 | Finished[j] = newFinished[j];
140 | }
141 | }
142 | }
143 | if (isSame == true){
144 | break;
145 | }
146 | }
147 | for (int i = 0; i < 4; i++){
148 | ui->tableWidget->setItem(0, i+13, new QTableWidgetItem(QString::number(oldData[i])));
149 | }
150 | for (int i = 0; i < 24; i++){
151 | if (i == pId) continue;
152 | if (Finished[i] == false){
153 | for (int j = 0; j < 24; j++){
154 | //qDebug() <
5 | #include "request.h"
6 | #include
7 | #include
8 | namespace Ui {
9 | class Dequip;
10 | }
11 |
12 | class Dequip : public QWidget
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | explicit Dequip(QWidget *parent = 0);
18 | Ui::Dequip *ui;
19 | virtual void timerEvent(QTimerEvent *event);
20 | ~Dequip();
21 | bool security(int pId);
22 | bool Finished[24];
23 | bool newFinished[24];
24 | signals:
25 | void sendWaitToWidget(int pId);
26 | private slots:
27 | void on_requestButton_clicked();
28 | void compareSlot(int requestData[], int pId, int time);
29 |
30 | private:
31 | int myTimerId;
32 | struct Pevent{
33 | int timeId;
34 | int pId;
35 | }pe[500];
36 | int peCount;
37 | };
38 |
39 | #endif // DEQUIP_H
40 |
--------------------------------------------------------------------------------
/equipment/dequip.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Dequip
4 |
5 |
6 |
7 | 0
8 | 0
9 | 1771
10 | 891
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 20
20 | 20
21 | 1731
22 | 771
23 |
24 |
25 |
26 |
27 |
28 |
29 | 810
30 | 810
31 | 171
32 | 41
33 |
34 |
35 |
36 | 发出请求
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/equipment/myprocess.cpp:
--------------------------------------------------------------------------------
1 | #include "myprocess.h"
2 | #include "ui_myprocess.h"
3 |
4 | myProcess::myProcess(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::myProcess)
7 | {
8 | ui->setupUi(this);
9 | ui->blueEdit->setReadOnly(true);
10 | ui->pIdEdit->setReadOnly(true);
11 | ui->printEdit->setReadOnly(true);
12 | ui->mouseEdit->setReadOnly(true);
13 | ui->keyEdit->setReadOnly(true);
14 | }
15 |
16 | myProcess::~myProcess()
17 | {
18 | delete ui;
19 | }
20 |
21 | void myProcess::on_backbutton_clicked()
22 | {
23 | myProcess::close();
24 | }
25 |
--------------------------------------------------------------------------------
/equipment/myprocess.h:
--------------------------------------------------------------------------------
1 | #ifndef MYPROCESS_H
2 | #define MYPROCESS_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class myProcess;
8 | }
9 |
10 | class myProcess : public QWidget
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit myProcess(QWidget *parent = 0);
16 | Ui::myProcess *ui;
17 | ~myProcess();
18 |
19 | private slots:
20 | void on_backbutton_clicked();
21 | private:
22 |
23 | };
24 |
25 | #endif // MYPROCESS_H
26 |
--------------------------------------------------------------------------------
/equipment/myprocess.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | myProcess
4 |
5 |
6 |
7 | 0
8 | 0
9 | 370
10 | 418
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 130
20 | 10
21 | 101
22 | 41
23 |
24 |
25 |
26 | <html><head/><body><p><span style=" font-size:16pt; font-weight:600;">进程详情</span></p></body></html>
27 |
28 |
29 |
30 |
31 |
32 | 150
33 | 360
34 | 75
35 | 23
36 |
37 |
38 |
39 | 返回
40 |
41 |
42 |
43 |
44 |
45 | 80
46 | 50
47 | 211
48 | 301
49 |
50 |
51 |
52 | -
53 |
54 |
-
55 |
56 |
57 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">pId</span></p></body></html>
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 | 50
66 | 0
67 |
68 |
69 |
70 |
71 | 50
72 | 16777215
73 |
74 |
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
-
82 |
83 |
84 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">bluetooth</span></p></body></html>
85 |
86 |
87 |
88 | -
89 |
90 |
91 |
92 | 50
93 | 0
94 |
95 |
96 |
97 |
98 | 50
99 | 16777215
100 |
101 |
102 |
103 |
104 |
105 |
106 | -
107 |
108 |
-
109 |
110 |
111 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">print</span></p></body></html>
112 |
113 |
114 |
115 | -
116 |
117 |
118 |
119 | 50
120 | 0
121 |
122 |
123 |
124 |
125 | 50
126 | 16777215
127 |
128 |
129 |
130 |
131 |
132 |
133 | -
134 |
135 |
-
136 |
137 |
138 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">mouse</span></p></body></html>
139 |
140 |
141 |
142 | -
143 |
144 |
145 |
146 | 50
147 | 0
148 |
149 |
150 |
151 |
152 | 50
153 | 16777215
154 |
155 |
156 |
157 |
158 |
159 |
160 | -
161 |
162 |
-
163 |
164 |
165 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">keyboard</span></p></body></html>
166 |
167 |
168 |
169 | -
170 |
171 |
172 |
173 | 50
174 | 0
175 |
176 |
177 |
178 |
179 | 50
180 | 16777215
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
--------------------------------------------------------------------------------
/equipment/request.cpp:
--------------------------------------------------------------------------------
1 | #include "request.h"
2 | #include "ui_request.h"
3 |
4 | request::request(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::request)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | request::~request()
12 | {
13 | delete ui;
14 | }
15 |
16 | void request::on_requestButton_clicked()
17 | {
18 | if (ui->blueEdit->text().isEmpty()||ui->keyEdit->text().isEmpty()||ui->mouseEdit->text().isEmpty()||ui->printEdit->text().isEmpty()){
19 | QMessageBox::warning(this,"警告","请求资源不能为空!");
20 | request::close();
21 | }
22 | requestId = ui->idEdit->text().toInt();
23 | requestBlue = ui->blueEdit->text().toInt();
24 | requestKey = ui->keyEdit->text().toInt();
25 | requestMouse = ui->mouseEdit->text().toInt();
26 | requestPrint = ui->printEdit->text().toInt();
27 | requestTime = ui->timeEdit->text().toInt();
28 | int requestData[5];
29 | requestData[0] = requestBlue;
30 | requestData[1] = requestKey;
31 | requestData[2] = requestMouse;
32 | requestData[3] = requestPrint;
33 | emit sendToDequip(requestData, requestId, requestTime);
34 | request::close();
35 | }
36 |
--------------------------------------------------------------------------------
/equipment/request.h:
--------------------------------------------------------------------------------
1 | #ifndef REQUEST_H
2 | #define REQUEST_H
3 |
4 | #include
5 | #include
6 | #include "dequip.h"
7 | #include "ui_dequip.h"
8 | #include "widget.h"
9 | #include
10 | namespace Ui {
11 | class request;
12 | }
13 |
14 | class request : public QWidget
15 | {
16 | Q_OBJECT
17 |
18 | public:
19 | explicit request(QWidget *parent = 0);
20 | Ui::request *ui;
21 | ~request();
22 | int requestId;
23 | int requestBlue;
24 | int requestKey;
25 | int requestMouse;
26 | int requestPrint;
27 | int requestTime;
28 | signals:
29 | void sendToDequip(int requestData[], int pId, int time);
30 | private slots:
31 | void on_requestButton_clicked();
32 | private:
33 |
34 | };
35 |
36 | #endif // REQUEST_H
37 |
--------------------------------------------------------------------------------
/equipment/request.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | request
4 |
5 |
6 |
7 | 0
8 | 0
9 | 452
10 | 539
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 170
20 | 10
21 | 111
22 | 41
23 |
24 |
25 |
26 | <html><head/><body><p align="center"><span style=" font-size:16pt; font-weight:600;">进程请求</span></p></body></html>
27 |
28 |
29 |
30 |
31 |
32 | 160
33 | 490
34 | 101
35 | 41
36 |
37 |
38 |
39 | 发送请求
40 |
41 |
42 |
43 |
44 |
45 | 50
46 | 100
47 | 296
48 | 350
49 |
50 |
51 |
52 | -
53 |
54 |
-
55 |
56 |
-
57 |
58 |
59 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">进程id(只需输入数字):</span></p></body></html>
60 |
61 |
62 |
63 | -
64 |
65 |
66 |
67 | 80
68 | 0
69 |
70 |
71 |
72 |
73 | 80
74 | 16777215
75 |
76 |
77 |
78 |
79 |
80 |
81 | -
82 |
83 |
84 | Qt::Vertical
85 |
86 |
87 |
88 | 20
89 | 40
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
-
97 |
98 |
99 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">请输入请求蓝牙资源数:</span></p></body></html>
100 |
101 |
102 |
103 | -
104 |
105 |
106 |
107 | 80
108 | 0
109 |
110 |
111 |
112 |
113 | 80
114 | 16777215
115 |
116 |
117 |
118 |
119 |
120 |
121 | -
122 |
123 |
124 | Qt::Vertical
125 |
126 |
127 |
128 | 20
129 | 40
130 |
131 |
132 |
133 |
134 | -
135 |
136 |
-
137 |
138 |
139 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">请输入请求键盘资源数:</span></p></body></html>
140 |
141 |
142 |
143 | -
144 |
145 |
146 |
147 | 80
148 | 0
149 |
150 |
151 |
152 |
153 | 80
154 | 16777215
155 |
156 |
157 |
158 |
159 |
160 |
161 | -
162 |
163 |
164 | Qt::Vertical
165 |
166 |
167 |
168 | 20
169 | 40
170 |
171 |
172 |
173 |
174 | -
175 |
176 |
-
177 |
178 |
179 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">请输入请求鼠标资源数:</span></p></body></html>
180 |
181 |
182 |
183 | -
184 |
185 |
186 |
187 | 80
188 | 0
189 |
190 |
191 |
192 |
193 | 80
194 | 16777215
195 |
196 |
197 |
198 |
199 |
200 |
201 | -
202 |
203 |
204 | Qt::Vertical
205 |
206 |
207 |
208 | 20
209 | 40
210 |
211 |
212 |
213 |
214 | -
215 |
216 |
-
217 |
218 |
219 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">请输入请求打印机资源数:</span></p></body></html>
220 |
221 |
222 |
223 | -
224 |
225 |
226 |
227 | 80
228 | 0
229 |
230 |
231 |
232 |
233 | 80
234 | 16777215
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 | -
244 |
245 |
246 | Qt::Vertical
247 |
248 |
249 |
250 | 20
251 | 40
252 |
253 |
254 |
255 |
256 | -
257 |
258 |
-
259 |
260 |
261 | <html><head/><body><p align="center"><span style=" font-size:12pt; font-weight:600;">请输入资源占有时间(ms)</span></p></body></html>
262 |
263 |
264 |
265 | -
266 |
267 |
268 |
269 | 80
270 | 0
271 |
272 |
273 |
274 |
275 | 80
276 | 16777215
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
--------------------------------------------------------------------------------
/equipment/widget.cpp:
--------------------------------------------------------------------------------
1 | #include "widget.h"
2 | #include "ui_widget.h"
3 | Widget::Widget(QWidget *parent) :
4 | QWidget(parent),
5 | ui(new Ui::Widget)
6 | {
7 | srand((unsigned)time(NULL));
8 | ui->setupUi(this);
9 | totalBluetooth = 200;
10 | totalKeyboard = 200;
11 | totalMouse = 200;
12 | totalPrint = 200;
13 | reBlue = 200;
14 | reKey = 200;
15 | reMouse = 200;
16 | rePrint = 200;
17 | for (int i = 0; i < 24; i++){
18 | proc[i].getBluetooth = 0;
19 | proc[i].getKey = 0;
20 | proc[i].getMouse = 0;
21 | proc[i].getPrint = 0;
22 | }
23 | ui->tableWidget->setColumnCount(5);
24 | ui->tableWidget->horizontalHeader()->setDefaultSectionSize(80);
25 | ui->tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
26 | ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"进程序列"<<"蓝牙资源数"<<"键盘资源数"<<"鼠标资源数"<<"打印机资源数");
27 | ui->tableWidget->setRowCount(24);
28 | }
29 |
30 | Widget::~Widget()
31 | {
32 | delete ui;
33 | }
34 |
35 | void Widget::on_createPro_clicked()
36 | {
37 | for (int i = 0; i < 24; i++){
38 | proc[i].pId = i;
39 | proc[i].bluetooth = rand() % 20;
40 | proc[i].getBluetooth = rand() % 5;
41 | while (proc[i].getBluetooth > proc[i].bluetooth){
42 | proc[i].getBluetooth = rand() % 5;
43 | }
44 | proc[i].keyboard = rand() % 20;
45 | proc[i].getKey = rand() % 5;
46 | while (proc[i].getKey > proc[i].keyboard){
47 | proc[i].getKey = rand() % 5;
48 | }
49 | proc[i].mouse = rand() % 20;
50 | proc[i].getMouse = rand() % 5;
51 | while (proc[i].getMouse > proc[i].mouse){
52 | proc[i].getMouse = rand() % 5;
53 | }
54 | proc[i].print = rand() % 20;
55 | proc[i].getPrint = rand() % 5;
56 | while (proc[i].getPrint > proc[i].print){
57 | proc[i].getPrint = rand() % 5;
58 | }
59 | //qDebug() << proc[i].bluetooth;
60 | }
61 | QMessageBox::information(this, "提示", "生成成功!");
62 | for (int i = 0; i < 24; i++){
63 | ui->tableWidget->setItem(i,0,new QTableWidgetItem("p"+QString::number(proc[i].pId)));
64 | ui->tableWidget->setItem(i,1,new QTableWidgetItem(QString::number(proc[i].bluetooth)));
65 | ui->tableWidget->setItem(i,2,new QTableWidgetItem(QString::number(proc[i].keyboard)));
66 | ui->tableWidget->setItem(i,3,new QTableWidgetItem(QString::number(proc[i].mouse)));
67 | ui->tableWidget->setItem(i,4,new QTableWidgetItem(QString::number(proc[i].print)));
68 | }
69 |
70 | }
71 |
72 | void Widget::on_closeButton_clicked()
73 | {
74 | Widget::close();
75 | }
76 |
77 |
78 | void Widget::on_pro1_clicked()
79 | {
80 | myProcess *p = new myProcess;
81 | p->show();
82 | p->ui->pIdEdit->setText("p"+QString::number(proc[0].pId));
83 | p->ui->blueEdit->setText(QString::number(proc[0].bluetooth));
84 | p->ui->keyEdit->setText(QString::number(proc[0].keyboard));
85 | p->ui->mouseEdit->setText(QString::number(proc[0].mouse));
86 | p->ui->printEdit->setText(QString::number(proc[0].print));
87 | }
88 |
89 | void Widget::on_pro2_clicked()
90 | {
91 | myProcess *p = new myProcess;
92 | p->show();
93 | p->ui->pIdEdit->setText("p"+QString::number(proc[1].pId));
94 | p->ui->blueEdit->setText(QString::number(proc[1].bluetooth));
95 | p->ui->keyEdit->setText(QString::number(proc[1].keyboard));
96 | p->ui->mouseEdit->setText(QString::number(proc[1].mouse));
97 | p->ui->printEdit->setText(QString::number(proc[1].print));
98 |
99 |
100 | }
101 |
102 | void Widget::on_pro3_clicked()
103 | {
104 | myProcess *p = new myProcess;
105 | p->show();
106 | p->ui->pIdEdit->setText("p"+QString::number(proc[2].pId));
107 | p->ui->keyEdit->setText(QString::number(proc[2].keyboard));
108 | p->ui->blueEdit->setText(QString::number(proc[2].bluetooth));
109 | p->ui->mouseEdit->setText(QString::number(proc[2].mouse));
110 | p->ui->printEdit->setText(QString::number(proc[2].print));
111 | }
112 |
113 | void Widget::on_pro4_clicked()
114 | {
115 | myProcess *p = new myProcess;
116 | p->show();
117 | p->ui->pIdEdit->setText("p"+QString::number (proc[3].pId));
118 | p->ui->keyEdit->setText(QString::number (proc[3].keyboard));
119 | p->ui->blueEdit->setText(QString::number (proc[3].bluetooth));
120 | p->ui->mouseEdit->setText(QString::number (proc[3].mouse));
121 | p->ui->printEdit->setText(QString::number (proc[3].print));
122 | }
123 |
124 | void Widget::on_pro5_clicked()
125 | {
126 | myProcess *p = new myProcess;
127 | p->show();
128 | p->ui->pIdEdit->setText("p"+QString::number (proc[4].pId));
129 | p->ui->keyEdit->setText(QString::number (proc[4].keyboard));
130 | p->ui->blueEdit->setText(QString::number (proc[4].bluetooth));
131 | p->ui->mouseEdit->setText(QString::number (proc[4].mouse));
132 | p->ui->printEdit->setText(QString::number (proc[4].print));
133 |
134 | }
135 |
136 | void Widget::on_pro6_clicked()
137 | {
138 | myProcess *p = new myProcess;
139 | p->show();
140 | p->ui->pIdEdit->setText("p"+QString::number (proc[5].pId));
141 | p->ui->keyEdit->setText(QString::number (proc[5].keyboard));
142 | p->ui->blueEdit->setText(QString::number (proc[5].bluetooth));
143 | p->ui->mouseEdit->setText(QString::number (proc[5].mouse));
144 | p->ui->printEdit->setText(QString::number (proc[5].print));
145 |
146 | }
147 |
148 | void Widget::on_pro7_clicked()
149 | {
150 | myProcess *p = new myProcess;
151 | p->show();
152 | p->ui->pIdEdit->setText("p"+QString::number (proc[6].pId));
153 | p->ui->keyEdit->setText(QString::number (proc[6].keyboard));
154 | p->ui->blueEdit->setText(QString::number (proc[6].bluetooth));
155 | p->ui->mouseEdit->setText(QString::number (proc[6].mouse));
156 | p->ui->printEdit->setText(QString::number (proc[6].print));
157 |
158 | }
159 |
160 | void Widget::on_pro8_clicked()
161 | {
162 | myProcess *p = new myProcess;
163 | p->show();
164 | p->ui->pIdEdit->setText("p"+QString::number (proc[7].pId));
165 | p->ui->keyEdit->setText(QString::number (proc[7].keyboard));
166 | p->ui->blueEdit->setText(QString::number (proc[7].bluetooth));
167 | p->ui->mouseEdit->setText(QString::number (proc[7].mouse));
168 | p->ui->printEdit->setText(QString::number (proc[7].print));
169 | }
170 |
171 | void Widget::on_pro9_clicked()
172 | {
173 | myProcess *p = new myProcess;
174 | p->show();
175 | p->ui->pIdEdit->setText("p"+QString::number (proc[8].pId));
176 | p->ui->keyEdit->setText(QString::number (proc[8].keyboard));
177 | p->ui->blueEdit->setText(QString::number (proc[8].bluetooth));
178 | p->ui->mouseEdit->setText(QString::number (proc[8].mouse));
179 | p->ui->printEdit->setText(QString::number (proc[8].print));
180 | }
181 |
182 | void Widget::on_pro10_clicked()
183 | {
184 | myProcess *p = new myProcess;
185 | p->show();
186 | p->ui->pIdEdit->setText("p"+QString::number (proc[9].pId));
187 | p->ui->keyEdit->setText(QString::number (proc[9].keyboard));
188 | p->ui->blueEdit->setText(QString::number (proc[9].bluetooth));
189 | p->ui->mouseEdit->setText(QString::number (proc[9].mouse));
190 | p->ui->printEdit->setText(QString::number (proc[9].print));
191 | }
192 |
193 | void Widget::on_pro11_clicked()
194 | {
195 | myProcess *p = new myProcess;
196 | p->show();
197 | p->ui->pIdEdit->setText("p"+QString::number (proc[10].pId));
198 | p->ui->keyEdit->setText(QString::number (proc[10].keyboard));
199 | p->ui->blueEdit->setText(QString::number (proc[10].bluetooth));
200 | p->ui->mouseEdit->setText(QString::number (proc[10].mouse));
201 | p->ui->printEdit->setText(QString::number (proc[10].print));
202 | }
203 |
204 | void Widget::on_pro12_clicked()
205 | {
206 | myProcess *p = new myProcess;
207 | p->show();
208 | p->ui->pIdEdit->setText("p"+QString::number (proc[11].pId));
209 | p->ui->keyEdit->setText(QString::number (proc[11].keyboard));
210 | p->ui->blueEdit->setText(QString::number (proc[11].bluetooth));
211 | p->ui->mouseEdit->setText(QString::number (proc[11].mouse));
212 | p->ui->printEdit->setText(QString::number (proc[11].print));
213 | }
214 |
215 | void Widget::on_pro13_clicked()
216 | {
217 | myProcess *p = new myProcess;
218 | p->show();
219 | p->ui->pIdEdit->setText("p"+QString::number (proc[12].pId));
220 | p->ui->keyEdit->setText(QString::number (proc[12].keyboard));
221 | p->ui->blueEdit->setText(QString::number (proc[12].bluetooth));
222 | p->ui->mouseEdit->setText(QString::number (proc[12].mouse));
223 | p->ui->printEdit->setText(QString::number (proc[12].print));
224 | }
225 |
226 | void Widget::on_pro14_clicked()
227 | {
228 | myProcess *p = new myProcess;
229 | p->show();
230 | p->ui->pIdEdit->setText("p"+QString::number (proc[13].pId));
231 | p->ui->keyEdit->setText(QString::number (proc[13].keyboard));
232 | p->ui->blueEdit->setText(QString::number (proc[13].bluetooth));
233 | p->ui->mouseEdit->setText(QString::number (proc[13].mouse));
234 | p->ui->printEdit->setText(QString::number (proc[13].print));
235 | }
236 |
237 | void Widget::on_pro15_clicked()
238 | {
239 | myProcess *p = new myProcess;
240 | p->show();
241 | p->ui->pIdEdit->setText("p"+QString::number (proc[14].pId));
242 | p->ui->keyEdit->setText(QString::number (proc[14].keyboard));
243 | p->ui->blueEdit->setText(QString::number (proc[14].bluetooth));
244 | p->ui->mouseEdit->setText(QString::number (proc[14].mouse));
245 | p->ui->printEdit->setText(QString::number (proc[14].print));
246 | }
247 |
248 | void Widget::on_pro16_clicked()
249 | {
250 | myProcess *p = new myProcess;
251 | p->show();
252 | p->ui->pIdEdit->setText("p"+QString::number (proc[15].pId));
253 | p->ui->keyEdit->setText(QString::number (proc[15].keyboard));
254 | p->ui->blueEdit->setText(QString::number (proc[15].bluetooth));
255 | p->ui->mouseEdit->setText(QString::number (proc[15].mouse));
256 | p->ui->printEdit->setText(QString::number (proc[15].print));
257 | }
258 |
259 | void Widget::on_pro17_clicked()
260 | {
261 | myProcess *p = new myProcess;
262 | p->show();
263 | p->ui->pIdEdit->setText("p"+QString::number (proc[16].pId));
264 | p->ui->keyEdit->setText(QString::number (proc[16].keyboard));
265 | p->ui->blueEdit->setText(QString::number (proc[16].bluetooth));
266 | p->ui->mouseEdit->setText(QString::number (proc[16].mouse));
267 | p->ui->printEdit->setText(QString::number (proc[16].print));
268 | }
269 |
270 | void Widget::on_pro18_clicked()
271 | {
272 | myProcess *p = new myProcess;
273 | p->show();
274 | p->ui->pIdEdit->setText("p"+QString::number (proc[17].pId));
275 | p->ui->keyEdit->setText(QString::number (proc[17].keyboard));
276 | p->ui->blueEdit->setText(QString::number (proc[17].bluetooth));
277 | p->ui->mouseEdit->setText(QString::number (proc[17].mouse));
278 | p->ui->printEdit->setText(QString::number (proc[17].print));
279 | }
280 |
281 | void Widget::on_pro19_clicked()
282 | {
283 | myProcess *p = new myProcess;
284 | p->show();
285 | p->ui->pIdEdit->setText("p"+QString::number (proc[18].pId));
286 | p->ui->keyEdit->setText(QString::number (proc[18].keyboard));
287 | p->ui->blueEdit->setText(QString::number (proc[18].bluetooth));
288 | p->ui->mouseEdit->setText(QString::number (proc[18].mouse));
289 | p->ui->printEdit->setText(QString::number (proc[18].print));
290 | }
291 |
292 | void Widget::on_pro20_clicked()
293 | {
294 | myProcess *p = new myProcess;
295 | p->show();
296 | p->ui->pIdEdit->setText("p"+QString::number (proc[19].pId));
297 | p->ui->keyEdit->setText(QString::number (proc[19].keyboard));
298 | p->ui->blueEdit->setText(QString::number (proc[19].bluetooth));
299 | p->ui->mouseEdit->setText(QString::number (proc[19].mouse));
300 | p->ui->printEdit->setText(QString::number (proc[19].print));
301 | }
302 |
303 | void Widget::on_pro21_clicked()
304 | {
305 | myProcess *p = new myProcess;
306 | p->show();
307 | p->ui->pIdEdit->setText("p"+QString::number (proc[20].pId));
308 | p->ui->keyEdit->setText(QString::number (proc[20].keyboard));
309 | p->ui->blueEdit->setText(QString::number (proc[20].bluetooth));
310 | p->ui->mouseEdit->setText(QString::number (proc[20].mouse));
311 | p->ui->printEdit->setText(QString::number (proc[20].print));
312 | }
313 |
314 | void Widget::on_pro22_clicked()
315 | {
316 | myProcess *p = new myProcess;
317 | p->show();
318 | p->ui->pIdEdit->setText("p"+QString::number (proc[21].pId));
319 | p->ui->keyEdit->setText(QString::number (proc[21].keyboard));
320 | p->ui->blueEdit->setText(QString::number (proc[21].bluetooth));
321 | p->ui->mouseEdit->setText(QString::number (proc[21].mouse));
322 | p->ui->printEdit->setText(QString::number (proc[21].print));
323 | }
324 |
325 | void Widget::on_pro23_clicked()
326 | {
327 | myProcess *p = new myProcess;
328 | p->show();
329 | p->ui->pIdEdit->setText("p"+QString::number (proc[22].pId));
330 | p->ui->keyEdit->setText(QString::number (proc[22].keyboard));
331 | p->ui->blueEdit->setText(QString::number (proc[22].bluetooth));
332 | p->ui->mouseEdit->setText(QString::number (proc[22].mouse));
333 | p->ui->printEdit->setText(QString::number (proc[22].print));
334 | }
335 |
336 | void Widget::on_pro24_clicked()
337 | {
338 | myProcess *p = new myProcess;
339 | p->show();
340 | p->ui->pIdEdit->setText("p"+QString::number (proc[23].pId));
341 | p->ui->keyEdit->setText(QString::number (proc[23].keyboard));
342 | p->ui->blueEdit->setText(QString::number (proc[23].bluetooth));
343 | p->ui->mouseEdit->setText(QString::number (proc[23].mouse));
344 | p->ui->printEdit->setText(QString::number (proc[23].print));
345 | }
346 |
347 | void Widget::waitAppendSlot(int pId){
348 | wait.enqueue(proc[pId]);
349 | }
350 |
351 | void Widget::on_StartButton_clicked()
352 | {
353 | Dequip *dist = new Dequip;
354 | dist->show();
355 | for (int i = 0; i < 24; i++){
356 | dist->ui->tableWidget->setItem(i,0,new QTableWidgetItem("p"+QString::number(proc[i].pId)));
357 | dist->ui->tableWidget->setItem(i,1,new QTableWidgetItem(QString::number(proc[i].bluetooth)));
358 | dist->ui->tableWidget->setItem(i,2,new QTableWidgetItem(QString::number(proc[i].keyboard)));
359 | dist->ui->tableWidget->setItem(i,3,new QTableWidgetItem(QString::number(proc[i].mouse)));
360 | dist->ui->tableWidget->setItem(i,4,new QTableWidgetItem(QString::number(proc[i].print)));
361 | dist->ui->tableWidget->setItem(i,5,new QTableWidgetItem(QString::number(proc[i].getBluetooth)));
362 | dist->ui->tableWidget->setItem(i,6,new QTableWidgetItem(QString::number(proc[i].getKey)));
363 | dist->ui->tableWidget->setItem(i,7,new QTableWidgetItem(QString::number(proc[i].getMouse)));
364 | dist->ui->tableWidget->setItem(i,8,new QTableWidgetItem(QString::number(proc[i].getPrint)));
365 | dist->ui->tableWidget->setItem(i,9,new QTableWidgetItem(QString::number(proc[i].bluetooth-proc[i].getBluetooth)));
366 | dist->ui->tableWidget->setItem(i,10,new QTableWidgetItem(QString::number(proc[i].keyboard-proc[i].getKey)));
367 | dist->ui->tableWidget->setItem(i,11,new QTableWidgetItem(QString::number(proc[i].mouse-proc[i].getMouse)));
368 | dist->ui->tableWidget->setItem(i,12,new QTableWidgetItem(QString::number(proc[i].print-proc[i].getPrint)));
369 | int useBlue = 0;
370 | int useKey = 0;
371 | int useMouse = 0;
372 | int usePrint = 0;
373 | for (int i = 0; i < 24; i++){
374 | useBlue += proc[i].getBluetooth;
375 | useKey += proc[i].getKey;
376 | useMouse += proc[i].getMouse;
377 | usePrint += proc[i].getPrint;
378 | }
379 | reBlue = totalBluetooth - useBlue;
380 | reKey = totalKeyboard - useKey;
381 | reMouse = totalMouse - useMouse;
382 | rePrint = totalPrint - usePrint;
383 | }
384 | dist->ui->tableWidget->setItem(0,13,new QTableWidgetItem(QString::number(reBlue)));
385 | dist->ui->tableWidget->setItem(0,14,new QTableWidgetItem(QString::number(reKey)));
386 | dist->ui->tableWidget->setItem(0,15,new QTableWidgetItem(QString::number(reMouse)));
387 | dist->ui->tableWidget->setItem(0,16,new QTableWidgetItem(QString::number(rePrint)));
388 | connect(dist, &Dequip::sendWaitToWidget, this, &Widget::waitAppendSlot);
389 |
390 | }
391 |
--------------------------------------------------------------------------------
/equipment/widget.h:
--------------------------------------------------------------------------------
1 | #ifndef WIDGET_H
2 | #define WIDGET_H
3 | #include
4 | #include
5 | #include
6 | #include "myprocess.h"
7 | #include
8 | #include
9 | #include
10 | #include "ui_myprocess.h"
11 | #include "ui_dequip.h"
12 | #include
13 | #include "dequip.h"
14 |
15 | namespace Ui {
16 | class Widget;
17 | }
18 |
19 | class Widget : public QWidget
20 | {
21 | Q_OBJECT
22 |
23 | public:
24 | explicit Widget(QWidget *parent = 0);
25 | int totalPrint;
26 | int totalKeyboard;
27 | int totalMouse;
28 | int totalBluetooth;
29 | int rePrint; //剩余
30 | int reKey;
31 | int reMouse;
32 | int reBlue;
33 | struct Process{
34 | int pId;
35 | int print;
36 | int keyboard;
37 | int mouse;
38 | int bluetooth;
39 | int getPrint;
40 | int getKey;
41 | int getMouse;
42 | int getBluetooth;
43 | };
44 | Process proc[24];
45 | QQueue wait;
46 | ~Widget();
47 |
48 | private slots:
49 | void on_pro1_clicked();
50 | void on_createPro_clicked();
51 | void on_closeButton_clicked();
52 |
53 | void on_pro2_clicked();
54 |
55 | void on_pro3_clicked();
56 |
57 | void on_pro4_clicked();
58 |
59 | void on_pro5_clicked();
60 |
61 | void on_pro6_clicked();
62 |
63 | void on_pro7_clicked();
64 |
65 | void on_pro8_clicked();
66 |
67 | void on_pro9_clicked();
68 |
69 | void on_pro10_clicked();
70 |
71 | void on_pro11_clicked();
72 |
73 | void on_pro12_clicked();
74 |
75 | void on_pro13_clicked();
76 |
77 | void on_pro14_clicked();
78 |
79 | void on_pro15_clicked();
80 |
81 | void on_pro16_clicked();
82 |
83 | void on_pro17_clicked();
84 |
85 | void on_pro18_clicked();
86 |
87 | void on_pro19_clicked();
88 |
89 | void on_pro20_clicked();
90 |
91 | void on_pro21_clicked();
92 |
93 | void on_pro22_clicked();
94 |
95 | void on_pro23_clicked();
96 |
97 | void on_pro24_clicked();
98 |
99 | void on_StartButton_clicked();
100 |
101 | void waitAppendSlot (int pId);
102 |
103 | private:
104 | Ui::Widget *ui;
105 | myProcess *mypro;
106 |
107 | };
108 |
109 | #endif // WIDGET_H
110 |
--------------------------------------------------------------------------------
/equipment/widget.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Widget
4 |
5 |
6 |
7 | 0
8 | 0
9 | 710
10 | 220
11 |
12 |
13 |
14 |
15 | 710
16 | 220
17 |
18 |
19 |
20 |
21 | 1000
22 | 300
23 |
24 |
25 |
26 | Widget
27 |
28 |
29 |
30 |
31 | 0
32 | 20
33 | 373
34 | 191
35 |
36 |
37 |
38 | -
39 |
40 |
-
41 |
42 |
43 |
44 | 36
45 | 40
46 |
47 |
48 |
49 |
50 | 36
51 | 40
52 |
53 |
54 |
55 | p0
56 |
57 |
58 |
59 | -
60 |
61 |
62 |
63 | 36
64 | 40
65 |
66 |
67 |
68 |
69 | 36
70 | 40
71 |
72 |
73 |
74 | p1
75 |
76 |
77 |
78 | -
79 |
80 |
81 |
82 | 36
83 | 40
84 |
85 |
86 |
87 |
88 | 36
89 | 40
90 |
91 |
92 |
93 | p2
94 |
95 |
96 |
97 | -
98 |
99 |
100 |
101 | 36
102 | 40
103 |
104 |
105 |
106 |
107 | 36
108 | 40
109 |
110 |
111 |
112 | p3
113 |
114 |
115 |
116 | -
117 |
118 |
119 |
120 | 36
121 | 40
122 |
123 |
124 |
125 |
126 | 36
127 | 40
128 |
129 |
130 |
131 | p4
132 |
133 |
134 |
135 | -
136 |
137 |
138 |
139 | 36
140 | 40
141 |
142 |
143 |
144 |
145 | 36
146 | 40
147 |
148 |
149 |
150 | p5
151 |
152 |
153 |
154 | -
155 |
156 |
157 |
158 | 36
159 | 40
160 |
161 |
162 |
163 |
164 | 36
165 | 40
166 |
167 |
168 |
169 | p6
170 |
171 |
172 |
173 | -
174 |
175 |
176 |
177 | 36
178 | 40
179 |
180 |
181 |
182 |
183 | 36
184 | 40
185 |
186 |
187 |
188 | p7
189 |
190 |
191 |
192 | -
193 |
194 |
195 |
196 | 36
197 | 40
198 |
199 |
200 |
201 |
202 | 36
203 | 40
204 |
205 |
206 |
207 | p9
208 |
209 |
210 |
211 | -
212 |
213 |
214 |
215 | 36
216 | 40
217 |
218 |
219 |
220 |
221 | 36
222 | 40
223 |
224 |
225 |
226 | p9
227 |
228 |
229 |
230 | -
231 |
232 |
233 |
234 | 36
235 | 40
236 |
237 |
238 |
239 |
240 | 36
241 | 40
242 |
243 |
244 |
245 | p10
246 |
247 |
248 |
249 | -
250 |
251 |
252 |
253 | 36
254 | 40
255 |
256 |
257 |
258 |
259 | 36
260 | 40
261 |
262 |
263 |
264 | p11
265 |
266 |
267 |
268 | -
269 |
270 |
271 |
272 | 36
273 | 40
274 |
275 |
276 |
277 |
278 | 36
279 | 40
280 |
281 |
282 |
283 | p12
284 |
285 |
286 |
287 | -
288 |
289 |
290 |
291 | 36
292 | 40
293 |
294 |
295 |
296 |
297 | 36
298 | 40
299 |
300 |
301 |
302 | p13
303 |
304 |
305 |
306 | -
307 |
308 |
309 |
310 | 36
311 | 40
312 |
313 |
314 |
315 |
316 | 36
317 | 40
318 |
319 |
320 |
321 | p14
322 |
323 |
324 |
325 | -
326 |
327 |
328 |
329 | 36
330 | 40
331 |
332 |
333 |
334 |
335 | 36
336 | 40
337 |
338 |
339 |
340 | p15
341 |
342 |
343 |
344 | -
345 |
346 |
347 |
348 | 36
349 | 40
350 |
351 |
352 |
353 |
354 | 36
355 | 40
356 |
357 |
358 |
359 | p16
360 |
361 |
362 |
363 | -
364 |
365 |
366 |
367 | 36
368 | 40
369 |
370 |
371 |
372 |
373 | 36
374 | 40
375 |
376 |
377 |
378 | p17
379 |
380 |
381 |
382 | -
383 |
384 |
385 |
386 | 36
387 | 40
388 |
389 |
390 |
391 |
392 | 36
393 | 40
394 |
395 |
396 |
397 | p18
398 |
399 |
400 |
401 | -
402 |
403 |
404 |
405 | 36
406 | 40
407 |
408 |
409 |
410 |
411 | 36
412 | 40
413 |
414 |
415 |
416 | p19
417 |
418 |
419 |
420 | -
421 |
422 |
423 |
424 | 36
425 | 40
426 |
427 |
428 |
429 |
430 | 36
431 | 40
432 |
433 |
434 |
435 | p21
436 |
437 |
438 |
439 | -
440 |
441 |
442 |
443 | 36
444 | 40
445 |
446 |
447 |
448 |
449 | 36
450 | 40
451 |
452 |
453 |
454 | p22
455 |
456 |
457 |
458 | -
459 |
460 |
461 |
462 | 36
463 | 40
464 |
465 |
466 |
467 |
468 | 36
469 | 40
470 |
471 |
472 |
473 | p23
474 |
475 |
476 |
477 | -
478 |
479 |
480 |
481 | 36
482 | 40
483 |
484 |
485 |
486 |
487 | 36
488 | 40
489 |
490 |
491 |
492 | p20
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 | 370
504 | 40
505 | 341
506 | 111
507 |
508 |
509 |
510 | false
511 |
512 |
513 |
514 |
515 |
516 | 390
517 | 160
518 | 100
519 | 30
520 |
521 |
522 |
523 |
524 | 100
525 | 30
526 |
527 |
528 |
529 | 开始
530 |
531 |
532 |
533 |
534 |
535 | 440
536 | 190
537 | 212
538 | 28
539 |
540 |
541 |
542 | 随机生成进程序列
543 |
544 |
545 |
546 |
547 |
548 | 600
549 | 160
550 | 100
551 | 30
552 |
553 |
554 |
555 |
556 | 100
557 | 30
558 |
559 |
560 |
561 | 关闭
562 |
563 |
564 |
565 |
566 |
567 | 330
568 | 10
569 | 72
570 | 15
571 |
572 |
573 |
574 | 设备管理
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
--------------------------------------------------------------------------------
/file/file.cpp:
--------------------------------------------------------------------------------
1 | #include "file.h"
2 | #include "ui_file.h"
3 | #include"mainwindow.h"
4 |
5 | extern MainWindow *w;
6 |
7 | File::File(QWidget *parent) :
8 | QWidget(parent),
9 | ui(new Ui::File)
10 | {
11 | ui->setupUi(this);
12 |
13 | ui->search_txt->setPlaceholderText("输入文件名");
14 | //初始化 文件信息 数组
15 | filepros=new QVector;
16 | ui->filetree->headerItem()->setText(0,"文件名");
17 | ui->filetree->headerItem()->setText(1,"类型");
18 | ui->filetree->headerItem()->setText(2,"日期");
19 | //
20 | ui->search_res_tree->headerItem()->setText(0,"文件名");
21 | ui->search_res_tree->headerItem()->setText(1,"大小");
22 | ui->search_res_tree->headerItem()->setText(2,"日期");
23 |
24 | //新建目录
25 | for (int i=1;i<=5;i++) {
26 | QTreeWidgetItem *rootItem1=new QTreeWidgetItem(ui->filetree);
27 | rootItem1->setText(0,"文件夹"+QString::number(i));
28 | rootItem1->setText(1,"文件夹");
29 | rootItem1->setText(2,QDateTime::currentDateTime().toString("yyyy-MM-dd"));
30 | rootItem1->setIcon(0,QIcon(":/file\\myPhotos/dirIcon.png"));
31 | }
32 | }
33 |
34 | File::~File()
35 | {
36 | delete ui;
37 | }
38 |
39 |
40 | void File::on_mag_createfile_clicked()
41 | {
42 | //获取当前目录
43 | pCurrentItem=ui->filetree->currentItem();
44 |
45 | //查找该文件的属性
46 | bool isFile=false;
47 | for (int i=0;idiskTab->fpol.size();i++)
48 | {
49 | if((w->diskTab->fpol[i]).filename==pCurrentItem->text(0)){
50 | isFile=true;
51 | break;
52 | }
53 | }
54 | if(isFile!=true){
55 | //创建“创建文件”窗口
56 | fcw=new fileCreate;
57 | fcw->setWindowTitle("创建文件");
58 | //信号、槽连接
59 | void (fileCreate::*sig)(QString,int,QString)=&fileCreate::createfile;
60 | void (File::*get)(QString,int,QString)=&File::getFilename;
61 | connect(fcw,sig,this,get);
62 |
63 | fcw->show();
64 | }
65 |
66 | }
67 |
68 | void File::on_mag_createfoler_clicked()
69 | {
70 | //获取当前目录
71 | pCurrentItem=ui->filetree->currentItem();
72 | //查找该文件的属性
73 | bool isFile=false;
74 | for (int i=0;idiskTab->fpol.size();i++)
75 | {
76 | if((w->diskTab->fpol[i]).filename==pCurrentItem->text(0)){
77 | isFile=true;
78 | break;
79 | }
80 | }
81 | if(isFile!=true){
82 | //创建“创建文件夹”窗口
83 | flw=new folderCreate;
84 | flw->setWindowTitle("创建文件");
85 | //信号、槽连接
86 | void (folderCreate::*sig)(QString)=&folderCreate::createfolder;
87 | void (File::*get)(QString)=&File::getFoldername;
88 | connect(flw,sig,this,get);
89 |
90 | flw->show();
91 | }
92 |
93 | }
94 |
95 | void File::getFilename(QString filename,int size,QString p)
96 | {
97 | qDebug()<<"在 "<text(0)<<"下创建文件";
98 |
99 | QTreeWidgetItem *file=new QTreeWidgetItem(pCurrentItem);
100 | file->setText(0,filename);
101 | file->setText(1,"文件");
102 | file->setText(2,QDateTime::currentDateTime().toString("yyyy-MM-dd"));
103 | file->setIcon(0,QIcon(":/file\\myPhotos/file.png"));
104 |
105 | //文件加入数组
106 | myFilepro *f=new myFilepro;
107 | QDateTime nd=QDateTime::currentDateTime();
108 | QString time = nd.toString("yyyy-MM-dd");
109 | f->setData(filepros->length(),"文件",file->text(0),"pos",QString::number(size),time,p);
110 | filepros->append(f);
111 |
112 | //调用磁盘空间分配函数 初始大小为 0 kB
113 | disk->distrcFileSpace(f->id,f->name,(f->size).toInt(),p);
114 | }
115 |
116 | void File::getFoldername(QString name)
117 | {
118 | qDebug()<<"在 "<text(0)<<"下创建文件夹";
119 |
120 | QTreeWidgetItem *file=new QTreeWidgetItem(pCurrentItem);
121 | file->setText(0,name);
122 | file->setText(1,"文件夹");
123 | file->setText(2,QDateTime::currentDateTime().toString("yyyy-MM-dd"));
124 | file->setIcon(0,QIcon(":/file\\myPhotos/dirIcon.png"));
125 |
126 | //文件夹加入
127 | QDateTime nd=QDateTime::currentDateTime();
128 | QString time = nd.toString("yyyy-MM-dd");
129 |
130 | //给文件夹分配空间
131 | w->diskTab->getSpaceToFolder();
132 | }
133 |
134 | void File::on_filetree_customContextMenuRequested(const QPoint &pos)
135 | {
136 | QTreeWidgetItem* curItem=ui->filetree->itemAt(pos); //获取当前被点击的节点
137 | if(curItem==NULL)return;
138 | qDebug()<<"右击了 : "<text(0);
139 | QVariant var = curItem->data(0,Qt::UserRole);
140 |
141 | //查找该文件的属性
142 | myFilepro *f=new myFilepro;
143 | QVector::iterator iter;
144 | bool isFile=false;
145 | for (iter=filepros->begin();iter!=filepros->end();iter++)
146 | {
147 | if(((*iter)->name)==curItem->text(0)){
148 | f->id=(*iter)->id;
149 | f->name=(*iter)->name;
150 | f->type=(*iter)->type;
151 | f->pos=(*iter)->pos;
152 | f->size=(*iter)->size;
153 | f->time=(*iter)->time;
154 |
155 | isFile=true;
156 | break;
157 | }
158 | }
159 | if(isFile==true){
160 | //创建属性窗口
161 | fileProperty *fp=new fileProperty;
162 | fp->setWindowTitle("文件属性");
163 | fp->move(QCursor::pos());
164 | //*****************************属性信号、槽连接
165 | //文件窗口(文件属性)->属性窗口
166 | void (File::*sig)(int,QString,QString,QString,QString,QString)=&File::propertyInfoTran;
167 | void (fileProperty::*pro)(int,QString,QString,QString,QString,QString)=&fileProperty::getFilepropertyInfo;
168 | connect(this,sig,fp,pro);
169 | //属性窗口(查看文件分配情况)->磁盘窗口
170 | void (fileProperty::*sig1)(int,QString,QString,QString,int,QString)=&fileProperty::diskLookFileSpace;
171 | void (Disk::*pro1)(int,QString,QString,QString,int,QString)=&Disk::LookFileSpace;
172 | connect(fp,sig1,this->disk,pro1);
173 |
174 | //信号触发
175 | emit this->propertyInfoTran(f->id,f->type,f->name,f->pos,f->size,f->time);
176 |
177 | this->fp=fp;
178 | fp->show();
179 | }
180 |
181 | }
182 |
183 | void File::on_del_file_clicked()
184 | {
185 | //获取当前目录
186 | pCurrentItem=ui->filetree->currentItem();
187 | qDebug()<<"删除 "<text(0);
188 | //____________________ 删除磁盘空间
189 | //在文件记录中根据文件名找文件分配策略
190 | QString policy;
191 | QVector::iterator iter;
192 | for (iter=filepros->begin();iter!=filepros->end();iter++){
193 | if((*iter)->name==pCurrentItem->text(0)){
194 | policy=(*iter)->policy;
195 | break;
196 | }
197 | }
198 | this->disk->releaseSpace(pCurrentItem->text(0),policy);
199 | //____________________ 删除树结构
200 | delete pCurrentItem;
201 | }
202 |
203 | void File::on_filetree_doubleClicked(const QModelIndex &index)
204 | {
205 |
206 | pCurrentItem=ui->filetree->currentItem();
207 | //判断双击的是否为文件
208 | bool isFile=false;
209 | for (int i=0;i<(this->disk->fpol).size();i++) {
210 | if((this->disk->fpol)[i].filename==pCurrentItem->text(0)){
211 | isFile=true;
212 | }
213 | }
214 | if(isFile){
215 | contextWind=new FileContext();
216 | contextWind->setFileName(pCurrentItem->text(0));
217 | contextWind->show();
218 | //获取当前目录
219 | pCurrentItem=ui->filetree->currentItem();
220 | qDebug()<<"打开文件 : "<text(0);
221 | //在文件记录中根据文件名找文件分配策略
222 | QString policy;
223 | QVector::iterator iter;
224 | for (iter=filepros->begin();iter!=filepros->end();iter++){
225 | if((*iter)->name==pCurrentItem->text(0)){
226 | policy=(*iter)->policy;
227 | break;
228 | }
229 | }
230 | this->disk->geentFileSeekWind(pCurrentItem->text(0),policy);
231 | }
232 | }
233 |
234 | QVector *File::getFileContext()
235 | {
236 | return this->filepros;
237 | }
238 |
239 |
240 |
241 | void File::on_search_btn_clicked()
242 | {
243 | ui->search_res_tree->clear();
244 | QString filename=ui->search_txt->text();
245 | bool findFile=false;
246 | QString policy;
247 | for (int i=0;i<(w->diskTab->fpol).size();i++) {
248 | if((w->diskTab->fpol)[i].filename==filename){
249 | findFile=true;
250 | policy=(w->diskTab->fpol)[i].policy;
251 | }
252 | }
253 | if(findFile==true){
254 | QTreeWidgetItem* root=new QTreeWidgetItem(ui->search_res_tree);
255 | root->setText(0,filename);
256 | }else{
257 | //
258 | QTreeWidgetItem* root=new QTreeWidgetItem(ui->search_res_tree);
259 | root->setText(0,"未找到文件");
260 | }
261 | }
262 |
263 | void File::on_search_res_tree_doubleClicked(const QModelIndex &index)
264 | {
265 | pCurrentItem=ui->search_res_tree->currentItem();
266 | //判断双击的是否为文件
267 | bool isFile=false;
268 | for (int i=0;i<(this->disk->fpol).size();i++) {
269 | if((this->disk->fpol)[i].filename==pCurrentItem->text(0)){
270 | isFile=true;
271 | }
272 | }
273 | if(isFile){
274 | contextWind=new FileContext;
275 | contextWind->setFileName(pCurrentItem->text(0));
276 | contextWind->show();
277 |
278 | //获取当前目录
279 | pCurrentItem=ui->search_res_tree->currentItem();
280 | qDebug()<<"打开文件 : "<text(0);
281 | //在文件记录中根据文件名找文件分配策略
282 | QString policy;
283 | QVector::iterator iter;
284 | for (iter=filepros->begin();iter!=filepros->end();iter++){
285 | if((*iter)->name==pCurrentItem->text(0)){
286 | policy=(*iter)->policy;
287 | break;
288 | }
289 | }
290 | this->disk->geentFileSeekWind(pCurrentItem->text(0),policy);
291 | }
292 | }
293 |
--------------------------------------------------------------------------------
/file/file.h:
--------------------------------------------------------------------------------
1 | #ifndef FILE_H
2 | #define FILE_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include"disk/disk.h"
10 | #include"filecreate.h"
11 | #include"foldercreate.h"
12 | #include"fileproperty.h"
13 | #include"myfilepro.h"
14 | #include"spaceexband.h"
15 | #include"filecontext.h"
16 |
17 | #include
18 |
19 | namespace Ui {
20 | class File;
21 | }
22 |
23 | class File : public QWidget
24 | {
25 | Q_OBJECT
26 |
27 | public:
28 | explicit File(QWidget *parent = nullptr);
29 | ~File();
30 | Disk *disk;//磁盘对象
31 | fileProperty *fp;//文件属性
32 |
33 | signals:
34 | //信号:磁盘中为新文件分配空间
35 | void getDiskMemery(int id,QString name,int size,QString sp);
36 | //信号:文件右键属性信息传送
37 | void propertyInfoTran(int i,QString ty,QString n,QString p,QString s,QString t);
38 |
39 |
40 | public slots:
41 | void on_mag_createfile_clicked();
42 |
43 | void on_mag_createfoler_clicked();
44 |
45 | void getFilename(QString filename,int size,QString p);
46 | void getFoldername(QString name);
47 |
48 | void on_filetree_customContextMenuRequested(const QPoint &pos);
49 |
50 | void on_del_file_clicked();
51 |
52 | void on_filetree_doubleClicked(const QModelIndex &index);
53 |
54 | //返回文件信息键值对列表
55 | QVector *getFileContext();
56 |
57 |
58 | private slots:
59 | void on_search_btn_clicked();
60 |
61 | void on_search_res_tree_doubleClicked(const QModelIndex &index);
62 |
63 | private:
64 | Ui::File *ui;
65 | QTreeWidgetItem *pCurrentItem;
66 | fileCreate *fcw;
67 | folderCreate *flw;
68 | spaceExband *spaceExbanWind;//内存扩充窗口
69 | FileContext *contextWind;//文件内容窗口
70 | //文件信息键值对
71 | QVector *filepros;
72 | };
73 |
74 | #endif // FILE_H
75 |
--------------------------------------------------------------------------------
/file/file.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | File
4 |
5 |
6 |
7 | 0
8 | 0
9 | 710
10 | 570
11 |
12 |
13 |
14 |
15 | 710
16 | 260
17 |
18 |
19 |
20 | Form
21 |
22 |
23 |
24 |
25 | 320
26 | 10
27 | 72
28 | 15
29 |
30 |
31 |
32 | 文件管理
33 |
34 |
35 |
36 |
37 |
38 | 490
39 | 160
40 | 201
41 | 34
42 |
43 |
44 |
45 |
46 | 0
47 | 50
48 |
49 |
50 |
51 | color: rgb(0, 85, 255);
52 |
53 |
54 | 创建文件
55 |
56 |
57 |
58 |
59 |
60 | 490
61 | 210
62 | 201
63 | 34
64 |
65 |
66 |
67 |
68 | 0
69 | 50
70 |
71 |
72 |
73 | color: rgb(0, 85, 255);
74 |
75 |
76 | 创建文件夹
77 |
78 |
79 |
80 |
81 |
82 | 20
83 | 90
84 | 451
85 | 471
86 |
87 |
88 |
89 | Qt::CustomContextMenu
90 |
91 |
92 |
93 | 1
94 |
95 |
96 |
97 |
98 |
99 |
100 | 490
101 | 260
102 | 201
103 | 34
104 |
105 |
106 |
107 |
108 | 0
109 | 50
110 |
111 |
112 |
113 | color: rgb(0, 85, 255);
114 |
115 |
116 | 删除文件
117 |
118 |
119 |
120 |
121 |
122 | 20
123 | 40
124 | 291
125 | 31
126 |
127 |
128 |
129 |
130 |
131 |
132 | 320
133 | 40
134 | 151
135 | 34
136 |
137 |
138 |
139 | color: rgb(0, 85, 255);
140 |
141 |
142 | 搜索
143 |
144 |
145 |
146 |
147 |
148 | 480
149 | 40
150 | 221
151 | 101
152 |
153 |
154 |
155 |
156 | 1
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------
/file/filecontext.cpp:
--------------------------------------------------------------------------------
1 | #include "filecontext.h"
2 | #include "ui_filecontext.h"
3 | #include "mainwindow.h"
4 |
5 | extern MainWindow *w;
6 |
7 | FileContext::FileContext(QWidget *parent) :
8 | QWidget(parent),
9 | ui(new Ui::FileContext)
10 | {
11 | ui->setupUi(this);
12 |
13 | }
14 |
15 | FileContext::~FileContext()
16 | {
17 | delete ui;
18 | }
19 |
20 | void FileContext::setFileName(QString filename)
21 | {
22 | this->filename=filename;
23 |
24 | QVector *filepros=w->fileTab->getFileContext();
25 | for (int i=0;isize();i++) {
26 | if(((*filepros)[i])->name==this->filename){
27 | //改变文件内容
28 | ui->context->setText(((*filepros)[i])->context);
29 | break;
30 | };
31 | }
32 | }
33 |
34 | void FileContext::on_save_clicked()
35 | {
36 | QVector *filepros=w->fileTab->getFileContext();
37 | QString s_con_str;//初始大小
38 | QString e_con_str;//改变后大小
39 | myFilepro mf;
40 | qDebug()<<"查找文件 :"<filename;
41 | for (int i=0;isize();i++) {
42 | qDebug()<<"遍历文件 :"<<((*filepros)[i])->name;
43 | if(((*filepros)[i])->name==this->filename){
44 | qDebug()<<"找到文件 :"<<((*filepros)[i])->name;
45 | s_con_str=((*filepros)[i])->context;
46 | e_con_str=ui->context->toPlainText();
47 | //改变文件内容
48 | ((*filepros)[i])->context=ui->context->toPlainText();
49 |
50 | mf.policy=((*filepros)[i])->policy;
51 | mf.name=((*filepros)[i])->name;
52 | mf.type=((*filepros)[i])->type;
53 |
54 | break;
55 | };
56 |
57 | }
58 | int s_size=s_con_str.size();
59 | int e_size=e_con_str.size();
60 | QString expanType=(e_size-s_size)>=0?"扩展":"缩小";
61 | QString exSize=QString::number(e_size-s_size);
62 | qDebug()<<"初始大小 :"<fileTab->disk->fileExband(mf.policy,mf.name,expanType,exSize);
65 | }
66 |
67 | void FileContext::on_close_clicked()
68 | {
69 | this->close();
70 | }
71 |
--------------------------------------------------------------------------------
/file/filecontext.h:
--------------------------------------------------------------------------------
1 | #ifndef FILECONTEXT_H
2 | #define FILECONTEXT_H
3 | #include
4 | #include"myfilepro.h"
5 |
6 | namespace Ui {
7 | class FileContext;
8 | }
9 |
10 | class FileContext : public QWidget
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit FileContext(QWidget *parent = nullptr);
16 | ~FileContext();
17 | QString filename;
18 | void setFileName(QString filename);
19 |
20 | private slots:
21 | void on_save_clicked();
22 |
23 | void on_close_clicked();
24 |
25 | private:
26 | Ui::FileContext *ui;
27 | };
28 |
29 | #endif // FILECONTEXT_H
30 |
--------------------------------------------------------------------------------
/file/filecontext.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | FileContext
4 |
5 |
6 |
7 | 0
8 | 0
9 | 782
10 | 812
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 10
20 | 10
21 | 112
22 | 34
23 |
24 |
25 |
26 | 保存
27 |
28 |
29 |
30 |
31 |
32 | 10
33 | 60
34 | 761
35 | 741
36 |
37 |
38 |
39 |
40 |
41 |
42 | 140
43 | 10
44 | 112
45 | 34
46 |
47 |
48 |
49 | 关闭
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/file/filecreate.cpp:
--------------------------------------------------------------------------------
1 | #include "filecreate.h"
2 | #include "ui_filecreate.h"
3 |
4 |
5 | fileCreate::fileCreate(QWidget *parent) :
6 | QWidget(parent),
7 | ui(new Ui::fileCreate)
8 | {
9 | ui->setupUi(this);
10 | ui->filename->setPlaceholderText("请输入文件名");
11 | ui->need_size->setText(QString::number(10));
12 | ui->need_size->setEnabled(false);
13 | }
14 |
15 | fileCreate::~fileCreate()
16 | {
17 | delete ui;
18 | }
19 |
20 | void fileCreate::on_createfile_clicked()
21 | {
22 | if(ui->filename->text().isEmpty()){
23 | QMessageBox::critical(this,"错误提醒",tr("文件名不能为空 !"));
24 | }else{
25 | //信号触发
26 | QString size=ui->need_size->text();
27 | emit this->createfile(ui->filename->text(),size.toInt(),ui->space_policy->currentText());
28 | this->close();
29 | }
30 | }
31 |
32 | void fileCreate::on_cancel_createfile_clicked()
33 | {
34 | qDebug()<<"取消 创建文件 ......";
35 | this->close();
36 | }
37 |
--------------------------------------------------------------------------------
/file/filecreate.h:
--------------------------------------------------------------------------------
1 | #ifndef FILECREATE_H
2 | #define FILECREATE_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | namespace Ui {
10 | class fileCreate;
11 | }
12 |
13 | class fileCreate : public QWidget
14 | {
15 | Q_OBJECT
16 |
17 | public:
18 | explicit fileCreate(QWidget *parent = nullptr);
19 | ~fileCreate();
20 |
21 | signals:
22 | void createfile(QString filename,int size,QString sp);
23 |
24 | private slots:
25 | void on_createfile_clicked();
26 |
27 | void on_cancel_createfile_clicked();
28 |
29 | private:
30 | Ui::fileCreate *ui;
31 | };
32 |
33 | #endif // FILECREATE_H
34 |
--------------------------------------------------------------------------------
/file/filecreate.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | fileCreate
4 |
5 |
6 |
7 | 0
8 | 0
9 | 530
10 | 253
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 140
20 | 20
21 | 371
22 | 41
23 |
24 |
25 |
26 |
27 |
28 |
29 | 50
30 | 190
31 | 112
32 | 34
33 |
34 |
35 |
36 | 创建
37 |
38 |
39 |
40 |
41 |
42 | 370
43 | 180
44 | 112
45 | 34
46 |
47 |
48 |
49 | 取消
50 |
51 |
52 |
53 |
54 |
55 | 140
56 | 80
57 | 113
58 | 25
59 |
60 |
61 |
62 |
63 |
64 |
65 | 40
66 | 80
67 | 91
68 | 18
69 |
70 |
71 |
72 | 初始内存 :
73 |
74 |
75 |
76 |
77 |
78 | 40
79 | 30
80 | 81
81 | 18
82 |
83 |
84 |
85 | 文件名:
86 |
87 |
88 |
89 |
90 |
91 | 260
92 | 80
93 | 81
94 | 18
95 |
96 |
97 |
98 | KB
99 |
100 |
101 |
102 |
103 |
104 | 40
105 | 140
106 | 161
107 | 18
108 |
109 |
110 |
111 | 选择空间分配方案:
112 |
113 |
114 |
115 |
116 |
117 | 220
118 | 140
119 | 161
120 | 24
121 |
122 |
123 | -
124 |
125 | 连续分配
126 |
127 |
128 | -
129 |
130 | 显式链接
131 |
132 |
133 | -
134 |
135 | 索引分配
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
--------------------------------------------------------------------------------
/file/fileproperty.cpp:
--------------------------------------------------------------------------------
1 | #include "fileproperty.h"
2 | #include "ui_fileproperty.h"
3 |
4 | fileProperty::fileProperty(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::fileProperty)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | fileProperty::~fileProperty()
12 | {
13 | delete ui;
14 | }
15 |
16 | void fileProperty::on_btn_close_clicked()
17 | {
18 | this->close();
19 | }
20 |
21 | void fileProperty::on_size_detail_clicked()
22 | {
23 | qDebug()<<"查看文件 : ";
24 | emit this->diskLookFileSpace(this->id,this->name,this->type,this->pos,(this->size).toInt(),this->time);
25 | this->close();
26 | }
27 |
28 | void fileProperty::getFilepropertyInfo(int i, QString ty, QString n, QString p, QString s, QString t)
29 | {
30 | this->id=i;
31 | this->type=ty;
32 | this->name=n;
33 | this->pos=p;
34 | this->size=s;
35 | this->time=t;
36 |
37 | this->setWindowTitle(n);
38 | ui->type_v->setText(ty);
39 | ui->pos_v->setText(p);
40 | ui->size_v->setText(s);
41 | ui->time_v->setText(t);
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/file/fileproperty.h:
--------------------------------------------------------------------------------
1 | #ifndef FILEPROPERTY_H
2 | #define FILEPROPERTY_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class fileProperty;
9 | }
10 |
11 | class fileProperty : public QWidget
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit fileProperty(QWidget *parent = nullptr);
17 | ~fileProperty();
18 |
19 | int id;
20 | QString type;
21 | QString name;
22 | QString pos;
23 | QString size;
24 | QString time;
25 |
26 | //信号
27 | signals:
28 | //查看某一文件的磁盘分配情况
29 | void diskLookFileSpace(int id,QString name,QString type,QString pos,int size,QString time);
30 |
31 | //槽:
32 | public slots:
33 | void on_btn_close_clicked();
34 |
35 | void on_size_detail_clicked();
36 |
37 | //获取文件属性信息
38 | void getFilepropertyInfo(int i,QString ty,QString n,QString p,QString s,QString t);
39 |
40 |
41 | private:
42 | Ui::fileProperty *ui;
43 | };
44 |
45 | #endif // FILEPROPERTY_H
46 |
--------------------------------------------------------------------------------
/file/fileproperty.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | fileProperty
4 |
5 |
6 |
7 | 0
8 | 0
9 | 400
10 | 362
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 30
20 | 30
21 | 81
22 | 18
23 |
24 |
25 |
26 | 类型 :
27 |
28 |
29 |
30 |
31 |
32 | 190
33 | 30
34 | 81
35 | 18
36 |
37 |
38 |
39 | 文件夹
40 |
41 |
42 |
43 |
44 |
45 | 30
46 | 80
47 | 81
48 | 18
49 |
50 |
51 |
52 | 位置 :
53 |
54 |
55 |
56 |
57 |
58 | 190
59 | 80
60 | 81
61 | 18
62 |
63 |
64 |
65 | p/c
66 |
67 |
68 |
69 |
70 |
71 | 30
72 | 130
73 | 91
74 | 20
75 |
76 |
77 |
78 | 占用空间 :
79 |
80 |
81 |
82 |
83 |
84 | 190
85 | 130
86 | 51
87 | 18
88 |
89 |
90 |
91 | 1k
92 |
93 |
94 |
95 |
96 |
97 | 300
98 | 120
99 | 61
100 | 34
101 |
102 |
103 |
104 | color: rgb(0, 85, 255);
105 |
106 |
107 | 详情
108 |
109 |
110 |
111 |
112 |
113 | 30
114 | 180
115 | 101
116 | 18
117 |
118 |
119 |
120 | 创建时间 :
121 |
122 |
123 |
124 |
125 |
126 | 190
127 | 170
128 | 81
129 | 20
130 |
131 |
132 |
133 | 2022.2.4
134 |
135 |
136 |
137 |
138 |
139 | 130
140 | 270
141 | 112
142 | 34
143 |
144 |
145 |
146 | 关闭
147 |
148 |
149 |
150 |
151 |
152 | 230
153 | 130
154 | 81
155 | 18
156 |
157 |
158 |
159 | KB
160 |
161 |
162 |
163 |
164 |
165 |
166 |
--------------------------------------------------------------------------------
/file/foldercreate.cpp:
--------------------------------------------------------------------------------
1 | #include "foldercreate.h"
2 | #include "ui_foldercreate.h"
3 |
4 | folderCreate::folderCreate(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::folderCreate)
7 | {
8 | ui->setupUi(this);
9 | }
10 |
11 | folderCreate::~folderCreate()
12 | {
13 | delete ui;
14 | }
15 |
16 | void folderCreate::on_folder_create_clicked()
17 | {
18 | if(ui->foldername->text().isEmpty()){
19 | QMessageBox::critical(this,"错误提醒",tr("文件名不能为空 !"));
20 | }else{
21 | //信号触发
22 | emit this->createfolder(ui->foldername->text());
23 | this->close();
24 | }
25 | }
26 |
27 | void folderCreate::on_can_folder_create_clicked()
28 | {
29 | qDebug()<<"取消创建文件夹";
30 | this->close();
31 | }
32 |
--------------------------------------------------------------------------------
/file/foldercreate.h:
--------------------------------------------------------------------------------
1 | #ifndef FOLDERCREATE_H
2 | #define FOLDERCREATE_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 |
9 | namespace Ui {
10 | class folderCreate;
11 | }
12 |
13 | class folderCreate : public QWidget
14 | {
15 | Q_OBJECT
16 |
17 | public:
18 | explicit folderCreate(QWidget *parent = nullptr);
19 | ~folderCreate();
20 |
21 | signals:
22 | void createfolder(QString fname);
23 |
24 | private slots:
25 | void on_folder_create_clicked();
26 |
27 | void on_can_folder_create_clicked();
28 |
29 | private:
30 | Ui::folderCreate *ui;
31 | };
32 |
33 | #endif // FOLDERCREATE_H
34 |
--------------------------------------------------------------------------------
/file/foldercreate.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | folderCreate
4 |
5 |
6 |
7 | 0
8 | 0
9 | 512
10 | 135
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 20
20 | 20
21 | 471
22 | 41
23 |
24 |
25 |
26 |
27 |
28 |
29 | 30
30 | 80
31 | 112
32 | 34
33 |
34 |
35 |
36 | 创建
37 |
38 |
39 |
40 |
41 |
42 | 360
43 | 80
44 | 112
45 | 34
46 |
47 |
48 |
49 | 取消
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/file/myPhotos/dirIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clarencexiehang/Analog_Operating_System/7ac5fa04b3b74543ffbe1adfc8ef7b1226d15527/file/myPhotos/dirIcon.png
--------------------------------------------------------------------------------
/file/myPhotos/file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clarencexiehang/Analog_Operating_System/7ac5fa04b3b74543ffbe1adfc8ef7b1226d15527/file/myPhotos/file.png
--------------------------------------------------------------------------------
/file/myfilepro.cpp:
--------------------------------------------------------------------------------
1 | #include "myfilepro.h"
2 |
3 | myFilepro::myFilepro()
4 | {
5 |
6 | }
7 |
8 | void myFilepro::setData(int i,QString ty,QString n, QString p, QString s, QString t,QString po)
9 | {
10 | this->id=i;
11 | this->type=ty;
12 | this->name=n;
13 | this->pos=p;
14 | this->size=s;
15 | this->time=t;
16 | this->policy=po;
17 | }
18 |
--------------------------------------------------------------------------------
/file/myfilepro.h:
--------------------------------------------------------------------------------
1 | #ifndef MYFILEPRO_H
2 | #define MYFILEPRO_H
3 |
4 | #include
5 |
6 | class myFilepro
7 | {
8 | public:
9 | myFilepro();
10 | void setData(int i,QString ty,QString n,QString p,QString s,QString t,QString po);
11 |
12 | int id;
13 | QString type;
14 | QString name;
15 | QString pos;
16 | QString size;
17 | int blockNum=0;
18 | QString time;
19 | QString policy;
20 | //内容
21 | QString context;
22 | };
23 |
24 | Q_DECLARE_METATYPE(myFilepro);
25 |
26 | QDebug operator<<(QDebug dbg, const myFilepro &fp);
27 |
28 | inline bool operator<(const myFilepro &fp1,const myFilepro &fp2){
29 | if(fp1.id!=fp2.id){
30 | return fp1.idfp2.id;
33 | }
34 | }
35 |
36 | #endif // MYFILEPRO_H
37 |
--------------------------------------------------------------------------------
/file/spaceexband.cpp:
--------------------------------------------------------------------------------
1 | #include "spaceexband.h"
2 | #include "ui_spaceexband.h"
3 |
4 | spaceExband::spaceExband(QWidget *parent) :
5 | QWidget(parent),
6 | ui(new Ui::spaceExband)
7 | {
8 | ui->setupUi(this);
9 | ui->exband_size->setPlaceholderText("输入扩展大小");
10 | }
11 |
12 | spaceExband::~spaceExband()
13 | {
14 | delete ui;
15 | }
16 |
17 | void spaceExband::setData(QString filename,QString policy)
18 | {
19 | this->filename=filename;
20 | this->policy=policy;
21 | ui->filename_lab->setText(this->filename);
22 | }
23 |
24 | void spaceExband::on_btn_exband_clicked()
25 | {
26 | QString exbandType=ui->exband_type->currentText();
27 | QString exbandSize=ui->exband_size->text();
28 |
29 | emit this->fileExband(this->policy,this->filename,exbandType,exbandSize);
30 | this->close();
31 | }
32 |
--------------------------------------------------------------------------------
/file/spaceexband.h:
--------------------------------------------------------------------------------
1 | #ifndef SPACEEXBAND_H
2 | #define SPACEEXBAND_H
3 |
4 | #include
5 | #include
6 |
7 | namespace Ui {
8 | class spaceExband;
9 | }
10 |
11 | class spaceExband : public QWidget
12 | {
13 | Q_OBJECT
14 |
15 | public:
16 | explicit spaceExband(QWidget *parent = nullptr);
17 | ~spaceExband();
18 | QString policy;
19 | QString filename;
20 | void setData(QString filename,QString policy);
21 | signals:
22 | //文件扩充信号
23 | void fileExband(QString policy,QString filename,QString exbandType,QString exbanSize);
24 |
25 | private slots:
26 | void on_btn_exband_clicked();
27 |
28 | private:
29 | Ui::spaceExband *ui;
30 | };
31 |
32 | #endif // SPACEEXBAND_H
33 |
--------------------------------------------------------------------------------
/file/spaceexband.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | spaceExband
4 |
5 |
6 |
7 | 0
8 | 0
9 | 400
10 | 300
11 |
12 |
13 |
14 | Form
15 |
16 |
17 |
18 |
19 | 20
20 | 30
21 | 81
22 | 18
23 |
24 |
25 |
26 | 文件名 :
27 |
28 |
29 |
30 |
31 |
32 | 140
33 | 30
34 | 81
35 | 18
36 |
37 |
38 |
39 | 文件名
40 |
41 |
42 |
43 |
44 |
45 | 20
46 | 80
47 | 101
48 | 18
49 |
50 |
51 |
52 | 扩展类型 :
53 |
54 |
55 |
56 |
57 |
58 | 140
59 | 80
60 | 99
61 | 24
62 |
63 |
64 | -
65 |
66 | 扩展
67 |
68 |
69 | -
70 |
71 | 缩小
72 |
73 |
74 |
75 |
76 |
77 |
78 | 20
79 | 140
80 | 111
81 | 18
82 |
83 |
84 |
85 | 扩展大小 :
86 |
87 |
88 |
89 |
90 |
91 | 140
92 | 130
93 | 113
94 | 25
95 |
96 |
97 |
98 |
99 |
100 |
101 | 130
102 | 230
103 | 112
104 | 34
105 |
106 |
107 |
108 | 确定
109 |
110 |
111 |
112 |
113 |
114 | 270
115 | 130
116 | 81
117 | 18
118 |
119 |
120 |
121 | KB
122 |
123 |
124 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/icon.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | file/myPhotos/dirIcon.png
4 | file/myPhotos/file.png
5 |
6 |
7 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 | #include "process/pcb.h"
4 | #include "vector"
5 | #include "time.h"
6 |
7 | MainWindow *w;
8 |
9 | int main(int argc, char *argv[])
10 | {
11 | QApplication a(argc, argv);
12 | w=new MainWindow;
13 | //随机产生进程并展示
14 | srand(time(nullptr));
15 | w->processTab->Random_Create_PCB();
16 | w->processTab->Create_Process_For_Synchronization();
17 | w->processTab->showProcess();
18 |
19 | w->show();
20 | return a.exec();
21 | }
22 |
--------------------------------------------------------------------------------
/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 |
4 | MainWindow::MainWindow(QWidget *parent) :
5 | QMainWindow(parent),
6 | ui(new Ui::MainWindow)
7 | {
8 | ui->setupUi(this);
9 | setFixedSize(1500,900);
10 | setWindowTitle("模拟操作系统");
11 | //添加每个管理页面
12 | processTab=new ProcessTab(this);
13 | memoryTab=new Memory(this);
14 | fileTab = new File(this);
15 | equipmentTab = new Widget(this);
16 | diskTab = new Disk(this);
17 |
18 |
19 | fileTab->disk=diskTab;
20 |
21 | ui->processArea->setWidget(processTab);
22 | ui->memoryArea->setWidget(memoryTab);
23 | ui->fileArea->setWidget(fileTab);
24 | ui->equipArea->setWidget(equipmentTab);
25 | ui->diskArea->setWidget(diskTab);
26 |
27 |
28 | }
29 |
30 | MainWindow::~MainWindow()
31 | {
32 | delete ui;
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include "process/processtab.h"
6 | #include "memory/memory.h"
7 | #include "equipment/Widget.h"
8 | #include "file/file.h"
9 | #include "disk/disk.h"
10 |
11 | namespace Ui {
12 | class MainWindow;
13 | }
14 |
15 | class MainWindow : public QMainWindow
16 | {
17 | Q_OBJECT
18 |
19 | public:
20 | ProcessTab *processTab;
21 | Memory *memoryTab;
22 | File *fileTab;
23 | Widget *equipmentTab;
24 | Disk *diskTab;
25 |
26 | explicit MainWindow(QWidget *parent = nullptr);
27 | ~MainWindow();
28 |
29 | private:
30 | Ui::MainWindow *ui;
31 | };
32 |
33 | #endif // MAINWINDOW_H
34 |
--------------------------------------------------------------------------------
/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 1500
10 | 900
11 |
12 |
13 |
14 |
15 | 1500
16 | 900
17 |
18 |
19 |
20 | MainWindow
21 |
22 |
23 |
24 | :/pics/tubiao.jpg:/pics/tubiao.jpg
25 |
26 |
27 |
28 |
29 |
30 | 20
31 | 10
32 | 720
33 | 610
34 |
35 |
36 |
37 |
38 | 720
39 | 610
40 |
41 |
42 |
43 | true
44 |
45 |
46 |
47 |
48 | 0
49 | 0
50 | 718
51 | 608
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | 20
60 | 629
61 | 720
62 | 231
63 |
64 |
65 |
66 |
67 | 720
68 | 200
69 |
70 |
71 |
72 |
73 | 16777215
74 | 2000
75 |
76 |
77 |
78 | true
79 |
80 |
81 |
82 |
83 | 0
84 | 0
85 | 718
86 | 229
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | 760
95 | 10
96 | 720
97 | 250
98 |
99 |
100 |
101 |
102 | 720
103 | 250
104 |
105 |
106 |
107 | true
108 |
109 |
110 |
111 |
112 | 0
113 | 0
114 | 718
115 | 248
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 | 760
124 | 280
125 | 720
126 | 250
127 |
128 |
129 |
130 |
131 | 720
132 | 250
133 |
134 |
135 |
136 | true
137 |
138 |
139 |
140 |
141 | 0
142 | 0
143 | 718
144 | 248
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 | 760
153 | 550
154 | 720
155 | 311
156 |
157 |
158 |
159 |
160 | 720
161 | 180
162 |
163 |
164 |
165 | true
166 |
167 |
168 |
169 |
170 | 0
171 | 0
172 | 718
173 | 309
174 |
175 |
176 |
177 |
178 |
179 |
189 |
190 |
191 | TopToolBarArea
192 |
193 |
194 | false
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
--------------------------------------------------------------------------------
/memory/memory.cpp:
--------------------------------------------------------------------------------
1 | #include "memory.h"
2 | #include "ui_memory.h"
3 | #include "mainwindow.h"
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | extern MainWindow *w;
12 | int color[10][3] = {
13 | {33,222,28},
14 | {188,133,240},
15 | {237,14,111},
16 | {240,20,138},
17 | {233,198,1},
18 | {233,94,1},
19 | {10,211,229},
20 | {180,10,229},
21 | {10,133,190},
22 | {9,154,135}
23 | };
24 | Memory::Memory(QWidget *parent) :
25 | QWidget(parent),
26 | ui(new Ui::Memory)
27 | {
28 | ui->setupUi(this);
29 | // QMessageBox::information(this,"info","信息");
30 | int columnCount = 20;
31 | int rowCount = 20;
32 | ui->check1->setChecked(true);
33 | ui->memeryTable->setColumnCount(columnCount);
34 | ui->memeryTable->setRowCount(rowCount);
35 | // ui->processtable->horizontalHeader()->setDefaultAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
36 | ui->memeryTable->setAlternatingRowColors(true);
37 | ui->memeryTable->verticalHeader()->setDefaultSectionSize(5);
38 | ui->memeryTable->horizontalHeader()->setDefaultSectionSize(5);
39 | ui->memeryTable->verticalHeader()->setVisible(false);
40 | ui->memeryTable->horizontalHeader()->setVisible(false);
41 | ui->memeryTable->setSelectionBehavior(QAbstractItemView::SelectRows); //设置选择每行且单元不可编辑
42 | // ui->memeryTable->setSelectionMode(QAbstractItemView::SingleSelection);
43 | ui->memeryTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
44 | ui->memeryTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
45 | for(int i=0;isetTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
49 | ui->memeryTable->setItem(i,j,tableitem);
50 | ui->memeryTable->item(i,j)->setBackground(QBrush(QColor(200,200,200)));
51 |
52 | }
53 | }
54 | this->initMemery();
55 |
56 | // 测试函数的代码
57 |
58 | // this->requestMemery(5,"22");
59 | // this->requestMemery(3,"21");
60 | // this->requestMemery(3,"23");
61 | // QTimer * timer = new QTimer(this);
62 | // QTimer * timer2 = new QTimer(this);
63 | // timer->start(500);
64 | // Memory * that = this;
65 | // srand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
66 | // connect(timer,&QTimer::timeout,[=](){
67 | // that->freeMemery("21");
68 | //// that->requestMemery(3,"23");
69 | // timer->stop();
70 | // });
71 | // timer2->start(1000);
72 | // connect(timer2,&QTimer::timeout,[=](){
73 | // int ran = rand() % 10;
74 | // that->freeMemery("22");
75 | //// that->requestMemery(3,"24");
76 | // that->replacePageByLRU("21",ran);
77 | // timer2->stop();
78 | // });
79 | // that->requestMemery(2,"1");
80 | // that->requestMemery(7,"1");
81 | }
82 |
83 | Memory::~Memory()
84 | {
85 | delete ui;
86 | }
87 | //初始化内存块的函数;
88 | void Memory::initMemery(){
89 | // struct freeMemeryBlock * newBlock = new struct freeMemeryBlock();
90 | // newBlock->memeryBlockSize = 20*20;
91 | // newBlock->endIndex = 399;
92 | // newBlock->startIndex = 0;
93 | // newBlock->nextBlock = nullptr;
94 | // this->freeMemeryList = newBlock;
95 | for(int i=0;i<400;i++){
96 | this->isUsed[i] = 0;
97 | }
98 | this->usedMemeryList = nullptr;
99 |
100 | ui->check1->setChecked(true);
101 | }
102 |
103 |
104 | void Memory::dye(struct usedMemeryBlock * block,int flag){
105 | int j;
106 | int i;
107 | for (int k=0;kmemeryBlockSize;k++){
108 | // qDebug()<pageList[k][1]/20;
110 | j = block->pageList[k][1]%20;
111 | ui->memeryTable->item(i,j)->setFont(QFont("song", 10));
112 | if(flag==0){
113 | QString text;
114 | text = block->pid+"|-1";
115 | ui->memeryTable->item(i,j)->setText(text);
116 | ui->memeryTable->item(i,j)->setBackground(QBrush(QColor(color[block->ranking%10][0],color[block->ranking%10][1],color[block->ranking%10][2])));
117 | }
118 | else if(flag==1){
119 | ui->memeryTable->item(i,j)->setBackground(QBrush(QColor(200,200,200)));
120 | ui->memeryTable->item(i,j)->setText("");
121 | }
122 | else{
123 | ui->memeryTable->item(i,j)->setBackground(QBrush(QColor(color[block->ranking%10][0],color[block->ranking%10][1],color[block->ranking%10][2])));
124 | }
125 | }
126 | }
127 | //请求内存块 首次适应算法
128 |
129 | //bool Memory::requestMemery1(int pageFrame,QString pid){
130 | //// qDebug()<<"1111";
131 | // struct freeMemeryBlock * tempBlock1;
132 | // struct freeMemeryBlock * tempBlock2;
133 | // tempBlock2 = nullptr;
134 | // if(this->freeMemeryList == nullptr) return false;
135 | // tempBlock1 = this->freeMemeryList;
136 | // this->BubbleSort(tempBlock1);//空闲区排序
137 | // int flag = 0;
138 | // while(tempBlock1!=nullptr){
139 | // if(tempBlock1->memeryBlockSize>=pageFrame){
140 |
141 | // struct usedMemeryBlock * block = new struct usedMemeryBlock();
142 | // block->memeryBlockSize = pageFrame;
143 |
144 | // for(int i=0;i<5;i++){
145 |
146 | // block->pageList[i][0] = -1;
147 |
148 | // }
149 | // for(int i=0;i<50;i++){
150 | // block->requestPageList[i] = -1;
151 | // }
152 |
153 | //// block->endIndex = tempBlock1->startIndex + pageFrame - 1;
154 | //// block->startIndex = tempBlock1->startIndex;
155 | // block->pid = pid;
156 | // block->nextBlock = this->usedMemeryList;
157 | // this->usedMemeryList = block;
158 | // this->dye(block,0);//对已分配的内存进行染色
159 | // qDebug()<memeryBlockSize<startIndex;
160 | // if(tempBlock1->memeryBlockSize!=pageFrame){
161 | // tempBlock1->memeryBlockSize = tempBlock1->memeryBlockSize-pageFrame;
162 | // tempBlock1->startIndex = tempBlock1->startIndex + pageFrame;
163 | // }
164 | // else {
165 | // if(tempBlock2==nullptr){
166 | // this->freeMemeryList = tempBlock1->nextBlock;
167 | // free(tempBlock1);
168 | // }
169 | // else{
170 | // tempBlock2->nextBlock = tempBlock1->nextBlock;
171 | // free(tempBlock1);
172 | // }
173 | // }
174 | // return true;
175 | // }
176 | // tempBlock1 = tempBlock1->nextBlock;
177 | // if(flag==0){
178 | // tempBlock2 = this->freeMemeryList;
179 | // }
180 | // else {
181 | // tempBlock2 = tempBlock2->nextBlock;
182 | // flag = 1;
183 | // }
184 | // }
185 |
186 | // return false;
187 | //}
188 |
189 | //请求内存块 分页式
190 | bool Memory::requestMemery(int pageFrame,QString pid){
191 | int count = 0;
192 | struct usedMemeryBlock * block = new struct usedMemeryBlock();
193 | block->memeryBlockSize = pageFrame;
194 | block->pid = pid;
195 | block->nextBlock = this->usedMemeryList;
196 | block->ranking = this->proCount;
197 | this->usedMemeryList = block;
198 | int i;
199 | for(i=0;i<50;i++){
200 | block->requestPageList[i] = -1;
201 | }
202 | for(i=0;ipageList[i][0] = -1;
204 | }
205 | for(int i=0;i<400;i++){
206 | if(this->isUsed[i]==0){
207 | block->pageList[count][1] = i;
208 | this->isUsed[i] = 1;
209 | count++;
210 | if(count==pageFrame) break;
211 | }
212 | }
213 | if(i==400) return false;
214 | this->dye(block,0);//对已分配的内存进行染色
215 | this->proCount++;
216 | w->diskTab->createVirtualMemoryBlock(pid,block->ranking);
217 | return true;
218 | }
219 | //链表排序
220 | void Memory:: BubbleSort(freeMemeryBlock * &L)
221 | {
222 | int i ,count = 0, num;//count记录链表结点的个数,num进行内层循环,
223 | freeMemeryBlock *p, *q, *tail;//创建三个指针,进行冒泡排序
224 | p = L;
225 | struct freeMemeryBlock * newBlock = new struct freeMemeryBlock();
226 | newBlock->memeryBlockSize = 20*20;
227 | newBlock->endIndex = 399;
228 | newBlock->startIndex = 0;
229 | newBlock->nextBlock = p;
230 | L = newBlock;
231 | p = L;
232 | while(p->nextBlock!= nullptr)//计算出结点的个数
233 | {
234 | count++;//注释①
235 | p = p->nextBlock;
236 | // qDebug()<nextBlock;//令q指向第一个结点
243 | p = q->nextBlock;//令p指向后一个结点
244 | tail = L;//让tail始终指向q前一个结点,方便交换,也方便与进行下一步操作
245 | while(num--)//内层循环 次数跟数组冒泡排序一样
246 | {
247 | if(q->startIndex > p->startIndex)//如果该结点的值大于后一个结点,则交换
248 | {
249 | // qDebug()<nextBlock = p->nextBlock;
251 | p->nextBlock = q;
252 | tail->nextBlock = p;
253 | }
254 | tail = tail->nextBlock;//注释②
255 | q = tail->nextBlock;//注释②
256 | p = q->nextBlock;//注释②
257 | }
258 | }
259 | free(newBlock);
260 | //
261 | p = L->nextBlock;
262 | L = L->nextBlock;
263 |
264 | // while(p!= nullptr)//计算出结点的个数
265 | // {
266 | // qDebug()<memeryBlockSize<<"----"<startIndex;
267 | // p = p->nextBlock;
268 |
269 | // }
270 | }
271 | //合并空闲内存
272 | void Memory::mergeFreeMemery(){
273 | freeMemeryBlock *p,*q;
274 | this->BubbleSort(this->freeMemeryList);
275 | p = this->freeMemeryList;
276 | if(p == nullptr) return;
277 | while(p->nextBlock!=nullptr){
278 | if(p->endIndex == p->nextBlock->startIndex-1){
279 | p->memeryBlockSize = p->memeryBlockSize + p->nextBlock->memeryBlockSize;
280 | p->endIndex = p->nextBlock->endIndex;
281 | q = p->nextBlock;
282 | p->nextBlock = p->nextBlock->nextBlock;
283 | free(q);//释放内存空间
284 | continue;
285 | }
286 | p = p->nextBlock;
287 | }
288 | }
289 | //释放内存
290 | void Memory::freeMemery(QString pid){
291 | struct usedMemeryBlock * block;
292 | struct usedMemeryBlock * block1;
293 | block = this->usedMemeryList;
294 | w->diskTab->freeMemory(pid);
295 | if(block->pid == pid){
296 | this->usedMemeryList = block->nextBlock;
297 | for(int i =0;imemeryBlockSize;i++){
298 | this->isUsed[block->pageList[i][1]] = 0;
299 | }
300 | this->dye(block,1);
301 | free(block);
302 |
303 | }
304 | else{
305 | while(block->nextBlock!=nullptr && block->nextBlock->pid != pid){
306 | qDebug()<nextBlock->pid<<"44444";
307 | block = block->nextBlock;
308 | }
309 | if(block->nextBlock==nullptr){
310 | qDebug()<<"pid找不到"<nextBlock->memeryBlockSize;i++){
315 | this->isUsed[block->nextBlock->pageList[i][1]] = 0;
316 | }
317 | this->dye(block->nextBlock,1);
318 | block1 = block->nextBlock;
319 | block->nextBlock = block->nextBlock->nextBlock;
320 | free(block1);
321 | }
322 | }
323 | }
324 |
325 | //先进先出置换算法
326 | void Memory::replacePageByFIFO(QString pid,int page){
327 |
328 | struct usedMemeryBlock * block;
329 | block = this->usedMemeryList;
330 | while(block != nullptr && block->pid != pid){
331 | block = block->nextBlock;
332 | }
333 | if(block == nullptr) return;
334 | block->requestPageList[block->requestPageCount] = page;
335 | block->requestPageCount++;
336 | int i,j;
337 |
338 | for(int k=0;kmemeryBlockSize;k++){
339 | //进入页在内存中
340 |
341 | i = block->pageList[k][1]/20;
342 | j = block->pageList[k][1]%20;
343 | if(block->pageList[k][0] == page){
344 | this->dye(block,2);
345 | ui->memeryTable->item(i,j)->setBackground(QBrush(QColor(16,126,239)));
346 | return;
347 | }
348 | }
349 | //内存空间未满
350 | if(block->blockSizememeryBlockSize){
351 | block->FIFOPageQueue.enqueue(page);
352 | block->blockSize++;
353 | block->pageList[block->blockSize-1][0] = page;
354 | i = block->pageList[block->blockSize-1][1]/20;
355 | j = block->pageList[block->blockSize-1][1]%20;
356 | this->dye(block,2);
357 | ui->memeryTable->item(i,j)->setBackground(QBrush(QColor(16,126,239)));
358 | QString text;
359 | // text = "" + page;
360 | ui->memeryTable->item(i,j)->setText(QString::number(page));
361 | w->diskTab->replacePage(pid,page);
362 | }
363 | else{
364 | int OutPage = block->FIFOPageQueue.dequeue();
365 | block->FIFOPageQueue.enqueue(page);
366 | //取出需要置换的位置
367 | int index;
368 | for(index=0;indexmemeryBlockSize;index++){
369 | if(block->pageList[index][0] == OutPage){
370 | break;
371 | }
372 | }
373 | w->diskTab->replacePage(pid,page);
374 | int xindex = block->pageList[index][1]/20;
375 | int yindex = block->pageList[index][1]%20;
376 | this->dye(block,2);
377 | block->pageList[index][0] = page;
378 | ui->memeryTable->item(xindex,yindex)->setBackground(QBrush(QColor(16,126,239)));
379 | QString text;
380 | // text = "" + page;
381 | ui->memeryTable->item(xindex,yindex)->setText(QString::number(page));
382 | }
383 | }
384 | //页面置换算法 最久未使用算法
385 | void Memory::replacePageByLRU(QString pid,int page){
386 | //找到该进程的内存
387 | struct usedMemeryBlock * block;
388 | block = this->usedMemeryList;
389 | while(block != nullptr && block->pid != pid){
390 | block = block->nextBlock;
391 | }
392 | if(block == nullptr) return;
393 | block->requestPageList[block->requestPageCount] = page;
394 | block->requestPageCount++;
395 | // qDebug()<<"----"<memeryBlockSize;k++){
400 | //进入页在内存中
401 |
402 | i = block->pageList[k][1]/20;
403 | j = block->pageList[k][1]%20;
404 | if(block->pageList[k][0] == page){
405 | this->dye(block,2);
406 | ui->memeryTable->item(i,j)->setBackground(QBrush(QColor(16,126,239)));
407 | return;
408 | }
409 | }
410 |
411 | //内存空间未满
412 | if(block->blockSizememeryBlockSize){
413 | block->blockSize++;
414 | block->pageList[block->blockSize-1][0] = page;
415 | i = block->pageList[block->blockSize-1][1]/20;
416 | j = block->pageList[block->blockSize-1][1]%20;
417 | this->dye(block,2);
418 | ui->memeryTable->item(i,j)->setBackground(QBrush(QColor(16,126,239)));
419 | QString text;
420 | // text = "" + page;
421 | ui->memeryTable->item(i,j)->setText(QString::number(page));
422 | w->diskTab->replacePage(pid,page);
423 | }
424 | else{
425 | //寻找替换的位置
426 | int k;
427 | int postion[block->memeryBlockSize];
428 | int count = 0;
429 | for(k = 0;kmemeryBlockSize;k++){
430 | postion[k] = -1;
431 | }
432 | //对前面的页进行扫描
433 | for(k = block->requestPageCount-1;k>=0;k--){
434 | int z;
435 | for(z=0;zmemeryBlockSize;z++){
436 | if(block->requestPageList[k] == block->pageList[z][0]){
437 | if(postion[z]!=0)
438 | {
439 | postion[z] = 0;
440 | count++;
441 | }
442 | }
443 | }
444 | if(count == block->memeryBlockSize-1){
445 | break;
446 | }
447 | }
448 | //取出需要置换的位置
449 | int index;
450 | for(index=0;indexmemeryBlockSize;index++){
451 | if(postion[index]==-1){
452 | break;
453 | }
454 | }
455 | //置换
456 | w->diskTab->replacePage(pid,page);
457 | int xindex = block->pageList[index][1]/20;
458 | int yindex = block->pageList[index][1]%20;
459 | this->dye(block,2);
460 | block->pageList[index][0] = page;
461 | ui->memeryTable->item(xindex,yindex)->setBackground(QBrush(QColor(16,126,239)));
462 | QString text;
463 | // text = "" + page;
464 | ui->memeryTable->item(xindex,yindex)->setText(QString::number(page));
465 |
466 | }
467 | }
468 |
469 | void Memory::replacePage(QString pid,int page){
470 | if (ui->check1->isChecked()) {
471 | // timer->start(1000); //启动定时器,运行完一个进程
472 | this->replacePageByLRU(pid,page);
473 | }else if(ui->check2->isChecked()){
474 | this->replacePageByFIFO(pid,page);
475 | }else{
476 | QMessageBox::warning(this,"错误提示",tr("请选择置换算法算法"));
477 | return ;
478 | }
479 | }
480 |
481 | void Memory::paintEvent(QPaintEvent *){
482 | QPainter painter(this); //指定绘图设备
483 |
484 |
485 | }
486 |
--------------------------------------------------------------------------------
/memory/memory.h:
--------------------------------------------------------------------------------
1 | #ifndef MEMORY_H
2 | #define MEMORY_H
3 |
4 | #include
5 | #include
6 | #include
7 | namespace Ui {
8 | class Memory;
9 | }
10 | struct freeMemeryBlock{
11 | int startIndex;
12 | int endIndex;
13 | int memeryBlockSize;
14 | freeMemeryBlock *nextBlock;
15 | };
16 | struct usedMemeryBlock{
17 | // int startIndex;
18 | // int endIndex;
19 | int memeryBlockSize;
20 | QString pid;
21 | int requestPageList[50];
22 | int blockSize = 0;
23 | int requestPageCount = 0;
24 | int ranking;
25 | int pageList[5][2];
26 | QQueue FIFOPageQueue;
27 | usedMemeryBlock *nextBlock;
28 | };
29 | class Memory : public QWidget
30 | {
31 | Q_OBJECT
32 |
33 | public:
34 | explicit Memory(QWidget *parent = nullptr);
35 | usedMemeryBlock * usedMemeryList;
36 | freeMemeryBlock * freeMemeryList;
37 | int isUsed[400];
38 | int proCount = 0;
39 | void paintEvent(QPaintEvent *);
40 | void initMemery();
41 | void BubbleSort(freeMemeryBlock * &L);
42 | void mergeFreeMemery();
43 | void dye(struct usedMemeryBlock * block,int flag);
44 | bool requestMemery(int pageFrame,QString pid);
45 | void replacePageByLRU(QString pid,int page);
46 | void freeMemery(QString pid);
47 | void replacePage(QString pid,int page);
48 | void replacePageByFIFO(QString pid,int page);
49 | ~Memory();
50 |
51 | private:
52 | Ui::Memory *ui;
53 | };
54 |
55 | #endif // MEMORY_H
56 |
--------------------------------------------------------------------------------
/memory/memory.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Memory
4 |
5 |
6 |
7 | 0
8 | 0
9 | 710
10 | 253
11 |
12 |
13 |
14 |
15 | 700
16 | 200
17 |
18 |
19 |
20 | Form
21 |
22 |
23 |
24 |
25 | 320
26 | 10
27 | 72
28 | 15
29 |
30 |
31 |
32 | 内存状态
33 |
34 |
35 |
36 |
37 |
38 | 100
39 | 30
40 | 601
41 | 211
42 |
43 |
44 |
45 |
46 |
47 |
48 | 10
49 | 60
50 | 120
51 | 26
52 |
53 |
54 |
55 | RLU
56 |
57 |
58 |
59 |
60 |
61 | 10
62 | 100
63 | 120
64 | 26
65 |
66 |
67 |
68 | FIFO
69 |
70 |
71 |
72 |
73 |
74 | 10
75 | 30
76 | 69
77 | 20
78 |
79 |
80 |
81 | 置换算法
82 |
83 |
84 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/pics.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | pics/tubiao.jpg
4 |
5 |
6 |
--------------------------------------------------------------------------------
/pics/tubiao.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clarencexiehang/Analog_Operating_System/7ac5fa04b3b74543ffbe1adfc8ef7b1226d15527/pics/tubiao.jpg
--------------------------------------------------------------------------------
/process/pcb.cpp:
--------------------------------------------------------------------------------
1 | #include "pcb.h"
2 |
3 | #include "mainwindow.h"
4 | extern MainWindow *w;
5 |
6 | PCB::PCB(string name)
7 | {
8 | this->name = name;
9 | this->needTime = rand()%19+1;
10 | this->prio = 20 - this->needTime;
11 | this->round = 2;
12 | this->cpuTime = 0;
13 | strcpy(this->state, "就绪"); //默认创建的新进程是就绪状态
14 | this->equip = "无";
15 | this->visit_page_index = 0;
16 | this->behaviour = "null";
17 |
18 | for(int i=0;ineedTime;i++){
19 | this->visit_pages[i] = rand()%20;
20 | }
21 |
22 |
23 | if(this->needTime>10){
24 | w->memoryTab->requestMemery(5,QString::fromStdString(this->name));
25 | }else{
26 | int pageFrame = rand()%4+1;
27 | w->memoryTab->requestMemery(pageFrame,QString::fromStdString(this->name));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/process/pcb.h:
--------------------------------------------------------------------------------
1 | #ifndef PCB_H
2 | #define PCB_H
3 |
4 | #include "vector"
5 | #include "string"
6 | using namespace std;
7 |
8 | #include "iostream"
9 | #include "cstring"
10 | #include "algorithm"
11 | #include "QString"
12 |
13 |
14 | class PCB
15 | {
16 | public:
17 | string name; /*进程标识符*/
18 | int prio; /*进程优先数*/
19 | int round; /*进程时间片轮转时间片*/
20 | int cpuTime; /*进程占用 CPU 时间*/
21 | int needTime; /*进程到完成还需要的时间*/
22 | char state[10]; /*进程的状态*/
23 | string equip; /*使用设备*/
24 | int visit_pages[20]; /*进程访问的页面顺序*/
25 | int visit_page_index; /*进程将要访问的页面下标*/
26 | string behaviour; /*进程的行为*/
27 | int track[100]; /*进程访问磁道的序列*/
28 |
29 | public:
30 | PCB(string name);
31 | void Random_Create_PCB();
32 | };
33 |
34 | #endif // PCB_H
35 |
--------------------------------------------------------------------------------
/process/processdialog.cpp:
--------------------------------------------------------------------------------
1 | #include "processdialog.h"
2 | #include "ui_processdialog.h"
3 | #include "QMessageBox"
4 | #include "QDebug"
5 | #include "mainwindow.h"
6 | #include "pcb.h"
7 |
8 | processDialog::processDialog(QWidget *parent) :
9 | QDialog(parent),
10 | ui(new Ui::processDialog)
11 | {
12 | ui->setupUi(this);
13 |
14 | ui->lineEdit_proid->setPlaceholderText("请输入标识符");
15 | ui->lineEdit_prio->setPlaceholderText("请输入优先级");
16 | ui->lineEdit_cpuTime->setPlaceholderText("请输入所需CPU时间");
17 |
18 | }
19 |
20 | processDialog::~processDialog()
21 | {
22 | delete ui;
23 | }
24 |
25 | void processDialog::on_pushButton_ok_clicked()
26 | {
27 | if(ui->lineEdit_proid->text().isEmpty()||ui->lineEdit_prio->text().isEmpty()||ui->lineEdit_cpuTime->text().isEmpty()){
28 | QMessageBox::critical(this,"错误提醒",tr("请完成数据输入"));
29 | return;
30 | }
31 |
32 | QString name = ui->lineEdit_proid->text();
33 | QString prio = ui->lineEdit_prio->text();
34 | QString cpuTime = ui->lineEdit_cpuTime->text();
35 |
36 | //存入readyQueue中
37 | PCB* process = new PCB(name.toStdString());
38 | process->needTime = cpuTime.toInt();
39 | process->prio = prio.toInt();
40 |
41 | if(process->needTime<=0||process->needTime>20){
42 | QMessageBox::critical(this,"格式错误",tr("输入值必须在[0,20]内"));
43 | return ;
44 | }
45 | if(process->prio<=0||process->prio>20){
46 | QMessageBox::critical(this,"格式错误",tr("输入值必须在[0,20]内"));
47 | return ;
48 | }
49 |
50 | //放入就绪队列
51 | extern MainWindow *w;
52 | w->processTab->processQueue.push_back(process);
53 | w->processTab->readyQueue.push_back(process);
54 |
55 |
56 | //更新表格
57 | w->processTab->showProcess();
58 | this->close();
59 | }
60 |
61 | void processDialog::on_pushButton_cancel_clicked()
62 | {
63 | this->close();
64 | }
65 |
--------------------------------------------------------------------------------
/process/processdialog.h:
--------------------------------------------------------------------------------
1 | #ifndef PROCESSDIALOG_H
2 | #define PROCESSDIALOG_H
3 |
4 | #include
5 |
6 | namespace Ui {
7 | class processDialog;
8 | }
9 |
10 | class processDialog : public QDialog
11 | {
12 | Q_OBJECT
13 |
14 | public:
15 | explicit processDialog(QWidget *parent = nullptr);
16 | ~processDialog();
17 |
18 | private slots:
19 | void on_pushButton_ok_clicked();
20 | void on_pushButton_cancel_clicked();
21 |
22 | signals: //信号不能像普通函数一样使用,也不需要权限声明
23 | void sendToShowProcess(); //信号不需要定义
24 |
25 | private:
26 | Ui::processDialog *ui;
27 | void *mainWindowPtr;
28 | };
29 |
30 | #endif // PROCESSDIALOG_H
31 |
--------------------------------------------------------------------------------
/process/processdialog.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | processDialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 316
10 | 318
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 |
18 |
19 | 30
20 | 40
21 | 111
22 | 51
23 |
24 |
25 |
26 |
27 | Arial
28 | 11
29 |
30 |
31 |
32 | QFrame::Plain
33 |
34 |
35 | 进程标识符:
36 |
37 |
38 |
39 |
40 |
41 | 130
42 | 50
43 | 151
44 | 31
45 |
46 |
47 |
48 |
49 |
50 |
51 | 30
52 | 100
53 | 111
54 | 51
55 |
56 |
57 |
58 |
59 | Arial
60 | 11
61 |
62 |
63 |
64 | QFrame::Plain
65 |
66 |
67 | 进程优先级:
68 |
69 |
70 |
71 |
72 |
73 | 130
74 | 110
75 | 151
76 | 31
77 |
78 |
79 |
80 |
81 |
82 |
83 | 10
84 | 160
85 | 121
86 | 51
87 |
88 |
89 |
90 |
91 | Arial
92 | 11
93 |
94 |
95 |
96 | QFrame::Plain
97 |
98 |
99 | 所需CPU时间:
100 |
101 |
102 |
103 |
104 |
105 | 130
106 | 170
107 | 151
108 | 31
109 |
110 |
111 |
112 |
113 |
114 |
115 | 70
116 | 250
117 | 71
118 | 31
119 |
120 |
121 |
122 | 确定
123 |
124 |
125 |
126 |
127 |
128 | 160
129 | 250
130 | 71
131 | 31
132 |
133 |
134 |
135 | 取消
136 |
137 |
138 |
139 |
140 |
141 |
142 |
--------------------------------------------------------------------------------
/process/processtab.cpp:
--------------------------------------------------------------------------------
1 | #include "processtab.h"
2 | #include "ui_processtab.h"
3 | #include "mainwindow.h"
4 |
5 | extern MainWindow *w;
6 |
7 | ProcessTab::ProcessTab(QWidget *parent) :
8 | QWidget(parent),
9 | ui(new Ui::ProcessTab)
10 | {
11 | ui->setupUi(this);
12 |
13 | //进程表格
14 | ui->processtable->setColumnCount(6);
15 | QStringList tableheader;
16 | tableheader<<"进程标识码"<<"优先级"<<"运行时间"<<"所需时间"<<"使用设备"<<"进程状态";
17 | ui->processtable->horizontalHeader()->setMinimumHeight(50);
18 | ui->processtable->setHorizontalHeaderLabels(tableheader);
19 | ui->processtable->verticalHeader()->setVisible(false);
20 | // ui->processtable->horizontalHeader()->setDefaultAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
21 | ui->processtable->setAlternatingRowColors(true);
22 | ui->processtable->setSelectionBehavior(QAbstractItemView::SelectRows); //设置选择每行且单元不可编辑
23 | ui->processtable->setSelectionMode(QAbstractItemView::SingleSelection);
24 | ui->processtable->setEditTriggers(QAbstractItemView::NoEditTriggers);
25 | ui->processtable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
26 |
27 | //队列外观
28 | ui->listWidget_ready->setViewMode(QListView::ListMode);
29 | ui->listWidget_ready->setAlternatingRowColors(true);
30 |
31 | //访问页面外观
32 | ui->listWidget->setViewMode(QListView::IconMode);
33 |
34 |
35 | //定时器
36 | // timer = new QTimer(this);
37 | // connect(timer,SIGNAL(timeout()),this,SLOT(on_pause_clicked(bool checked)));
38 | // timer->start(100);
39 |
40 | ui->DPTSR->setChecked(true);
41 | }
42 |
43 | ProcessTab::~ProcessTab()
44 | {
45 | delete ui;
46 | }
47 |
48 | //展示三个队列的情况
49 | void ProcessTab::showQueue(){
50 | ui->listWidget_ready->clear();
51 | ui->listWidget_running->clear();
52 | ui->listWidget_block->clear();
53 | //就绪队列
54 | QStringList readyProcess;
55 | for (unsigned int i=0;iname);
57 | }
58 | ui->listWidget_ready->addItems(readyProcess);
59 |
60 | //运行队列
61 | QStringList runProcess;
62 | for (unsigned int i=0;iname);
64 | }
65 | ui->listWidget_running->addItems(runProcess);
66 |
67 | //阻塞队列
68 | QStringList blockProcess;
69 | for (int i=0;iname);
71 | }
72 | ui->listWidget_block->addItems(blockProcess);
73 |
74 | QCoreApplication::processEvents();
75 | }
76 |
77 | //展示要访问的页面
78 | void ProcessTab::showVisitPages(PCB *process){
79 | ui->listWidget->clear();
80 | QStringList visitpage;
81 | int num = process->needTime;
82 | for (int i=0;ivisit_pages[i]);
84 | }
85 |
86 | ui->listWidget->addItems(visitpage);
87 | QCoreApplication::processEvents();
88 | }
89 |
90 |
91 | //更新表格状态
92 | void ProcessTab::updateTableWidget(PCB *runOne,string state){
93 | for(unsigned int i=0;iname==runOne->name){
95 | if(state == "完成"){
96 | strcpy( processQueue[i]->state, "完成");
97 | processQueue[i]->needTime = 0;
98 | w->memoryTab->freeMemery(QString::fromStdString(processQueue[i]->name));
99 | }else if (state == "运行"){
100 | strcpy( processQueue[i]->state, "运行");
101 | processQueue[i]->needTime = runOne->needTime;
102 |
103 | }else if (state == "round"){
104 | strcpy(processQueue[i]->state, "就绪");
105 | processQueue[i]->prio = runOne->prio;
106 | processQueue[i]->needTime = runOne->needTime;
107 | processQueue[i]->cpuTime = runOne->cpuTime;
108 | }
109 | }
110 | }
111 | this->showProcess();
112 | QCoreApplication::processEvents();
113 | }
114 |
115 | //展示进程
116 | void ProcessTab::showProcess(){
117 | ui->processtable->setRowCount(0);
118 | for(unsigned int i=0;iprocesstable->rowCount();
120 | ui->processtable->insertRow(nCount);
121 | ui->processtable->setItem(int(i),0,new QTableWidgetItem(QString::fromStdString( processQueue[i]->name)));
122 | ui->processtable->setItem(int(i),1,new QTableWidgetItem(QString::number(processQueue[i]->prio)));
123 | ui->processtable->setItem(int(i),2,new QTableWidgetItem(QString::number(processQueue[i]->cpuTime)));
124 | ui->processtable->setItem(int(i),3,new QTableWidgetItem(QString::number(processQueue[i]->needTime)));
125 | ui->processtable->setItem(int(i),4,new QTableWidgetItem(QString::fromStdString(processQueue[i]->equip)));
126 | ui->processtable->setItem(int(i),5,new QTableWidgetItem(QString::fromStdString(processQueue[i]->state)));
127 |
128 | for(int j=0;j<6;j++){
129 | ui->processtable->item(int(i),j)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
130 | ui->processtable->item(int(i),j)->setBackground(QBrush(QColor(255,244,196)));
131 | if(strcmp(processQueue[i]->state,"运行")==0){
132 | ui->processtable->item(int(i),j)->setBackground(QBrush(QColor(255,210,100)));
133 | }
134 | }
135 | }
136 | QCoreApplication::processEvents();
137 | }
138 |
139 | //随机创建进程
140 | void ProcessTab::Random_Create_PCB(){
141 | for(int i=0;i<3;i++){
142 | PCB* p = nullptr;
143 | string name = "pro"+to_string(i);
144 | insertReadyQueue(p,name);
145 | }
146 | }
147 |
148 | void ProcessTab::insertReadyQueue(PCB* process,string name){
149 | process = new PCB(name);
150 |
151 | //放入就绪队列
152 | processQueue.push_back(process);
153 | readyQueue.push_back(process);
154 |
155 | // //分配内存
156 | // QString p = QString::fromStdString(process->name);
157 | // if(process->needTime>10){
158 | // w->memoryTab->requestMemery(5,QString::fromStdString(process->name));
159 | // }else{
160 | // int pageFrame = rand()%4+1;
161 | // w->memoryTab->requestMemery(pageFrame,QString::fromStdString(process->name));
162 | // }
163 | }
164 |
165 |
166 | //创建进程按钮槽
167 | void ProcessTab::on_createprocess_clicked()
168 | {
169 | processDialog *newProcessDialog = new processDialog;
170 | newProcessDialog->setAttribute(Qt::WA_DeleteOnClose);
171 | newProcessDialog->setWindowTitle("创建进程");
172 |
173 | newProcessDialog->show();
174 |
175 | }
176 |
177 | //删除表格按钮
178 | void ProcessTab::on_deleteprocess_clicked()
179 | {
180 | int currentRow = ui->processtable->currentRow();
181 | for(int i=0;iname) == ui->processtable->item(currentRow,0)->text()){
183 | processQueue.erase(processQueue.begin()+i);
184 | }
185 | }
186 | if(!readyQueue.empty()){
187 | for(unsigned int i=0;iname) == ui->processtable->item(currentRow,0)->text()){
189 | readyQueue.erase(readyQueue.begin()+i);
190 | }
191 | }
192 | }else{
193 | ui->processtable->removeRow(currentRow);
194 | return ;
195 | }
196 | // qDebug()<<"pid:"<processtable->item(currentRow,0)->text();
197 | w->memoryTab->freeMemery(ui->processtable->item(currentRow,0)->text()); //释放内存物理块
198 | ui->processtable->removeRow(currentRow);
199 |
200 | }
201 |
202 | //开始按钮
203 | void ProcessTab::on_start_clicked()
204 | {
205 | //判断使用哪种调度方法
206 | if (ui->FCFS->isChecked()) {
207 | // timer->start(1000); //启动定时器,运行完一个进程
208 | FCFS();
209 | }else if(ui->SJF->isChecked()){
210 | this->SJF();
211 | }else if(ui->DPTSR->isChecked()){
212 | this->Dynamic_Priority_Time_Slice_Rotation();
213 | }else{
214 | QMessageBox::warning(this,"错误提示",tr("请选择调度算法"));
215 | return ;
216 | }
217 |
218 | }
219 |
220 |
221 | //重置按钮
222 | void ProcessTab::on_reset_clicked()
223 | {
224 | for (int i=0;istate,"完成")!=0){
226 | w->memoryTab->freeMemery(QString::fromStdString( processQueue[i]->name));
227 | }
228 | }
229 | this->semaphore_keyboard = 1;
230 | this->semaphore_full = 0;
231 | this->mutex = 1;
232 | this->isUsed1 = false;
233 | this->isUsed2 = false;
234 | readyQueue.clear();
235 | processQueue.clear();
236 | Random_Create_PCB();
237 | Create_Process_For_Synchronization();
238 | showProcess();
239 | }
240 |
241 |
242 |
243 |
244 | /**************************************先来先服务法********************************************/
245 | void ProcessTab::FCFS(){
246 | h:
247 | while(!readyQueue.empty() || !blockQueue.empty() || !runningQueue.empty()){
248 | PCB *runOne = readyQueue[0];
249 | readyQueue.erase(readyQueue.begin());
250 | runningQueue.push_back(runOne);
251 | this->showQueue();
252 | this->showVisitPages(runOne);
253 |
254 | //判断进程是否有事件,进行PV操作
255 | bool flag;
256 | if(runOne->behaviour == "键盘输入" && !isUsed1){
257 | isUsed1 = true;
258 | flag = this->Process_Behaviour("键盘输入",runOne);
259 | if(flag){
260 | goto h;
261 | }
262 |
263 | }else if(runOne->behaviour == "获取键值" && !isUsed2){
264 | isUsed2 = true;
265 | flag = this->Process_Behaviour("获取键值",runOne);
266 | if(flag){
267 | goto h;
268 | };
269 | }
270 |
271 | while(runOne->needTime>0){
272 |
273 | runOne->needTime--;
274 | runOne->cpuTime++;
275 |
276 | //更新进程信息,更新表格状态
277 | this->updateTableWidget(runOne,"运行");
278 | w->memoryTab->replacePage(QString::fromStdString(runOne->name),runOne->visit_pages[runOne->visit_page_index]);
279 |
280 |
281 | //更新输出日志
282 | ui->textBrowser->insertPlainText("正在执行进程"+QString::fromStdString(runOne->name)+", 访问页面:"+QString::number(runOne->visit_pages[runOne->visit_page_index++])
283 | +", 已运行时间:"+ QString::number(runOne->cpuTime));
284 | ui->textBrowser->moveCursor(QTextCursor::End);
285 | ui->textBrowser->append(QString(""));
286 |
287 | //延时1s
288 | t.start();
289 | while(t.elapsed()<1000);
290 | }
291 |
292 | //进程执行完后更新
293 | this->updateTableWidget(runOne,"完成");
294 | runningQueue.pop_back();
295 | this->showQueue();
296 |
297 | ui->textBrowser->insertPlainText("进程 "+QString::fromStdString(runOne->name)+" 执行完毕!!!");
298 | ui->textBrowser->moveCursor(QTextCursor::End);
299 | ui->textBrowser->append(QString(""));
300 |
301 | if(runOne->behaviour == "键盘输入"){
302 | V(mutex);
303 | flag = V(semaphore_full);
304 | }else if(runOne->behaviour == "获取键值"){
305 | V(this->mutex);
306 | V(semaphore_keyboard);
307 | }
308 | }
309 | }
310 |
311 |
312 | /**********************************短作业优先法*******************************/
313 | //按照优先级从大到小排序
314 | bool ProcessTab::cmp_needtime(PCB *a, PCB *b){
315 | return a->needTime < b->needTime;
316 | }
317 |
318 | void ProcessTab::SJF(){
319 | h: while(!readyQueue.empty() || !blockQueue.empty() || !runningQueue.empty()){
320 | sort(readyQueue.begin(),readyQueue.end(),ProcessTab::cmp_needtime); //就绪队列排序
321 | PCB *runOne = readyQueue[0];
322 | readyQueue.erase(readyQueue.begin());
323 | runningQueue.push_back(runOne);
324 | this->showQueue();
325 | this->showVisitPages(runOne);
326 |
327 | //判断进程是否有事件,进行PV操作
328 | bool flag;
329 | if(runOne->behaviour == "键盘输入" && !isUsed1){
330 | isUsed1 = true;
331 | flag = this->Process_Behaviour("键盘输入",runOne);
332 | if(flag){
333 | goto h;
334 | }
335 |
336 | }else if(runOne->behaviour == "获取键值" && !isUsed2){
337 | isUsed2 = true;
338 | flag = this->Process_Behaviour("获取键值",runOne);
339 | if(flag){
340 | goto h;
341 | };
342 | }
343 |
344 | while(runOne->needTime>0){
345 | runOne->needTime--;
346 | runOne->cpuTime++;
347 |
348 | //更新进程信息,更新表格状态
349 | this->updateTableWidget(runOne,"运行");
350 | w->memoryTab->replacePage(QString::fromStdString(runOne->name),runOne->visit_pages[runOne->visit_page_index]);
351 |
352 |
353 | //更新输出日志
354 | ui->textBrowser->insertPlainText("正在执行进程"+QString::fromStdString(runOne->name)+", 访问页面:"+QString::number(runOne->visit_pages[runOne->visit_page_index++])
355 | +", 已运行时间:"+ QString::number(runOne->cpuTime));
356 | ui->textBrowser->moveCursor(QTextCursor::End);
357 | ui->textBrowser->append(QString(""));
358 |
359 | //延时1s
360 | t.start();
361 | while(t.elapsed()<1000);
362 | }
363 | //进程执行完后更新
364 | this->updateTableWidget(runOne,"完成");
365 | runningQueue.pop_back();
366 | this->showQueue();
367 |
368 | ui->textBrowser->insertPlainText("进程 "+QString::fromStdString(runOne->name)+" 执行完毕!!!");
369 | ui->textBrowser->moveCursor(QTextCursor::End);
370 | ui->textBrowser->append(QString(""));
371 |
372 | if(runOne->behaviour == "键盘输入"){
373 | V(mutex);
374 | flag = V(semaphore_full);
375 | }else if(runOne->behaviour == "获取键值"){
376 | V(this->mutex);
377 | V(semaphore_keyboard);
378 | }
379 | }
380 | }
381 |
382 |
383 | /**********************************动态优先级时间片轮转法*******************************/
384 | //按照优先级从大到小排序
385 | bool ProcessTab::compare(PCB* a,PCB* b){
386 | return a->prio > b->prio;
387 | }
388 |
389 |
390 | void ProcessTab::Dynamic_Priority_Time_Slice_Rotation(){
391 | h: while(!readyQueue.empty() || !blockQueue.empty() || !runningQueue.empty()){
392 | sort(readyQueue.begin(),readyQueue.end(),ProcessTab::compare); //就绪队列排序
393 | PCB *runOne = readyQueue[0];
394 | readyQueue.erase(readyQueue.begin());
395 | strcpy(runOne->state, "运行");
396 | runningQueue.push_back(runOne);
397 | this->showQueue();
398 | this->showVisitPages(runOne);
399 |
400 |
401 | //判断进程是否有事件,进行PV操作
402 | bool flag;
403 | if(runOne->behaviour == "键盘输入" && !isUsed1){
404 | isUsed1 = true;
405 | flag = this->Process_Behaviour("键盘输入",runOne);
406 | if(flag){
407 | goto h;
408 | }
409 |
410 | }else if(runOne->behaviour == "获取键值" && !isUsed2){
411 | isUsed2 = true;
412 | flag = this->Process_Behaviour("获取键值",runOne);
413 | if(flag){
414 | goto h;
415 | };
416 | }
417 |
418 |
419 | //如果进程的所需执行时间<时间片,则进程执行完毕
420 | if(runOne->needTime<=runOne->round){
421 | runOne->cpuTime += runOne->needTime;
422 | runOne->needTime=0;
423 | qDebug()<<"进程 "<name)<<" 执行完毕!";
424 | this->updateTableWidget(runOne,"完成");
425 |
426 | runningQueue.pop_back();
427 | this->showQueue();
428 |
429 | ui->textBrowser->insertPlainText("进程 "+QString::fromStdString(runOne->name)+" 执行完毕!!!");
430 | ui->textBrowser->moveCursor(QTextCursor::End);
431 | ui->textBrowser->append(QString(""));
432 |
433 | if(runOne->behaviour == "键盘输入"){
434 | V(mutex);
435 | flag = V(semaphore_full);
436 | }else if(runOne->behaviour == "获取键值"){
437 | V(this->mutex);
438 | V(semaphore_keyboard);
439 | }
440 |
441 | }
442 | //如果进程没有执行完
443 | else{
444 | runOne->needTime -= runOne->round;
445 | runOne->cpuTime += runOne->round;
446 |
447 | this->updateTableWidget(runOne,"运行");
448 | w->memoryTab->replacePage(QString::fromStdString(runOne->name),runOne->visit_pages[runOne->visit_page_index]);
449 | this->showQueue();
450 |
451 |
452 | //更新输出日志
453 | ui->textBrowser->insertPlainText("正在执行进程"+QString::fromStdString(runOne->name)+", 访问页面:"+QString::number(runOne->visit_pages[runOne->visit_page_index++])
454 | +", 优先级:"+QString::number(runOne->prio)+", 已运行时间:"+ QString::number(runOne->cpuTime));
455 | ui->textBrowser->moveCursor(QTextCursor::End);
456 | ui->textBrowser->append(QString(""));
457 | QCoreApplication::processEvents();
458 | //延时1s
459 | t.start();
460 | while(t.elapsed()<1000);
461 |
462 | for(unsigned int i=0;i< readyQueue.size();i++){
463 | readyQueue[i]->prio+=1; //就绪队列中所有进程优先级提高1
464 | }
465 | if(runOne->prio!=1){
466 | runOne->prio = runOne->prio-1;
467 | }
468 |
469 | //将时间片轮转的进程重新放入就绪队列中
470 | strcpy(runOne->state, "就绪");
471 | runningQueue.clear();
472 | readyQueue.push_back(runOne);
473 | this->showQueue();
474 | this->updateTableWidget(runOne,"round");
475 |
476 | //更新输出日志
477 | ui->textBrowser->insertPlainText("进程 "+QString::fromStdString(runOne->name)+"优先级降低为:"+QString::number(runOne->prio));
478 | ui->textBrowser->moveCursor(QTextCursor::End);
479 | ui->textBrowser->append(QString(""));
480 | QCoreApplication::processEvents();
481 | //延时1s,轮转效果
482 | t1.start();
483 | while(t1.elapsed()<1000);
484 | }
485 | }
486 | }
487 |
488 |
489 | /**************************************** 信号量模拟进程同步 *************************************************/
490 | bool ProcessTab::P(int &semaphore){
491 | semaphore--; //qDebug()<<"P--full:"<state, "阻塞");
496 | blockQueue.push_back(tempProcess);
497 | return true;
498 | }
499 | return false;
500 | }
501 |
502 | bool ProcessTab::V(int &semaphore){
503 | semaphore++;
504 |
505 | //唤醒一个进程
506 | if(semaphore<=0){
507 | semaphore++;
508 | PCB* tempProcess = blockQueue[0];
509 | blockQueue.erase(blockQueue.begin());
510 | strcpy(tempProcess->state, "就绪");
511 | readyQueue.push_back(tempProcess);
512 | return true;
513 | }
514 | return false;
515 | }
516 |
517 | //模拟进程的行为
518 | bool ProcessTab::Process_Behaviour(string behaviour,PCB* runOne){
519 | bool flag;
520 | if(behaviour == "键盘输入"){
521 | flag = P(this->semaphore_keyboard);
522 | P(this->mutex);
523 |
524 | //日志
525 | ui->textBrowser->insertPlainText("键盘正在输入...");
526 | ui->textBrowser->moveCursor(QTextCursor::End);
527 | ui->textBrowser->append(QString(""));
528 | QCoreApplication::processEvents();
529 | return flag;
530 | }
531 |
532 | else if(behaviour == "获取键值"){
533 | flag = P(semaphore_full);
534 |
535 | if(flag == true){
536 | return flag;
537 | }
538 |
539 | P(this->mutex);
540 | //日志
541 | ui->textBrowser->insertPlainText("正在获取键值...");
542 | ui->textBrowser->moveCursor(QTextCursor::End);
543 | ui->textBrowser->append(QString(""));
544 | QCoreApplication::processEvents();
545 |
546 | return flag;
547 | }
548 |
549 | }
550 |
551 | //创建进程模拟进程同步
552 | void ProcessTab::Create_Process_For_Synchronization(){
553 | PCB* p2 = new PCB("获取键值");
554 | p2->behaviour = "获取键值";
555 | //放入就绪队列
556 | processQueue.push_back(p2);
557 | readyQueue.push_back(p2);
558 |
559 |
560 |
561 | PCB* p1 = new PCB("键盘输入");
562 | p1->behaviour = "键盘输入";
563 | //放入就绪队列
564 | processQueue.push_back(p1);
565 | readyQueue.push_back(p1);
566 | }
567 |
568 |
569 |
570 | /**************************************** 文件系统和磁盘调度访问磁道号顺序 *************************************************/
571 | void ProcessTab::Create_Process_For_File(QVector seq){
572 | PCB* file = new PCB("file");
573 |
574 | file->needTime = seq.size();
575 | strcpy( file->state, "运行");
576 | //放入就绪队列
577 |
578 | runningQueue.push_back(file);
579 | processQueue.push_back(file);
580 | this->showProcess();
581 | this->showQueue();
582 |
583 | //磁盘调度
584 | int num = seq.size();
585 | int start_index = 1;
586 | int total_mov_distance = 0;
587 | sort(seq.begin(),seq.end());
588 |
589 | //找到起始位置位于访问序列的相对位置
590 | if(start_index < seq[0]){
591 | for (int i=0;itrack[i] = seq[i];
593 | }
594 | total_mov_distance = seq[num-1]-start_index;
595 | }else if(start_index > seq[num-1]){
596 | for (int i=seq.size()-1;i>= 0;i--) {
597 | file->track[seq.size()-i-1] = seq[i];
598 | }
599 | total_mov_distance = start_index-seq[0];
600 | }else{
601 | //找到磁头在哪个具体位置
602 | for (int i=0;itrack[index++] = seq[j];
608 | }
609 | //然后向左扫描
610 | for (int j=i-1;j>=0;j--) {
611 | file->track[index++] = seq[j];
612 | }
613 | break;
614 | }
615 | }
616 | total_mov_distance = seq[num-1]-seq[0]+seq[num-1]-start_index;
617 | }
618 |
619 |
620 | for (int i=0;idiskTab->ShowDiskTrack(file->track[i]);
622 | ui->textBrowser->insertPlainText("正在执行进程"+QString::fromStdString(file->name)+", 访问磁道号:"+QString::number(file->track[i]));
623 |
624 | ui->textBrowser->moveCursor(QTextCursor::End);
625 | ui->textBrowser->append(QString(""));
626 | QCoreApplication::processEvents();
627 |
628 | file->needTime--;
629 | this->updateTableWidget(file,"运行");
630 |
631 | }
632 |
633 | //访问磁道结束
634 | this->updateTableWidget(file,"完成");
635 | runningQueue.pop_back();
636 | ui->processtable->removeRow(ui->processtable->rowCount()-1);
637 | processQueue.pop_back();
638 | this->showQueue();
639 | this->showProcess();
640 | float avg_dis = (float)total_mov_distance / seq.size();
641 | ui->textBrowser->insertPlainText("总长度 "+QString::number(total_mov_distance)+" 平均寻道长度:"+QString::number(avg_dis));
642 | ui->textBrowser->moveCursor(QTextCursor::End);
643 | ui->textBrowser->append(QString(""));
644 | }
645 |
646 |
647 |
--------------------------------------------------------------------------------
/process/processtab.h:
--------------------------------------------------------------------------------
1 | #ifndef PROCESSTAB_H
2 | #define PROCESSTAB_H
3 |
4 | #include
5 | #include "pcb.h"
6 | #include "QPainter"
7 | #include "vector"
8 | #include "time.h"
9 | #include "algorithm"
10 | #include "QDebug"
11 | #include "QFont"
12 | #include "QBrush"
13 | #include "processdialog.h"
14 | #include "QMessageBox"
15 | #include "QStringListModel"
16 | #include "QTimer"
17 | #include
18 | #include
19 |
20 | #include
21 | #include
22 | #include "QTabWidget"
23 | #include "vector"
24 | #include"cstring"
25 | #include "algorithm"
26 | namespace Ui {
27 | class ProcessTab;
28 | }
29 |
30 | class ProcessTab : public QWidget
31 | {
32 | Q_OBJECT
33 |
34 | public:
35 | explicit ProcessTab(QWidget *parent = nullptr);
36 | ~ProcessTab();
37 |
38 | vector processQueue;
39 | vector readyQueue;
40 | vector runningQueue;
41 | vector blockQueue;
42 |
43 | const int maxPrio=50;
44 | static bool compare(PCB* a,PCB* b);
45 | static bool cmp_needtime(PCB* a,PCB* b);
46 | void Random_Create_PCB();
47 | void insertReadyQueue(PCB* process,string name);
48 | void FCFS();
49 | void SJF();
50 | void Dynamic_Priority_Time_Slice_Rotation(); //动态优先级时间片轮转法
51 | void showQueue();
52 | void showVisitPages(PCB *process);
53 | void updateTableWidget(PCB *runOne,string state);
54 |
55 | int semaphore_keyboard = 1;
56 | int semaphore_full = 0;
57 | int mutex = 1;
58 | bool isUsed1 = false;
59 | bool isUsed2 = false;
60 | bool P(int &semaphore);
61 | bool V(int &semaphore);
62 | bool Process_Behaviour(string behaviour,PCB* runOne);
63 | void Create_Process_For_Synchronization();
64 |
65 | void Create_Process_For_File(QVector disk_visit_Queue);
66 |
67 |
68 |
69 | private slots:
70 | void on_createprocess_clicked();
71 | void on_deleteprocess_clicked();
72 | void on_start_clicked();
73 | void on_reset_clicked();
74 |
75 | public slots:
76 | void showProcess();
77 |
78 |
79 |
80 | private:
81 | Ui::ProcessTab *ui;
82 | QTimer * timer;
83 | QElapsedTimer t;
84 | QElapsedTimer t1;
85 | };
86 |
87 | #endif // PROCESSTAB_H
88 |
--------------------------------------------------------------------------------
/process/processtab.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | ProcessTab
4 |
5 |
6 |
7 | 0
8 | 0
9 | 710
10 | 605
11 |
12 |
13 |
14 |
15 | 710
16 | 605
17 |
18 |
19 |
20 | Form
21 |
22 |
23 |
24 |
25 | 0
26 | 60
27 | 80
28 | 40
29 |
30 |
31 |
32 |
33 | 80
34 | 40
35 |
36 |
37 |
38 |
39 | 黑体
40 |
41 |
42 |
43 | 创建进程
44 |
45 |
46 |
47 |
48 |
49 | 90
50 | 30
51 | 531
52 | 291
53 |
54 |
55 |
56 |
57 | 黑体
58 |
59 |
60 |
61 |
62 |
63 |
64 | 0
65 | 130
66 | 80
67 | 40
68 |
69 |
70 |
71 |
72 | 80
73 | 40
74 |
75 |
76 |
77 |
78 | 黑体
79 |
80 |
81 |
82 | 删除进程
83 |
84 |
85 |
86 |
87 |
88 | 0
89 | 200
90 | 80
91 | 40
92 |
93 |
94 |
95 |
96 | 80
97 | 40
98 |
99 |
100 |
101 |
102 | 黑体
103 |
104 |
105 |
106 | 开始
107 |
108 |
109 |
110 |
111 |
112 | 630
113 | 40
114 | 72
115 | 15
116 |
117 |
118 |
119 | 就绪队列
120 |
121 |
122 |
123 |
124 |
125 | 630
126 | 240
127 | 72
128 | 15
129 |
130 |
131 |
132 | 运行队列
133 |
134 |
135 |
136 |
137 |
138 | 630
139 | 430
140 | 72
141 | 15
142 |
143 |
144 |
145 | 阻塞队列
146 |
147 |
148 |
149 |
150 |
151 | 330
152 | 0
153 | 81
154 | 21
155 |
156 |
157 |
158 | CPU状态
159 |
160 |
161 |
162 |
163 |
164 | 100
165 | 440
166 | 511
167 | 161
168 |
169 |
170 |
171 |
172 |
173 |
174 | 320
175 | 410
176 | 72
177 | 15
178 |
179 |
180 |
181 | 运行信息
182 |
183 |
184 |
185 |
186 |
187 | 20
188 | 430
189 | 72
190 | 15
191 |
192 |
193 |
194 | 调度方法
195 |
196 |
197 |
198 |
199 |
200 | 300
201 | 340
202 | 111
203 | 21
204 |
205 |
206 |
207 | 进程访问页面号
208 |
209 |
210 |
211 |
212 |
213 | 20
214 | 470
215 | 115
216 | 19
217 |
218 |
219 |
220 | FCFS
221 |
222 |
223 |
224 |
225 |
226 | 20
227 | 510
228 | 115
229 | 19
230 |
231 |
232 |
233 | SJF
234 |
235 |
236 |
237 |
238 |
239 | 20
240 | 550
241 | 115
242 | 19
243 |
244 |
245 |
246 | DPTSR
247 |
248 |
249 |
250 |
251 |
252 | 630
253 | 70
254 | 71
255 | 130
256 |
257 |
258 |
259 |
260 | 70
261 | 130
262 |
263 |
264 |
265 |
266 |
267 |
268 | 630
269 | 270
270 | 71
271 | 130
272 |
273 |
274 |
275 |
276 | 70
277 | 130
278 |
279 |
280 |
281 |
282 |
283 |
284 | 630
285 | 460
286 | 71
287 | 130
288 |
289 |
290 |
291 |
292 | 70
293 | 130
294 |
295 |
296 |
297 |
298 |
299 |
300 | 120
301 | 370
302 | 441
303 | 31
304 |
305 |
306 |
307 |
308 |
309 |
310 | 0
311 | 270
312 | 80
313 | 40
314 |
315 |
316 |
317 |
318 | 80
319 | 40
320 |
321 |
322 |
323 |
324 | 黑体
325 |
326 |
327 |
328 | false
329 |
330 |
331 | 重置
332 |
333 |
334 | true
335 |
336 |
337 |
338 |
339 |
340 |
341 |
--------------------------------------------------------------------------------
/操作系统课程设计.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Clarencexiehang/Analog_Operating_System/7ac5fa04b3b74543ffbe1adfc8ef7b1226d15527/操作系统课程设计.docx
--------------------------------------------------------------------------------