Importnant update:
- Add callback functions for change in socket states
This commit is contained in:
@@ -47,6 +47,9 @@ typedef struct SHandle THandle;
|
||||
class CSelect;
|
||||
class CSelectableCore;
|
||||
|
||||
// Callback function for handle events
|
||||
typedef void (*FHandleCallback)( CSelectableCore * Function, THandle * Handle, EConnectState State );
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// List of Handles for Select Object
|
||||
@@ -71,6 +74,14 @@ struct SHandle {
|
||||
char * Name;
|
||||
EConnectType Type;
|
||||
|
||||
// State
|
||||
int FD;
|
||||
EConnectState State;
|
||||
bool Auto;
|
||||
|
||||
// Callback functions
|
||||
FHandleCallback StateCallback[ 6 ];
|
||||
|
||||
// Type specific parameters
|
||||
char * Path; // Port (file)name or Exec path
|
||||
|
||||
@@ -80,11 +91,6 @@ struct SHandle {
|
||||
int PortNo; // Socket port no
|
||||
bool KeepAlive; // Socket keep alive
|
||||
|
||||
// State
|
||||
int FD;
|
||||
EConnectState State;
|
||||
bool Auto;
|
||||
|
||||
// Buffers
|
||||
CBuffer * InBuffer;
|
||||
CBuffer * OutBuffer;
|
||||
@@ -174,6 +180,15 @@ protected:
|
||||
return ((Handle)? Handle->State : csNone);
|
||||
};
|
||||
|
||||
// General fucntions
|
||||
inline bool ChangeState( THandle * Handle, EConnectState State ) {
|
||||
if (!Handle || (Handle->State == State)) return false;
|
||||
if (Handle->StateCallback[ (int)State ])
|
||||
(Handle->StateCallback[ (int)State ])( this, Handle, State );
|
||||
Handle->State = State;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Port Operations
|
||||
virtual int OpenPort( THandle * Handle );
|
||||
|
||||
@@ -220,6 +235,7 @@ public:
|
||||
|
||||
// Configuration
|
||||
THandle * CreateHandle( const char * HandleName, bool CreateChannel );
|
||||
bool SetCallback( THandle * Handle, EConnectState pState, FHandleCallback pCallback );
|
||||
bool SetAutoManage( THandle * Handle, bool AutoManage, int ReopenTime = 0 );
|
||||
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 );
|
||||
|
||||
Reference in New Issue
Block a user