BOOL CMainFrame::RefreshStatus() { // lock ActivateUI(FALSE); m_viewTreeList.GetTreeControl().DeleteAllItems(); ClearDevices(); // retrieve all the device & unit device information if(!NdasEnumDevices( EnumDevicesCallBack, reinterpret_cast<LPVOID>(&m_listDevices))) return FALSE; m_wndRefreshProgress.ShowWindow(SW_SHOW); m_wndRefreshProgress.SetRange32(0, m_listDevices.size()); m_wndRefreshProgress.SetStep(1); m_wndRefreshProgress.SetPos(0); // initialize all the unit devices for(NBNdasDevicePtrList::iterator itDevice = m_listDevices.begin(); itDevice != m_listDevices.end(); itDevice++) { if(!(*itDevice)->UnitDevicesInitialize()) { m_wndRefreshProgress.ShowWindow(SW_HIDE); return FALSE; } m_wndRefreshProgress.StepIt(); } // create logical devices CNBUnitDevice *pUnitDevice; CNBLogicalDevice *pLogicalDevice; UINT32 nLogicalDeviceIndex = 0; m_wndRefreshProgress.SetPos(0); for(NBNdasDevicePtrList::iterator itDevice = m_listDevices.begin(); itDevice != m_listDevices.end(); itDevice++) { for(UINT32 i = 0; i < (*itDevice)->UnitDevicesCount(); i++) { // find logical device which has this unit device as member pLogicalDevice = NULL; pUnitDevice = (*(*itDevice))[i]; for(NBLogicalDevicePtrMap::iterator itLogicalDevice = m_mapLogicalDevices.begin(); itLogicalDevice != m_mapLogicalDevices.end(); itLogicalDevice++) { if(itLogicalDevice->second->IsMember(pUnitDevice)) { // add to this logical device pLogicalDevice = itLogicalDevice->second; break; } } if(NULL == pLogicalDevice) { // create new logical device pLogicalDevice = new CNBLogicalDevice(nLogicalDeviceIndex); m_mapLogicalDevices[nLogicalDeviceIndex++] = pLogicalDevice; } if(!pLogicalDevice->UnitDeviceAdd(pUnitDevice)) { m_wndRefreshProgress.ShowWindow(SW_HIDE); return FALSE; } } m_wndRefreshProgress.StepIt(); } m_viewTreeList.SetDevices(&m_mapLogicalDevices); m_wndRefreshProgress.ShowWindow(SW_HIDE); ActivateUI(TRUE); return TRUE; }
BOOL CMainFrame::ThreadRefreshStatus() { if(m_bRefreshing) { return FALSE; } // lock ActivateUI(FALSE); ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus); m_bRefreshing = TRUE; // Get registered device list CDeviceInfoFactory *pFactory = CDeviceInfoFactory::GetInstance(); CDeviceInfoList listDevice; try { listDevice = pFactory->Create(); } catch ( CNDASException &e ) { e.PrintStackTrace(); // TODO : String resource WTL::CString strMsg; WTL::CString strTitle; strTitle.LoadString(IDS_APPLICATION); strMsg.LoadString(IDS_MAINFRAME_SERVICE_FAIL_AT_START); MessageBox( strMsg, strTitle, MB_OK | MB_ICONERROR ); m_bRefreshing = FALSE; LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus); ActivateUI(TRUE); return FALSE; } if(m_pRoot) { CDiskObjectList::iterator itr; for ( itr = m_pRoot->begin(); itr != m_pRoot->end(); ++itr ) { m_view.DeleteDiskObject( *itr ); } m_mapObject.clear(); } m_pRoot = boost::dynamic_pointer_cast<CRootDiskObject>( CDiskObjectBuilder::Build(listDevice) ); // Initialize treeview m_view.SetImageList( CObjectUIHandler::GetImageList(), TVSIL_NORMAL ); m_view.InsertDiskObject( m_pRoot ); BuildObjectMap(m_pRoot); m_bRefreshing = FALSE; LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus); ActivateUI(TRUE); return TRUE; }
BOOL CMainFrame::RefreshStatus() { // lock ActivateUI(FALSE); m_viewTreeList.GetTreeControl().DeleteAllItems(); ClearDevices(); // retrieve all the device & unit device information if(!NdasEnumDevices( EnumDevicesCallBack, reinterpret_cast<LPVOID>(&m_listDevices))) return FALSE; m_wndRefreshProgress.ShowWindow(SW_SHOW); m_wndRefreshProgress.SetRange32(0, m_listDevices.size()); m_wndRefreshProgress.SetStep(1); m_wndRefreshProgress.SetPos(0); // initialize all the unit devices for(NBNdasDevicePtrList::iterator itDevice = m_listDevices.begin(); itDevice != m_listDevices.end(); itDevice++) { if(!(*itDevice)->UnitDevicesInitialize()) { // add single empty device ATLTRACE(_T("Device not connected : %s\n"), (*itDevice)->GetName()); // m_wndRefreshProgress.ShowWindow(SW_HIDE); // return FALSE; } m_wndRefreshProgress.StepIt(); } // create logical devices CNBUnitDevice *pUnitDevice; CNBLogicalDevice *pLogicalDevice; m_wndRefreshProgress.SetPos(0); for(NBNdasDevicePtrList::iterator itDevice = m_listDevices.begin(); itDevice != m_listDevices.end(); itDevice++) { /* if(0 == (*itDevice)->UnitDevicesCount()) { // suppose to be disconnected pLogicalDevice = new CNBLogicalDevice(); pLogicalDevice->SetEmpty(); m_listLogicalDevices.push_back(pLogicalDevice); ATLTRACE(_T("new CNBLogicalDevice(%p) : empty\n"), pLogicalDevice); } */ for(UINT32 i = 0; i < (*itDevice)->UnitDevicesCount(); i++) { // find logical device which has this unit device as member pLogicalDevice = NULL; pUnitDevice = (*(*itDevice))[i]; ATLASSERT(pUnitDevice); if(!pUnitDevice) return FALSE; for(NBLogicalDevicePtrList::iterator itLogicalDevice = m_listLogicalDevices.begin(); itLogicalDevice != m_listLogicalDevices.end(); itLogicalDevice++) { if((*itLogicalDevice)->IsMember(pUnitDevice)) { // add to this logical device pLogicalDevice = *itLogicalDevice; ATLTRACE(_T("use CNBLogicalDevice(%p) : %s\n"), pLogicalDevice, pUnitDevice->GetName()); break; } } if(NULL == pLogicalDevice) { // create new logical device pLogicalDevice = new CNBLogicalDevice(); m_listLogicalDevices.push_back(pLogicalDevice); ATLTRACE(_T("new CNBLogicalDevice(%p) : %s\n"), pLogicalDevice, pUnitDevice->GetName()); } if(!pLogicalDevice->UnitDeviceAdd(pUnitDevice)) { m_wndRefreshProgress.ShowWindow(SW_HIDE); return FALSE; } } m_wndRefreshProgress.StepIt(); } m_viewTreeList.SetDevices(&m_listLogicalDevices); m_wndRefreshProgress.ShowWindow(SW_HIDE); ActivateUI(TRUE); return TRUE; }