⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intelmobilestorageclassprovider.cpp

📁 270的linux说明
💻 CPP
字号:
/*

Copyright (c) 2008, Intel Corporation. 

All rights reserved.

 

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:


    * Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution.

    * Neither the name of Intel Corporation nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.

*/#include "IntelMobileStorageClassProvider.h"#include "inc/base/Layer_Manager.h"#include "storage_util.h"StorageClassProvider LocalClassProvider;//==============================================================================PROVIDER_API IClassProvider* CreateClassProvider(/* HWND& hWnd*/ ){	//LocalClassProvider.SetWindowHandle( hWnd );	return &LocalClassProvider;}//==============================================================================StorageClassProvider::~StorageClassProvider(){	Unload();	DeleteCriticalSection( &m_DefaultProviderCS );}bool StorageClassProvider::Load(){	_Log(IntelMobileText("StorageClassProvider::Load()"));	bool bRet = true;	bRet = Scan();	if (bRet == false)		return false;	// event monitor initialization	bRet = RegisterThread();	return bRet;}bool StorageClassProvider::Unload(){	_Log(IntelMobileText("StorageClassProvider::Unload()"));	return UnRegisterThread();}bool StorageClassProvider::Scan(){//#ifdef _DEBUG	_Log(IntelMobileText("StorageClassProvider::Scan()"));//#endif	Lock();	m_Devices.clear();	m_Logicals.clear();	/*	HANDLE hFlashCard;					// Search handle for storage cards	WIN32_FIND_DATA wfdFlashCard;		// Structure for storing card information.	hFlashCard = FindFirstFlashCard( &wfdFlashCard );	if (hFlashCard == INVALID_HANDLE_VALUE)	{		return false;	}	CreateInstance( wfdFlashCard.cFileName, wfdFlashCard.cFileName, IntelMobileText("PhysicalDisk" ));	CreateInstance( wfdFlashCard.cFileName, wfdFlashCard.cFileName, IntelMobileText("LogicalDisk" ));	m_Devices.push_back( wfdFlashCard.cFileName );	while ( FindNextFlashCard(hFlashCard, &wfdFlashCard) )	{		CreateInstance( wfdFlashCard.cFileName, wfdFlashCard.cFileName, IntelMobileText("PhysicalDisk" ));		CreateInstance( wfdFlashCard.cFileName, wfdFlashCard.cFileName, IntelMobileText("LogicalDisk" ));		m_Devices.push_back( wfdFlashCard.cFileName );	}	FindClose( hFlashCard );			// Close the search handle.	*/	/*	int ret;	store_info_t pinfo, next;	ret = FindStoreInit();	if(ret < 0)		return false;	ret = FindFirstStore(&pinfo);	if(ret < 0)	{		return false;	}	if(IsPhysicalDisk(&pinfo))	{		CreateInstance(pinfo.name, pinfo.name, IntelMobileText("PhysicalDisk"));		CreateInstance(pinfo.name, pinfo.name, IntelMobileText("LogicalDisk"));		m_Devices.push_back(pinfo.name);	}	while((ret = FindNextStore(&pinfo)) == 0)	{		if(IsPhysicalDisk(&pinfo))		{			CreateInstance(pinfo.name, pinfo.name, IntelMobileText("PhysicalDisk"));			CreateInstance(pinfo.name, pinfo.name, IntelMobileText("LogicalDisk"));			m_Devices.push_back(pinfo.name);		}	}	FindStoreFini();	*/		//Support new storage info model	//1. get disk and its partions	list<disk_info_t> diskInfoList;	if(GetDiskList(diskInfoList))	{		list<disk_info_t>::iterator it = diskInfoList.begin();		for(; it != diskInfoList.end(); it++)		{			//find a disk, create Instance			ServerInstanceObject* pInstance = CreateInstance((*it).name, (*it).name, IntelMobileText("PhysicalDisk"));			m_Devices.push_back( (*it).name );			ServerPhysicalDiskInstanceObject* pPhysicalDiskInstance = reinterpret_cast<ServerPhysicalDiskInstanceObject*>(pInstance);			disk_info_t diskInfo;			strncpy(diskInfo.name, (*it).name, 256);			list<part_info_t> partInfoList;			if(GetDiskPartitionList(&diskInfo, partInfoList))			{				list<part_info_t>::iterator itp = partInfoList.begin();				for(; itp != partInfoList.end(); itp++)				{					ServerInstanceObject* pInstance = CreateInstance((*itp).name, (*itp).name, IntelMobileText("LogicalDisk"));					m_Logicals.push_back( (*itp).name );					ServerLogicalDiskInstanceObject* pPartInstance = reinterpret_cast<ServerLogicalDiskInstanceObject*>(pInstance);					//establish the relation					pPhysicalDiskInstance->AddLogicalDisk(pPartInstance);					pPartInstance->AddPhysicalDisk(pPhysicalDiskInstance);				}			}		}	}	//2. find the flash	list<flash_info_t> flashInfoList;	if(GetInternalFlashList(flashInfoList))	{		list<flash_info_t>::iterator it = flashInfoList.begin();		for(; it != flashInfoList.end(); it++)		{			ServerInstanceObject* pInstance = CreateInstance((*it).name, (*it).name, IntelMobileText("PhysicalDisk"));			m_Devices.push_back( (*it).name );			ServerPhysicalDiskInstanceObject* pPhysicalDiskInstance = reinterpret_cast<ServerPhysicalDiskInstanceObject*>(pInstance);			ServerInstanceObject* pInstance1 = CreateInstance((*it).name, (*it).name, IntelMobileText("LogicalDisk"));			m_Logicals.push_back( (*it).name );			ServerLogicalDiskInstanceObject* pPartInstance = reinterpret_cast<ServerLogicalDiskInstanceObject*>(pInstance1);			//establish the relation			pPhysicalDiskInstance->AddLogicalDisk(pPartInstance);			pPartInstance->AddPhysicalDisk(pPhysicalDiskInstance);		}	}	//3. find network partition	list<part_info_t> netPartList;	if(GetNetworkPartitionList(netPartList))	{		list<part_info_t>::iterator it = netPartList.begin();		for(; it != netPartList.end(); it++)		{			ServerInstanceObject* pInstance = CreateInstance((*it).name, (*it).name, IntelMobileText("LogicalDisk"));			m_Logicals.push_back( (*it).name );			ServerLogicalDiskInstanceObject* pPartInstance = reinterpret_cast<ServerLogicalDiskInstanceObject*>(pInstance);			pPartInstance->Pnet = true;		}	}	//4. find the memory	CreateInstance( IntelMobileText("Memory"), IntelMobileText("Memory"), IntelMobileText("Memory") );	//TODO: Linux	Unlock();	return true;}/*bool StorageClassProvider::WindowNotification(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam){	bool bRet = true;	//	// TODO For CE, but Window Notification is not supported on WinCE	return bRet;}*///==============================================================================ServerClassObject& StorageClassProvider::GetClassObject( const IntelMobileString& sType ){	if ( sType == IntelMobileText( "PhysicalDisk" ) )		return m_PhysicalDiskClass;	else if ( sType == IntelMobileText( "LogicalDisk" ) )		return m_LogicalDiskClass;	else if ( sType == IntelMobileText( "Memory" ) )		return m_MemoryClass;	else		throw;}//==============================================================================ServerInstanceObject* StorageClassProvider::CreateInstance( const IntelMobileString& externalKey,															const IntelMobileString& internalKey,															const IntelMobileString& sType ){	_Log(IntelMobileText("StorageClassProvider::CreateInstance(%s, %s, %s)"),externalKey.c_str(), internalKey.c_str(), sType.c_str());	ServerInstanceObject* pObject = GetClassObject( sType ).GetInstance( internalKey );	if ( pObject == NULL )	{		IInstanceProvider* pProvider = GetLayer()->GetLayerInstanceProvider( sType, externalKey );		if ( pProvider != NULL )		{			pObject = pProvider->CreateInstance( internalKey );			if ( pObject != NULL )			{				ServerInstanceCollection* pCollection = GetClassObject( sType ).GetInstances();				pCollection->Add( pObject );			}		}	}	return pObject;}//==============================================================================DWORD StorageClassProvider::ThreadProc(LPVOID pParam){			StorageClassProvider *pThis = reinterpret_cast<StorageClassProvider *>(pParam);	if ( pThis )		pThis->MonitorProc();	return 0;}bool StorageClassProvider::RegisterThread(){	DWORD threadId;//#ifdef _DEBUG	_Log(IntelMobileText("StorageClassProvider::RegisterThread()"));//#endif	Lock();	if ( m_bThreadActive == false )	{		if ( m_hThreadHandle )		{			CloseHandle( m_hThreadHandle );			m_hThreadHandle = NULL;		}		m_hThreadHandle = ::CreateThread( NULL, 0, ThreadProc, this, NULL, &threadId );		if ( m_hThreadHandle )			m_bThreadActive = true;	}	Unlock();	return m_bThreadActive;}bool StorageClassProvider::UnRegisterThread(){//#ifdef _DEBUG	_Log(IntelMobileText("StorageClassProvider::UnRegisterThread()"));//#endif	Lock();	if ( m_hThreadHandle )	{		CloseHandle( m_hThreadHandle );		m_hThreadHandle = NULL;		m_bThreadActive = false;	}	Unlock();	return true;}void StorageClassProvider::MonitorProc(){	while ( m_bThreadActive )	{		/*		int count = 0;		HANDLE hFlashCard;					// Search handle for storage cards		WIN32_FIND_DATA wfdFlashCard;		// Structure for storing card information.		hFlashCard = FindFirstFlashCard( &wfdFlashCard );		if (hFlashCard != INVALID_HANDLE_VALUE)		{			count++;			while ( FindNextFlashCard(hFlashCard, &wfdFlashCard) )			{				count++;			}		}		FindClose( hFlashCard );		int preCount = this->m_Devices.size();		if (preCount != count)		{			if (preCount > count)				this->m_PhysicalDiskClass.FireEvent( ServerEvent(ServerEvent::eRemove) );			else				this->m_PhysicalDiskClass.FireEvent( ServerEvent(ServerEvent::eAdd) );			this->Scan();		}		::Sleep( 1000 );		*//*		int count = 0;		store_info_t pinfo, next;		int ret;		ret = FindStoreInit();		ret = FindFirstStore( &pinfo );		if (ret == 0)		{			count++;			while ((ret = FindNextStore(&pinfo)) == 0 )			{				printf("cout num %d\n", count);				count++;			}		}*/	vector <IntelMobileString> temp_Devs, temp_Logs;	list<disk_info_t> diskInfoList;	if(GetDiskList(diskInfoList))	{		list<disk_info_t>::iterator it = diskInfoList.begin();		for(; it != diskInfoList.end(); it++)		{			//find a disk, create Instance			temp_Devs.push_back( (*it).name );			disk_info_t diskInfo;			strncpy(diskInfo.name, (*it).name, 256);			list<part_info_t> partInfoList;			if(GetDiskPartitionList(&diskInfo, partInfoList))			{				list<part_info_t>::iterator itp = partInfoList.begin();				for(; itp != partInfoList.end(); itp++)				{					temp_Logs.push_back( (*itp).name );				}			}		}	}	//2. find the flash	list<flash_info_t> flashInfoList;	if(GetInternalFlashList(flashInfoList))	{		list<flash_info_t>::iterator it = flashInfoList.begin();		for(; it != flashInfoList.end(); it++)		{			temp_Devs.push_back( (*it).name );			temp_Logs.push_back( (*it).name );			//establish the relation		}	}	//3. find network partition	list<part_info_t> netPartList;	if(GetNetworkPartitionList(netPartList))	{		list<part_info_t>::iterator it = netPartList.begin();		for(; it != netPartList.end(); it++)		{			temp_Logs.push_back( (*it).name );		}	}		int preDevCount = this->m_Devices.size();		int preLogCount = this->m_Logicals.size();		int curDevCount = temp_Devs.size();		int curLogCount = temp_Logs.size();	//	printf("predevcout %d : prelogcout %d\ncurdevcount %d curlogcout %d\n", preDevCount, preLogCount, curDevCount, curLogCount);			while( curDevCount - preDevCount > 0 )		{			this->m_PhysicalDiskClass.FireEvent( ServerEvent(ServerEvent::eAdded) );			preDevCount++;		}		while( curDevCount - preDevCount < 0 )		{			this->m_PhysicalDiskClass.FireEvent( ServerEvent(ServerEvent::eRemoved) );			preDevCount--;		}		while( curLogCount - preLogCount > 0 )		{			this->m_LogicalDiskClass.FireEvent( ServerEvent(ServerEvent::eAdded) );			preLogCount++;		}		while( curLogCount - preLogCount < 0 )		{			this->m_LogicalDiskClass.FireEvent( ServerEvent(ServerEvent::eRemoved) );			preLogCount--;		}/*		if (preCount != count)		{			if (preCount > count)				this->m_PhysicalDiskClass.FireEvent( ServerEvent(ServerEvent::eRemoved) );			else				this->m_PhysicalDiskClass.FireEvent( ServerEvent(ServerEvent::eAdded) );			this->Scan();		}*/		this->Scan();	//	FindStoreFini();		::Sleep( 1000 );		//TODO: Linux	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -