1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket: X11 part
5 * Licence: The wxWindows licence
7 * ------------------------------------------------------------------------- */
14 #include "wx/gsocket.h"
15 #include "wx/unix/gsockunx.h"
18 * FIXME: have these in a common header instead of being repeated
19 * in evtloop.cpp and gsockx11.c
22 typedef void (*wxSocketCallback
) (int fd
, void* data
);
25 { wxSocketTableInput
, wxSocketTableOutput
} wxSocketTableType
;
27 extern "C" void wxRegisterSocketCallback(int fd
, wxSocketTableType socketType
, wxSocketCallback cback
, void* data
);
28 extern "C" void wxUnregisterSocketCallback(int fd
, wxSocketTableType socketType
);
31 static void _GSocket_X11_Input(int *fid
, void* data
)
33 GSocket
*socket
= (GSocket
*)data
;
35 socket
->Detected_Read();
38 static void _GSocket_X11_Output(int *fid
, void* data
)
40 GSocket
*socket
= (GSocket
*)data
;
42 socket
->Detected_Write();
45 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
48 bool GSocketGUIFunctionsTableConcrete::OnInit(void)
53 void GSocketGUIFunctionsTableConcrete::OnExit(void)
57 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket
*socket
)
61 socket
->m_gui_dependent
= (char *)malloc(sizeof(int)*2);
62 m_id
= (int *)(socket
->m_gui_dependent
);
70 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket
*socket
)
72 free(socket
->m_gui_dependent
);
75 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket
*socket
, GSocketEvent event
)
77 int *m_id
= (int *)(socket
->m_gui_dependent
);
80 if (socket
->m_fd
== -1)
85 case GSOCK_LOST
: /* fall-through */
86 case GSOCK_INPUT
: c
= 0; break;
87 case GSOCK_OUTPUT
: c
= 1; break;
88 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
94 XtRemoveInput(m_id
[c
]);
99 m_id
[0] = socket
->m_fd
;
101 wxRegisterSocketCallback(socket
->m_fd
, wxSocketTableInput
,
102 (wxSocketCallback
) _GSocket_X11_Input
, (void*) socket
);
106 m_id
[1] = socket
->m_fd
;
108 wxRegisterSocketCallback(socket
->m_fd
, wxSocketTableOutput
,
109 (wxSocketCallback
) _GSocket_X11_Output
, (void*) socket
);
113 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
115 int *m_id
= (int *)(socket
->m_gui_dependent
);
120 case GSOCK_LOST
: /* fall-through */
121 case GSOCK_INPUT
: c
= 0; break;
122 case GSOCK_OUTPUT
: c
= 1; break;
123 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
130 wxUnregisterSocketCallback(m_id
[c
], wxSocketTableInput
);
132 wxUnregisterSocketCallback(m_id
[c
], wxSocketTableOutput
);
138 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket
*socket
)
140 Install_Callback(socket
, GSOCK_INPUT
);
141 Install_Callback(socket
, GSOCK_OUTPUT
);
144 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket
*socket
)
146 Uninstall_Callback(socket
, GSOCK_INPUT
);
147 Uninstall_Callback(socket
, GSOCK_OUTPUT
);
150 #else /* !wxUSE_SOCKETS */
152 /* some compilers don't like having empty source files */
153 static int wxDummyGsockVar
= 0;
155 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */