]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/gsockgtk.cpp
1. don't assert if we're passed an empty defaultDir and full path in
[wxWidgets.git] / src / gtk / gsockgtk.cpp
CommitLineData
180f9714
DE
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
9b5f1895 3 * Name: src/gtk/gsockgtk.cpp
180f9714 4 * Purpose: GSocket: GTK part
65571936 5 * Licence: The wxWindows licence
180f9714
DE
6 * CVSID: $Id$
7 * -------------------------------------------------------------------------
8 */
9b5f1895
WS
9// For compilers that support precompilation, includes "wx.h".
10#include "wx/wxprec.h"
180f9714
DE
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
865bb325
VZ
25extern "C" {
26static
180f9714
DE
27void _GSocket_GDK_Input(gpointer data,
28 gint source,
29 GdkInputCondition condition)
30{
31 GSocket *socket = (GSocket *)data;
32
33 if (condition & GDK_INPUT_READ)
0a647691 34 socket->Detected_Read();
180f9714 35 if (condition & GDK_INPUT_WRITE)
0a647691 36 socket->Detected_Write();
180f9714 37}
865bb325 38}
180f9714 39
0a647691
DE
40bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
41{ return true; }
42
43bool GSocketGUIFunctionsTableConcrete::OnInit(void)
180f9714
DE
44{
45 return 1;
46}
47
0a647691 48void GSocketGUIFunctionsTableConcrete::OnExit(void)
180f9714
DE
49{
50}
3d257b8d 51
0a647691 52bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
180f9714
DE
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
0a647691 65void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
180f9714
DE
66{
67 free(socket->m_gui_dependent);
68}
69
0a647691 70void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
180f9714
DE
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
0a647691 96void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
180f9714
DE
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)
05036fe0 113 {
180f9714 114 gdk_input_remove(m_id[c]);
05036fe0
KH
115 m_id[c] = -1;
116 }
180f9714
DE
117}
118
0a647691 119void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
180f9714 120{
0a647691
DE
121 Install_Callback(socket, GSOCK_INPUT);
122 Install_Callback(socket, GSOCK_OUTPUT);
180f9714
DE
123}
124
0a647691 125void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
180f9714 126{
0a647691
DE
127 Uninstall_Callback(socket, GSOCK_INPUT);
128 Uninstall_Callback(socket, GSOCK_OUTPUT);
180f9714
DE
129}
130
131#else /* !wxUSE_SOCKETS */
132
133/* some compilers don't like having empty source files */
134static int wxDummyGsockVar = 0;
135
136#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */