]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/gsockunx.h
fix for non-unicode DMC builds
[wxWidgets.git] / include / wx / unix / gsockunx.h
CommitLineData
dbd300df
GL
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockunx.h
4 * Purpose: GSocket Unix header
5 * CVSID: $Id$
6 * -------------------------------------------------------------------------
7 */
483249fc 8
a324a7bc
GL
9#ifndef __GSOCK_UNX_H
10#define __GSOCK_UNX_H
11
483249fc 12#ifndef __GSOCKET_STANDALONE__
d422d01e 13#include "wx/setup.h"
483249fc 14#endif
d422d01e 15
483249fc 16#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
d422d01e 17
483249fc 18#ifndef __GSOCKET_STANDALONE__
d422d01e 19#include "wx/gsocket.h"
483249fc
GRG
20#else
21#include "gsocket.h"
22#endif
23
5c9eff30
GRG
24#ifndef TRUE
25#define TRUE 1
26#endif
27
28#ifndef FALSE
29#define FALSE 0
30#endif
31
09e6e5ec
DE
32#ifdef wxUSE_GSOCKET_CPLUSPLUS
33class GSocketBSD
34{
35public:
36 GSocketBSD();
444cb1fd 37 virtual ~GSocketBSD();
09e6e5ec
DE
38 bool IsOk() { return m_ok; }
39 void Close();
40 void Shutdown();
41 GSocketError SetLocal(GAddress *address);
42 GSocketError SetPeer(GAddress *address);
43 GAddress *GetLocal();
44 GAddress *GetPeer();
45 GSocketError SetServer();
46 GSocket *WaitConnection();
47 GSocketError Connect(GSocketStream stream);
48 GSocketError SetNonOriented();
49 int Read(char *buffer, int size);
50 int Write(const char *buffer, int size);
51 GSocketEventFlags Select(GSocketEventFlags flags);
52 void SetNonBlocking(int non_block);
53 void SetTimeout(unsigned long millisec);
54 GSocketError GetError();
55 void SetCallback(GSocketEventFlags flags,
56 GSocketCallback callback, char *cdata);
57 void UnsetCallback(GSocketEventFlags flags);
58 /* API compatibility functions */
59 static void _GSocket_Detected_Read(GSocket *socket);
60 static void _GSocket_Detected_Write(GSocket *socket);
61protected:
62 void Enable(GSocketEvent event);
63 void Disable(GSocketEvent event);
64 GSocketError Input_Timeout();
65 GSocketError Output_Timeout();
66 int Recv_Stream(char *buffer, int size);
67 int Recv_Dgram(char *buffer, int size);
68 int Send_Stream(const char *buffer, int size);
69 int Send_Dgram(const char *buffer, int size);
70 void Detected_Read();
71 void Detected_Write();
72 bool m_ok;
444cb1fd
DE
73 virtual void EventLoop_Enable_Events() = 0;
74 virtual void EventLoop_Disable_Events() = 0;
75 virtual void EventLoop_Install_Callback(GSocketEvent event) = 0;
76 virtual void EventLoop_Uninstall_Callback(GSocketEvent event) = 0;
09e6e5ec
DE
77public:
78//DFE: We can't protect these data member until the GUI code is updated
79//protected:
80#else //def wxUSE_GSOCKET_CPLUSPLUS
a324a7bc 81
09e6e5ec
DE
82#ifdef __cplusplus
83extern "C" {
84#endif /* __cplusplus */
a324a7bc 85/* Definition of GSocket */
483249fc
GRG
86struct _GSocket
87{
09e6e5ec 88#endif //def wxUSE_GSOCKET_CPLUSPLUS
a324a7bc 89 int m_fd;
483249fc
GRG
90 GAddress *m_local;
91 GAddress *m_peer;
a324a7bc
GL
92 GSocketError m_error;
93
27a97d02
GRG
94 int m_non_blocking;
95 int m_server;
96 int m_stream;
97 int m_oriented;
98 int m_establishing;
39b91eca 99 unsigned long m_timeout;
a324a7bc 100
39b91eca 101 /* Callbacks */
483249fc 102 GSocketEventFlags m_detected;
98781fa3 103 GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
a324a7bc
GL
104 char *m_data[GSOCK_MAX_EVENT];
105
a324a7bc 106 char *m_gui_dependent;
38bb138f
VS
107
108 /* Function pointers */
109 struct GSocketBaseFunctionsTable *m_functions;
a324a7bc 110};
09e6e5ec
DE
111#ifndef wxUSE_GSOCKET_CPLUSPLUS
112#ifdef __cplusplus
113}
114#endif /* __cplusplus */
1119a830
DE
115#else
116///////////////////////////////////////////////////////////////////////////
117// GSocketBSDGUIShim
118class GSocketBSDGUIShim:public GSocketBSD
119{
120 friend void GSocket_SetGUIFunctions(struct GSocketGUIFunctionsTable *guifunc);
121public:
122 static inline bool GUI_Init();
123 static inline void GUI_Cleanup();
124 static inline bool UseGUI();
125 GSocketBSDGUIShim();
126 virtual ~GSocketBSDGUIShim();
127protected:
128 virtual void EventLoop_Enable_Events();
129 virtual void EventLoop_Disable_Events();
130 virtual void EventLoop_Install_Callback(GSocketEvent event);
131 virtual void EventLoop_Uninstall_Callback(GSocketEvent event);
132private:
133/* Table of GUI-related functions. We must call them indirectly because
134 * of wxBase and GUI separation: */
135
136 static struct GSocketGUIFunctionsTable *ms_gui_functions;
137};
138
09e6e5ec 139#endif //ndef wxUSE_GSOCKET_CPLUSPLUS
a324a7bc 140
09e6e5ec
DE
141#ifdef __cplusplus
142extern "C" {
143#endif /* __cplusplus */
a324a7bc 144/* Definition of GAddress */
483249fc
GRG
145struct _GAddress
146{
a324a7bc
GL
147 struct sockaddr *m_addr;
148 size_t m_len;
149
150 GAddressType m_family;
151 int m_realfamily;
152
153 GSocketError m_error;
154};
09e6e5ec
DE
155#ifdef __cplusplus
156}
157#endif /* __cplusplus */
158
159// Compatibility methods to support old C API (from gsocket.h)
160#ifdef wxUSE_GSOCKET_CPLUSPLUS
161inline void GSocket_Shutdown(GSocket *socket)
162{ socket->Shutdown(); }
163inline GSocketError GSocket_SetLocal(GSocket *socket, GAddress *address)
164{ return socket->SetLocal(address); }
165inline GSocketError GSocket_SetPeer(GSocket *socket, GAddress *address)
166{ return socket->SetPeer(address); }
167inline GAddress *GSocket_GetLocal(GSocket *socket)
168{ return socket->GetLocal(); }
169inline GAddress *GSocket_GetPeer(GSocket *socket)
170{ return socket->GetPeer(); }
171inline GSocketError GSocket_SetServer(GSocket *socket)
172{ return socket->SetServer(); }
173inline GSocket *GSocket_WaitConnection(GSocket *socket)
174{ return socket->WaitConnection(); }
175inline GSocketError GSocket_Connect(GSocket *socket, GSocketStream stream)
176{ return socket->Connect(stream); }
177inline GSocketError GSocket_SetNonOriented(GSocket *socket)
178{ return socket->SetNonOriented(); }
179inline int GSocket_Read(GSocket *socket, char *buffer, int size)
180{ return socket->Read(buffer,size); }
181inline int GSocket_Write(GSocket *socket, const char *buffer, int size)
182{ return socket->Write(buffer,size); }
183inline GSocketEventFlags GSocket_Select(GSocket *socket, GSocketEventFlags flags)
184{ return socket->Select(flags); }
185inline void GSocket_SetNonBlocking(GSocket *socket, int non_block)
186{ socket->SetNonBlocking(non_block); }
187inline void GSocket_SetTimeout(GSocket *socket, unsigned long millisec)
188{ socket->SetTimeout(millisec); }
189inline void GSocket_SetCallback(GSocket *socket, GSocketEventFlags flags,
190 GSocketCallback fallback, char *cdata)
191{ socket->SetCallback(flags,fallback,cdata); }
192inline void GSocket_UnsetCallback(GSocket *socket, GSocketEventFlags flags)
193{ socket->UnsetCallback(flags); }
194
195#endif //def wxUSE_GSOCKET_CPLUSPLUS
196
197#ifdef __cplusplus
198extern "C" {
199#endif /* __cplusplus */
a324a7bc 200
483249fc
GRG
201/* Input / Output */
202
203GSocketError _GSocket_Input_Timeout(GSocket *socket);
204GSocketError _GSocket_Output_Timeout(GSocket *socket);
a324a7bc
GL
205int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size);
206int _GSocket_Recv_Dgram(GSocket *socket, char *buffer, int size);
207int _GSocket_Send_Stream(GSocket *socket, const char *buffer, int size);
208int _GSocket_Send_Dgram(GSocket *socket, const char *buffer, int size);
483249fc
GRG
209
210/* Callbacks */
211
38bb138f
VS
212int _GSocket_GUI_Init(void);
213void _GSocket_GUI_Cleanup(void);
214
215int _GSocket_GUI_Init_Socket(GSocket *socket);
216void _GSocket_GUI_Destroy_Socket(GSocket *socket);
5ff86996 217
483249fc
GRG
218void _GSocket_Enable_Events(GSocket *socket);
219void _GSocket_Disable_Events(GSocket *socket);
220void _GSocket_Install_Callback(GSocket *socket, GSocketEvent event);
221void _GSocket_Uninstall_Callback(GSocket *socket, GSocketEvent event);
222
5ff86996
GRG
223void _GSocket_Enable(GSocket *socket, GSocketEvent event);
224void _GSocket_Disable(GSocket *socket, GSocketEvent event);
09e6e5ec
DE
225
226#ifndef wxUSE_GSOCKET_CPLUSPLUS
5ff86996
GRG
227void _GSocket_Detected_Read(GSocket *socket);
228void _GSocket_Detected_Write(GSocket *socket);
09e6e5ec 229#endif //ndef wxUSE_GSOCKET_CPLUSPLUS
5ff86996 230
483249fc 231/* GAddress */
e00f35bb 232
54e575f9
GL
233GSocketError _GAddress_translate_from(GAddress *address,
234 struct sockaddr *addr, int len);
9bf10d6b
GRG
235GSocketError _GAddress_translate_to (GAddress *address,
236 struct sockaddr **addr, int *len);
54e575f9 237GSocketError _GAddress_Init_INET(GAddress *address);
54e575f9 238GSocketError _GAddress_Init_UNIX(GAddress *address);
a324a7bc 239
9bf10d6b 240
d422d01e
RR
241#ifdef __cplusplus
242}
483249fc 243#endif /* __cplusplus */
d422d01e 244
483249fc 245#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
d422d01e 246
483249fc 247#endif /* __GSOCK_UNX_H */