1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket: X11 part
6 * ------------------------------------------------------------------------- */
13 #include "wx/gsocket.h"
14 #include "wx/unix/gsockunx.h"
17 * FIXME: have these in a common header instead of being repeated
18 * in evtloop.cpp and gsockx11.c
21 typedef void (*wxSocketCallback
) (int fd
, void* data
);
24 { wxSocketTableInput
, wxSocketTableOutput
} wxSocketTableType
;
26 void wxRegisterSocketCallback(int fd
, wxSocketTableType socketType
, wxSocketCallback cback
, void* data
);
27 void wxUnregisterSocketCallback(int fd
, wxSocketTableType socketType
);
30 static void _GSocket_X11_Input(int *fid
, void* data
)
32 GSocket
*socket
= (GSocket
*)data
;
34 _GSocket_Detected_Read(socket
);
37 static void _GSocket_X11_Output(int *fid
, void* data
)
39 GSocket
*socket
= (GSocket
*)data
;
41 _GSocket_Detected_Write(socket
);
44 int _GSocket_GUI_Init(GSocket
*socket
)
48 socket
->m_gui_dependent
= (char *)malloc(sizeof(int)*2);
49 m_id
= (int *)(socket
->m_gui_dependent
);
57 void _GSocket_GUI_Destroy(GSocket
*socket
)
59 free(socket
->m_gui_dependent
);
62 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
)
64 int *m_id
= (int *)(socket
->m_gui_dependent
);
67 if (socket
->m_fd
== -1)
72 case GSOCK_LOST
: /* fall-through */
73 case GSOCK_INPUT
: c
= 0; break;
74 case GSOCK_OUTPUT
: c
= 1; break;
75 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
81 XtRemoveInput(m_id
[c
]);
86 m_id
[0] = socket
->m_fd
;
88 wxRegisterSocketCallback(socket
->m_fd
, wxSocketTableInput
,
89 (wxSocketCallback
) _GSocket_X11_Input
, (void*) socket
);
93 m_id
[1] = socket
->m_fd
;
95 wxRegisterSocketCallback(socket
->m_fd
, wxSocketTableOutput
,
96 (wxSocketCallback
) _GSocket_X11_Output
, (void*) socket
);
100 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
102 int *m_id
= (int *)(socket
->m_gui_dependent
);
107 case GSOCK_LOST
: /* fall-through */
108 case GSOCK_INPUT
: c
= 0; break;
109 case GSOCK_OUTPUT
: c
= 1; break;
110 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
117 wxUnregisterSocketCallback(m_id
[c
], wxSocketTableInput
);
119 wxUnregisterSocketCallback(m_id
[c
], wxSocketTableOutput
);
125 void _GSocket_Enable_Events(GSocket
*socket
)
127 _GSocket_Install_Callback(socket
, GSOCK_INPUT
);
128 _GSocket_Install_Callback(socket
, GSOCK_OUTPUT
);
131 void _GSocket_Disable_Events(GSocket
*socket
)
133 _GSocket_Uninstall_Callback(socket
, GSOCK_INPUT
);
134 _GSocket_Uninstall_Callback(socket
, GSOCK_OUTPUT
);
137 #else /* !wxUSE_SOCKETS */
139 /* some compilers don't like having empty source files */
140 static int wxDummyGsockVar
= 0;
142 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */