]>
Commit | Line | Data |
---|---|---|
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 | |
22 | void _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 | ||
34 | void _GSocket_GUI_Init(GSocket *socket) | |
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; | |
a324a7bc GL |
43 | } |
44 | ||
45 | void _GSocket_GUI_Destroy(GSocket *socket) | |
46 | { | |
a324a7bc GL |
47 | free(socket->m_gui_dependent); |
48 | } | |
49 | ||
39b91eca | 50 | void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event) |
a324a7bc | 51 | { |
483249fc | 52 | gint *m_id = (gint *)(socket->m_gui_dependent); |
a324a7bc | 53 | int c; |
a324a7bc | 54 | |
483249fc GRG |
55 | if (socket->m_fd == -1) |
56 | return; | |
a324a7bc | 57 | |
483249fc GRG |
58 | switch (event) |
59 | { | |
60 | case GSOCK_LOST: /* fall-through */ | |
06b466c7 | 61 | case GSOCK_INPUT: c = 0; break; |
483249fc GRG |
62 | case GSOCK_OUTPUT: c = 1; break; |
63 | case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break; | |
64 | default: return; | |
a324a7bc GL |
65 | } |
66 | ||
67 | if (m_id[c] != -1) | |
68 | gdk_input_remove(m_id[c]); | |
69 | ||
483249fc GRG |
70 | m_id[c] = gdk_input_add(socket->m_fd, |
71 | (c ? GDK_INPUT_WRITE : GDK_INPUT_READ), | |
72 | _GSocket_GDK_Input, | |
73 | (gpointer)socket); | |
a324a7bc GL |
74 | } |
75 | ||
39b91eca | 76 | void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event) |
a324a7bc | 77 | { |
483249fc | 78 | gint *m_id = (gint *)(socket->m_gui_dependent); |
a324a7bc | 79 | int c; |
a324a7bc | 80 | |
483249fc GRG |
81 | switch (event) |
82 | { | |
83 | case GSOCK_LOST: /* fall-through */ | |
06b466c7 | 84 | case GSOCK_INPUT: c = 0; break; |
483249fc GRG |
85 | case GSOCK_OUTPUT: c = 1; break; |
86 | case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break; | |
87 | default: return; | |
a324a7bc GL |
88 | } |
89 | ||
90 | if (m_id[c] != -1) | |
91 | gdk_input_remove(m_id[c]); | |
92 | ||
93 | m_id[c] = -1; | |
94 | } | |
95 | ||
483249fc | 96 | void _GSocket_Enable_Events(GSocket *socket) |
a324a7bc | 97 | { |
483249fc GRG |
98 | _GSocket_Install_Callback(socket, GSOCK_INPUT); |
99 | _GSocket_Install_Callback(socket, GSOCK_OUTPUT); | |
a324a7bc GL |
100 | } |
101 | ||
483249fc | 102 | void _GSocket_Disable_Events(GSocket *socket) |
a324a7bc | 103 | { |
483249fc GRG |
104 | _GSocket_Uninstall_Callback(socket, GSOCK_INPUT); |
105 | _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT); | |
a324a7bc | 106 | } |
3646fd68 | 107 | |
06b466c7 VZ |
108 | #else /* !wxUSE_SOCKETS */ |
109 | ||
110 | /* some compilers don't like having empty source files */ | |
111 | static int wxDummyGsockVar = 0; | |
112 | ||
113 | #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */ |