1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: src/x11/gsockx11.cpp
4 * Purpose: GSocket: X11 part
5 * Licence: The wxWindows licence
7 * ------------------------------------------------------------------------- */
9 // for compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
12 #if defined(__BORLANDC__)
19 #include "wx/gsocket.h"
20 #include "wx/unix/gsockunx.h"
23 * FIXME: have these in a common header instead of being repeated
24 * in evtloop.cpp and gsockx11.c
27 typedef void (*wxSocketCallback
) (int fd
, void* data
);
30 { wxSocketTableInput
, wxSocketTableOutput
} wxSocketTableType
;
32 extern "C" void wxRegisterSocketCallback(int fd
, wxSocketTableType socketType
, wxSocketCallback cback
, void* data
);
33 extern "C" void wxUnregisterSocketCallback(int fd
, wxSocketTableType socketType
);
36 static void _GSocket_X11_Input(int *fid
, void* data
)
38 GSocket
*socket
= (GSocket
*)data
;
40 socket
->Detected_Read();
43 static void _GSocket_X11_Output(int *fid
, void* data
)
45 GSocket
*socket
= (GSocket
*)data
;
47 socket
->Detected_Write();
50 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
53 bool GSocketGUIFunctionsTableConcrete::OnInit(void)
58 void GSocketGUIFunctionsTableConcrete::OnExit(void)
62 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket
*socket
)
66 socket
->m_gui_dependent
= (char *)malloc(sizeof(int)*2);
67 m_id
= (int *)(socket
->m_gui_dependent
);
75 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket
*socket
)
77 free(socket
->m_gui_dependent
);
80 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket
*socket
, GSocketEvent event
)
82 int *m_id
= (int *)(socket
->m_gui_dependent
);
85 if (socket
->m_fd
== -1)
90 case GSOCK_LOST
: /* fall-through */
91 case GSOCK_INPUT
: c
= 0; break;
92 case GSOCK_OUTPUT
: c
= 1; break;
93 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
99 XtRemoveInput(m_id
[c
]);
104 m_id
[0] = socket
->m_fd
;
106 wxRegisterSocketCallback(socket
->m_fd
, wxSocketTableInput
,
107 (wxSocketCallback
) _GSocket_X11_Input
, (void*) socket
);
111 m_id
[1] = socket
->m_fd
;
113 wxRegisterSocketCallback(socket
->m_fd
, wxSocketTableOutput
,
114 (wxSocketCallback
) _GSocket_X11_Output
, (void*) socket
);
118 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
120 int *m_id
= (int *)(socket
->m_gui_dependent
);
125 case GSOCK_LOST
: /* fall-through */
126 case GSOCK_INPUT
: c
= 0; break;
127 case GSOCK_OUTPUT
: c
= 1; break;
128 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
135 wxUnregisterSocketCallback(m_id
[c
], wxSocketTableInput
);
137 wxUnregisterSocketCallback(m_id
[c
], wxSocketTableOutput
);
143 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket
*socket
)
145 Install_Callback(socket
, GSOCK_INPUT
);
146 Install_Callback(socket
, GSOCK_OUTPUT
);
149 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket
*socket
)
151 Uninstall_Callback(socket
, GSOCK_INPUT
);
152 Uninstall_Callback(socket
, GSOCK_OUTPUT
);
155 #else /* !wxUSE_SOCKETS */
157 /* some compilers don't like having empty source files */
158 static int wxDummyGsockVar
= 0;
160 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */