]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/gsockgtk.cpp
The mmedia contrib requires sys/soundcard.h on unix, so disable it on unix
[wxWidgets.git] / src / gtk1 / gsockgtk.cpp
CommitLineData
180f9714
DE
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockgtk.c
4 * Purpose: GSocket: GTK part
65571936 5 * Licence: The wxWindows licence
180f9714
DE
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
865bb325
VZ
24extern "C" {
25static
180f9714
DE
26void _GSocket_GDK_Input(gpointer data,
27 gint source,
28 GdkInputCondition condition)
29{
30 GSocket *socket = (GSocket *)data;
31
32 if (condition & GDK_INPUT_READ)
0a647691 33 socket->Detected_Read();
180f9714 34 if (condition & GDK_INPUT_WRITE)
0a647691 35 socket->Detected_Write();
180f9714 36}
865bb325 37}
180f9714 38
0a647691
DE
39bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
40{ return true; }
41
42bool GSocketGUIFunctionsTableConcrete::OnInit(void)
180f9714
DE
43{
44 return 1;
45}
46
0a647691 47void GSocketGUIFunctionsTableConcrete::OnExit(void)
180f9714
DE
48{
49}
50
0a647691 51bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
180f9714
DE
52{
53 gint *m_id;
54
55 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
56 m_id = (gint *)(socket->m_gui_dependent);
57
58 m_id[0] = -1;
59 m_id[1] = -1;
60
61 return TRUE;
62}
63
0a647691 64void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
180f9714
DE
65{
66 free(socket->m_gui_dependent);
67}
68
0a647691 69void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
180f9714
DE
70{
71 gint *m_id = (gint *)(socket->m_gui_dependent);
72 int c;
73
74 if (socket->m_fd == -1)
75 return;
76
77 switch (event)
78 {
79 case GSOCK_LOST: /* fall-through */
80 case GSOCK_INPUT: c = 0; break;
81 case GSOCK_OUTPUT: c = 1; break;
82 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
83 default: return;
84 }
85
86 if (m_id[c] != -1)
87 gdk_input_remove(m_id[c]);
88
89 m_id[c] = gdk_input_add(socket->m_fd,
90 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
91 _GSocket_GDK_Input,
92 (gpointer)socket);
93}
94
0a647691 95void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
180f9714
DE
96{
97 gint *m_id = (gint *)(socket->m_gui_dependent);
98 int c;
99
100 assert( m_id != NULL );
101
102 switch (event)
103 {
104 case GSOCK_LOST: /* fall-through */
105 case GSOCK_INPUT: c = 0; break;
106 case GSOCK_OUTPUT: c = 1; break;
107 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
108 default: return;
109 }
110
111 if (m_id[c] != -1)
112 gdk_input_remove(m_id[c]);
113
114 m_id[c] = -1;
115}
116
0a647691 117void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
180f9714 118{
0a647691
DE
119 Install_Callback(socket, GSOCK_INPUT);
120 Install_Callback(socket, GSOCK_OUTPUT);
180f9714
DE
121}
122
0a647691 123void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
180f9714 124{
0a647691
DE
125 Uninstall_Callback(socket, GSOCK_INPUT);
126 Uninstall_Callback(socket, GSOCK_OUTPUT);
180f9714
DE
127}
128
129#else /* !wxUSE_SOCKETS */
130
131/* some compilers don't like having empty source files */
132static int wxDummyGsockVar = 0;
133
134#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */