📄 processorinstanceobject.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.
*///==============================================================================// ProcessorInstanceObject.cpp // Implementation of the class ProcessorInstance//==============================================================================#include "IntelMobile/Base/base_Exception.h"#include "IntelMobile/Base/base_InstanceObject.h"#include "IntelMobile/Base/base_ClassObject.h"#include "ProcessorInstanceObject.h"#include "CoreInstanceObject.h"#include "X86CoreInstanceObject.h"
#include "X86LogicalInstanceObject.h"#include "Utility/StringHelper.h"#include "inc/Base/base_Exception.h"#include "inc/Base/VectorTemplateMacros.h"
using namespace Intel::Mobile::Processor;//==============================================================================//class ProcessorInstance//==============================================================================// C_Tor()//==============================================================================Intel::Mobile::Processor::ProcessorInstance::ProcessorInstance( void *pImpl ) : InstanceObject ( pImpl ), Manufacturer( *this ), Brand( *this ), Id( *this ), Role( *this ), Fsb( *this ), CpuUsage( *this ), LogicalCount( *this ), CoreCount( *this ){ if ( m_pImpl != NULL ) { Intel::Mobile::BaseAPI::InstanceObject* pImpl = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject*>(m_pImpl); Manufacturer.Init( pImpl->GetPropertyByName(IntelMobileText("Manufacturer"), IntelMobileText("String")) ); Brand.Init( pImpl->GetPropertyByName(IntelMobileText("Brand"), IntelMobileText("String")) ); Id.Init( pImpl->GetPropertyByName(IntelMobileText("Id"), IntelMobileText("String")) ); Role.Init( pImpl->GetPropertyByName(IntelMobileText("Role"), IntelMobileText("String")) ); Fsb.Init( pImpl->GetPropertyByName(IntelMobileText("Fsb"), IntelMobileText("UInt")) ); CpuUsage.Init( pImpl->GetPropertyByName(IntelMobileText("CpuUsage"), IntelMobileText("Float")) ); LogicalCount.Init( pImpl->GetPropertyByName(IntelMobileText("LogicalCount"), IntelMobileText("UInt")) ); CoreCount.Init( pImpl->GetPropertyByName(IntelMobileText("CoreCount"), IntelMobileText("UInt")) ); }}//==============================================================================// D_Tor()//==============================================================================Intel::Mobile::Processor::ProcessorInstance::~ProcessorInstance(){ if (m_flag)
{
if (m_pImpl)
{
Intel::Mobile::BaseAPI::InstanceObject *pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject *>(m_pImpl);
if (pAPI_Instance)
{
delete pAPI_Instance;
}
m_pImpl = NULL;
}
}}//==============================================================================// GetType()//==============================================================================Intel::Mobile::Base::StringObject Intel::Mobile::Processor::ProcessorInstance::GetType() const{ if (m_pImpl) { Intel::Mobile::BaseAPI::InstanceObject *pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject *>(m_pImpl); if (pAPI_Instance) { TRYBLOCK { IntelMobileChar* pType = pAPI_Instance->GetType();
Intel::Mobile::Base::StringObject sType( pType );
delete[] pType;
return sType; } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Processor::ProcessorInstance"), IntelMobileText("GetType")); } else THROWNE(IntelMobileText("Intel::Mobile::Processor::ProcessorInstance"), IntelMobileText("GetType"));}//==============================================================================// GetType()//==============================================================================Intel::Mobile::Base::StringObject Intel::Mobile::Processor::ProcessorInstance::GetKey() const{ if (m_pImpl) { Intel::Mobile::BaseAPI::InstanceObject *pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject *>(m_pImpl); if (pAPI_Instance) { TRYBLOCK { IntelMobileChar* pKey = pAPI_Instance->GetKey();
Intel::Mobile::Base::StringObject sKey( pKey );
delete[] pKey;
return sKey; } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Processor::ProcessorInstance"), IntelMobileText("GetKey")); } else THROWNE(IntelMobileText("Intel::Mobile::Processor::ProcessorInstance"), IntelMobileText("GetKey"));}//==============================================================================// GetCacheInfo()//==============================================================================Intel::Mobile::Processor::CacheInfoVector Intel::Mobile::Processor::ProcessorInstance::GetCacheInfo(){ //CacheInfoVector ciVector;
vector<CacheInfo> ciVector; IntelMobileString strInner, strOuter; vector<IntelMobileString> vectInner, vectOuter; if (m_pImpl) { Intel::Mobile::BaseAPI::InstanceObject *pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject *>(m_pImpl); if (pAPI_Instance && IsAvailable( IntelMobileText("GetCacheInfo") ) ) { TRYBLOCK { IntelMobileChar data[1024]; IntelMobileChar* infoString = pAPI_Instance->InvokeMethod( IntelMobileText("GetCacheInfo"), IntelMobileText("") ); strcpy( data, infoString ); printf("Intel::Mobile::Processor::ProcessorInstance::GetCacheInfo() = %s\r\n",infoString); delete infoString; IntelMobileChar line[256]; IntelMobileChar item[256]; IntelMobileChar* remain = strchr( data, ';' ); while ( remain != NULL ) { size_t pos = remain - data + 1; strncpy( line, data, pos-1 ); line[pos-1] = '\0'; unsigned int itemdata[6] = {0, 0, 0, 0, 0, 0}; int j = 0; IntelMobileChar* itemremain = strchr( line, ',' ); while( itemremain != NULL ) { size_t itempos = itemremain - line + 1; strncpy ( item, line, itempos-1 ); item[itempos-1] = '\0'; itemdata[j++] = (unsigned int)atol( item ); strcpy( line, line+itempos ); itemremain = strchr( line, ',' ); } CacheInfo pci; pci.CacheType = (Intel::Mobile::Processor::CacheTypeEnum)(itemdata[0]); pci.Size = itemdata[1]; pci.Associativity = itemdata[2]; pci.LineSize = itemdata[3]; pci.LineCount = itemdata[4]; pci.Shared = ( itemdata[5] != 0 ); ciVector.push_back( pci ); strcpy( data, data+pos ); remain = strchr( data, ';' ); } } CATCHBLOCK } else THROWNE(IntelMobileText("Intel::Mobile::Processor::ProcessorInstance"), IntelMobileText("GetCacheInfo")); } else THROWNE(IntelMobileText("Intel::Mobile::Processor::ProcessorInstance"), IntelMobileText("GetCacheInfo")); return CacheInfoVector( ciVector );}CoreVector Intel::Mobile::Processor::ProcessorInstance::GetCores(){ vector<CoreInstance*> vCores;
Intel::Mobile::BaseAPI::InstanceObject *pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject *>(m_pImpl);
if (pAPI_Instance)
{
TRYBLOCK {
IntelMobileChar data[1024];
IntelMobileChar* infoString = pAPI_Instance->InvokeMethod( "GetCores", "" );
strcpy( data, infoString ); printf("Intel::Mobile::Processor::ProcessorInstance::GetCores() = %s\r\n",infoString);
delete infoString;
Intel::Mobile::BaseAPI::ClassObject *pObject = new Intel::Mobile::BaseAPI::ClassObject("Core", "1.1");
if ( pObject )
{
IntelMobileChar *current = data;
IntelMobileChar* remain = strchr( current, ',' );
while ( remain != NULL )
{
*remain = L'\0';
Intel::Mobile::BaseAPI::InstanceObject *pAPI_Instance = pObject->GetInstance( current );
if ( pAPI_Instance )
{
CoreInstance *pInstance = new X86CoreInstance( pAPI_Instance );
vCores.push_back( pInstance );
}
current = remain + 1;
remain = strchr( current, ',' );
}
delete pObject;
}
} CATCHBLOCK
}
return CoreVector( vCores );}LogicalProcessorVector Intel::Mobile::Processor::ProcessorInstance::GetLogicals(){ vector<LogicalInstance*> vLogicals;
Intel::Mobile::BaseAPI::InstanceObject *pAPI_Instance = reinterpret_cast<Intel::Mobile::BaseAPI::InstanceObject *>(m_pImpl);
if (pAPI_Instance)
{
TRYBLOCK {
IntelMobileChar data[1024];
IntelMobileChar* infoString = pAPI_Instance->InvokeMethod( "GetLogicals", "" );
strcpy( data, infoString );
delete infoString;
Intel::Mobile::BaseAPI::ClassObject *pObject = new Intel::Mobile::BaseAPI::ClassObject("Logical", "1.1");
if ( pObject )
{
IntelMobileChar *current = data;
IntelMobileChar* remain = strchr( current, ',' );
while ( remain != NULL )
{
*remain = L'\0';
Intel::Mobile::BaseAPI::InstanceObject *pAPI_Instance = pObject->GetInstance( current );
if ( pAPI_Instance )
{
LogicalInstance *pInstance = new X86LogicalInstance( pAPI_Instance );
vLogicals.push_back( pInstance );
}
current = remain + 1;
remain = strchr( current, ',' );
}
delete pObject;
}
} CATCHBLOCK
}
return LogicalProcessorVector( vLogicals );}//==============================================================================// Generate VetorObject template
namespace Intel
{
namespace Mobile
{
namespace Processor
{
#define PCoreInstance CoreInstance *
#define PLogicalInstance LogicalInstance *
GENERATE_VECTOROBJECT(CacheInfo);
GENERATE_VECTOROBJECT(PCoreInstance);
GENERATE_VECTOROBJECT(PLogicalInstance);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -