void CTask::_callbackFunc(void * pData) { CTask* pTask = (CTask*)pData; if (pTask->Initialize()){ printf("[%02d]%s is running.\n", pTask->GetPrio(), pTask->GetName()); while (pTask->Execution()); printf("[%02d]%s is end.\n", pTask->GetPrio(), pTask->GetName()); }else{ printf("[%02d]%s initialze fail!.\n", pTask->GetPrio(), pTask->GetName()); } OSTaskDel(OS_PRIO_SELF); }
LRESULT CBackEndDialog::OnAddTask(WPARAM wParam, LPARAM lParam) { //extract the task CTask* pNewTask = (CTask*)wParam; ASSERT(pNewTask); //see if this task is already in the list CTask* pCurr = m_pHeadTask; while(pCurr) { if(stricmp(pCurr->GetName(), pNewTask->GetName()) == 0) { //already have a task of that name delete pNewTask; return 0; } pCurr = pCurr->GetNextTask(); } if(m_pHeadTask == NULL) { m_pHeadTask = pNewTask; } else { //add it onto the end CTask* pCurr = m_pHeadTask; while(pCurr->GetNextTask()) pCurr = pCurr->GetNextTask(); pCurr->SetNextTask(pNewTask); } //now we can update the list control int nIndex = GetTaskList()->AddString(pNewTask->GetName()); GetTaskList()->SetItemData(nIndex, (DWORD)pNewTask); return 0; }
//saves all the messages and tasks to a file of the specified name bool CBackEndDialog::SaveLogToFile(const char* pszFilename) { //open up the file and write out all the tasks and all their messages #if _MSC_VER >= 1300 std::ofstream OutFile(pszFilename); #else ofstream OutFile(pszFilename); #endif if(OutFile.fail()) { return false; } CTask* pCurrTask = m_pHeadTask; while(pCurrTask) { //write out the task title OutFile << "Task: " << pCurrTask->GetName() << "\n\n"; //write out the messages CTaskMessage* pCurrMsg = pCurrTask->GetMessageHead(); while(pCurrMsg) { OutFile << "\t" << FormatFinalMsg(pCurrMsg); pCurrMsg = pCurrMsg->GetNext(); } pCurrTask = pCurrTask->GetNextTask(); } OutFile.close(); return true; }
LRESULT CBackEndDialog::OnActivateTask(WPARAM wParam, LPARAM lParam) { //get the text char* pszTaskName = (char*)wParam; //track the old task CTask* pOldTask = m_pCurrTask; //run through the list and find the task CTask* pCurr = m_pHeadTask; while(pCurr) { if(stricmp(pszTaskName, pCurr->GetName()) == 0) { m_pCurrTask = pCurr; break; } pCurr = pCurr->GetNextTask(); } //clean up the name now delete [] pszTaskName; pszTaskName = NULL; //see if we didn't find the task if(pCurr == NULL) { return false; } //set the active task name around the progress bar CStatic* pTaskName = (CStatic*)GetDlgItem(IDC_STATIC_TASK_NAME); CString sText; sText.Format("Task: %s", (m_pCurrTask) ? m_pCurrTask->GetName() : "None"); ((CStatic*)GetDlgItem(IDC_STATIC_TASK_NAME))->SetWindowText(sText); //also update the progress bar to reflect the change SetTaskProgress((m_pCurrTask) ? m_pCurrTask->GetProgress() : 0.0f); //if the user was viewing the previous task, then we want to start viewing the new //task, the same goes for if the user isn't viewing any tasks CTask* pViewedTask = GetViewedTask(); if((pOldTask == pViewedTask) || (pViewedTask == NULL)) { //find this new task for(uint32 nCurrTask = 0; nCurrTask < (uint32)GetTaskList()->GetCount(); nCurrTask++) { if((CTask*)GetTaskList()->GetItemData(nCurrTask) == m_pCurrTask) { //this is a match, select it GetTaskList()->SetCurSel(nCurrTask); ResetMessageList(); break; } } } //save this task as our current subtask m_sSubTaskName = (m_pCurrTask) ? m_pCurrTask->GetName() : ""; //update the title bar UpdateTitleNonIconic(); return 0; }