1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket: X11 part
5 * Licence: The wxWidgets licence
7 * ------------------------------------------------------------------------- */
14 #include "wx/gsocket.h"
15 #include "wx/unix/gsockunx.h"
18 * FIXME: have these in a common header instead of being repeated
19 * in evtloop.cpp and gsockx11.c
22 typedef void (*wxSocketCallback
) (int fd
, void* data
);
25 { wxSocketTableInput
, wxSocketTableOutput
} wxSocketTableType
;
27 void wxRegisterSocketCallback(int fd
, wxSocketTableType socketType
, wxSocketCallback cback
, void* data
);
28 void wxUnregisterSocketCallback(int fd
, wxSocketTableType socketType
);
31 static void _GSocket_X11_Input(int *fid
, void* data
)
33 GSocket
*socket
= (GSocket
*)data
;
35 socket
->m_functions
->Detected_Read(socket
);
38 static void _GSocket_X11_Output(int *fid
, void* data
)
40 GSocket
*socket
= (GSocket
*)data
;
42 socket
->m_functions
->Detected_Write(socket
);
45 int _GSocket_GUI_Init(void)
50 void _GSocket_GUI_Cleanup(void)
54 int _GSocket_GUI_Init_Socket(GSocket
*socket
)
58 socket
->m_gui_dependent
= (char *)malloc(sizeof(int)*2);
59 m_id
= (int *)(socket
->m_gui_dependent
);
67 void _GSocket_GUI_Destroy_Socket(GSocket
*socket
)
69 free(socket
->m_gui_dependent
);
72 void _GSocket_Install_Callback(GSocket
*socket
, GSocketEvent event
)
74 int *m_id
= (int *)(socket
->m_gui_dependent
);
77 if (socket
->m_fd
== -1)
82 case GSOCK_LOST
: /* fall-through */
83 case GSOCK_INPUT
: c
= 0; break;
84 case GSOCK_OUTPUT
: c
= 1; break;
85 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
91 XtRemoveInput(m_id
[c
]);
96 m_id
[0] = socket
->m_fd
;
98 wxRegisterSocketCallback(socket
->m_fd
, wxSocketTableInput
,
99 (wxSocketCallback
) _GSocket_X11_Input
, (void*) socket
);
103 m_id
[1] = socket
->m_fd
;
105 wxRegisterSocketCallback(socket
->m_fd
, wxSocketTableOutput
,
106 (wxSocketCallback
) _GSocket_X11_Output
, (void*) socket
);
110 void _GSocket_Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
112 int *m_id
= (int *)(socket
->m_gui_dependent
);
117 case GSOCK_LOST
: /* fall-through */
118 case GSOCK_INPUT
: c
= 0; break;
119 case GSOCK_OUTPUT
: c
= 1; break;
120 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
127 wxUnregisterSocketCallback(m_id
[c
], wxSocketTableInput
);
129 wxUnregisterSocketCallback(m_id
[c
], wxSocketTableOutput
);
135 void _GSocket_Enable_Events(GSocket
*socket
)
137 _GSocket_Install_Callback(socket
, GSOCK_INPUT
);
138 _GSocket_Install_Callback(socket
, GSOCK_OUTPUT
);
141 void _GSocket_Disable_Events(GSocket
*socket
)
143 _GSocket_Uninstall_Callback(socket
, GSOCK_INPUT
);
144 _GSocket_Uninstall_Callback(socket
, GSOCK_OUTPUT
);
147 #else /* !wxUSE_SOCKETS */
149 /* some compilers don't like having empty source files */
150 static int wxDummyGsockVar
= 0;
152 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */