- FunctionCore:
- Improve Channel Events:
- Remove important actions from ChannelStateEvent()
(now only used for custom actions)
- Add new method UpdateChannelOutState()
- Add Channel Events to Link and Unlink actions
- Rename SetChannelState() -> SetChannelInState()
- Use Channel->Ref (instead of name) on all channel events
- DeviceCore/SelectableCore:
- Rename SetChannelState() -> SetChannelInState()
144 lines
4.9 KiB
C++
144 lines
4.9 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"
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Enumarate Types
|
|
typedef enum { CH_off = 0, CH_wait = 1, CH_ready = 2 } EChannelState;
|
|
const char ChannelStateName[][15] = { "Off", "Waiting", "Ready" };
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Preview
|
|
typedef struct SChannel TChannel;
|
|
typedef struct SChannelLink TChannelLink;
|
|
|
|
class CFunctionCore;
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
struct SChannel
|
|
{
|
|
char * Name = NULL;
|
|
char * Ref = NULL;
|
|
|
|
TChannelLink * FirstLink = NULL; // List of channels linked for input/output
|
|
|
|
EChannelState InState = CH_off; // Channel ready to receive input (determined by parent function)
|
|
EChannelState OutState = CH_off; // Channel ready to send output (determined by InStates of linked channels)
|
|
|
|
TChannel * Next = NULL;
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
|
|
struct SChannelLink
|
|
{
|
|
CFunctionCore * Function = NULL;
|
|
TChannel * Channel = NULL;
|
|
|
|
bool Input = false;
|
|
bool Output = false;
|
|
|
|
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;
|
|
bool WaitToTerminate = false;
|
|
|
|
// JSON Config
|
|
CDataMember * Config = NULL;
|
|
|
|
// Channels
|
|
TChannel * FirstChannel = NULL;
|
|
|
|
// Logging
|
|
CLogCore * Log = NULL;
|
|
EDebugLevel LogLevel = dlNone;
|
|
int LogOutput = loNone;
|
|
|
|
// 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;
|
|
}
|
|
inline TChannelLink * GetLinkChannel( TChannel * Channel, const char * LinkRef ) {
|
|
if (!Channel || !LinkRef ) return NULL;
|
|
SChannelLink * LinkChannel = Channel->FirstLink;
|
|
while (LinkChannel && strcmp( LinkRef, LinkChannel->Channel->Ref ))
|
|
LinkChannel = LinkChannel->Next;
|
|
return LinkChannel;
|
|
}
|
|
|
|
// Data Input/Output
|
|
virtual int Output( const TChannel * Channel, const char * TargetRef, const bool SourceRef, const char * Data, int Len, int OutputFormat = loNone );
|
|
|
|
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 EChannelState State );
|
|
|
|
virtual bool SetChannelInState( TChannel * Channel, const EChannelState State );
|
|
virtual bool ChannelStateEvent( TChannel * Channel, const char * SourceRef, const EChannelState OldState, const EChannelState NewState ) { return true; };
|
|
virtual bool UpdateChannelOutState( TChannel * Channel );
|
|
virtual EChannelState GetChannelOutState( TChannel * Channel, const char * TargetRef );
|
|
|
|
// Pushing Data Output -> Input
|
|
virtual int Output( const char * ChannelName, const char * TargetRef, const bool SourceRef, const char * Data, int Len = -1 );
|
|
virtual int Input( const char * ChannelName, const char * SourceRef, const char * Data, int Len = -1 );
|
|
|
|
// Automated Data Input/Output
|
|
virtual bool LinkChannel( const char * ChannelName, const char * LinkFunctionName, const char * LinkChannelName, bool Input, bool Output );
|
|
virtual bool UnlinkChannel( const char * ChannelName, const char * LinkFunctionName, const char * LinkChannelName );
|
|
virtual bool Process() = 0;
|
|
|
|
friend class CApplication;
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif /* REDACORE_FUNCTIONCORE_H_ */
|