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

📄 intelmobilebatteryclassprovider.cpp

📁 270的linux说明
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//			hr = S_OK;//			break;//		case DBT_CUSTOMEVENT:			//_Log( LOG_DEBUG_DEVICE_DEVICE, L"Received DBT_CUSTOMEVENT" );//			bRet = true;//			hr = S_OK;//			break;//		case DBT_DEVICEARRIVAL:			//_Log( LOG_DEBUG_DEVICE_DEVICE, L"Received DBT_DEVICEARRIVAL" );		//	printf("Receive add Notification\n");		//	Lock();//			pDevBroadcastHdr = (PDEV_BROADCAST_HDR) lParam;//			if ( pDevBroadcastHdr != NULL )///			{//				switch (pDevBroadcastHdr->dbch_devicetype)//				{///				case DBT_DEVTYP_DEVICEINTERFACE:					// A request has been made to remove the device;//					pDevBroadcastInterface = (PDEV_BROADCAST_DEVICEINTERFACE) pDevBroadcastHdr;//					if (GuidEqual(pDevBroadcastInterface->dbcc_classguid, GUID_DEVICE_BATTERY))//						Refresh();//					break;//				}//				hr = S_OK;//			}		//	Unlock();//			break;//		case DBT_DEVICEQUERYREMOVE:			//_Log( LOG_DEBUG_DEVICE_DEVICE, L"Received DBT_DEVICEQUERYREMOVE" );//			bRet = true;//			hr = S_OK;///			break;//		case DBT_DEVICEQUERYREMOVEFAILED:			//_Log( LOG_DEBUG_DEVICE_DEVICE, L"Received DBT_DEVICEQUERYREMOVEFAILED" );//			bRet = true;///			hr = S_OK;//			break;//		case DBT_DEVICEREMOVECOMPLETE:			//_Log( LOG_DEBUG_DEVICE_DEVICE, L"Received DBT_DEVICEREMOVECOMPLETE" );		//	printf("Receive Remove Notification\n");		//	Lock();//			pDevBroadcastHdr = (PDEV_BROADCAST_HDR) lParam;//			if ( pDevBroadcastHdr != NULL )//			{//				switch (pDevBroadcastHdr->dbch_devicetype)//				{//				case DBT_DEVTYP_DEVICEINTERFACE:					// A request has been made to remove the device;//					pDevBroadcastInterface = (PDEV_BROADCAST_DEVICEINTERFACE) pDevBroadcastHdr;//					if (GuidEqual(pDevBroadcastInterface->dbcc_classguid, GUID_DEVICE_BATTERY))//						Refresh();//					break;//				}//				hr = S_OK;//			}		//	Unlock();//			break;//		case DBT_DEVICEREMOVEPENDING:			//_Log( LOG_DEBUG_DEVICE_DEVICE, L"Received DBT_DEVICEREMOVEPENDING" );//			bRet = true;///			hr = S_OK;//			break;//		case DBT_DEVICETYPESPECIFIC:			//_Log( LOG_DEBUG_DEVICE_DEVICE, L"Received DBT_DEVICETYPESPECIFIC" );//			bRet = true;//			hr = S_OK;//			break;//		case DBT_DEVNODES_CHANGED:			//_Log( LOG_DEBUG_DEVICE_DEVICE, L"Received DBT_DEVNODES_CHANGED" );//			bRet = true;//			hr = S_OK;//			break;//		case DBT_QUERYCHANGECONFIG:			//_Log( LOG_DEBUG_DEVICE_DEVICE, L"Received DBT_QUERYCHANGECONFIG" );//			bRet = true;//			hr = S_OK;//			break;//		case DBT_USERDEFINED:			//_Log( LOG_DEBUG_DEVICE_DEVICE, L"Received DBT_USERDEFINED" );//			bRet = true;//			hr = S_OK;//			break;//		}//		break;//	case WM_POWERBROADCAST ://		switch ( wParam )//		{//		case PBT_APMBATTERYLOW: // Battery power is low//			bRet = true;//			hr = S_OK;//			break;//		case PBT_APMOEMEVENT : // OEM-defined event occurred//			bRet = true;//			hr = S_OK;//			break;//		case PBT_APMPOWERSTATUSCHANGE : // Power status has changed			//Lock();//			Refresh();//			hr = S_OK;			//Unlock();//			break;//		case PBT_APMQUERYSUSPEND : // Request for permission to suspend//			bRet = true;//			hr = S_OK;//			break;//		case PBT_APMQUERYSUSPENDFAILED : // Suspension request denied//			bRet = true;//			hr = S_OK;///			break;//		case PBT_APMRESUMEAUTOMATIC : // Operation resuming automatically after event//			bRet = true;//			hr = S_OK;///			break;///		case PBT_APMRESUMECRITICAL : // Operation resuming after critical suspension//			bRet = true;//			hr = S_OK;//			break;//		case PBT_APMRESUMESUSPEND : // Operation resuming after suspension//			bRet = true;///			hr = S_OK;//			break;//		case PBT_APMSUSPEND : // System is suspending operation//			bRet = true;//			hr = S_OK;//			break;//		}//		break;	}//	printf("Receive Battery Notification : %d, %d\n", wParam, lParam);	return bRet;}//==============================================================================ServerInstanceObject* BatteryClassProvider::CreateInstanceBattery( const IntelMobileString& szKey ){//cout<<"Create battery instance"<<endl;	try 	{		ServerInstanceObject* pObject = GetClassObject().GetInstance( szKey );		if ( pObject != NULL )			return pObject;	}	catch(ServerException se) {		if (se.IfServerBaseObjectException()) 		{			ServerException nse(IntelMobileText("80043044"));			nse.SetParent( &se );			throw nse;		}		throw se;	}	IntelMobileString externalKey = GetExternalKey ( szKey );	return CreateInstance( externalKey, szKey );}IntelMobileString BatteryClassProvider::GetExternalKey( const IntelMobileString& szKey ){	try	{/*		BATTERY_DEVICE_LIST DeviceList;		BATTERY_DEVICE * BatteryDevice;		IntelMobileString externalKey = IntelMobileText("";		TCHAR eKey[MAX_PATH];//		int index = _wtol( szKey.c_str() )/10000000 - 1;int index=1;		DWORD ret = GetBatteryInstances( &DeviceList );					//TODO optimize code, pull Devicelist out as a global 		if ( ret == 0)		{			if(DeviceList.Device[index].Tag !=0) 			{				char Manufacturer[MAX_PATH];				char Name[MAX_PATH];				BSTR Manvalue = NULL;  				BSTR Namevalue = NULL;  								BatteryDevice = &DeviceList.Device[index];				ret =  GetBatteryManufactureName( BatteryDevice, Manufacturer );					if ( ret == 0) 				{					ret = GetBatteryName( BatteryDevice, Name );					if ( ret == 0 ) 					{//						Manvalue = _com_util::ConvertStringToBSTR( Manufacturer );//						Namevalue = _com_util::ConvertStringToBSTR( Name );//						wsprintf(eKey, L"%s:%s", static_cast<wchar_t*>( Manvalue ), static_cast<wchar_t*>( Namevalue ));						externalKey = eKey;						//::SysFreeString( Manvalue );						//::SysFreeString( Namevalue );					}				}			}		}		// wprintf(L"Battery External Key === [%s]\n", externalKey.c_str() );		return externalKey;	}	catch(ServerException se) {		if (se.IfServerBaseObjectException()) 		{			ServerException nse(L"80043045");			nse.SetParent( &se );			throw nse;		}		throw se;*/	}	catch(...) {		THROWIMEXCEPTION("80043045");	}}ServerInstanceObject* BatteryClassProvider::CreateInstance( const IntelMobileString& externalKey,															  const IntelMobileString& internalKey,															  const IntelMobileString& sType ){//cout<<"BattertyClassProvider::CreateInstance"<<endl;	try	{		ServerInstanceObject* pObject = NULL;		ServerInstanceCollection* pCollection = NULL;		IInstanceProvider* pProvider = GetLayer()->GetLayerInstanceProvider( IntelMobileText("Battery"), externalKey );		if ( pProvider != NULL )		{//cout<<"if1"<<endl;			pObject = pProvider->CreateInstance( internalKey );//cout<<"if1 finish"<<endl;			if ( pObject != NULL )			{//cout<<"if2"<<endl;				pCollection = GetClassObject().GetInstances();				if ( pCollection != NULL ){//cout<<"if3"<<endl;					pCollection->Add( pObject );}				else				{//cout<<"else delete"<<endl;					delete pObject;					pObject = NULL;				}			}		}		return pObject;	}	catch(ServerException se) {//cout<<"try create failed"<<endl;		if (se.IfServerBaseObjectException()) 		{			ServerException nse(IntelMobileText("80043046"));			nse.SetParent( &se );			throw nse;		}		throw se;	}	catch(...) {//cout<<"try create failed"<<endl;		THROWIMEXCEPTION("80043046");	}}// register notification for Battery, so m_hWnd will receive the notification for a battery to be added or removedHRESULT BatteryClassProvider::RegisterForHwndDeviceNotifications(){	try	{		/*DEV_BROADCAST_DEVICEINTERFACE devInterface;		ZeroMemory( &devInterface, sizeof( devInterface ) );		devInterface.dbcc_size = sizeof( devInterface );		devInterface.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;				devInterface.dbcc_classguid = GUID_DEVICE_BATTERY;		HDEVNOTIFY hRes = RegisterDeviceNotification( m_hWnd, &devInterface, DEVICE_NOTIFY_WINDOW_HANDLE );*/	//	RegisterDeviceNotification( m_hWnd, &devInterface, DEVICE_NOTIFY_ALL_INTERFACE_CLASSES );		_Log( LOG_DEBUG_DEVICE, IntelMobileText("Trace RegisterForHwndDeviceNotifications(), registered for Battery Notifications\n" ));				// printf("RegisterForHwndDeviceNotifications --- Battery(%p:%p) !\n", m_hWnd, hRes);		return S_OK;	}	catch(...) {		THROWIMEXCEPTION("80043047");	}}bool BatteryClassProvider::GuidEqual(GUID id1, GUID id2) {/*	if ( ( id1.Data1 == id2.Data1 ) && ( id1.Data2 == id2.Data2 ) && ( id1.Data3 == id2.Data3 ) )	{		for (int i=0; i<8; i++) 		{  			if( id1.Data4[i] != id2.Data4[i] )				return false;		}		return true;	}*/	return false;}

⌨️ 快捷键说明

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