Add virtual methods to GSocketBSD for calling the event loop handler
instead of the GUI event functions table. Also added a compatibility class to gsocket.cpp until we can update all of the GUIs. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25234 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
2a9d84d006
commit
444cb1fdcb
@ -34,7 +34,7 @@ class GSocketBSD
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GSocketBSD();
|
GSocketBSD();
|
||||||
~GSocketBSD();
|
virtual ~GSocketBSD();
|
||||||
bool IsOk() { return m_ok; }
|
bool IsOk() { return m_ok; }
|
||||||
void Close();
|
void Close();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
@ -70,6 +70,10 @@ protected:
|
|||||||
void Detected_Read();
|
void Detected_Read();
|
||||||
void Detected_Write();
|
void Detected_Write();
|
||||||
bool m_ok;
|
bool m_ok;
|
||||||
|
virtual void EventLoop_Enable_Events() = 0;
|
||||||
|
virtual void EventLoop_Disable_Events() = 0;
|
||||||
|
virtual void EventLoop_Install_Callback(GSocketEvent event) = 0;
|
||||||
|
virtual void EventLoop_Uninstall_Callback(GSocketEvent event) = 0;
|
||||||
public:
|
public:
|
||||||
//DFE: We can't protect these data member until the GUI code is updated
|
//DFE: We can't protect these data member until the GUI code is updated
|
||||||
//protected:
|
//protected:
|
||||||
|
@ -156,30 +156,83 @@ int _System soclose(int);
|
|||||||
# define GSocket_Debug(args)
|
# define GSocket_Debug(args)
|
||||||
#endif /* __GSOCKET_DEBUG__ */
|
#endif /* __GSOCKET_DEBUG__ */
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// GSocketBSDGUIShim
|
||||||
|
class GSocketBSDGUIShim:public GSocketBSD
|
||||||
|
{
|
||||||
|
friend void GSocket_SetGUIFunctions(struct GSocketGUIFunctionsTable *guifunc);
|
||||||
|
public:
|
||||||
|
static inline bool GUI_Init();
|
||||||
|
static inline void GUI_Cleanup();
|
||||||
|
static inline bool UseGUI();
|
||||||
|
GSocketBSDGUIShim();
|
||||||
|
virtual ~GSocketBSDGUIShim();
|
||||||
|
protected:
|
||||||
|
virtual void EventLoop_Enable_Events();
|
||||||
|
virtual void EventLoop_Disable_Events();
|
||||||
|
virtual void EventLoop_Install_Callback(GSocketEvent event);
|
||||||
|
virtual void EventLoop_Uninstall_Callback(GSocketEvent event);
|
||||||
|
private:
|
||||||
/* Table of GUI-related functions. We must call them indirectly because
|
/* Table of GUI-related functions. We must call them indirectly because
|
||||||
* of wxBase and GUI separation: */
|
* of wxBase and GUI separation: */
|
||||||
|
|
||||||
static struct GSocketGUIFunctionsTable *gs_gui_functions;
|
static struct GSocketGUIFunctionsTable *ms_gui_functions;
|
||||||
|
};
|
||||||
|
|
||||||
#define USE_GUI() (gs_gui_functions != NULL)
|
struct GSocketGUIFunctionsTable *GSocketBSDGUIShim::ms_gui_functions = NULL;
|
||||||
|
|
||||||
/* Define macros to simplify indirection: */
|
void GSocket_SetGUIFunctions(struct GSocketGUIFunctionsTable *guifunc)
|
||||||
#define _GSocket_GUI_Init() \
|
{
|
||||||
if (gs_gui_functions) gs_gui_functions->GUI_Init()
|
GSocketBSDGUIShim::ms_gui_functions = guifunc;
|
||||||
#define _GSocket_GUI_Cleanup() \
|
}
|
||||||
if (gs_gui_functions) gs_gui_functions->GUI_Cleanup()
|
|
||||||
#define _GSocket_GUI_Init_Socket(socket) \
|
inline bool GSocketBSDGUIShim::UseGUI()
|
||||||
(gs_gui_functions ? gs_gui_functions->GUI_Init_Socket(socket) : 1)
|
{
|
||||||
#define _GSocket_GUI_Destroy_Socket(socket) \
|
return ms_gui_functions;
|
||||||
if (gs_gui_functions) gs_gui_functions->GUI_Destroy_Socket(socket)
|
}
|
||||||
#define _GSocket_Enable_Events(socket) \
|
|
||||||
if (gs_gui_functions) gs_gui_functions->Enable_Events(socket)
|
inline bool GSocketBSDGUIShim::GUI_Init()
|
||||||
#define _GSocket_Disable_Events(socket) \
|
{
|
||||||
if (gs_gui_functions) gs_gui_functions->Disable_Events(socket)
|
return (ms_gui_functions)?ms_gui_functions->GUI_Init():true;
|
||||||
#define _GSocket_Install_Callback(socket, event) \
|
}
|
||||||
if (gs_gui_functions) gs_gui_functions->Install_Callback(socket, event)
|
|
||||||
#define _GSocket_Uninstall_Callback(socket, event) \
|
inline void GSocketBSDGUIShim::GUI_Cleanup()
|
||||||
if (gs_gui_functions) gs_gui_functions->Uninstall_Callback(socket, event)
|
{
|
||||||
|
if (ms_gui_functions) ms_gui_functions->GUI_Cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
GSocketBSDGUIShim::GSocketBSDGUIShim()
|
||||||
|
{
|
||||||
|
m_ok = (ms_gui_functions ? ms_gui_functions->GUI_Init_Socket(this) : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
GSocketBSDGUIShim::~GSocketBSDGUIShim()
|
||||||
|
{
|
||||||
|
if (ms_gui_functions) ms_gui_functions->GUI_Destroy_Socket(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GSocketBSDGUIShim::EventLoop_Enable_Events()
|
||||||
|
{
|
||||||
|
if (ms_gui_functions) ms_gui_functions->Enable_Events(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GSocketBSDGUIShim::EventLoop_Disable_Events()
|
||||||
|
{
|
||||||
|
if (ms_gui_functions) ms_gui_functions->Disable_Events(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GSocketBSDGUIShim::EventLoop_Install_Callback(GSocketEvent event)
|
||||||
|
{
|
||||||
|
if (ms_gui_functions) ms_gui_functions->Install_Callback(this, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GSocketBSDGUIShim::EventLoop_Uninstall_Callback(GSocketEvent event)
|
||||||
|
{
|
||||||
|
if (ms_gui_functions) ms_gui_functions->Uninstall_Callback(this, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// GSocketBSD
|
||||||
|
|
||||||
static struct GSocketBaseFunctionsTable gs_base_functions =
|
static struct GSocketBaseFunctionsTable gs_base_functions =
|
||||||
{
|
{
|
||||||
@ -189,27 +242,14 @@ static struct GSocketBaseFunctionsTable gs_base_functions =
|
|||||||
|
|
||||||
/* Global initialisers */
|
/* Global initialisers */
|
||||||
|
|
||||||
void GSocket_SetGUIFunctions(struct GSocketGUIFunctionsTable *guifunc)
|
|
||||||
{
|
|
||||||
gs_gui_functions = guifunc;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GSocket_Init(void)
|
int GSocket_Init(void)
|
||||||
{
|
{
|
||||||
if (gs_gui_functions)
|
return GSocketBSDGUIShim::GUI_Init();
|
||||||
{
|
|
||||||
if ( !gs_gui_functions->GUI_Init() )
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSocket_Cleanup(void)
|
void GSocket_Cleanup(void)
|
||||||
{
|
{
|
||||||
if (gs_gui_functions)
|
GSocketBSDGUIShim::GUI_Cleanup();
|
||||||
{
|
|
||||||
gs_gui_functions->GUI_Cleanup();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GSocketBSD::GSocketBSD()
|
GSocketBSD::GSocketBSD()
|
||||||
@ -235,13 +275,12 @@ GSocketBSD::GSocketBSD()
|
|||||||
|
|
||||||
m_functions = &gs_base_functions;
|
m_functions = &gs_base_functions;
|
||||||
|
|
||||||
/* Per-socket GUI-specific initialization */
|
m_ok = true;
|
||||||
m_ok = _GSocket_GUI_Init_Socket(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSocketBSD::Close()
|
void GSocketBSD::Close()
|
||||||
{
|
{
|
||||||
_GSocket_Disable_Events(this);
|
EventLoop_Disable_Events();
|
||||||
// gsockosx.c calls CFSocketInvalidate which closes the socket for us
|
// gsockosx.c calls CFSocketInvalidate which closes the socket for us
|
||||||
#if !(defined(__DARWIN__) && (defined(__WXMAC__) || defined(__WXCOCOA__)))
|
#if !(defined(__DARWIN__) && (defined(__WXMAC__) || defined(__WXCOCOA__)))
|
||||||
close(m_fd);
|
close(m_fd);
|
||||||
@ -251,15 +290,6 @@ void GSocketBSD::Close()
|
|||||||
|
|
||||||
GSocketBSD::~GSocketBSD()
|
GSocketBSD::~GSocketBSD()
|
||||||
{
|
{
|
||||||
assert(this);
|
|
||||||
|
|
||||||
/* Check that the socket is really shutdowned */
|
|
||||||
if (m_fd != INVALID_SOCKET)
|
|
||||||
Shutdown();
|
|
||||||
|
|
||||||
/* Per-socket GUI-specific cleanup */
|
|
||||||
_GSocket_GUI_Destroy_Socket(this);
|
|
||||||
|
|
||||||
/* Destroy private addresses */
|
/* Destroy private addresses */
|
||||||
if (m_local)
|
if (m_local)
|
||||||
GAddress_destroy(m_local);
|
GAddress_destroy(m_local);
|
||||||
@ -459,7 +489,7 @@ GSocketError GSocketBSD::SetServer()
|
|||||||
#else
|
#else
|
||||||
ioctl(m_fd, FIONBIO, &arg);
|
ioctl(m_fd, FIONBIO, &arg);
|
||||||
#endif
|
#endif
|
||||||
_GSocket_Enable_Events(this);
|
EventLoop_Enable_Events();
|
||||||
|
|
||||||
/* allow a socket to re-bind if the socket is in the TIME_WAIT
|
/* allow a socket to re-bind if the socket is in the TIME_WAIT
|
||||||
state after being previously closed.
|
state after being previously closed.
|
||||||
@ -517,9 +547,9 @@ GSocket *GSocketBSD::WaitConnection()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create a GSocket object for the new connection */
|
/* Create a GSocket object for the new connection */
|
||||||
connection = new GSocketBSD();
|
connection = GSocket_new();
|
||||||
|
|
||||||
if (!connection->IsOk())
|
if (!connection)
|
||||||
{
|
{
|
||||||
delete connection;
|
delete connection;
|
||||||
m_error = GSOCK_MEMERR;
|
m_error = GSOCK_MEMERR;
|
||||||
@ -573,7 +603,7 @@ GSocket *GSocketBSD::WaitConnection()
|
|||||||
#else
|
#else
|
||||||
ioctl(connection->m_fd, FIONBIO, &arg);
|
ioctl(connection->m_fd, FIONBIO, &arg);
|
||||||
#endif
|
#endif
|
||||||
_GSocket_Enable_Events(connection);
|
connection->EventLoop_Enable_Events();
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
@ -645,7 +675,7 @@ GSocketError GSocketBSD::Connect(GSocketStream stream)
|
|||||||
#else
|
#else
|
||||||
ioctl(m_fd, FIONBIO, &arg);
|
ioctl(m_fd, FIONBIO, &arg);
|
||||||
#endif
|
#endif
|
||||||
_GSocket_Enable_Events(this);
|
EventLoop_Enable_Events();
|
||||||
|
|
||||||
/* Connect it to the peer address, with a timeout (see below) */
|
/* Connect it to the peer address, with a timeout (see below) */
|
||||||
ret = connect(m_fd, m_peer->m_addr, m_peer->m_len);
|
ret = connect(m_fd, m_peer->m_addr, m_peer->m_len);
|
||||||
@ -752,7 +782,7 @@ GSocketError GSocketBSD::SetNonOriented()
|
|||||||
#else
|
#else
|
||||||
ioctl(m_fd, FIONBIO, &arg);
|
ioctl(m_fd, FIONBIO, &arg);
|
||||||
#endif
|
#endif
|
||||||
_GSocket_Enable_Events(this);
|
EventLoop_Enable_Events();
|
||||||
|
|
||||||
/* Bind to the local address,
|
/* Bind to the local address,
|
||||||
* and retrieve the actual address bound.
|
* and retrieve the actual address bound.
|
||||||
@ -883,7 +913,7 @@ int GSocketBSD::Write(const char *buffer, int size)
|
|||||||
*/
|
*/
|
||||||
GSocketEventFlags GSocketBSD::Select(GSocketEventFlags flags)
|
GSocketEventFlags GSocketBSD::Select(GSocketEventFlags flags)
|
||||||
{
|
{
|
||||||
if (!USE_GUI())
|
if (!GSocketBSDGUIShim::UseGUI())
|
||||||
{
|
{
|
||||||
|
|
||||||
GSocketEventFlags result = 0;
|
GSocketEventFlags result = 0;
|
||||||
@ -1122,13 +1152,13 @@ void GSocketBSD::UnsetCallback(GSocketEventFlags flags)
|
|||||||
void GSocketBSD::Enable(GSocketEvent event)
|
void GSocketBSD::Enable(GSocketEvent event)
|
||||||
{
|
{
|
||||||
m_detected &= ~(1 << event);
|
m_detected &= ~(1 << event);
|
||||||
_GSocket_Install_Callback(this, event);
|
EventLoop_Install_Callback(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSocketBSD::Disable(GSocketEvent event)
|
void GSocketBSD::Disable(GSocketEvent event)
|
||||||
{
|
{
|
||||||
m_detected |= (1 << event);
|
m_detected |= (1 << event);
|
||||||
_GSocket_Uninstall_Callback(this, event);
|
EventLoop_Uninstall_Callback(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _GSocket_Input_Timeout:
|
/* _GSocket_Input_Timeout:
|
||||||
@ -1392,7 +1422,7 @@ void GSocketBSD::Detected_Write()
|
|||||||
/* Compatibility functions for GSocket */
|
/* Compatibility functions for GSocket */
|
||||||
GSocket *GSocket_new(void)
|
GSocket *GSocket_new(void)
|
||||||
{
|
{
|
||||||
GSocket *newsocket = new GSocketBSD();
|
GSocket *newsocket = new GSocketBSDGUIShim();
|
||||||
if(newsocket->IsOk())
|
if(newsocket->IsOk())
|
||||||
return newsocket;
|
return newsocket;
|
||||||
delete newsocket;
|
delete newsocket;
|
||||||
@ -1401,6 +1431,12 @@ GSocket *GSocket_new(void)
|
|||||||
|
|
||||||
void GSocket_destroy(GSocket *socket)
|
void GSocket_destroy(GSocket *socket)
|
||||||
{
|
{
|
||||||
|
assert(socket);
|
||||||
|
|
||||||
|
/* Check that the socket is really shutdowned */
|
||||||
|
if (socket->m_fd != INVALID_SOCKET)
|
||||||
|
socket->Shutdown();
|
||||||
|
|
||||||
delete socket;
|
delete socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user