]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/gsocket.h
New API for wxdataViewCtrl (doesn't run yet).
[wxWidgets.git] / include / wx / gsocket.h
... / ...
CommitLineData
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket)
3 * Name: gsocket.h
4 * Author: Guilhem Lavaux
5 * Guillermo Rodriguez Garcia <guille@iies.es> (maintainer)
6 * Copyright: (c) Guilhem Lavaux
7 * Licence: wxWindows Licence
8 * Purpose: GSocket include file (system independent)
9 * CVSID: $Id$
10 * -------------------------------------------------------------------------
11 */
12
13#ifndef __GSOCKET_H
14#define __GSOCKET_H
15
16#ifndef __GSOCKET_STANDALONE__
17#include "wx/defs.h"
18
19#include "wx/dlimpexp.h" /* for WXDLLIMPEXP_NET */
20
21#endif
22
23#if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__)
24
25#include <stddef.h>
26
27/*
28 Including sys/types.h under cygwin results in the warnings about "fd_set
29 having been defined in sys/types.h" when winsock.h is included later and
30 doesn't seem to be necessary anyhow. It's not needed under Mac neither.
31 */
32#if !defined(__WXMAC__) && !defined(__CYGWIN__) && !defined(__WXWINCE__)
33#include <sys/types.h>
34#endif
35
36#ifdef __WXWINCE__
37#include <stdlib.h>
38#endif
39
40class GSocket;
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46typedef struct _GAddress GAddress;
47
48typedef enum {
49 GSOCK_NOFAMILY = 0,
50 GSOCK_INET,
51 GSOCK_INET6,
52 GSOCK_UNIX
53} GAddressType;
54
55typedef enum {
56 GSOCK_STREAMED,
57 GSOCK_UNSTREAMED
58} GSocketStream;
59
60typedef enum {
61 GSOCK_NOERROR = 0,
62 GSOCK_INVOP,
63 GSOCK_IOERR,
64 GSOCK_INVADDR,
65 GSOCK_INVSOCK,
66 GSOCK_NOHOST,
67 GSOCK_INVPORT,
68 GSOCK_WOULDBLOCK,
69 GSOCK_TIMEDOUT,
70 GSOCK_MEMERR,
71 GSOCK_OPTERR
72} GSocketError;
73
74/* See below for an explanation on how events work.
75 */
76typedef enum {
77 GSOCK_INPUT = 0,
78 GSOCK_OUTPUT = 1,
79 GSOCK_CONNECTION = 2,
80 GSOCK_LOST = 3,
81 GSOCK_MAX_EVENT = 4
82} GSocketEvent;
83
84enum {
85 GSOCK_INPUT_FLAG = 1 << GSOCK_INPUT,
86 GSOCK_OUTPUT_FLAG = 1 << GSOCK_OUTPUT,
87 GSOCK_CONNECTION_FLAG = 1 << GSOCK_CONNECTION,
88 GSOCK_LOST_FLAG = 1 << GSOCK_LOST
89};
90
91typedef int GSocketEventFlags;
92
93typedef void (*GSocketCallback)(GSocket *socket, GSocketEvent event,
94 char *cdata);
95
96
97/* Functions tables for internal use by GSocket code: */
98
99/* Actually this is a misnomer now, but reusing this name means I don't
100 have to ifdef app traits or common socket code */
101class GSocketGUIFunctionsTable
102{
103public:
104 // needed since this class declares virtual members
105 virtual ~GSocketGUIFunctionsTable() { }
106 virtual bool OnInit() = 0;
107 virtual void OnExit() = 0;
108 virtual bool CanUseEventLoop() = 0;
109 virtual bool Init_Socket(GSocket *socket) = 0;
110 virtual void Destroy_Socket(GSocket *socket) = 0;
111#ifndef __WINDOWS__
112 virtual void Install_Callback(GSocket *socket, GSocketEvent event) = 0;
113 virtual void Uninstall_Callback(GSocket *socket, GSocketEvent event) = 0;
114#endif
115 virtual void Enable_Events(GSocket *socket) = 0;
116 virtual void Disable_Events(GSocket *socket) = 0;
117};
118
119
120/* Global initializers */
121
122/* Sets GUI functions callbacks. Must be called *before* GSocket_Init
123 if the app uses async sockets. */
124void GSocket_SetGUIFunctions(GSocketGUIFunctionsTable *guifunc);
125
126/* GSocket_Init() must be called at the beginning */
127int GSocket_Init(void);
128
129/* GSocket_Cleanup() must be called at the end */
130void GSocket_Cleanup(void);
131
132
133/* Constructors / Destructors */
134
135GSocket *GSocket_new(void);
136
137
138/* GAddress */
139
140GAddress *GAddress_new(void);
141GAddress *GAddress_copy(GAddress *address);
142void GAddress_destroy(GAddress *address);
143
144void GAddress_SetFamily(GAddress *address, GAddressType type);
145GAddressType GAddress_GetFamily(GAddress *address);
146
147/* The use of any of the next functions will set the address family to
148 * the specific one. For example if you use GAddress_INET_SetHostName,
149 * address family will be implicitly set to AF_INET.
150 */
151
152GSocketError GAddress_INET_SetHostName(GAddress *address, const char *hostname);
153GSocketError GAddress_INET_SetBroadcastAddress(GAddress *address);
154GSocketError GAddress_INET_SetAnyAddress(GAddress *address);
155GSocketError GAddress_INET_SetHostAddress(GAddress *address,
156 unsigned long hostaddr);
157GSocketError GAddress_INET_SetPortName(GAddress *address, const char *port,
158 const char *protocol);
159GSocketError GAddress_INET_SetPort(GAddress *address, unsigned short port);
160
161GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname,
162 size_t sbuf);
163unsigned long GAddress_INET_GetHostAddress(GAddress *address);
164unsigned short GAddress_INET_GetPort(GAddress *address);
165
166/* TODO: Define specific parts (INET6, UNIX) */
167
168GSocketError GAddress_UNIX_SetPath(GAddress *address, const char *path);
169GSocketError GAddress_UNIX_GetPath(GAddress *address, char *path, size_t sbuf);
170
171#ifdef __cplusplus
172}
173#endif /* __cplusplus */
174
175# if defined(__WINDOWS__)
176# include "wx/msw/gsockmsw.h"
177# elif defined(__WXMAC__) && !defined(__DARWIN__)
178# include "wx/mac/gsockmac.h"
179# else
180# include "wx/unix/gsockunx.h"
181# endif
182
183#endif /* wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) */
184
185#endif /* __GSOCKET_H */