]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/gsockgtk.c
no more _ftime instead of ftime
[wxWidgets.git] / src / gtk1 / gsockgtk.c
... / ...
CommitLineData
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockgtk.c
4 * Purpose: GSocket: GTK part
5 * CVSID: $Id$
6 * -------------------------------------------------------------------------
7 */
8#include "wx/setup.h"
9
10#if wxUSE_SOCKETS
11
12#include <stdlib.h>
13#include <stdio.h>
14
15#include <gdk/gdk.h>
16#include <glib.h>
17
18#include "wx/gsocket.h"
19#include "wx/unix/gsockunx.h"
20
21
22void _GSocket_GDK_Input(gpointer data,
23 gint source,
24 GdkInputCondition condition)
25{
26 GSocket *socket = (GSocket *)data;
27
28 if (condition & GDK_INPUT_READ)
29 _GSocket_Detected_Read(socket);
30 if (condition & GDK_INPUT_WRITE)
31 _GSocket_Detected_Write(socket);
32}
33
34void _GSocket_GUI_Init(GSocket *socket)
35{
36 gint *m_id;
37
38 socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2);
39 m_id = (gint *)(socket->m_gui_dependent);
40
41 m_id[0] = -1;
42 m_id[1] = -1;
43}
44
45void _GSocket_GUI_Destroy(GSocket *socket)
46{
47 free(socket->m_gui_dependent);
48}
49
50void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event)
51{
52 gint *m_id = (gint *)(socket->m_gui_dependent);
53 int c;
54
55 if (socket->m_fd == -1)
56 return;
57
58 switch (event)
59 {
60 case GSOCK_LOST: /* fall-through */
61 case GSOCK_INPUT: c = 0; break;
62 case GSOCK_OUTPUT: c = 1; break;
63 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
64 default: return;
65 }
66
67 if (m_id[c] != -1)
68 gdk_input_remove(m_id[c]);
69
70 m_id[c] = gdk_input_add(socket->m_fd,
71 (c ? GDK_INPUT_WRITE : GDK_INPUT_READ),
72 _GSocket_GDK_Input,
73 (gpointer)socket);
74}
75
76void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event)
77{
78 gint *m_id = (gint *)(socket->m_gui_dependent);
79 int c;
80
81 switch (event)
82 {
83 case GSOCK_LOST: /* fall-through */
84 case GSOCK_INPUT: c = 0; break;
85 case GSOCK_OUTPUT: c = 1; break;
86 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
87 default: return;
88 }
89
90 if (m_id[c] != -1)
91 gdk_input_remove(m_id[c]);
92
93 m_id[c] = -1;
94}
95
96void _GSocket_Enable_Events(GSocket *socket)
97{
98 _GSocket_Install_Callback(socket, GSOCK_INPUT);
99 _GSocket_Install_Callback(socket, GSOCK_OUTPUT);
100}
101
102void _GSocket_Disable_Events(GSocket *socket)
103{
104 _GSocket_Uninstall_Callback(socket, GSOCK_INPUT);
105 _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT);
106}
107
108#else /* !wxUSE_SOCKETS */
109
110/* some compilers don't like having empty source files */
111static int wxDummyGsockVar = 0;
112
113#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */