cache.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <math.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
#include <dirent.h>
#include "common.h"

Include dependency graph for cache.c:

Go to the source code of this file.

Functions

void ResetCacheCounters (void)
 reset all the counters
int CacheFileSelect (const struct dirent *t)
 filter for SN T1 T2
void OpenCacheFileWrite (int wr)
 Open the cache file.
char * CacheRead (char *line)
 read a line in the cache file
void RewindCache (void)
 rewind the cache file is open for read
int OpenCacheFileRead (char *SN, time_t t)
 look for the cache file corresponding to the current data stream
int CompareCacheLines (const void *p1, const void *p2)
 comparison method for qsort
void SortCacheFile (char *fn)
 sort the cache file
void CloseCacheFile (int cancel)
 Close the cache file, if open.
void CachePrint (const char *format,...)
 print a formatted line in the cache file, open it if neccessary
void CachePrintCST (void)
 issue a #CST message (continuous segment tag)
void CachePrintTIME (void)
 issue a #TIME message
void CacheCallBack (void)
 Build the cache for the current input.
void InitCache (void)
 initialize the cache directory This function should cleanup the cache by removing the oldest files

Variables

struct dirent ** cacheFileList = NULL
FILE * cacheFile = NULL
char cacheFileName [128]
char cacheDir [128]
time_t lastCacheTime = 0
int64_t lastCacheOffset = 0
int cacheOutput = -1
int startCacheTime = 0
char testForSN [128]
time_t testForTime
int nTimesInCache = 0


Function Documentation

void CacheCallBack ( void   ) 

Build the cache for the current input.

Definition at line 508 of file cache.c.

References beginWindow, cacheOutput, CachePrintTIME(), currentTime, HWConfig, lastCacheOffset, lastCacheTime, noCache, OpenCacheFileRead(), HWConfigType::serialNumber, totalFrameProcessed, and Titan2TimeType::usecond.

Referenced by ProcessTimeFrame().

Here is the call graph for this function:

int CacheFileSelect ( const struct dirent *  t  ) 

filter for SN T1 T2

Definition at line 74 of file cache.c.

References cacheDir, testForSN, and testForTime.

Referenced by OpenCacheFileRead().

void CachePrint ( const char *  format,
  ... 
)

print a formatted line in the cache file, open it if neccessary

Parameters:
format,... the same format and arguments as for *printf

Definition at line 454 of file cache.c.

References cacheFile, currentTime, noCache, OpenCacheFileWrite(), startCacheTime, and Titan2TimeType::usecond.

Referenced by CachePrintTIME().

Here is the call graph for this function:

void CachePrintCST ( void   ) 

issue a #CST message (continuous segment tag)

Definition at line 478 of file cache.c.

References cacheOutput.

Referenced by EndSuperFrame(), and ProcessTimeFrame().

void CachePrintTIME ( void   ) 

issue a #TIME message

Definition at line 489 of file cache.c.

References cacheFile, cacheOutput, CachePrint(), currentFile, currentTime, nTimesInCache, titan2File, and Titan2TimeType::usecond.

Referenced by CacheCallBack().

Here is the call graph for this function:

char* CacheRead ( char *  line  ) 

read a line in the cache file

Parameters:
line the output char buffer
Returns:
the status of fgets

Definition at line 180 of file cache.c.

References cacheFile, and cacheOutput.

Referenced by SeekTime().

void CloseCacheFile ( int  cancel  ) 

Close the cache file, if open.

Parameters:
cancel juste close and unlink the cache file if 1

Definition at line 402 of file cache.c.

References cacheDir, cacheFile, cacheFileName, cacheOutput, currentTime, HWConfig, localCache, nTimesInCache, PrintDebug, Rename(), ResetCacheCounters(), HWConfigType::serialNumber, SortCacheFile(), startCacheTime, and Titan2TimeType::usecond.

Referenced by FlushNonDataFiles(), and MainCleanUp().

Here is the call graph for this function:

int CompareCacheLines ( const void *  p1,
const void *  p2 
)

comparison method for qsort

Parameters:
p1 first element
p2 second element
Returns:
-1 if p1<p2, 0 if p1=p2 or if p1 or p2 is not a TIME line, and +1 if p1>p2

Definition at line 305 of file cache.c.

Referenced by SortCacheFile().

void InitCache ( void   ) 

initialize the cache directory This function should cleanup the cache by removing the oldest files

Definition at line 555 of file cache.c.

References cacheDir, noCache, OpenCacheFileWrite(), and PrintDebug.

Referenced by main().

Here is the call graph for this function:

int OpenCacheFileRead ( char *  SN,
time_t  t 
)

look for the cache file corresponding to the current data stream

Parameters:
SN the serial number to look for
t the time to look for If SN is NULL and t is -2, then the cache is cleared

Definition at line 205 of file cache.c.

References __alphasort(), __scandir(), cacheDir, cacheFile, cacheFileList, cacheFileName, CacheFileSelect(), cacheOutput, localCache, OpenCacheFileWrite(), PrintDebug, PrintLog, PrintWarning, testForSN, and testForTime.

Referenced by CacheCallBack(), ParseOptions(), and SeekTime().

Here is the call graph for this function:

void OpenCacheFileWrite ( int  wr  ) 

Open the cache file.

Parameters:
wr do the job if 1 else just set and create cacheDir

Definition at line 121 of file cache.c.

References baseDir, cacheDir, cacheFile, cacheFileName, cacheOutput, currentTime, localCache, nTimesInCache, OpenTempFile(), PrintDebug, startCacheTime, and Titan2TimeType::usecond.

Referenced by CachePrint(), InitCache(), and OpenCacheFileRead().

Here is the call graph for this function:

void ResetCacheCounters ( void   ) 

reset all the counters

Definition at line 66 of file cache.c.

References cacheOutput, lastCacheOffset, and lastCacheTime.

Referenced by CloseCacheFile().

void RewindCache ( void   ) 

rewind the cache file is open for read

Definition at line 190 of file cache.c.

References cacheFile, and cacheOutput.

Referenced by SeekTime().

void SortCacheFile ( char *  fn  ) 

sort the cache file

Parameters:
fn the filename of the cache file to sort

Definition at line 329 of file cache.c.

References CompareCacheLines(), and PrintDebug.

Referenced by CloseCacheFile().

Here is the call graph for this function:


Variable Documentation

char cacheDir[128]

FILE* cacheFile = NULL

struct dirent** cacheFileList = NULL

Definition at line 46 of file cache.c.

Referenced by OpenCacheFileRead().

char cacheFileName[128]

Definition at line 49 of file cache.c.

Referenced by CloseCacheFile(), OpenCacheFileRead(), and OpenCacheFileWrite().

int cacheOutput = -1

int64_t lastCacheOffset = 0

Definition at line 54 of file cache.c.

Referenced by CacheCallBack(), and ResetCacheCounters().

time_t lastCacheTime = 0

Definition at line 52 of file cache.c.

Referenced by CacheCallBack(), and ResetCacheCounters().

int nTimesInCache = 0

Definition at line 63 of file cache.c.

Referenced by CachePrintTIME(), CloseCacheFile(), and OpenCacheFileWrite().

int startCacheTime = 0

Definition at line 58 of file cache.c.

Referenced by CachePrint(), CloseCacheFile(), and OpenCacheFileWrite().

char testForSN[128]

Definition at line 60 of file cache.c.

Referenced by CacheFileSelect(), and OpenCacheFileRead().

time_t testForTime

Definition at line 61 of file cache.c.

Referenced by CacheFileSelect(), and OpenCacheFileRead().


Generated on Tue Jul 22 23:11:56 2008 for Titan2Reader by  doxygen 1.5.6