]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/unix/gsockunx.h
wxStaticBitmapBase::DoGetBestSize
[wxWidgets.git] / include / wx / unix / gsockunx.h
... / ...
CommitLineData
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockunx.h
4 * Purpose: GSocket Unix header
5 * CVSID: $Id$
6 * -------------------------------------------------------------------------
7 */
8
9#ifndef __GSOCK_UNX_H
10#define __GSOCK_UNX_H
11
12#ifndef __GSOCKET_STANDALONE__
13#include "wx/setup.h"
14#endif
15
16#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
17
18#ifndef __GSOCKET_STANDALONE__
19#include "wx/gsocket.h"
20#else
21#include "gsocket.h"
22#endif
23
24#ifndef TRUE
25#define TRUE 1
26#endif
27
28#ifndef FALSE
29#define FALSE 0
30#endif
31
32#ifdef wxUSE_GSOCKET_CPLUSPLUS
33class GSocketBSD
34{
35public:
36 GSocketBSD();
37 virtual ~GSocketBSD();
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;
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;
77public:
78 /* DFE: We can't protect these data member until the GUI code is updated */
79 /* protected: */
80#else /* def wxUSE_GSOCKET_CPLUSPLUS */
81
82#ifdef __cplusplus
83extern "C" {
84#endif /* __cplusplus */
85/* Definition of GSocket */
86struct _GSocket
87{
88#endif /* def wxUSE_GSOCKET_CPLUSPLUS */
89 int m_fd;
90 GAddress *m_local;
91 GAddress *m_peer;
92 GSocketError m_error;
93
94 int m_non_blocking;
95 int m_server;
96 int m_stream;
97 int m_oriented;
98 int m_establishing;
99 unsigned long m_timeout;
100
101 /* Callbacks */
102 GSocketEventFlags m_detected;
103 GSocketCallback m_cbacks[GSOCK_MAX_EVENT];
104 char *m_data[GSOCK_MAX_EVENT];
105
106 char *m_gui_dependent;
107
108 /* Function pointers */
109 struct GSocketBaseFunctionsTable *m_functions;
110};
111#ifndef wxUSE_GSOCKET_CPLUSPLUS
112#ifdef __cplusplus
113}
114#endif /* __cplusplus */
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
139#endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
140
141#ifdef __cplusplus
142extern "C" {
143#endif /* __cplusplus */
144/* Definition of GAddress */
145struct _GAddress
146{
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};
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 */
200
201/* Input / Output */
202
203GSocketError _GSocket_Input_Timeout(GSocket *socket);
204GSocketError _GSocket_Output_Timeout(GSocket *socket);
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);
209
210/* Callbacks */
211
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);
217
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
223void _GSocket_Enable(GSocket *socket, GSocketEvent event);
224void _GSocket_Disable(GSocket *socket, GSocketEvent event);
225
226#ifndef wxUSE_GSOCKET_CPLUSPLUS
227void _GSocket_Detected_Read(GSocket *socket);
228void _GSocket_Detected_Write(GSocket *socket);
229#endif /* ndef wxUSE_GSOCKET_CPLUSPLUS */
230
231/* GAddress */
232
233GSocketError _GAddress_translate_from(GAddress *address,
234 struct sockaddr *addr, int len);
235GSocketError _GAddress_translate_to (GAddress *address,
236 struct sockaddr **addr, int *len);
237GSocketError _GAddress_Init_INET(GAddress *address);
238GSocketError _GAddress_Init_UNIX(GAddress *address);
239
240
241#ifdef __cplusplus
242}
243#endif /* __cplusplus */
244
245#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
246
247#endif /* __GSOCK_UNX_H */