]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/gsockgtk.cpp
Minor header cleaning.
[wxWidgets.git] / src / gtk1 / gsockgtk.cpp
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: src/gtk1/gsockgtk.cpp
4 * Purpose: GSocket: GTK part
5 * Licence: The wxWindows licence
6 * CVSID: $Id$
7 * -------------------------------------------------------------------------
8 */
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
11
12 #if wxUSE_SOCKETS
13
14 #include <assert.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17
18 #include <gdk/gdk.h>
19 #include <glib.h>
20
21 #include "wx/gsocket.h"
22 #include "wx/unix/gsockunx.h"
23
24
25 extern "C" {
26 static
27 void _GSocket_GDK_Input(gpointer data,
28 gint source,
29 GdkInputCondition condition)
30 {
31 GSocket *socket = (GSocket *)data;
32
33 if (condition & GDK_INPUT_READ)
34 socket->Detected_Read();
35 if (condition & GDK_INPUT_WRITE)
36 socket->Detected_Write();
37 }
38 }
39
40 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
41 { return true; }
42
43 bool GSocketGUIFunctionsTableConcrete::OnInit(void)
44 {
45 return 1;
46 }
47
48 void GSocketGUIFunctionsTableConcrete::OnExit(void)
49 {
50 }
51
52 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
53 {
54 gint *m_id;
55
56 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
57 m_id = (gint *)(socket->m_gui_dependent);
58
59 m_id[0] = -1;
60 m_id[1] = -1;
61
62 return TRUE;
63 }
64
65 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
66 {
67 free(socket->m_gui_dependent);
68 }
69
70 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
71 {
72 gint *m_id = (gint *)(socket->m_gui_dependent);
73 int c;
74
75 if (socket->m_fd == -1)
76 return;
77
78 switch (event)
79 {
80 case GSOCK_LOST: /* fall-through */
81 case GSOCK_INPUT: c = 0; break;
82 case GSOCK_OUTPUT: c = 1; break;
83 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
84 default: return;
85 }
86
87 if (m_id[c] != -1)
88 gdk_input_remove(m_id[c]);
89
90 m_id[c] = gdk_input_add(socket->m_fd,
91 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
92 _GSocket_GDK_Input,
93 (gpointer)socket);
94 }
95
96 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
97 {
98 gint *m_id = (gint *)(socket->m_gui_dependent);
99 int c;
100
101 assert( m_id != NULL );
102
103 switch (event)
104 {
105 case GSOCK_LOST: /* fall-through */
106 case GSOCK_INPUT: c = 0; break;
107 case GSOCK_OUTPUT: c = 1; break;
108 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
109 default: return;
110 }
111
112 if (m_id[c] != -1)
113 {
114 gdk_input_remove(m_id[c]);
115 m_id[c] = -1;
116 }
117 }
118
119 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
120 {
121 Install_Callback(socket, GSOCK_INPUT);
122 Install_Callback(socket, GSOCK_OUTPUT);
123 }
124
125 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
126 {
127 Uninstall_Callback(socket, GSOCK_INPUT);
128 Uninstall_Callback(socket, GSOCK_OUTPUT);
129 }
130
131 #else /* !wxUSE_SOCKETS */
132
133 /* some compilers don't like having empty source files */
134 static int wxDummyGsockVar = 0;
135
136 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */