Major Update:
- Minor fix: Set correct names in comments at top of file - New FileCore Class: - Writing data to output file - BufferCore: - Check for "EAGAIN" on write and retry write - FunctionCore: - Add new Output method that references LocalIO directly - SelectableCore: - New method SetAutomanage to specify auto re-open parameters - Re-open timer implemented to slow re-open events - Only call ProcessBuffer() if data received on socket - Force processing input data when no input marker set - Use new Output method to simplify code - Bug fix: Read correctly from buffer on multiple reads/writes on FD - Check for "EAGAIN" on write to FD and retry write
This commit is contained in:
83
FileCore.h
Normal file
83
FileCore.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* FileCore.h
|
||||
*
|
||||
* Created on: 1 Jun 2016
|
||||
* Author: wentzelc
|
||||
*/
|
||||
|
||||
#ifndef JOANETELEMETRY_FILECORE_H_
|
||||
#define JOANETELEMETRY_FILECORE_H_
|
||||
|
||||
// redA Libraries
|
||||
#include "FunctionCore.h"
|
||||
|
||||
// Standard C/C++ Libraries
|
||||
/* none */
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
const int NO_FD = -1;
|
||||
|
||||
typedef struct SFileHandle TFileHandle;
|
||||
struct SFileHandle
|
||||
{
|
||||
char * Name; // Quick reference
|
||||
char * Path; // Actual location of file
|
||||
int FD; // File Descriptor
|
||||
|
||||
bool Append; // Append data to end of file
|
||||
|
||||
bool Persistent; // Keep file open after write
|
||||
timeval PersistTime; // Time opened/last written to
|
||||
bool PersistTimeout; // Time to remain open, 0 = permanently open
|
||||
|
||||
TFileHandle * Next;
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class CFileCore : public CFunctionCore
|
||||
{
|
||||
private:
|
||||
// File
|
||||
TFileHandle * FirstFile;
|
||||
|
||||
// temp
|
||||
int count;
|
||||
int x;
|
||||
// temp
|
||||
|
||||
// Manage File
|
||||
virtual bool OpenFile( TFileHandle * FileHandle );
|
||||
virtual bool CloseFile( TFileHandle * FileHandle );
|
||||
|
||||
virtual int ReadFromFD( int FD, char * Data, int MaxLen );
|
||||
virtual int WriteToFD( int FD, const char * Data, int Len );
|
||||
|
||||
inline TFileHandle * GetFile( const char * Name ) {
|
||||
if (!Name || !*Name) return NULL;
|
||||
TFileHandle * FileHandle = FirstFile;
|
||||
while (FileHandle && strcmp( Name, FileHandle->Name ))
|
||||
FileHandle = FileHandle->Next;
|
||||
return FileHandle;
|
||||
};
|
||||
|
||||
inline bool isOpen( TFileHandle * FileHandle ) { return (FileHandle->FD != NO_FD); };
|
||||
|
||||
public:
|
||||
// Life cycle
|
||||
CFileCore( const char * Name, EDebugLevel pDebugLevel, int pOuputDisplay );
|
||||
~CFileCore();
|
||||
|
||||
// Manage files
|
||||
virtual TFileHandle * AddFile( const char * Name, const char * Path, bool Append = true, bool CreateLocalIO = true );
|
||||
virtual bool SetFilePersistence( TFileHandle * FileHandle, bool Persistent, int PersistTimeout );
|
||||
|
||||
// Data Input
|
||||
virtual int Input( const char * IOName, const char * Data, int MaxLen = -1 );
|
||||
|
||||
// Processing data
|
||||
virtual bool Process();
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#endif /* JOANETELEMETRY_FILECORE_H_ */
|
||||
Reference in New Issue
Block a user