]> git.saurik.com Git - wxWidgets.git/blame - src/motif/gsockmot.cpp
fixed warnings about truncating 64 bit integers
[wxWidgets.git] / src / motif / gsockmot.cpp
CommitLineData
793ba541
DE
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockmot.c
4 * Purpose: GSocket: Motif part
5 * CVSID: $Id$
65571936 6 * Licence: The wxWindows licence
793ba541
DE
7 * ------------------------------------------------------------------------- */
8
9#include "wx/setup.h"
10
11#if wxUSE_SOCKETS
12
13#include <stdlib.h>
14#include <X11/Intrinsic.h>
15#include "wx/gsocket.h"
16#include "wx/unix/gsockunx.h"
17
0a647691 18extern "C" XtAppContext wxGetAppContext();
793ba541
DE
19
20static void _GSocket_Motif_Input(XtPointer data, int *fid,
21 XtInputId *id)
22{
23 GSocket *socket = (GSocket *)data;
24
0a647691 25 socket->Detected_Read();
793ba541
DE
26}
27
28static void _GSocket_Motif_Output(XtPointer data, int *fid,
29 XtInputId *id)
30{
31 GSocket *socket = (GSocket *)data;
32
0a647691 33 socket->Detected_Write();
793ba541
DE
34}
35
0a647691
DE
36bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
37{ return true; }
38
39bool GSocketGUIFunctionsTableConcrete::OnInit(void)
793ba541
DE
40{
41 return 1;
42}
43
0a647691 44void GSocketGUIFunctionsTableConcrete::OnExit(void)
793ba541
DE
45{
46}
47
0a647691 48bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
793ba541
DE
49{
50 int *m_id;
51
52 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
53 m_id = (int *)(socket->m_gui_dependent);
54
55 m_id[0] = -1;
56 m_id[1] = -1;
57
948c96ef 58 return true;
793ba541
DE
59}
60
0a647691 61void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
793ba541
DE
62{
63 free(socket->m_gui_dependent);
64}
65
0a647691 66void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
793ba541
DE
67{
68 int *m_id = (int *)(socket->m_gui_dependent);
69 int c;
70
71 if (socket->m_fd == -1)
72 return;
73
74 switch (event)
75 {
76 case GSOCK_LOST: /* fall-through */
77 case GSOCK_INPUT: c = 0; break;
78 case GSOCK_OUTPUT: c = 1; break;
79 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
80 default: return;
81 }
82
83 if (m_id[c] != -1)
84 XtRemoveInput(m_id[c]);
85
86 if (c == 0)
87 {
88 m_id[0] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
89 (XtPointer *)XtInputReadMask,
90 (XtInputCallbackProc) _GSocket_Motif_Input,
91 (XtPointer) socket);
92 }
93 else
94 {
95 m_id[1] = XtAppAddInput(wxGetAppContext(), socket->m_fd,
96 (XtPointer *)XtInputWriteMask,
97 (XtInputCallbackProc) _GSocket_Motif_Output,
98 (XtPointer) socket);
99 }
100}
101
0a647691 102void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
793ba541
DE
103{
104 int *m_id = (int *)(socket->m_gui_dependent);
105 int c;
106
107 switch (event)
108 {
109 case GSOCK_LOST: /* fall-through */
110 case GSOCK_INPUT: c = 0; break;
111 case GSOCK_OUTPUT: c = 1; break;
112 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
113 default: return;
114 }
115
116 if (m_id[c] != -1)
117 XtRemoveInput(m_id[c]);
118
119 m_id[c] = -1;
120}
121
0a647691 122void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
793ba541 123{
0a647691
DE
124 Install_Callback(socket, GSOCK_INPUT);
125 Install_Callback(socket, GSOCK_OUTPUT);
793ba541
DE
126}
127
0a647691 128void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
793ba541 129{
0a647691
DE
130 Uninstall_Callback(socket, GSOCK_INPUT);
131 Uninstall_Callback(socket, GSOCK_OUTPUT);
793ba541
DE
132}
133
134#else /* !wxUSE_SOCKETS */
135
136/* some compilers don't like having empty source files */
137static int wxDummyGsockVar = 0;
138
139#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */