]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | void _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 | ||
34 | void _GSocket_GUI_Init(GSocket *socket) | |
35 | { | |
36 | int i; | |
37 | gint *m_id; | |
38 | ||
39 | socket->m_gui_dependent = (char *)malloc(sizeof(gint)*2); | |
40 | m_id = (gint *)(socket->m_gui_dependent); | |
41 | ||
42 | m_id[0] = -1; | |
43 | m_id[1] = -1; | |
44 | } | |
45 | ||
46 | void _GSocket_GUI_Destroy(GSocket *socket) | |
47 | { | |
48 | free(socket->m_gui_dependent); | |
49 | } | |
50 | ||
51 | void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event) | |
52 | { | |
53 | gint *m_id = (gint *)(socket->m_gui_dependent); | |
54 | int c; | |
55 | ||
56 | if (socket->m_fd == -1) | |
57 | return; | |
58 | ||
59 | switch (event) | |
60 | { | |
61 | case GSOCK_LOST: /* fall-through */ | |
62 | case GSOCK_INPUT: c = 0; break; | |
63 | case GSOCK_OUTPUT: c = 1; break; | |
64 | case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break; | |
65 | default: return; | |
66 | } | |
67 | ||
68 | if (m_id[c] != -1) | |
69 | gdk_input_remove(m_id[c]); | |
70 | ||
71 | m_id[c] = gdk_input_add(socket->m_fd, | |
72 | (c ? GDK_INPUT_WRITE : GDK_INPUT_READ), | |
73 | _GSocket_GDK_Input, | |
74 | (gpointer)socket); | |
75 | } | |
76 | ||
77 | void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event) | |
78 | { | |
79 | gint *m_id = (gint *)(socket->m_gui_dependent); | |
80 | int c; | |
81 | ||
82 | switch (event) | |
83 | { | |
84 | case GSOCK_LOST: /* fall-through */ | |
85 | case GSOCK_INPUT: c = 0; break; | |
86 | case GSOCK_OUTPUT: c = 1; break; | |
87 | case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break; | |
88 | default: return; | |
89 | } | |
90 | ||
91 | if (m_id[c] != -1) | |
92 | gdk_input_remove(m_id[c]); | |
93 | ||
94 | m_id[c] = -1; | |
95 | } | |
96 | ||
97 | void _GSocket_Enable_Events(GSocket *socket) | |
98 | { | |
99 | _GSocket_Install_Callback(socket, GSOCK_INPUT); | |
100 | _GSocket_Install_Callback(socket, GSOCK_OUTPUT); | |
101 | } | |
102 | ||
103 | void _GSocket_Disable_Events(GSocket *socket) | |
104 | { | |
105 | _GSocket_Uninstall_Callback(socket, GSOCK_INPUT); | |
106 | _GSocket_Uninstall_Callback(socket, GSOCK_OUTPUT); | |
107 | } | |
108 | ||
109 | #endif /* wxUSE_SOCKETS */ |