📄 piplat.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/PiAPI/PIPlat.h,v $
* $Date: 2003/05/13 18:42:12 $
*
Description:
Definition of platform specific functions.
\*____________________________________________________________________________*/
/* $HeaderTop:$ */
#ifndef PIPLAT_H_
#define PIPLAT_H_
#include "PiAPI.h"
#include "PISync.h"
#include "PIThread.h"
/*____________________________________________________________________________*\
*
Typedefs:
\*____________________________________________________________________________*/
typedef void (* PIPlatformFn)(void);
#define PIPLATFORM_VERSION_1_0 100
#define PIPLATFORM_POLL_READ 0x1
#define PIPLATFORM_POLL_WRITE 0x2
#define PIPLATFORM_POLL_NOTIMEOUT (-1)
#define PIPLATFORM_POLL_NOWAIT (0)
#define PIPLATFORM_FD int /* a regular file descriptor */
#define PIPLATFORM_NETFD int /* a network file descriptor */
#define PIPLATFORM_FD_INVALID ((PIPLATFORM_FD)-1)
#define PIPLATFORM_TIME int /* should be time_t */
/*____________________________________________________________________________*\
*
Name:
PIPlatform_enter
Synopsis:
int PIPlatform_enter( const char *pArgv0, int iVersion, PIPlatformFn fn )
Description:
Initializes the platform facilities including user context threads
and custom memory management, then calls the user supplied function
fn. PIPlatform_enter() cleans platform facilities before returning.
Notes:
The parameter pArgv0 should be passed argv[0] from the main() entry
point to the program, as certain implementations of dynamic loading
require this. However this is not essential to the functioning of
most platform functionality and NULL may be passed instead.
The constant PLATFORM_VERSION_1_0 should be used as parameter iVersion
to this function.
A typical use of this function is to invoke it immediately on entering
main() or equivalent function.
The function fn is run in the main thread with initial priority
PITHREAD_PRIORIY_MED.
<!--
*/
#if 0
--><PRE>
/* --- globals --- */
int iArgc;
char **ppArgv;
int iRet;
/* --- Main program function --- */
void foo()
{
/* ... */
iRet = 0;
}
/* --- initialize the platform and invoke foo() --- */
int main( int iArgc, char *ppArgv[] )
{
iArgc = iTheArgc;
ppArgv = ppTheArgv;
if ( PIPlatform_enter( ppArgv[0], PLATFORM_VERSION_1_0, foo ) )
{
printf( "Error initializing platform\n" );
return 0;
};
return iRet;
}
</PRE>
<!--
#endif
/*
-->
Return Values:
PIPlatform_enter() returns zero (PIAPI_COMPLETED) on success.
Errors:
On error PIPlatform_enter() returns a negative value.
More error information can be retrieved using PIPlatform_getLastError().
See Also:
PIPlatform_getDescription().
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIPlatform_enter( const char *pArgv0, int iVersion,
PIPlatformFn fn );
/*____________________________________________________________________________*\
*
Name:
PIPlatform_getDescription
Synopsis:
const char *PIPlatform_getDescription()
Description:
Returns a string which describes the range of operating systems
and machine/processor sets for which this build is compatible.
Notes:
The description is of the form
Operating system ( machine processor )
Return Values:
Returns an internally allocated pointer to a string. The caller should
not modify this string.
Errors:
PIPlatform_getDescription returns NULL if PIPlatform_Init() has not
been called.
More error information can be retrieved using PIPlatform_getLastError().
See Also:
PIPlatform_enter().
\*____________________________________________________________________________*/
PUBLIC_PIAPI const char *PIPlatform_getDescription();
/*____________________________________________________________________________*\
*
Name:
PIPlatform_getUniqueId
Synopsis:
int PIPlatform_getUniqueId(const char *szBuf, unsigned int iLen)
Description:
Generates a new id that is a sequence of hexadecimal digits guaranteed
to be unique for the lifetime of this object.
Notes:
None.
Return Values:
If PIAPI_COMPLETED is returned, szBuf contains the unique Id.
If iLen is set to 0 the required size of szBuf is returned.
Errors:
PIAPI_ERROR may be returned if an unique identifier couldn't created
or PIAPI_EINVAL if the buffer is to small.
More information can be retrieved using PIPlatform_getLastError().
See Also:
PIPlatform_enter().
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIPlatform_getUniqueId(const char *szBuf, unsigned int iLen);
/*____________________________________________________________________________*\
*
Name:
PIPlatform_allocLocalMutex
Synopsis:
PISync *PIPlatform_allocLocalMutex()
Description:
Returns a new local mutex which can be used to synchronize threads of
control within a process.
Notes:
The synchronization object should be destroyed using PISync_delete() when
it is no longer needed.
Return Values:
Returns a pointer to a new synchronization object or NULL on error.
Errors:
NULL may be returned if a new syncronization object could not be
created due to exhausted memory, kernel mutexes or user mutexes.
More information can be retrieved using PIPlatform_getLastError().
See Also:
PISync_lock(), PISync_unlock(), PISync_tryLock(), PISync_delete().
\*____________________________________________________________________________*/
PUBLIC_PIAPI PISync *PIPlatform_allocLocalMutex();
/*____________________________________________________________________________*\
*
Name:
PIPlatform_allocLocalSemaphore
Synopsis:
PISync *PIPlatform_allocLocalSemaphore( int iInitalCount, int iMaxCount )
Description:
Returns a new local semaphore which can be used to synchronize
threads of control within a process.
Notes:
The synchronization object should be destroyed using PISync_delete() when
it is no longer needed.
Return Values:
Returns a pointer to a new synchronization object or NULL on error.
Errors:
NULL may be returned if a new syncronization object could not be
created due to exhausted memory, kernel semaphores or user semaphores.
More specific error information can be retrieved using
PIPlatform_getLastError().
See Also:
PISync_lock(), PISync_unlock(), PISync_tryLock(), PISync_delete().
\*____________________________________________________________________________*/
PUBLIC_PIAPI PISync *PIPlatform_allocLocalSemaphore( int iInitialCount,
int iMaxCount );
/*____________________________________________________________________________*\
*
Name:
PIPlatform_pollNetFD
Synopsis:
int PIPlatform_pollNetFD( PIPLATFORM_NETFD fdSocket, int iFlags,
int iTimeout )
Description:
Waits for the activity on the specified network file descriptor
(socket). The value iFlags is formed by OR'ing together any
combination of the values PIPLATFORM_POLL_READ and PIPLATFORM_POLL_WRITE.
The value piTimeout is a pointer to an integer containing a time to
wait in seconds.
Notes:
A value of PIPLATFORM_NOTIMEOUT for iTimeout specifies no timeout.
A value of PIPLATFORM_NOWAIT for iTimeout specifies that
PIPlatform_pollNetFD() should test for activity on fdSocket but return
immediately even if there is none.
Return Values:
On success PIPlatform_pollNetFD() returns a value formed by OR'ing
some of the values PIPLATFORM_POLL_READ and PIPLATFORM_POLL_WRITE together
indicating which operations may be performed on socket fdSocket
without blocking.
If the specified timeout period expires, PIPlatform_pollNetFD() returns
a value of zero.
Errors:
On failure PIPlatform_pollNetFD() returns a negative value.
More specific error information can be retreived using
PIPlatform_getLastError().
See Also:
PIPlatform_pollFD(), PIPlatform_pollPipeFD(), PIPlatform_sleep().
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIPlatform_pollNetFD( PIPLATFORM_NETFD fdSocket, int iFlags,
int iTimeout );
/*____________________________________________________________________________*\
*
Name:
PIPlatform_pollPipeFD
Synopsis:
int PIPlatform_pollPipeFD( PIPLATFORM_FD fd, int iFlags,
int iTimeout )
Description:
Waits for activity on the specified pipe.
The value iFlags is formed by OR'ing together any
combination of the values PIPLATFORM_POLL_READ and PIPLATFORM_POLL_WRITE.
The value piTimeout is a pointer to an integer containing a time to
wait in seconds.
Notes:
A value of PIPLATFORM_NOTIMEOUT for iTimeout specifies no timeout.
A value of PIPLATFORM_NOWAIT for iTimeout specifies that
PIPlatform_pollNetFD() should test for activity on fd but return
immediately even if there is none.
On systems where differences between pipes and file descriptors
are transparent, PIPlatform_pollPipeFD() is implemented using
PIPlatform_pollFD(). On other systems PIPlatform_pollPipeFD() may not
be implemented, see below under 'Errors'.
Return Values:
On success PIPlatform_pollPipeFD() returns a value formed by OR'ing
some of the values PIPLATFORM_POLL_READ and PIPLATFORM_POLL_WRITE
together indicating which operations may be performed on
pipe fd without blocking.
If the specified timeout period expires, PIPlatform_pollPipeFD()
returns a value of zero.
Errors:
On failure PIPlatform_pollNetFD() returns a negative value.
More specific error information can be retreived using
PIPlatform_getLastError().
On some systems PIPlatform_pollPipeFD() is not yet implemented, in this
case a value of PIAPI_ERROR will be returned and
PIPlatform_getLastError() will return a value of PIAPI_NOTSUPPORTED.
See Also:
PIPlatform_pollPipeFD(), IPlatform_pollNetFD(), PIPlatform_sleep().
\*____________________________________________________________________________*/
PUBLIC_PIAPI int PIPlatform_pollPipeFD( PIPLATFORM_FD fd, int iFlags,
int iTimeout );
/*____________________________________________________________________________*\
*
Name:
PIPlatform_pollFD
Synopsis:
int PIPlatform_pollFD( PIPLATFORM_FD fd, int iFlags,
int iTimeout )
Description:
Waits for the activity on the specified file descriptor.
The value iFlags is formed by OR'ing together any
combination of the values PIPLATFORM_POLL_READ and PIPLATFORM_POLL_WRITE.
The value piTimeout is a pointer to an integer containing a time to
wait in seconds.
Notes:
A value of PIPLATFORM_NOTIMEOUT for iTimeout specifies no timeout.
A value of PIPLATFORM_NOWAIT for iTimeout specifies that
PIPlatform_pollNetFD() should test for activity on fd but return
immediately even if there is none.
On systems where differences between sockets and file descriptors
are transparent, PIPlatform_pollFD() is implemented using
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -