Files
redAcore/FunctionCore.h
Charl Wentzel dc76d99b58 Important Update;
- ApplicationCore:
  - Minor log updates
- FunctionCore:
  - Initialise structs & object params in declaration
- DeviceCore:
  - Update logs with more consistent structure
  - Initialise structs & object params in declaration
  - Implemented DeviceType templates
    - Added Add/Get/Destroy methods
    - Load from config or separate template file
    - Build Devices/Params from template
  - Implemented ParamGroups
    - Added Add/Get/Destroy methods
    - Load with DeviceTypes
  - Added JSON parser to read separate template files
  - Bug fix: Getxxxx() methods
2018-12-13 09:17:39 +02:00

146 lines
4.6 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 = NULL;
TChannelLink * FirstInput = NULL;
TChannelLink * FirstOutput = NULL;
bool InputEnabled = NULL;
bool OutputEnabled = NULL;
TChannel * Next = NULL;
};
//---------------------------------------------------------------------------
struct SChannelLink
{
CFunctionCore * Function = NULL;
char * Name = NULL;
SChannelLink * Next = NULL;
};
//---------------------------------------------------------------------------
// Function Constructor
#define TYPE_FUNCTION "Function"
//CFunctionCore * NewFunctionCore( const char * Name );
//---------------------------------------------------------------------------
class CFunctionCore
{
protected:
// Function Definition
const char * Type = NULL;
char * Name = NULL;
// Channels
TChannel * FirstChannel = NULL;
// Logging
CLogCore * Log = NULL;
EDebugLevel LogLevel = dlNone;
int LogOutput = loNone;
// Stored Output
char * StoredOutput = NULL;
int StoredOutputLen = 0;
// Manage Channel
inline TChannel * GetChannel( const char * pName ) {
if (!pName) return NULL;
TChannel * Channel = FirstChannel;
while (Channel && strcmp( pName, Channel->Name ))
Channel = Channel->Next;
return Channel;
}
// 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 * pType = TYPE_FUNCTION );
virtual ~CFunctionCore();
// Load Configuration
virtual bool Init( CDataMember * FunctionConfig );
virtual bool InitChannelLinks( CDataMember *LinkConfig );
// 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_ */