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