📄 slog_header.c
字号:
#ifdef HAVE_SLOGCONF_H#include "slog_config.h"#endif#ifdef HAVE_SLOG_WINCONFIG_H#include "slog_winconfig.h"#endif#if defined( STDC_HEADERS ) || defined( HAVE_STDLIB_H )#include <stdlib.h>#endif#if defined( HAVE_UNISTD_H )#include <unistd.h>#endif#include "slog_fileio.h"#include "slog_header.h"SLOG_hdr_t *SLOG_HDR_Create( FILE *outfd ){ SLOG_hdr_t *hdr; hdr = ( SLOG_hdr_t * ) malloc( sizeof( SLOG_hdr_t ) ); /* Initialize the various fields in the SLOG_hdr_t data structure */ hdr->version[ 0 ] = VERSION_MainID; hdr->version[ 1 ] = VERSION_SubID; hdr->frame_bytesize = SLOG_BUFFER_UNIT; hdr->frame_reserved_size = SLOG_FRAME_RESERVED_SIZE; hdr->max_Ndirframe = SLOG_NDirEntry; hdr->IsIncreasingStarttime = SLOG_FALSE; hdr->IsIncreasingEndtime = SLOG_FALSE; hdr->HasReserveSpaceBeenUsed = SLOG_FALSE; hdr->fptr2statistics = SLOG_fptr_NULL; hdr->fptr2preview = SLOG_fptr_NULL; hdr->fptr2profile = SLOG_fptr_NULL; hdr->fptr2threadtable = SLOG_fptr_NULL; hdr->fptr2recdefs = SLOG_fptr_NULL; hdr->fptr2framedata = SLOG_fptr_NULL; /* Initialize the file buffer and the location of header in file */ hdr->file_loc = SLOG_fptr_NULL; hdr->fbuf = ( filebuf_t * ) fbuf_create( SLOG_typesz[ Header ] ); fbuf_filedesc( hdr->fbuf, outfd ); return hdr;}void SLOG_HDR_Free( SLOG_hdr_t *hdr ){ if ( hdr != NULL && SLOG_typesz[ Header ] > 0 ) { if ( hdr->fbuf != NULL ) { fbuf_free( hdr->fbuf ); hdr->fbuf = NULL; } free( hdr ); hdr = NULL; }}/*@C SLOG_SetFrameByteSize - Set the byte size of the frame of SLOG file Unmodified Input Variables :. frame_bytesize - unsigned integer to specify the size of the frame. Modified Input Variables :. slog - pointer to SLOG_STREAM where interval records will be stored. Modified Output Variables :. returned value - integer return status. Include File Needed : slog_header.h@*/int SLOG_SetFrameByteSize( SLOG_STREAM *slog, SLOG_uint32 frame_bytesize ){ int ierr; if ( slog == NULL ) { fprintf( errfile, __FILE__":SLOG_SetFrameByteSize() - " "the input SLOG_STREAM is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } if ( slog->hdr == NULL ) { fprintf( errfile, __FILE__":SLOG_SetFrameByteSize() - " "the input SLOG_hdr_t is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } if ( slog->hdr->frame_reserved_size != SLOG_FRAME_RESERVED_SIZE ) { if ( ( SLOG_typesz[ FrameHdr ] + SLOG_typesz[ min_IntvlRec ] + slog->hdr->frame_reserved_size ) > frame_bytesize ) { fprintf( errfile, __FILE__":SLOG_SetFrameByteSize() - " "the input frame byte size, "fmt_ui32", is " "too small\n", frame_bytesize ); fprintf( errfile, "\t""It is NOT even enough for 1 minimal " "interval record.\n" ); fflush( errfile ); return SLOG_FAIL; } } slog->hdr->frame_bytesize = frame_bytesize; ierr = SLOG_WriteUpdatedHeader( slog ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_SetFrameByteSize() - " "SLOG_WriteUpdatedHeader() fails\n" ); fflush( errfile ); return ierr; } return SLOG_SUCCESS;}/*@C SLOG_SetFrameReservedSpace - Set the byte size of the frame's reserved space for SLOG file Unmodified Input Variables :. reserved_bytesize - unsigned integer to specify the reserved byte size of the frame. Modified Input Variables :. slog - pointer to SLOG_STREAM where interval records will be stored. Modified Output Variables :. returned value - integer return status. Usage Notes on this subroutine : The routine is one of the methods provided to reserve frame space for the pseudo records in the 1st pass of the logfile. Reservation of the frame space is only necessary if the completed interval records are arranged in increasing endtime order and there is no way that user can rearrange the call sequence of the start event to call SLOG_Irec_ReserveSpace(). When the completed interval records are arranged in increasing starttime order, there is no need to reserve space for the pseudo interval records, so this routine should NOT be called. Also if user has knowledge of the start event of the interval record, like in an event based model where all start and end events are mixed and are arranged in increasing time order, one should call SLOG_Irec_ReserveSpace() instead of this routine to do frame space reservation. Include File Needed : slog_header.h@*/int SLOG_SetFrameReservedSpace( SLOG_STREAM *slog, SLOG_uint32 reserved_bytesize ){ int ierr; if ( slog == NULL ) { fprintf( errfile, __FILE__":SLOG_SetFrameReservedSpace() - " "the input SLOG_STREAM is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } if ( slog->hdr == NULL ) { fprintf( errfile, __FILE__":SLOG_SetFrameReservedSpace() - " "the input SLOG_hdr_t is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } if ( slog->hdr->frame_bytesize != SLOG_BUFFER_UNIT ) { if ( ( SLOG_typesz[ FrameHdr ] + SLOG_typesz[ min_IntvlRec ] + reserved_bytesize ) > slog->hdr->frame_bytesize ) { fprintf( errfile, __FILE__":SLOG_SetFrameReservedSpace() - " "the input frame reserved size, "fmt_ui32", is " "too big\n", reserved_bytesize ); fprintf( errfile, "\t""It is NOT even enough for 1 minimal " "interval record.\n" ); fflush( errfile ); return SLOG_FAIL; } } slog->hdr->frame_reserved_size = reserved_bytesize; ierr = SLOG_WriteUpdatedHeader( slog ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_SetFrameReservedSpace() - " "SLOG_WriteUpdatedHeader() fails\n" ); fflush( errfile ); return ierr; } return SLOG_SUCCESS;}/*@C SLOG_SetMaxNumOfFramesPerDir - Set the Maximum Number of frames per directory in SLOG file Unmodified Input Variables :. Ndirframe - unsigned integer to specify the maximum number of frames per directory in SLOG file. Modified Input Variables :. slog - pointer to SLOG_STREAM where interval records will be stored. Modified Output Variables :. returned value - integer return status. Include File Needed : slog_header.h@*/int SLOG_SetMaxNumOfFramesPerDir( SLOG_STREAM *slog, SLOG_uint32 Ndirframe ){ int ierr; if ( slog == NULL ) { fprintf( errfile, __FILE__":SLOG_SetMaxNumOfFramesPerDir() - " "the input SLOG_STREAM is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } if ( slog->hdr == NULL ) { fprintf( errfile, __FILE__":SLOG_SetMaxNumOfFramesPerDir() - " "the input SLOG_hdr_t is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } slog->hdr->max_Ndirframe = Ndirframe; ierr = SLOG_WriteUpdatedHeader( slog ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_SetMaxNumOfFramesPerDir() - " "SLOG_WriteUpdatedHeader() fails\n" ); fflush( errfile ); return ierr; } return SLOG_SUCCESS;}/*@C SLOG_SetIncreasingStarttimeOrder - Set the flag for the interval records will be arranged in increasing starttime order. That means there is NO second pass of the logfile and the starttime of the interval will be used to determine endtime of the frame. Modified Input Variables :. slog - pointer to SLOG_STREAM where interval records will be stored. Modified Output Variables :. returned value - integer return status. Include File Needed : slog_header.h@*/int SLOG_SetIncreasingStarttimeOrder( SLOG_STREAM *slog ){ int ierr; if ( slog == NULL ) { fprintf( errfile, __FILE__":SLOG_SetIncreasingStarttimeOrder() - " "the input SLOG_STREAM is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } if ( slog->hdr == NULL ) { fprintf( errfile, __FILE__":SLOG_SetIncreasingStarttimeOrder() - " "the input SLOG_hdr_t is NULL\n" ); fflush( errfile ); return SLOG_FAIL; } slog->hdr->IsIncreasingStarttime = SLOG_TRUE; ierr = SLOG_WriteUpdatedHeader( slog ); if ( ierr != SLOG_SUCCESS ) { fprintf( errfile, __FILE__":SLOG_SetIncreasingStarttimeOrder() - " "SLOG_WriteUpdatedHeader() fails\n" ); fflush( errfile ); return ierr; } return SLOG_SUCCESS;}/*@C SLOG_SetIncreasingEndtimeOrder - Set the flag for the interval records will be arranged in increasing endtime order. That means there will be a second pass of the logfile and the endtime of the interval will be used to determine endtime of the frame. Modified Input Variables :. slog - pointer to SLOG_STREAM where interval records will be stored. Modified Output Variables :. returned value - integer return status. Include File Needed : slog_header.h@*/int SLOG_SetIncreasingEndtimeOrder( SLOG_STREAM *slog ){ int ierr; if ( slog == NULL ) { fprintf( errfile, __FILE__":SLOG_SetIncreasingEndtimeOrder() - "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -