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

📄 platform.h

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 H
字号:
/*____________________________________________________________________________*\
 *

 Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.

 These sources, libraries and applications are
 FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
 as long as the following conditions are adhered to.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer. 

 2. 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.

 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 AUTHORS OR ITS 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.

 *____________________________________________________________________________*|
 *
 * $Source: /cvsroot/pi3web/Pi3Web_200/Source/Platform/Platform.h,v $
 * $Date: 2003/05/13 18:42:14 $
 *
 Description:
	Specifies platform abstraction instance and static methods.
	A different implementation of this class is provided for 
	different operating systems.

	NOTE: 
		Some of the functions prototyped here are now obselete and
	are not implemented.
\*____________________________________________________________________________*/
//$HeaderTop:$

#ifndef PLATFORM_H_
#define PLATFORM_H_

#include "PICompat.h"
#include "PIString.h"
#include "StrToken.h"
#include "OSEntity.h"
#include "FSEntity.h"
#include "Allocate.h"

/*____________________________________________________________________________*\
 *
 Declarations:
\*____________________________________________________________________________*/

/*____________________________________________________________________________*\
 *
 Class:
 Description:
\*____________________________________________________________________________*/
class Platform
{
private:
	static void Internal_EnterThreads( void (* fnFunc)( void ) );

protected:

public:
	Platform();

	/* --- initialization and cleanup --- */
	static void Enter( const char *pProgram, void (* fn)(void) );
	static void CatchExceptions( void (* fn)( void * ), void *pArg );

	/* --- OS, Machine description --- */
	static const char *GetDescription();

	/* --- Windows manipulation methods --- */
	static bool GetTimeString( PIString &sResult );
	static bool GetPrettyTimeString( PIString &sResult );

	/* --- heap and allocator methods --- */
	static Allocator *GetGlobalAllocator();
	static Allocator *GetCurrentAllocator();
	static Allocator *SetCurrentAllocator( Allocator *pAlloc );
	static void *AllocMemory( size_t tSize );
	static bool FreeMemory( void *pV );
	static size_t GetBusAddressAlignment();
	static void *PICustomNew( size_t tSize );
	static void PICustomDelete( void *pData );	
#if !defined(NDEBUG)
	static void PICustomBeforeNew( int iLine, const char *pFileName );
	static void PICustomBeforeDelete( int iLine, const char *pFileName );
	static void PICustomMark( int iLine, const char *pFileName );
#endif

	/* --- 
		mutex'es, semaphores and locks 

		A local mutex or semaphore is valid only for threads in the current
	process. A global mutex effects all processes on the OS.
	--- */
	static Semaphore *AllocLocalMutex();
	static Semaphore *AllocLocalSemaphore( int iInitialCount, int iMaxCount );
	static Semaphore *AllocGlobalMutex();
	static Semaphore *AllocGlobalSemaphore( int iInitialCount, int iMaxCount );
	static Thread *AllocThread( 
/*				Allocator *pAllocator,  */
				void *pFudge,	/* LATER, link problems with MSVC4.0 */ 
				int iStackSize = 0 );
	static void YieldThread();
	static void UserYieldThread();
	static int WaitForThread( Thread *pThread );
	static Thread *GetCurrentThread();
	static Thread *GetMainThread();
	static int AllocThreadKey();
	static bool DeleteThreadKey( int iKey );
	static void ThreadDbgDump( ostream &os );
	static int GetLastError();
	static void SetLastError( int iErrorCode );
	static int OSErrorToPIError();
	static int OSErrorToPIError( long iErrorCode );

	/* --- mutex to surrond unsafe syscalls and make them thread-safe --- */
	static int BeforeUnsafeBlock(); 	
	static int AfterUnsafeBlock(); 	

	/* --- Polling and sleeping --- */
	enum { POLL_READ = 0x1, POLL_WRITE = 0x2 };
	static int PollFD( int iFD, int iFlags, int iTimeout );
	static int PollPipeFD( int iFD, int iFlags, int iTimeout );
	static int PollNetFD( int iFD, int iFlags, int iTimeout );
	static int Sleep( int iMilliseconds );

	/* --- 
	Other operating system entities. DLL's etc.
	--- */
	static DLL *AllocDLL( const char * );
	static void *AllocDLL( void * ); 		/* for MSVC4.0 */
	static MappedFile *AllocMappedFile( FileSystemEntity &tFSE );
	static void *AllocMappedFile( char &c );	/* for MSVC4.0 */

	/* --- new operations on files and file systems --- */
	static FileSystemEntity *GetFile( const PIString &sPath );
	static void *GetFile( void *pV );	/* LATER, link problems with MSVC4.0 */

	/* --- processes --- */
	static unsigned long Fork();
	static unsigned long GetPID();

	/* ---
	Miscellaneous
	--- */
	static int GetUniqueId( const char *szBuf, unsigned int iLen );
	static int GetErrno();
	static bool DaemonInit();
	static Timer *AllocTimer();

	/* --- open, close, read, write and lock on file handles, unlink  --- */
	static int Open( const char *pPath, const char *pFlags );
	static int Close( int iFd );
	static int Unlink( const char *pPath );
	static int Read( int iFd, int iLength, void *pData );
	static int Write( int iFd, int iLength, const void *pData );
	static int WriteAtomic( int iFd, int iLength, const void *pData );
	static int LockFd( int iFd );
	static int UnlockFd( int iFd );

	/* --- current directory --- */
	/* ---
	this function cannot be called 'GetCurrentDirectory' because
	the name 'GetCurrentDirectory' is a macro under windows...
	--- */
	static int RetrieveCurrentDirectory( PIString &sCurrentDirectory );
	static char getDirectorySeparator();

	/* --- processes --- */
	static int GetProcess();
	static int GetProcessId();
	static int WaitForProcess( int tProcess, int iFlags, int iTimeout );
};

#endif /* PLATFORM_H_ */

⌨️ 快捷键说明

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