- Implement consistent Function addition to application
- Use TYPE_XXX constants to declare function type
- Use NewXXXX() methods to call constructor correctly
- Add FunctionType list (with constructor) to Application
- Create Function by comparison to FunctionType list
- Simplify LoadConfig() and Init() methods for functions
- Combine methods into Init() method
- Pass relevant data member to Init() method
- Remove all CDataMember references on functions
- ApplicationCore:
- Split ReadParam() method from LoadConfig() method
- Split main configuration into separate files:
- config/ - main config file, general application settings
- definition/ - application definition, e.g. function blocks
- Definition and Address List files specified in config file
- Load address file in address/ branch
- Made DataTree & JSONparser private
- Made Config, Definition & Address branches public
- Removed unnecessary branch references
- Improved event logging
- DataTreeCore:
- Allow GetChFirstChild & GetChElement to create parent branches
with correct type, ie. Object/Array
- Remove unnecessary Create param from GetXxx functions
- Bug fix: Print empty objects/arrays correct, ie. empty brackets
- Bug fix: Adding element at specific index
- Bug fix: Error when get/create string value with "null"
- FunctionCore:
- Type param now set as constant via constructor
- Create empty Handles & Channels objects if none in Config
- SelectableCore:
- Add Queue length parameter to handles for UNIX and TCP sockets
- DeviceCore:
- Bug fix: missing Process() method
146 lines
4.4 KiB
C++
146 lines
4.4 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;
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Function Constructor
|
|
#define TYPE_FUNCTION "Function"
|
|
//CFunctionCore * NewFunctionCore( const char * Name );
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
class CFunctionCore
|
|
{
|
|
protected:
|
|
// Function Definition
|
|
const char * Type;
|
|
char * Name;
|
|
|
|
// Channels
|
|
TChannel * FirstChannel;
|
|
|
|
// Logging
|
|
CLogCore * Log;
|
|
EDebugLevel LogLevel;
|
|
int LogOutput;
|
|
|
|
// Stored Output
|
|
char * StoredOutput;
|
|
int StoredOutputLen;
|
|
|
|
// 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_ */
|