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

📄 processorinstancejni.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 "IntelMobileJNI.h"#include <vector>#include "Utility/StringHelper.h"#ifdef SHOW_MEMORY_LEAK#include "DebugHeap.h"#define new new(__FILE__, __LINE__)#define malloc(size) (void *)new BYTE[size]#define free(o) delete o#endifusing namespace Intel::Mobile::BaseAPI;/* * Class:     com_intel_mobile_processor_ProcessorInstance * Method:    init * Signature: (J)V */JNIEXPORT void JNICALL Java_com_intel_mobile_processor_ProcessorInstance_init(JNIEnv *JniEnv, jobject JObject, jlong nativeObjRef ){	try	{		InstanceObject * TheProcessorInstance = (InstanceObject *) nativeObjRef;				// To set the properties.		Set_Property( JniEnv, JObject, TheProcessorInstance->GetPropertyByName("Manufacturer", "String"), "com/intel/mobile/base/StringProperty", "Manufacturer" );		Set_Property( JniEnv, JObject, TheProcessorInstance->GetPropertyByName("Brand", "String"), "com/intel/mobile/base/StringProperty", "Brand" );		Set_Property( JniEnv, JObject, TheProcessorInstance->GetPropertyByName("Id", "String"), "com/intel/mobile/base/StringProperty", "Id" );		Set_Property( JniEnv, JObject, TheProcessorInstance->GetPropertyByName("Role", "String"), "com/intel/mobile/base/StringProperty", "Role" );		Set_Property( JniEnv, JObject, TheProcessorInstance->GetPropertyByName("Fsb", "UInt"), "com/intel/mobile/base/UIntProperty", "Fsb" );		Set_Property( JniEnv, JObject, TheProcessorInstance->GetPropertyByName("CpuUsage", "Float"), "com/intel/mobile/base/FloatProperty", "CpuUsage" );		Set_Property( JniEnv, JObject, TheProcessorInstance->GetPropertyByName("LogicalCount", "UInt"), "com/intel/mobile/base/UIntProperty", "LogicalCount" );		Set_Property( JniEnv, JObject, TheProcessorInstance->GetPropertyByName("CoreCount", "UInt"), "com/intel/mobile/base/UIntProperty", "CoreCount" );		// Events		bool bRtn = false;		char* infoString = TheProcessorInstance->InvokeMethod( "GetCores", "");		string wsRtn = infoString;		delete []infoString;		std::vector<string> vtKey;		CStringHelper::Str2ParamVect(wsRtn, vtKey );		ClassObject * TheCoreClass = new ClassObject( "Core", "1.1" );		jclass jclassList = JniEnv->FindClass( "java/util/ArrayList" );		jmethodID MethodId = JniEnv->GetMethodID( jclassList, "<init>", "()V" );		jobject jobjectList = JniEnv->NewObject( jclassList, MethodId );		jmethodID jmethodAdd = JniEnv->GetMethodID( jclassList, "add", "(Ljava/lang/Object;)Z" );		char *ClassName = "com/intel/mobile/processor/ProcessorInstance";		char *Signature = new char[strlen(ClassName) + 3];		strcpy( Signature, "L" );		strcat( Signature, ClassName );		strcat( Signature, ";" );		for ( size_t i=0;i<vtKey.size();i++ )		{			if( strlen( vtKey[i].c_str() ) == 0)	// for the compatice with V1.1				break;			InstanceObject *TheCoreInstance = TheCoreClass->GetInstance( vtKey[i].c_str() );			if ( TheCoreInstance )			{				jobject jobjectCore = Create_jobject( JniEnv, "com/intel/mobile/processor/X86CoreInstance", TheCoreInstance );				jclass jclassCore = JniEnv->GetObjectClass( jobjectCore );				jfieldID jfieldIDProperty = JniEnv->GetFieldID( jclassCore, "Parent", Signature );				JniEnv->SetObjectField( jobjectCore, jfieldIDProperty, JObject );				JniEnv->CallBooleanMethod( jobjectList, jmethodAdd, jobjectCore );			}		}		delete [] Signature;		ClassName = "java/util/List";		Signature = new char[strlen(ClassName) + 3];		strcpy( Signature, "L" );		strcat( Signature, ClassName );		strcat( Signature, ";" );				jclass jclassParent = JniEnv->GetObjectClass( JObject );		jfieldID jfieldIDProperty = JniEnv->GetFieldID( jclassParent, "CoreList", Signature );		JniEnv->SetObjectField( JObject, jfieldIDProperty, jobjectList );				delete [] Signature;		}	catch (IntelMobileException Ex)	{		ThrowException( JniEnv, Ex );	}	catch (...)	{		ThrowUnknownException( JniEnv, "ProcessorInstance", "init" );	}}jobject ProcessorGetCacheInfoHelper( JNIEnv *JniEnv, jobject JObject ){	try	{		jclass jclassList = JniEnv->FindClass( "java/util/ArrayList" );		jmethodID MethodId = JniEnv->GetMethodID( jclassList, "<init>", "()V" );		jobject jobjectList = JniEnv->NewObject( jclassList, MethodId );		jmethodID jmethodAdd = JniEnv->GetMethodID( jclassList, "add", "(Ljava/lang/Object;)Z" );		InstanceObject * TheProcessorInstance = (InstanceObject *) Get_nativeObjRef( JniEnv, JObject );		if ( TheProcessorInstance->IsAvailable( "GetCacheInfo" ) )		{			jclass jclassCache = JniEnv->FindClass( "com/intel/mobile/processor/CacheInfo" );			MethodId = JniEnv->GetMethodID( jclassCache, "<init>", "(IIIIIZ)V" );			char data[1024];			char* infoString = TheProcessorInstance->InvokeMethod( "GetCacheInfo", "" );			strcpy( data, infoString );			strcat( data, ";" );			delete infoString;			char line[256];			char item[256];			char* 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;				char* itemremain = strchr( line, L',' );				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, ',' );				}								jobject jobjectCache = JniEnv->NewObject( jclassCache, MethodId, (int)itemdata[0], (int)itemdata[1], itemdata[2], itemdata[3], itemdata[4], itemdata[5] );				JniEnv->CallBooleanMethod( jobjectList, jmethodAdd, jobjectCache );				strcpy( data, data+pos );				remain = strchr( data, ';' );			}		}		return jobjectList;	}	catch (IntelMobileException Ex)	{		ThrowException( JniEnv, Ex );	}	catch (...)	{		ThrowUnknownException( JniEnv, "ProcessorInstance", "GetCacheInfo()" );	}	return NULL;}/** Class:     com_intel_mobile_processor_ProcessorInstance* Method:    GetCacheInfoNative* Signature: ()Ljava/util/List;*/JNIEXPORT jobject JNICALL Java_com_intel_mobile_processor_ProcessorInstance_GetCacheInfoNative( JNIEnv *JniEnv, jobject JObject ){	return ProcessorGetCacheInfoHelper( JniEnv, JObject );}

⌨️ 快捷键说明

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