Files
redAcore/FunctionCore.h
Charl Wentzel 748b62d235 Important Update:
- SelectableCore:
  - Made GetType() & GetState() public methods
  - Update logs in Input()
- FunctionCore:
  - Add Input/OutputEnabled parameters with Get/Set methods.
  - Update logging in Input() and Output()
  - Check if input/output enabled in Input() and Output()
2017-07-05 10:59:24 +02:00

129 lines
3.7 KiB
C++

/*
* 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 <string.h>
#include <sys/time.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;
// Configuration
CDataTree * DataTree;
TDataMember * BaseMember;
// Channels
TChannel * FirstChannel;
// Output
CLogCore * Log;
EDebugLevel DebugLevel;
int OutputDisplay;
// 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;
}
// Manual Data Input/Output
virtual int Output( const TChannel * Channel, const char * Data, int Len );
public:
// Life cycle
CFunctionCore( const char * FunctionName, CLogCore * pLog, EDebugLevel pDebugLevel, int pOuputDisplay );
virtual ~CFunctionCore();
virtual bool LoadConfig( CDataTree * DataTree, const char * BasePath );
// 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_ */