/* * FunctionCore.h * * Created on: 18 May 2016 * Author: wentzelc */ #ifndef REDACORE_FUNCTIONCORE_H_ #define REDACORE_FUNCTIONCORE_H_ // redA Libraries #include "LogCore.h" #include "BufferCore.h" #include "DataTreeCore.h" // Standard C/C++ Libraries #include #include //--------------------------------------------------------------------------- // 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; // Configuration CDataTree * DataTree; TDataMember * BaseMember; // Channels TChannel * FirstChannel; // Output CLogCore * Log; EDebugLevel LogLevel; int LogOutput; // 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 configuraiton virtual bool LoadConfigData(); // Manual Data Input/Output virtual int Output( const TChannel * Channel, const char * Data, int Len ); public: // Life cycle CFunctionCore( const char * pName, CLogCore * pLog ); virtual ~CFunctionCore(); // Load Configuration virtual bool LoadConfig( CDataTree * pDataTree, const char * pBasePath ); virtual bool LoadConfig( CDataTree * pDataTree, TDataMember * pBaseMember ); // Set Parameters Manually bool InitLogging( EDebugLevel pDebugLevel, int pOutputDisplay ); bool SetDebugLevel( EDebugLevel pDebugLevel ); // Miscellaneous inline const char * GetName() { return Name; }; // 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); } // Manual Data Input/Output virtual int Input( const char * ChannelName, const char * Data, int MaxLen = -1 ); virtual int Output( const char * ChannelName, const char * Data, int Len = -1 ); // Automated Data Input/Output virtual bool LinkInputChannel( const char * ChannelName, CFunctionCore * OutFunction, const char * OutChannelName, bool Bidirectional ); virtual bool LinkOutputChannel( const char * ChannelName, CFunctionCore * InFunction, const char * InChannelName, bool Bidirectional ); virtual bool Process() = 0; }; //--------------------------------------------------------------------------- #endif /* REDACORE_FUNCTIONCORE_H_ */