I'm going through this code to try to understand it but everything about it is strange. I don't even understand it. Can someone help me understand it please?
Here are chunks of the code:
in the .h file:
// [serialOpen] Arg# -- Description ----------------------- // 1 (const vt_char *) pathname / com dev. description // 2 (vt_int32) flags // return (vt_int32) descriptor handle // [serialWrite] Arg# -- Description ----------------------- // 1 (vt_int32) descriptor handle // 2 (const vt_char *) buffer // 3 (vt_uint32) buffer data len // [serialRead] Arg# -- Description ----------------------- // 1 (vt_int32) descriptor handle // 2 (vt_char *) buffer // 3 (vt_uint32) buffer space len // [serialClose] Arg# -- Description ----------------------- // 1 (vt_int32) descriptor handle // return (vt_int32) 0 on success, -1 on failure // [serialErrno] Arg# -- Description ----------------------- // return (vt_int32) errno, see errno.h (GNU C Compiler Version) (*) // // (*) The error numbers of interest are; // #define EIO 5 /* I/O error (used as a generic error) */ // #define EAGAIN 11 /* No more processes */ // #define EWOULDBLOCK EAGAIN /* Operation would block */ // EIO is treated as a generic error condition. // // functions behave the same as the standard stdio & errno calls // (open, close, read, write, errno) // // any function that returns -1 should update a local copy of // their errno appropriately. // ------------------------------------------------------*/ typedef vt_int32 (*serialOpen) ( const vt_char *, vt_int32 ); typedef vt_int32 (*serialWrite) ( vt_int32, const vt_char *, vt_uint32 ); typedef vt_int32 (*serialRead) ( vt_int32, vt_char *, vt_uint32 ); typedef vt_int32 (*serialClose) ( vt_int32 ); typedef vt_int32 (*serialErrno) ( void ); // Change the serial API to the physical serial port. // Call this function after opening the channel, but before // using it. // Arguements ----------------------------------------------- // (serialOpen) function to open serial port // (serialWrite) function to write to port (out to far end device) // (serialRead) function to read from port (in from far end device) // (serialClose) function to close serial port // (serialErrno) function to return the last error // Returns -------------------------------------------------- // (vt_int32) VCL_OK, operation succeeded // VCL_ERROR, operation failed // Notes ---------------------------------------------------- // --------------------------------------------------------*/ vt_int32 vcl_ChangeSerInterface( serialOpen, serialWrite, serialRead, serialClose, serialErrno );
First of all, right there...Why would someone do that? Why would you input the functions to another function?
#if (USE_SERLIB==1) serialOpen serOpen = slOpen; serialWrite serWrite = slWrite; serialRead serRead = slRead; serialClose serClose = slClose; serialErrno serErrNo = slErrno; static vt_flag serIsInit = TRUE; #else serialOpen serOpen = NULL; serialWrite serWrite = NULL; serialRead serRead = NULL; serialClose serClose = NULL; serialErrno serErrNo = NULL; static vt_flag serIsInit = FALSE; #endifHere is the definition of vcl_changeserinterface:
vt_bool vcl_ChangeSerInterface( serialOpen sopen, serialWrite swrt,
serialRead sread, serialClose sclose, serialErrno serrno )
{
if (!serIsInit)
{
serOpen = sopen;
serWrite = swrt;
serRead = sread;
serClose = sclose;
serErrNo = serrno;
serIsInit = TRUE;
return TRUE;
}
else
{
return FALSE;
}
}
but when you look at the definition of say "slOpen", it uses the function "open"
vt_int32 slOpen( const vt_char * chanName , vt_int32 flags )
{
return open( (const char*)chanName, (int)flags );
}
I absolutely don't follow this. Can someone please help me figure this out?
Thanks
Edited by dargueta, 30 April 2011 - 10:58 PM.
Please use [code][/code] tags next time.


Sign In
Create Account


Back to top









