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