📄 intelmobileprocessorclassprovider.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.
*///==============================================================================// IntelMobileProcessorClassProvider.cpp//// Defines the class for the processor class provider. This module// contains the methods for the public interfaces of the inherited classes.//// //==============================================================================//#include "stdafx.h"#include "IntelMobileProcessorClassProvider.h"#include "libLinCPUID/LinCPUID.h"ProcessorClassProvider LocalClassProvider;//==============================================================================PROVIDER_API IClassProvider* CreateClassProvider( /*HWND& hWnd*/ ){ //LocalClassProvider.SetWindowHandle( hWnd ); return &LocalClassProvider;}//==============================================================================ProcessorClassProvider::~ProcessorClassProvider(){ Unload(); DeleteCriticalSection( &m_DefaultProviderCS );}bool ProcessorClassProvider::Load(){ bool bRet = true; bRet = Scan(); // the processor has no event for now return bRet;}bool ProcessorClassProvider::Unload(){ return true;}bool ProcessorClassProvider::Scan(){ _Log( IntelMobileText("Initializing Processors" )); try { Lock(); DWORD dwAffinityMask; CPUINFO_T tempCPUInfo = CPUINFO_T_INIT_VAL; // Get the processor affinity information tempCPUInfo.htInfo.nMaxPhysGetProcAff = 8; tempCPUInfo.htInfo.pPhysProcAff = new PHYSPROCAFF_T[8]; if (tempCPUInfo.htInfo.pPhysProcAff) { ZeroMemory(tempCPUInfo.htInfo.pPhysProcAff, sizeof(PHYSPROCAFF_T)*8); } tempCPUInfo.pProcString = new char [PROCSTRING_BYTES]; LinCPUID_Init(0, &tempCPUInfo); // Get brand which is the external key char brand[256]; IntelMobileChar value[256]; if ( (*tempCPUInfo.pProcString) != 0 ) strcpy( brand, tempCPUInfo.pProcString ); else LinCPUID_getBrandStrEx( brand, sizeof(brand), &(tempCPUInfo.coreInfo) ); //value = _com_util::ConvertStringToBSTR( brand );#ifdef _UNICODE mbstowcs(value, brand, 256);#else strncpy(value, brand, 256);#endif // Create an Instance Object for each processor in the system (logical processors count too) for (int i = 0; i < tempCPUInfo.htInfo.nPhysicalProcs; i++) { dwAffinityMask = (DWORD) ( tempCPUInfo.htInfo.pPhysProcAff[i].dwPhysAffinity | tempCPUInfo.htInfo.pPhysProcAff[i].dwLogAffinity ); IntelMobileChar strID[256]; //_itow(dwAffinityMask, strID, 10);#ifdef _UNICODE swprintf(strID, 256, IntelMobileText("%d"), dwAffinityMask); #else snprintf(strID, 256, IntelMobileText("%d"), dwAffinityMask); #endif CreateInstance( value, strID , IntelMobileText("X86Processor") ); } //::SysFreeString( value ); //Leak fixed. delete [] tempCPUInfo.pProcString; delete[] tempCPUInfo.htInfo.pPhysProcAff; //. // only for test Unlock(); } catch(ServerException se) { Unlock(); if (se.IfServerBaseObjectException()) { ServerException nse(IntelMobileText("80043009")); nse.SetParent( &se ); throw nse; } throw se; } catch(...) { Unlock(); THROWIMEXCEPTION("80043009"); } _Log( IntelMobileText("Processor init complete.") ); return true;}/*bool ProcessorClassProvider::WindowNotification(HWND m_hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam){ bool bRet = true; // do nothing for processor return bRet;}*///==============================================================================ServerInstanceObject* ProcessorClassProvider::CreateInstance( const IntelMobileString& externalKey, const IntelMobileString& internalKey, const IntelMobileString& sType ){ //cout << "ProcessorClassProvider::CreateInstance" << endl; ServerInstanceObject* pObject = GetClassObject().GetInstance( internalKey ); if ( pObject == NULL ) { IInstanceProvider* pProvider = GetLayer()->GetLayerInstanceProvider( sType, externalKey ); if ( pProvider != NULL ) { pObject = pProvider->CreateInstance( internalKey ); if ( pObject != NULL ) { ServerInstanceCollection* pCollection = GetClassObject().GetInstances(); pCollection->Add( pObject ); } } } //cout << "ProcessorClassProvider::CreateInstance Success" << endl; //cout << "pObject: " << pObject << endl; return pObject;}ServerClassObject& ProcessorClassProvider::GetClassObject( /*in*/ const IntelMobileString& sType ) { if ( sType == ( "Processor" ) ) return m_ProcessorClass; else if ( sType == ( "Core" ) ) return m_CoreClass; else if ( sType == ("Logical") ) return m_LogicalClass; else throw 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -