Major update:
- Logging
- Created LogCore Class
- Updated LogCore to use file descriptors instead of stdout
- Add Log object reference to constructors for:
FunctionCore, SelectCore
- Use extern Log() object in SignalCore
- SelectableCore
- Added new connection type: ForkedPipe
Create pipe, fork process, connect pipe out to child stdin, exec
This commit is contained in:
@@ -8,17 +8,19 @@
|
||||
#ifndef REDACORE_SELECTABLECORE_H_
|
||||
#define REDACORE_SELECTABLECORE_H_
|
||||
|
||||
// Standard C/C++ Libraries
|
||||
#include <stdio.h>
|
||||
#include <sys/wait.h>
|
||||
#include <string.h>
|
||||
|
||||
// redA Libraries
|
||||
#include "FunctionCore.h"
|
||||
|
||||
// Standard C/C++ Libraries
|
||||
#include <string.h>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// Types required for connections
|
||||
typedef enum { ctNone = 0, ctPort = 1, ctServer = 2, ctRemoteClient = 3, ctClient = 4 } EConnectType;
|
||||
const char ConnectTypeName[][15] = { "None", "Port", "Server", "RemoteClient", "Client" };
|
||||
typedef enum { ctNone = 0, ctPort = 1, ctForkPipe = 2, ctServer = 3, ctRemoteClient = 4, ctClient = 5 } EConnectType;
|
||||
const char ConnectTypeName[][15] = { "None", "Port", "ForkPipe", "Server", "RemoteClient", "Client" };
|
||||
|
||||
typedef enum { csNone = 0, csWaitingtoOpen = 1, csOpen = 2, csDataWaiting = 3, csClosed = 4, csFailed = 5 } EConnectState;
|
||||
const char ConnectStateName[][15] = { "None", "WaitingToOpen", "Open", "DataWaiting", "Closed", "Failed" };
|
||||
@@ -69,12 +71,16 @@ struct SHandle {
|
||||
char * Name;
|
||||
EConnectType Type;
|
||||
|
||||
char * FileName;
|
||||
// Type specific parameters
|
||||
char * Path; // Port (file)name or Exec path
|
||||
|
||||
char * Address;
|
||||
int PortNo;
|
||||
bool KeepAlive;
|
||||
pid_t ChildPID; // Forked child PID
|
||||
|
||||
char * Address; // Socket IP address
|
||||
int PortNo; // Socket port no
|
||||
bool KeepAlive; // Socket keep alive
|
||||
|
||||
// State
|
||||
int FD;
|
||||
EConnectState State;
|
||||
bool Auto;
|
||||
@@ -121,11 +127,12 @@ protected:
|
||||
timeval Timeout;
|
||||
|
||||
// Output
|
||||
CLogCore * Log;
|
||||
EDebugLevel DebugLevel;
|
||||
|
||||
public:
|
||||
// Life Cycle
|
||||
CSelect( long SelectTimeout, EDebugLevel DebugLevel );
|
||||
CSelect( long SelectTimeout, CLogCore * pLog, EDebugLevel DebugLevel );
|
||||
~CSelect();
|
||||
|
||||
// Manage FDs
|
||||
@@ -170,6 +177,9 @@ protected:
|
||||
// Port Operations
|
||||
virtual int OpenPort( THandle * Handle );
|
||||
|
||||
// ForkPipe Operations
|
||||
virtual int OpenForkPipe( THandle * Handle );
|
||||
|
||||
// Socket Operations
|
||||
virtual int OpenServerSocket( THandle * Handle );
|
||||
virtual int OpenRemoteClientSocket( THandle * Handle );
|
||||
@@ -187,9 +197,12 @@ protected:
|
||||
// Buffer operations
|
||||
virtual bool ProcessBuffer( THandle * Handle, bool Force );
|
||||
|
||||
// Specific operations
|
||||
bool BuildArgs( const char * ExecPath, int &Count, char * Args[] );
|
||||
|
||||
public:
|
||||
// Life Cycle
|
||||
CSelectableCore( const char * Name, CSelect * Selector, EDebugLevel pDebugLevel, int pOuputDisplay );
|
||||
CSelectableCore( const char * Name, CSelect * Selector, CLogCore * pLog, EDebugLevel pDebugLevel, int pOuputDisplay );
|
||||
~CSelectableCore();
|
||||
|
||||
// Finding Handles
|
||||
@@ -216,8 +229,9 @@ public:
|
||||
bool SetBuffers( THandle * Handle, int InBufSize, int OutBufSize, int InTimeout, const char * InMarker, int InMarkerLen );
|
||||
bool SerialConfig( THandle * Handle, int Baud, short DataBits, short StopBits, short Parity, short FlowCtrl, int Wait );
|
||||
|
||||
// Device Interface
|
||||
// File Interface
|
||||
bool SetPortHandle( THandle * Handle, const char * FileName );
|
||||
bool SetForkPipeHandle( THandle * Handle, const char * ExecPath );
|
||||
bool SetSocketHandle( THandle * Handle, EConnectType Type, const char * Address, const int PortNo, bool KeepAlive );
|
||||
bool ClearHandle( THandle * Handle );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user