Files
redAcore/FileCore.h
Charl Wentzel ade3c10a1a Important Update:
- DataTreeCore:
  - Add GetLen() method to get length of (text) value
- FileCore:
  - Minor fix: rename MaxLen -> Len
2017-08-02 03:38:37 +02:00

79 lines
2.2 KiB
C++

/*
* FileCore.h
*
* Created on: 1 Jun 2016
* Author: wentzelc
*/
#ifndef JOANETELEMETRY_FILECORE_H_
#define JOANETELEMETRY_FILECORE_H_
// Standard C/C++ Libraries
/* none */
// redA Libraries
#include "FunctionCore.h"
//---------------------------------------------------------------------------
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;
// 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 * pName, const char * pType = "File" );
virtual ~CFileCore();
// Manage files
virtual TFileHandle * AddFile( const char * Name, const char * Path, bool Append = true, bool CreateChannel = true );
virtual bool SetFilePersistence( TFileHandle * FileHandle, bool Persistent, int PersistTimeout );
// Data Input
virtual int Input( const char * ChannelName, const char * Data, int Len = -1 );
// Processing data
virtual bool Process();
};
//---------------------------------------------------------------------------
#endif /* JOANETELEMETRY_FILECORE_H_ */