Files
redAcore/FunctionCore.h
Charl Wentzel f2a1ca950a Major Update:
- DataTreeCore:
  - Merge TDataMember and CDataTree into => CDataMember
  - Each node, incl root is now CDataMember object
  - Modified function to not require BaseMember (Object is basemember)
  - Split/duplicat most functions to require, or not require child path
  - Added isNull/Object/Array/Sting() etc methods
  - Many other methods removed or restructured
- Updated DataTree usage in: JSONparseCore,
  ApplicationCore, FunctionCore, SelectableCore, WatchdogCore
2018-11-17 19:10:59 +02:00

154 lines
4.5 KiB
C++

/*
* FunctionCore.h
*
* Created on: 18 May 2016
* Author: wentzelc
*/
#ifndef REDACORE_FUNCTIONCORE_H_
#define REDACORE_FUNCTIONCORE_H_
// Standard C/C++ Libraries
#include <string.h>
// redA Libraries
#include "LogCore.h"
#include "DataTreeCore.h"
//---------------------------------------------------------------------------
// Preview
typedef struct SChannel TChannel;
typedef struct SChannelLink TChannelLink;
class CFunctionCore;
//---------------------------------------------------------------------------
struct SChannel
{
char * Name;
TChannelLink * FirstInput;
TChannelLink * FirstOutput;
bool InputEnabled;
bool OutputEnabled;
TChannel * Next;
};
//---------------------------------------------------------------------------
struct SChannelLink
{
CFunctionCore * Function;
char * Name;
SChannelLink * Next;
};
//---------------------------------------------------------------------------
class CFunctionCore
{
protected:
// Function Definition
char * Name;
char * Type;
// Configuration
CDataMember * DataTree;
CDataMember * ConfigMember;
CDataMember * LinkConfigMember;
// Channels
TChannel * FirstChannel;
// Logging
CLogCore * Log;
EDebugLevel LogLevel;
int LogOutput;
// Stored Output
char * StoredOutput;
int StoredOutputLen;
// Manage Channel
inline TChannel * GetChannel( const char * Name ) {
if (!Name) return NULL;
TChannel * Channel = FirstChannel;
while (Channel && strcmp( Name, Channel->Name ))
Channel = Channel->Next;
return Channel;
}
// Load configuration
virtual bool LoadConfigData();
virtual bool LoadChannelLinkData();
// Data Input/Output
virtual int Output( const TChannel * Channel, const char * Data, int Len );
virtual bool PullInput( TChannel * Channel );
public:
// Life cycle
CFunctionCore( const char * pName, const char * Type );
virtual ~CFunctionCore();
// Load Configuration
virtual bool Init();
bool InitConfig( const char * pConfigPath );
bool InitConfig( CDataMember * pConfigMember );
bool InitChannelLinks( const char * pLinkConfigPath );
bool InitChannelLinks( CDataMember *pLinkConfigMember );
// Set Parameters Manually
bool SetLogParam( EDebugLevel pDebugLevel, int pOutputDisplay );
bool SetLogLevel( EDebugLevel pDebugLevel );
// Miscellaneous
inline const char * GetName() { return Name; };
inline const char * GetType() { return Type; };
// Manage Channels
virtual TChannel * AddChannel( const char * ChannelName, const bool pInputEnable = true, const bool pOutputEnabled = true );
inline bool SetChannelOutEnable( const char * ChannelName, const bool pOutputEnable ) {
TChannel * Channel = GetChannel( ChannelName );
if (!Channel) return false;
Channel->OutputEnabled = pOutputEnable;
return true;
}
inline bool SetChannelInEnable( const char * ChannelName, const bool pInputEnable ) {
TChannel * Channel = GetChannel( ChannelName );
if (!Channel) return false;
Channel->InputEnabled = pInputEnable;
return true;
}
inline bool isInputEnabled( const char * ChannelName ) {
TChannel * Channel = GetChannel( ChannelName );
return ((Channel)? Channel->InputEnabled : false);
}
inline bool isOutputEnabled( const char * ChannelName ) {
TChannel * Channel = GetChannel( ChannelName );
return ((Channel)? Channel->OutputEnabled : false);
}
// Pushing Data Output -> Input
virtual int Output( const char * ChannelName, const char * Data, int Len = -1 );
virtual int Input( const char * ChannelName, const char * Data, int Len = -1 );
// Pulling Data Input <- Output
virtual bool PullInput( const char * ChannelName );
virtual bool PullOutput( const char * ChannelName, char ** Data, int * Len = NULL );
// Automated Data Input/Output
virtual bool LinkInputChannel( const char * ChannelName, const char * OutFunctionName, const char * OutChannelName, bool Bidirectional );
virtual bool LinkOutputChannel( const char * ChannelName, const char * InFunctionName, const char * InChannelName, bool Bidirectional );
virtual bool Process() = 0;
};
//---------------------------------------------------------------------------
#endif /* REDACORE_FUNCTIONCORE_H_ */