]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/gsockgtk.c
fixed MSLU check
[wxWidgets.git] / src / gtk / gsockgtk.c
CommitLineData
dbd300df
GL
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockgtk.c
4 * Purpose: GSocket: GTK part
5 * CVSID: $Id$
6 * -------------------------------------------------------------------------
7 */
3646fd68
VZ
8#include "wx/setup.h"
9
10#if wxUSE_SOCKETS
11
a324a7bc 12#include <stdlib.h>
483249fc 13#include <stdio.h>
16c1f79c
RR
14
15#include <gdk/gdk.h>
16#include <glib.h>
17
d422d01e 18#include "wx/gsocket.h"
1a9469d7 19#include "wx/unix/gsockunx.h"
a324a7bc 20
483249fc
GRG
21
22void _GSocket_GDK_Input(gpointer data,
23 gint source,
24 GdkInputCondition condition)
a324a7bc
GL
25{
26 GSocket *socket = (GSocket *)data;
27
aa8fb7a0 28 if (condition & GDK_INPUT_READ)
a324a7bc 29 _GSocket_Detected_Read(socket);
aa8fb7a0 30 if (condition & GDK_INPUT_WRITE)
a324a7bc 31 _GSocket_Detected_Write(socket);
a324a7bc
GL
32}
33
27a97d02 34int _GSocket_GUI_Init(GSocket *socket)
a324a7bc 35{
a324a7bc
GL
36 gint *m_id;
37
483249fc 38 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
a324a7bc
GL
39 m_id = (gint *)(socket->m_gui_dependent);
40
483249fc
GRG
41 m_id[0] = -1;
42 m_id[1] = -1;
5ff86996
GRG
43
44 return TRUE;
a324a7bc
GL
45}
46
47void _GSocket_GUI_Destroy(GSocket *socket)
48{
a324a7bc
GL
49 free(socket->m_gui_dependent);
50}
51
39b91eca 52void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 53{
483249fc 54 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 55 int c;
a324a7bc 56
483249fc
GRG
57 if (socket->m_fd == -1)
58 return;
a324a7bc 59
483249fc
GRG
60 switch (event)
61 {
62 case GSOCK_LOST: /* fall-through */
06b466c7 63 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
64 case GSOCK_OUTPUT: c = 1; break;
65 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
66 default: return;
a324a7bc
GL
67 }
68
69 if (m_id[c] != -1)
70 gdk_input_remove(m_id[c]);
71
483249fc
GRG
72 m_id[c] = gdk_input_add(socket->m_fd,
73 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
74 _GSocket_GDK_Input,
75 (gpointer)socket);
a324a7bc
GL
76}
77
39b91eca 78void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
a324a7bc 79{
483249fc 80 gint *m_id = (gint *)(socket->m_gui_dependent);
a324a7bc 81 int c;
a324a7bc 82
483249fc
GRG
83 switch (event)
84 {
85 case GSOCK_LOST: /* fall-through */
06b466c7 86 case GSOCK_INPUT: c = 0; break;
483249fc
GRG
87 case GSOCK_OUTPUT: c = 1; break;
88 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
89 default: return;
a324a7bc
GL
90 }
91
92 if (m_id[c] != -1)
93 gdk_input_remove(m_id[c]);
94
95 m_id[c] = -1;
96}
97
483249fc 98void _GSocket_Enable_Events(GSocket *socket)
a324a7bc 99{
483249fc
GRG
100 _GSocket_Install_Callback(socket, GSOCK_INPUT);
101 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
a324a7bc
GL
102}
103
483249fc 104void _GSocket_Disable_Events(GSocket *socket)
a324a7bc 105{
483249fc
GRG
106 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
107 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
a324a7bc 108}
3646fd68 109
06b466c7
VZ
110#else /* !wxUSE_SOCKETS */
111
112/* some compilers don't like having empty source files */
113static int wxDummyGsockVar = 0;
114
115#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */