]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/gsockgtk.cpp
Link against import libraries of DLLs when building DLLs.
[wxWidgets.git] / src / gtk / gsockgtk.cpp
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
24 void _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 socket->m_functions->Detected_Read(socket);
32 if (condition & GDK_INPUT_WRITE)
33 socket->m_functions->Detected_Write(socket);
34 }
35
36 int _GSocket_GUI_Init(void)
37 {
38 return 1;
39 }
40
41 void _GSocket_GUI_Cleanup(void)
42 {
43 }
44
45 int _GSocket_GUI_Init_Socket(GSocket *socket)
46 {
47 gint *m_id;
48
49 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
50 m_id = (gint *)(socket->m_gui_dependent);
51
52 m_id[0] = -1;
53 m_id[1] = -1;
54
55 return TRUE;
56 }
57
58 void _GSocket_GUI_Destroy_Socket(GSocket *socket)
59 {
60 free(socket->m_gui_dependent);
61 }
62
63 void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
64 {
65 gint *m_id = (gint *)(socket->m_gui_dependent);
66 int c;
67
68 if (socket->m_fd == -1)
69 return;
70
71 switch (event)
72 {
73 case GSOCK_LOST: /* fall-through */
74 case GSOCK_INPUT: c = 0; break;
75 case GSOCK_OUTPUT: c = 1; break;
76 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
77 default: return;
78 }
79
80 if (m_id[c] != -1)
81 gdk_input_remove(m_id[c]);
82
83 m_id[c] = gdk_input_add(socket->m_fd,
84 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
85 _GSocket_GDK_Input,
86 (gpointer)socket);
87 }
88
89 void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
90 {
91 gint *m_id = (gint *)(socket->m_gui_dependent);
92 int c;
93
94 assert( m_id != NULL );
95
96 switch (event)
97 {
98 case GSOCK_LOST: /* fall-through */
99 case GSOCK_INPUT: c = 0; break;
100 case GSOCK_OUTPUT: c = 1; break;
101 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
102 default: return;
103 }
104
105 if (m_id[c] != -1)
106 gdk_input_remove(m_id[c]);
107
108 m_id[c] = -1;
109 }
110
111 void _GSocket_Enable_Events(GSocket *socket)
112 {
113 _GSocket_Install_Callback(socket, GSOCK_INPUT);
114 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
115 }
116
117 void _GSocket_Disable_Events(GSocket *socket)
118 {
119 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
120 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
121 }
122
123 #else /* !wxUSE_SOCKETS */
124
125 /* some compilers don't like having empty source files */
126 static int wxDummyGsockVar = 0;
127
128 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */