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