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

📄 hx_moreprocesses.c

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

#include "platform/mac/HX_MoreProcesses.h"

#if defined(_CARBON) || defined(_MAC_UNIX)
#include "platform/mac/MoreFilesX.h"
#endif

#ifndef _MAC_UNIX
#include "hxmm.h"
#endif

#ifndef _MAC_UNIX /* this is defined always true for _MAC_UNIX builds */
Boolean IsRunningNativeOnMacOSX()
{
#ifdef _CARBON

	long sysVersion;
	OSErr err;

	static int zIsNative = 0;
	
	if (zIsNative == 1) return true;
	if (zIsNative == -1) return false;
	
	
	err = Gestalt(gestaltSystemVersion, &sysVersion);
	check_noerr(err);
	
	if (err == noErr && sysVersion >= 0x1000)
	{
		zIsNative = 1;
		return true;
	}
	else
	{
		zIsNative = -1;
		return false;
	}

#else
	return false;
#endif
}
#endif


Boolean	IsMacInCooperativeThread()
{
	// stuff that's ok to do at system time is OK to do
	// if we're in a cooperative MP task. This includes
	// both the main app MP task ("system time") as well
	// as thread manager threads.
	
	// This is basically a more OS X friendly way to do
	// a HXMM_ATINTERRUPT() check, only it also checks
	// against all preemptive threads and not just the
	// faux interrupt time for which we've called the
	// pnmm interrupt-setting routines.
	
	// MPTaskIsPreemptive(kMPInvalidIDErr) used to work
	// for this but fails to compile now that the task
	// parameter is opaque. That's why it pulls out the
	// actual current task ID.
	
	if ( MPTaskIsPreemptive( MPCurrentTaskID() ) )
	{
		return false;
	}
	else
	{
		return true;
	}
}



//
//	SameFSSpec
//
//	Compares two FSSpec structures and returns true if they point to the same file.
//

Boolean  SameFSSpec(FSSpecPtr   sa,  FSSpecPtr  sb)
{

	if (sa->vRefNum==sb->vRefNum)
	{
		if (sa->parID==sb->parID)
		{
			if (EqualString(sb->name,sa->name,false,false))
			{
				return true;
			}
		}
	}
	return false;
}



//
//	CheckForAppRunningAtPath
//
//	Looks through all processes and looks for one with the same path name.
//
/*
Boolean	CheckForAppRunningAtPath(Str255		path)
{
		OSErr						e 		 	= noErr;		
		ProcessSerialNumber	psn 	 	= {kNoProcess, kNoProcess};
		Boolean					theResult=false;
		FSSpec					serverSpec;
		FSSpec					appSpec;					

		// Get the fsspec of the path.		
		// Return if there isn't a server at the path.
		if (FSMakeFSSpec(0,0,path,&serverSpec)) return false;
		
		
		while (noErr == (e = GetNextProcess (&psn))) 
		{
			ProcessInfoRec	info;
			
			info.processInfoLength = sizeof (info);
			info.processName = nil;
			info.processAppSpec = &appSpec;
			
			if (noErr != (e = GetProcessInformation (&psn, &info))) break;
			
			// Check to see if this is the correct 
			if (SameFSSpec(&appSpec,&serverSpec)) 
			{
				theResult=true;
				break;
			}
			
			continue;
		} 
			
		return (theResult);
}

*/


//
// CheckForApplicationRunning
//
// Looks through all the processes for one matching the signature passed in the "AppSignature"
// 

Boolean	CheckForApplicationRunning(OSType	AppSignature) {
	
	OSErr	err;
	
	err = GetPSNFromSignature(AppSignature, NULL);
	
	return (err == noErr);
	
}


Boolean	CheckForApplicationRunningFSSpec(OSType	AppSignature,FSSpec *spec) {

	return GetApplicationSpec(AppSignature, spec);
	
}

//
// GetPSNSpec
//
// Returns the FSSpec for the related PSN.
// 
Boolean	GetPSNSpec(ProcessSerialNumber*	psn,FSSpec*	theSpec)
{
	Boolean					theResult= false;
	ProcessInfoRec			info;
	OSErr						e=noErr;
	
			
	info.processInfoLength = sizeof (info);
	info.processName = nil;
	info.processAppSpec = theSpec;
	
	e=GetProcessInformation (psn, &info);

	theResult = e ? false : true;

	return theResult;
}


//
// GetApplicationSpec
//
// Looks through all the processes for one matching the signature passed in the "AppSignature"
// Then returns the Application's FSSpec.
// 
Boolean	GetApplicationSpec(OSType	AppSignature, FSSpec	*theSpec) 
{

		OSErr					e 		 = noErr;		
		ProcessSerialNumber		psn 	 = {kNoProcess, kNoProcess};
		Boolean					theResult=false;
		
		while (noErr == (e = GetNextProcess (&psn))) {
			ProcessInfoRec	info;
			
			info.processInfoLength = sizeof (info);
			info.processName = nil;
			info.processAppSpec = theSpec;
			if (noErr != (e = GetProcessInformation (&psn, &info))) break;
			
			if (AppSignature != info.processSignature) continue;
			theResult=true;
			break;
			} /* while */
			
		return (theResult);
}


//
// GetCurrentAppSpec
//
// Returns the FSSpec for the currently running application.
// 

Boolean GetCurrentAppSpec(FSSpec *theSpec)
{

	OSErr				err;	
	ProcessSerialNumber	psn;
	ProcessInfoRec		pir;

	if (theSpec == NULL) return false;
		
	psn.highLongOfPSN = 0;
	psn.lowLongOfPSN = kCurrentProcess;
	
	pir.processInfoLength = sizeof(ProcessInfoRec);
	pir.processName = nil;
	pir.processAppSpec = theSpec;
	err = GetProcessInformation (&psn, &pir);
	
	return (err == noErr);
}


//
// GetCurrentAppSignature
//
// Returns the signature for the currently running application.
// 

OSType GetCurrentAppSignature(void)
{

	OSErr				err;	
	ProcessSerialNumber	psn;
	ProcessInfoRec		pir;
		
	psn.highLongOfPSN = 0;
	psn.lowLongOfPSN = kCurrentProcess;
	
	pir.processInfoLength = sizeof(ProcessInfoRec);
	pir.processName = nil;
	pir.processAppSpec = nil;
	err = GetProcessInformation (&psn, &pir);
	
	if (err == noErr)	return pir.processSignature;
	else				return '????';
}


//
// GetPSNFromSignature returns the ProcessSerialNumber for the
// app with the given signature if the app is running
//
// psn can be nil if the caller only wants to know if the
// app is running
//

OSErr GetPSNFromSignature(OSType signature, ProcessSerialNumber *psn)
{
	ProcessSerialNumber	currPSN;
	ProcessInfoRec		currPIR;
	OSErr				err;
	
	currPSN.lowLongOfPSN = kNoProcess;
	currPSN.highLongOfPSN = 0;
	
	do {
		err = GetNextProcess(&currPSN);
		if (err == noErr)
		{
			currPIR.processName = NULL;
			currPIR.processAppSpec = NULL;
			currPIR.processInfoLength = sizeof(ProcessInfoRec);
			err = GetProcessInformation(&currPSN, &currPIR);
			if (err == noErr && currPIR.processSignature == signature)
			{
				if (psn) *psn = currPSN;
				break;
			}
		}
	} while (err == noErr);
	
	return err;
}

//
// GetSignatureFromPSN returns the signature for the
// app with the given PSN
//
// signature can be nil if the caller only wants to know if the
// app is running
//

OSErr GetSignatureFromPSN(const ProcessSerialNumber *psn, OSType *signature)
{
	ProcessSerialNumber	currPSN;
	ProcessInfoRec		currPIR;
	OSErr			err;
	Boolean 		bSamePSN;
	
	currPSN.lowLongOfPSN = kNoProcess;
	currPSN.highLongOfPSN = 0;
	
	do {
		err = GetNextProcess(&currPSN);
		if (err == noErr)
		{
			if (SameProcess(&currPSN, psn, &bSamePSN) == noErr
			  && bSamePSN)
			{
				currPIR.processName = NULL;
				currPIR.processAppSpec = NULL;
				currPIR.processInfoLength = sizeof(ProcessInfoRec);
				err = GetProcessInformation(&currPSN, &currPIR);
				if (err == noErr)
				{
					if (signature) 
					{
						*signature = currPIR.processSignature;
					}
				}
				break;
			}
			
			
		}
	} while (err == noErr);
	
	return err;
}



//
// CountAppSignatures
//
// Looks through all the processes and returns a count of the processes with AppSignature.
//
short	CountAppSignatures(OSType	AppSignature) {

		OSErr					e 		 = noErr;		
		ProcessSerialNumber		psn 	 = {kNoProcess, kNoProcess};
		short					theResult=0;
		
		while (noErr == (e = GetNextProcess (&psn))) {
			ProcessInfoRec	info;
			
			info.processInfoLength = sizeof (info);
			info.processName = nil;

⌨️ 快捷键说明

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