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