Files
redAcore/FileCore.h
Charl Wentzel 5ea05d119e Major update:
- Logging
  - Created LogCore Class
  - Updated LogCore to use file descriptors instead of stdout
  - Add Log object reference to constructors for:
    FunctionCore, SelectCore
  - Use extern Log() object in SignalCore
- SelectableCore
  - Added new connection type: ForkedPipe
    Create pipe, fork process, connect pipe out to child stdin, exec
2016-08-22 12:14:53 +02:00

84 lines
2.3 KiB
C++

/*
* 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, CLogCore * pLog, 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_ */