/* * SYSTEM CALL */ int sys_send_msg(MSG *p_msg , int send_pid , int send_pid_parent , int p_tty , int p_flag){ // char *str = {"Victory!"}; // MAIL_BOX *p_mail_box; if(p_msg -> type < MSG_SPECIAL_TYPE){ //如果不是特殊消息包,将消息包放入目标进程的邮箱。否则函数自己处理 //获得目的进程的邮箱指针 // p_mail_box = &(mail_center.mail_box_row[p_msg -> recv_pid]); //封装填充消息的部分内容 p_msg -> send_pid = send_pid; p_msg -> int_proc_info[0] = send_pid_parent;//依照在PCB中的顺序填入 p_msg -> int_proc_info[1] = p_tty; p_msg -> int_proc_info[2] = p_flag; return post_msg(p_msg); }else{ //处理特殊消息包 switch(p_msg -> type){ case MSG_SUSPEND_PROC: if(send_pid == 0){ //必须0进程才能暂停某进程 proc_table.p_pcb[p_msg -> recv_pid] -> p_flag = P_FLAG_SUS; //根据接收进程的pid设置其p_flag为挂起状态 } del_msg(p_msg); break; case MSG_AWAKE_PROC: proc_table.p_pcb[p_msg -> recv_pid] -> p_flag = P_FLAG_RUN; //根据接收进程的pid设置其p_flag为激活状态 del_msg(p_msg); break; case MSG_RELOAD: //重新装填消息到自身收件队列中 post_msg((MSG *)p_msg -> int_info[0]); //因为p_msg -> int_info[0]存储的是目标消息指针 del_msg(p_msg); break; case MSG_PAUSE: proc_table.p_pcb[send_pid] -> p_flag = P_FLAG_SUS; //将发送者的进程挂起。因为这是其自己提出的 del_msg(p_msg); break; default: del_msg(p_msg); break; } return 0; } }
/* * int pause(); * 使自身进程处于挂起状态 *其他进程向其发送信号将使它激活 * * 成功返回信号类型。失败返回-1 */ int pause(){ MSG *p_msg; int signal = -1; p_msg = get_msg(); p_msg->type = MSG_PAUSE; send_msg(p_msg); /* * 这里使借鉴了wait(signal)的设计。因为发送包到处理会有一段时间,因此调用程序完全可能跨越pause()而执行之后的部分程序 * 这是不被允许的。因此使用此循环,因为pause()的进程被激活是有进程向其发送包,所以其接收队列中一定有信号包。 */ while(1){ p_msg = recv_msg(); if(p_msg -> type == MSG_SIGNAL){ signal = p_msg->signal; del_msg(p_msg); return signal; //返回信号的类型 } if(p_msg != (MSG *)NULL) reload_msg(p_msg); //如果出现了自己不需要的消息,将会把该消息重新放入自己的收件箱 } //end while }
void ncurs_chat() { /* TODO: figure out this toggle mess */ toggle_chat += 1; if (toggle_chat >= 3) /* never loop messageboard */ toggle_chat = 0; /* redraw the input line - chat toggle*/ ncurs_bold_input(toggle_chat); char *line = NULL; size_t len = 0; if (toggle_chat != 0) { if (todd_getline(&line, &len, input_win)) { Message msg = create_chat_msg(line, len); /* a chat message was succesfully input(ted) */ if (toggle_chat == 1) { // party message msg = wrap_as_partymsg(msg); } if (!send_msg(msg)) { ncurs_log_sysmsg(_("Message send failure")); } del_msg(msg); } // return to basic input prompt -> press any key for game commands // this is done here because if todd_getline returns 0 it means there's an empty line // TODO.. or todd_getline has an error... toggle_chat = 0; ncurs_bold_input(0); free(line); } }
void* recv_thread(void * params) { char *buf; uint32_t len; uint32_t i; struct bc_msg *m; uint32_t module_id; int ret; module_id = ((struct vars *)params)->id; while (1) { ret = recv_msg(module_id, &m); assert(ret == 0); del_msg(m); pthread_mutex_lock(&rlock); rcount++; fprintf(stderr, "recv %d\n", rcount); pthread_mutex_unlock(&rlock); } return NULL; }
/* * definition */ void task_tty(){ int i; MSG *p_msg; /* * Can not change */ init_console(); init_tty(); // tty_write_str("LeiMing" , (TTY *)&tty_table[TTY_ENABLE]); // tty_write_ctrl((TTY *)&tty_table[TTY_ENABLE]); // tty_write_str("is Best!" , (TTY *)&tty_table[TTY_ENABLE]); /* * Test msg = get_msg(); msg -> type = 8; tty_write_int((u32)msg -> type , (TTY *)&tty_table[TTY_ENABLE]); del_msg(msg); msg = get_msg(); tty_write_int((u32)msg -> type , (TTY *)&tty_table[TTY_ENABLE]); */ // int i; // char *src = {"Lei Ming is best hahaha"}; // char dest[20]; // for(i = 0; i < 20; i++){ // dest[i] = '0'; // } // strcpy(dest , src , sizeof(dest) - 1); // tty_write_str(dest , (TTY *)&tty_table[TTY_ENABLE]); // disp_int(i); // set_start_vmem((u32)(80 * 1)); while(1){ p_msg = recv_msg(); if(p_msg == (MSG *)NULL){ }else{ switch(p_msg -> type){ //根据消息的不同类型来不同地处理 // case MSG_WRITE_ENTER: case MSG_WRITE_CHAR: tty_write_char(p_msg -> int_info[0] , (TTY *)&tty_table[p_msg -> int_proc_info[1]]); del_msg(p_msg); break; case MSG_WRITE_INT: tty_write_int(p_msg -> int_info[0] , (TTY *)&tty_table[p_msg -> int_proc_info[1]]); del_msg(p_msg); break; case MSG_WRITE_STR: tty_write_str(p_msg -> str_info , (TTY *)&tty_table[p_msg -> int_proc_info[1]]); //第二个参数是进程所在的p_tty del_msg(p_msg); break; case MSG_PRINT_CTRL: tty_print_ctrl((TTY *)&tty_table[p_msg -> int_proc_info[1]]); del_msg(p_msg); break; default: break; } } key_control((TTY *)&tty_table[TTY_ENABLE]); } }
//////////////////////////////////////////////////////////// /////////////////硬盘系统进程///////////////////////////// void task_hd(){ // u8 hd_buff[SEC_SIZE]; MSG *p_msg; u8 status; u32 *p; init_hd_info(&hd_info); while(1){ p_msg = recv_msg(); if(p_msg != (MSG *)NULL){ switch(p_msg -> type){ case MSG_SIGNAL: switch(p_msg -> signal){ case 0: // printf("Get SIGNAL 0!"); break; default: break; } del_msg(p_msg); break; case MSG_HD_OPEN: hd_identify(0); /*获得硬盘的数量 0x475是BIOS规定的数据点。从这里可以取出硬盘的数量*/ // u8 *pNrDrives = (u8 *)(0x475); // printf("NrDrives:%d./n", *((u8 *)(0x475))); get_hd_partion(fs_buff , 0 , 0 , -1); // print_hd_info(&hd_info); printf("Hard Disk Opened!/n"); kill(p_msg->send_pid , SIG_READY); //发送信号。表示分区信息已经获得。 del_msg(p_msg); break; case MSG_READ_HD: //MSG-> int_info[0]:char *buff int_info[1]:driver int_info[2]:abs_sec read_hd_sector((u8 *)p_msg->int_info[0] , p_msg->int_info[1] , p_msg->int_info[2]); kill(p_msg->send_pid , SIG_READY);//需要发送信号给目标进程。表示已经成功读入。解除对方的死虚幻 // printf("Read!"); del_msg(p_msg); break; case MSG_WRITE_HD: //MSG-> int_info[0]:char *buff int_info[1]:driver int_info[2]:abs_sec write_hd_sector((u8 *)p_msg->int_info[0] , p_msg->int_info[1] , p_msg->int_info[2]); kill(p_msg->send_pid , SIG_READY);//发送信号给发送进程。表示已经成功写入。解除对方的死循环 // printf("Write!"); del_msg(p_msg); break; default: del_msg(p_msg); break; } } } }
void MyMainWindow::on_delete_checked_clicked() { std::vector<MyFileInfoPtr> item_list; // get a list of all the items checked for deletion for(int n = file_model->rowCount(), i = 0; i < n; i++) { if(file_model->data(file_model->index(i, MyFileSystemModelPublic::CHECKED_HEADER), Qt::CheckStateRole) == Qt::Checked) { QString full_path = file_model->data(file_model->index(i, MyFileSystemModelPublic::FULL_PATH_HEADER)).toString(); item_list.push_back(MyFileInfoPtr(new MyFileInfo(nullptr, full_path))); } } int total_items = item_list.size(); if(total_items != 0) { QMessageBox::StandardButton ret_val = QMessageBox::question(this, "Delete items?", "Are you " "sure you wish to permanently delete the selected items?", QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel); if(ret_val == QMessageBox::Ok) { std::vector<QString> result_list; for(int i = 0; i < total_items; i++) { QString full_path = item_list[i]->getFullPath(); QString item_type = item_list[i]->getType(); if(item_type == MyFileInfo::typeToString(MyFileInfoPublic::MFIT_FILE)) { if(QFile::remove(full_path)) { file_model->removeItem(full_path); result_list.push_back("Successfully deleted file!"); } else result_list.push_back("Error deleting file!"); } else if(item_type == MyFileInfo::typeToString(MyFileInfoPublic::MFIT_DIR)) { if(QDir(full_path).removeRecursively()) { file_model->removeItem(full_path); result_list.push_back("Successfully deleted directory!"); } else result_list.push_back("Error deleting directory!"); } else { file_model->removeItem(full_path); result_list.push_back("Item was not found!"); } } // items were most likely removed from the model, resize columns setModel(file_model); QString det_string; // create a string containing the list of items and results for(int i = 0; i < item_list.size(); i++) { det_string += item_list[i]->getFullPath(); det_string += "\n" + result_list[i]; if(i < item_list.size() - 1) det_string += "\n\n"; } QMessageBox del_msg(QMessageBox::Information, "Deletion completed!", "The deletion process " "was completed. Click below to show details.", QMessageBox::Close, this); del_msg.setDetailedText(det_string); del_msg.exec(); } // total_items != 0 } }