Files
redAcore/FileCore.h
Charl Wentzel a972fb9101 Major Update:
- Implement consistent Function addition to application
  - Use TYPE_XXX constants to declare function type
  - Use NewXXXX() methods to call constructor correctly
  - Add FunctionType list (with constructor) to Application
  - Create Function by comparison to FunctionType list
- Simplify LoadConfig() and Init() methods for functions
  - Combine methods into Init() method
  - Pass relevant data member to Init() method
  - Remove all CDataMember references on functions
- ApplicationCore:
  - Split ReadParam() method from LoadConfig() method
  - Split main configuration into separate files:
    - config/ - main config file, general application settings
    - definition/ - application definition, e.g. function blocks
  - Definition and Address List files specified in config file
  - Load address file in address/ branch
  - Made DataTree & JSONparser private
  - Made Config, Definition & Address branches public
  - Removed unnecessary branch references
  - Improved event logging
- DataTreeCore:
  - Allow GetChFirstChild & GetChElement to create parent branches
    with correct type, ie. Object/Array
  - Remove unnecessary Create param from GetXxx functions
  - Bug fix: Print empty objects/arrays correct, ie. empty brackets
  - Bug fix: Adding element at specific index
  - Bug fix: Error when get/create string value with "null"
- FunctionCore:
  - Type param now set as constant via constructor
  - Create empty Handles & Channels objects if none in Config
- SelectableCore:
  - Add Queue length parameter to handles for UNIX and TCP sockets
- DeviceCore:
  - Bug fix: missing Process() method
2018-11-24 13:35:23 +02:00

84 lines
2.4 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;
};
//---------------------------------------------------------------------------
// Function Constructor List
#define TYPE_FILE "File"
CFunctionCore * NewFileCore( const char * Name );
//---------------------------------------------------------------------------
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 = TYPE_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_ */