Files
redAcore/FileCore.h
Charl Wentzel 434377f122 Major Update:
- Implement new ApplicationCore:
  - Manage Tools: Log, DataTree, JSONparser & Selector
  - Load configuration, Manage FunctionBlocks
- FunctionCore & dirived classes, SignalCore:
  - affects: SelectableCore, DeviceCore, FileCore, WatchdogCore
  - Do not pass Log()
  - Define and pass Type
  - Update/reduce included headers
  - Use ProcessName and Application global vars
  - Get Log, DataTree from Application
  - Use virtual Init() function to set must have Channels/Handles
- DataTreeCore:
  - Bug fix: Check if child members exist and destroy in SetValuePtr()
  - Add method GetFirstChild with BaseMember & Path
  - Bug fix: do not use RootMember if no Parent in GetChildxxx() methods
- SignalCore, SelectCore:
  - Use Application->Log()
- FunctionCore:
  - Add itself to Application (function list)
  - Add parameter: LinkConfigMember, Type
  - Use virtual LoadConfigData() to configure from DataTree
  - Rename methods: LoadConfig() -> InitConfig(),
      InitLogging() -> SetLogParam(), SetDebugLevel() -> SetLogLevel()
  - Add method: GetType(), LoadChannelLinkData(), InitChannelLinks()
  - Modify LinkIn/OutputChannel() to use name for InFunction, not pointer
- SelectableCore & Dirived classes:
  - Affects DeviceCore & WatchdogClient
  - Rename parameter: Select -> Selector, BaseMember -> ConfigMember
  - Get Selector from Application->Selector
  - Change Handles JSON structure from Array to Key:Value pairs
  - Bug fix: check if Selector exist during Input()
  - Bug fix: do not set PortNo if not exist
2017-07-16 20:29:01 +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_
// 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;
// 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 MaxLen = -1 );
// Processing data
virtual bool Process();
};
//---------------------------------------------------------------------------
#endif /* JOANETELEMETRY_FILECORE_H_ */