/* * FunctionCore.h * * Created on: 18 May 2016 * Author: wentzelc */ #ifndef REDACORE_FUNCTIONCORE_H_ #define REDACORE_FUNCTIONCORE_H_ // Standard C/C++ Libraries /* none */ // redA Libraries #include "LogCore.h" #include "DataTreeCore.h" #include "CharBufferCore.h" #include "ItemBufferCore.h" //--------------------------------------------------------------------------- // Preview typedef struct SChannel TChannel; typedef struct SChannelLink TChannelLink; typedef struct SProcessBuffer TProcessBuffer; typedef struct SProcessItem TProcessItem; class CFunctionCore; //--------------------------------------------------------------------------- struct SChannel { char * Name; TChannelLink * FirstInput; TChannelLink * FirstOutput; bool InputEnabled; bool OutputEnabled; TProcessBuffer * InputBuffer; TChannel * Next; }; //--------------------------------------------------------------------------- struct SChannelLink { CFunctionCore * Function; char * Name; SChannelLink * Next; }; //--------------------------------------------------------------------------- struct SProcessBuffer { // Process buffer char * Name; // Name of buffer; CItemBufferCore Buffer; // Message buffer unsigned long LastRefNo; // Last RefNo for item // Input parameters bool PassthroughCallback; // Send Callback once processed message has been passed on, else once processed // Output parameters TChannel * OutputChannel; // Channel to which to pass buffer output bool OutputCallback; // Expect callback on output? TProcessBuffer * Next; // Next buffer in list }; //--------------------------------------------------------------------------- struct SProcessItem { // Input Parameters TChannel * SourceChannel; char * SourceRef; bool SourceCallback; // Processing Parameters bool Processed; bool Completed; // Output Parameters timeval CallbackTimer; TChannelLink FirstOutput; // Input Data void * DataIn; int DataInLen; // Output Data void * DataOut; int DateOutLen; }; //--------------------------------------------------------------------------- class CFunctionCore_not_used { protected: // Function Definition char * Name; char * Type; // Configuration CDataTree * DataTree; TDataMember * ConfigMember; TDataMember * LinkConfigMember; // Channels TChannel * FirstChannel; // Processing Queues TProcessBuffer * FirstProcessBuffer; // Logging CLogCore * Log; EDebugLevel LogLevel; int LogOutput; // Stored Output char * StoredOutput; int StoredOutputLen; // 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 configuration virtual bool LoadConfigData(); virtual bool LoadChannelLinkData(); // Data Input/Output virtual int Output( const TChannel * Channel, const char * Data, int Len ); virtual bool PullInput( TChannel * Channel ); // Processing Queue TProcessItem * CreateProcessItem(); public: // Life cycle CFunctionCore_not_used( const char * pName, const char * Type ); virtual ~CFunctionCore_not_used(); // Load Configuration virtual bool Init(); bool InitConfig( const char * pConfigPath ); bool InitConfig( TDataMember * pConfigMember ); bool InitChannelLinks( const char * pLinkConfigPath ); bool InitChannelLinks( TDataMember *pLinkConfigMember ); // 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 ); // Manages Process Buffers TProcessBuffer * CreateProcessBuffer( const char * Name ); TProcessBuffer * GetProcessBuffer( const char * Name ); TProcessItem * CreateProcessItem( const char * BufferName ); TProcessItem * GetProcessItem( const char BufferName, const int Ref ); bool DestroyProcessItem( const char * BufferName, const int Ref ); // Queued Output virtual bool OutputMessage( TChannel * SourceChannel, const char * TargetChannelName, const int RefNo, bool Callback, const char * Data, int Len = -1 ); virtual bool OutputMessageCallback( TChannel * SourceChannel, const char * TargetChannelName, const int RefNo, const bool Success, const char * Error ); virtual bool InputMessage( TChannel * SourceChannel, const char * TargetChannelName, const int RefNo, bool Callback, const char * Data, int Len = -1 ); virtual bool InputMessageCancel( TChannel * SourceChannel, const char * TargetChannelName, const int RefNo ); // 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_ */