friend class wxTCPServer;
friend class wxTCPClient;
friend void Client_OnRequest(wxSocketBase&,
- GSocketEvent, char *);
+ wxSocketNotify, char *);
friend void Server_OnRequest(wxSocketServer&,
- GSocketEvent, char *);
+ wxSocketNotify, char *);
public:
wxTCPConnection(char *buffer, int size);
#include "wx/sckaddr.h"
#include "wx/gsocket.h"
+// ------------------------------------------------------------------------
+// GSocket type alias
+// ------------------------------------------------------------------------
+
+typedef enum {
+ wxSOCKET_INPUT = GSOCK_INPUT,
+ wxSOCKET_OUTPUT = GSOCK_OUTPUT,
+ wxSOCKET_CONNECTION = GSOCK_CONNECTION,
+ wxSOCKET_LOST = GSOCK_LOST
+} wxSocketNotify;
+
+enum {
+ wxSOCKET_INPUT_FLAG = GSOCK_INPUT_FLAG,
+ wxSOCKET_OUTPUT_FLAG = GSOCK_OUTPUT_FLAG,
+ wxSOCKET_CONNECTION_FLAG = GSOCK_CONNECTION_FLAG,
+ wxSOCKET_LOST_FLAG = GSOCK_LOST_FLAG,
+};
+
+typedef GSocketEventFlags wxSocketEventFlags;
+
+typedef enum {
+ wxSOCKET_NOERROR = GSOCK_NOERROR,
+ wxSOCKET_INPOP = GSOCK_INVOP,
+ wxSOCKET_IOERR = GSOCK_IOERR,
+ wxSOCKET_INVADDR = GSOCK_INVADDR,
+ wxSOCKET_INVSOCK = GSOCK_INVSOCK,
+ wxSOCKET_NOHOST = GSOCK_NOHOST,
+ wxSOCKET_INVPORT = GSOCK_INVPORT,
+ wxSOCKET_WOULDBLOCK = GSOCK_WOULDBLOCK,
+ wxSOCKET_TIMEOUT = GSOCK_TIMEOUT,
+ wxSOCKET_MEMERR = GSOCK_MEMERR
+} wxSocketError;
+
+// ------------------------------------------------------------------------
+// wxSocket base
+// ------------------------------------------------------------------------
+
class WXDLLEXPORT wxTimer;
class WXDLLEXPORT wxSocketEvent;
class WXDLLEXPORT wxSocketBase : public wxEvtHandler
// Type of request
enum wxSockType { SOCK_CLIENT, SOCK_SERVER, SOCK_INTERNAL, SOCK_UNINIT };
- typedef void (*wxSockCbk)(wxSocketBase& sock,GSocketEvent evt,char *cdata);
+ typedef void (*wxSockCbk)(wxSocketBase& sock,wxSocketNotify evt,char *cdata);
protected:
GSocket *m_socket; // wxSocket socket
inline bool IsNoWait() const { return ((m_flags & NOWAIT) != 0); };
bool IsData() const;
inline size_t LastCount() const { return m_lcount; }
- inline GSocketError LastError() const { return GSocket_GetError(m_socket); }
+ inline wxSocketError LastError() const { return (wxSocketError)GSocket_GetError(m_socket); }
inline wxSockType GetType() const { return m_type; }
void SetFlags(wxSockFlags _flags);
void SetEventHandler(wxEvtHandler& evt_hdlr, int id = -1);
// Method called when it happens something on the socket
- void SetNotify(GSocketEventFlags flags);
- virtual void OnRequest(GSocketEvent req_evt);
+ void SetNotify(wxSocketEventFlags flags);
+ virtual void OnRequest(wxSocketNotify req_evt);
// Public internal callback
- virtual void OldOnNotify(GSocketEvent WXUNUSED(evt));
+ virtual void OldOnNotify(wxSocketNotify WXUNUSED(evt));
// Some info on the socket...
virtual bool GetPeer(wxSockAddress& addr_man) const;
void Notify(bool notify);
// So you can know what the socket driver is looking for ...
- inline GSocketEventFlags NeededReq() const { return m_neededreq; }
+ inline wxSocketEventFlags NeededReq() const { return m_neededreq; }
- static GSocketEventFlags EventToNotify(GSocketEvent evt);
+ static wxSocketEventFlags EventToNotify(wxSocketNotify evt);
protected:
friend class wxSocketServer;
bool WaitOnConnect(long seconds = -1, long microseconds = 0);
- virtual void OnRequest(GSocketEvent flags);
+ virtual void OnRequest(wxSocketNotify flags);
};
class WXDLLEXPORT wxSocketEvent : public wxEvent {
public:
wxSocketEvent(int id = 0);
- GSocketEvent SocketEvent() const { return m_skevt; }
+ wxSocketNotify SocketEvent() const { return (wxSocketNotify)m_skevt; }
wxSocketBase *Socket() const { return m_socket; }
void CopyObject(wxObject& obj_d) const;
/* No 2 */
sock->SetEventHandler(*this, SKDEMO_SCK);
- sock->SetNotify(GSOCK_INPUT | GSOCK_LOST);
+ sock->SetNotify(GSOCK_INPUT_FLAG | GSOCK_LOST_FLAG);
sock->Notify(TRUE);
text_win->WriteText("Test 1B: sending bytes to the server\n");
#endif
void Server_OnRequest(wxSocketServer& server,
- GSocketEvent evt,
+ wxSocketNotify evt,
char *cdata);
void Client_OnRequest(wxSocketBase& sock,
- GSocketEvent evt,
+ wxSocketNotify evt,
char *cdata);
// ---------------------------------------------------------------------------
wxDataInputStream data_is(*stream);
wxDataOutputStream data_os(*stream);
- client->SetNotify(GSOCK_INPUT_FLAG | GSOCK_LOST_FLAG);
+ client->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
addr.Service(server_name);
addr.Hostname(host);
// Create a socket listening on specified port
server = new wxSocketServer(addr);
server->Callback((wxSocketBase::wxSockCbk)Server_OnRequest);
- server->SetNotify(GSOCK_CONNECTION_FLAG);
+ server->SetNotify(wxSOCKET_CONNECTION_FLAG);
server->CallbackData((char *)this);
return TRUE;
}
-void Client_OnRequest(wxSocketBase& sock, GSocketEvent evt,
+void Client_OnRequest(wxSocketBase& sock, wxSocketNotify evt,
char *cdata)
{
int msg = 0;
wxString item;
// The socket handler signals us that we lost the connection: destroy all.
- if (evt == GSOCK_LOST) {
+ if (evt == wxSOCKET_LOST) {
sock.Close();
connection->OnDisconnect();
return;
}
void Server_OnRequest(wxSocketServer& server,
- GSocketEvent evt, char *cdata)
+ wxSocketNotify evt, char *cdata)
{
wxTCPServer *ipcserv = (wxTCPServer *)cdata;
wxSocketStream *stream;
wxDataInputStream *codeci;
wxDataOutputStream *codeco;
- if (evt != GSOCK_CONNECTION)
+ if (evt != wxSOCKET_CONNECTION)
return;
/* Accept the connection, getting a new socket */
wxSocketBase *sock = server.Accept();
sock->Notify(FALSE);
- sock->SetNotify(GSOCK_INPUT_FLAG | GSOCK_LOST_FLAG);
+ sock->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
stream = new wxSocketStream(*sock);
codeci = new wxDataInputStream(*stream);
// --------- wxSocketBase callback management -------------------
// --------------------------------------------------------------
-GSocketEventFlags wxSocketBase::EventToNotify(GSocketEvent evt)
+wxSocketEventFlags wxSocketBase::EventToNotify(wxSocketNotify evt)
{
switch (evt)
{
return m_flags;
}
-void wxSocketBase::SetNotify(GSocketEventFlags flags)
+void wxSocketBase::SetNotify(wxSocketEventFlags flags)
{
/* Check if server */
if (m_type != SOCK_SERVER)
{
wxSocketBase *sckobj = (wxSocketBase *)cdata;
- sckobj->OnRequest(event);
+ sckobj->OnRequest((wxSocketNotify)event);
}
void wxSocketBase::Notify(bool notify)
GSocket_SetCallback(m_socket, m_neededreq, wx_socket_fallback, (char *)this);
}
-void wxSocketBase::OnRequest(GSocketEvent req_evt)
+void wxSocketBase::OnRequest(wxSocketNotify req_evt)
{
wxSocketEvent event(m_id);
GSocketEventFlags notify = EventToNotify(req_evt);
if (m_defering != NO_DEFER) {
- DoDefer(req_evt);
+ DoDefer((GSocketEvent)req_evt);
return;
}
if ((m_neededreq & notify) == notify) {
event.m_socket = this;
- event.m_skevt = req_evt;
+ event.m_skevt = (GSocketEvent) req_evt;
ProcessEvent(event);
OldOnNotify(req_evt);
}
- if (req_evt == GSOCK_LOST)
+ if ((GSocketEvent)req_evt == GSOCK_LOST)
Close();
}
-void wxSocketBase::OldOnNotify(GSocketEvent evt)
+void wxSocketBase::OldOnNotify(wxSocketNotify evt)
{
}
return m_connected;
}
-void wxSocketClient::OnRequest(GSocketEvent evt)
+void wxSocketClient::OnRequest(wxSocketNotify evt)
{
- if (evt == GSOCK_CONNECTION)
+ if ((GSocketEvent)evt == GSOCK_CONNECTION)
{
if (m_connected)
{
{
GSocket *socket = (GSocket *)data;
- switch (condition) {
- case GDK_INPUT_READ:
+ if (condition & GDK_INPUT_READ)
_GSocket_Detected_Read(socket);
- break;
- case GDK_INPUT_WRITE:
+ if (condition & GDK_INPUT_WRITE)
_GSocket_Detected_Write(socket);
- break;
- default:
- break;
- }
}
void _GSocket_GUI_Init(GSocket *socket)
{
GSocket *socket = (GSocket *)data;
- switch (condition) {
- case GDK_INPUT_READ:
+ if (condition & GDK_INPUT_READ)
_GSocket_Detected_Read(socket);
- break;
- case GDK_INPUT_WRITE:
+ if (condition & GDK_INPUT_WRITE)
_GSocket_Detected_Write(socket);
- break;
- default:
- break;
- }
}
void _GSocket_GUI_Init(GSocket *socket)
return TRUE;
}
-bool wxSoundWave::HandlePCM(wxDataInputStream& data, wxUint16 channels,
+bool wxSoundWave::HandleOutputPCM(wxDataInputStream& data, wxUint16 channels,
wxUint32 sample_fq, wxUint32 byte_p_sec,
wxUint16 byte_p_spl, wxUint16 bits_p_spl)
{
return TRUE;
}
-bool wxSoundWave::HandleG721(wxDataInputStream& data, wxUint16 channels,
+bool wxSoundWave::HandleOutputG721(wxDataInputStream& data, wxUint16 channels,
wxUint32 sample_fq, wxUint32 byte_p_sec,
wxUint16 byte_p_spl, wxUint16 bits_p_spl)
{
switch (format) {
case 0x01:
- if (!HandlePCM(data, channels, sample_fq,
+ if (!HandleOutputPCM(data, channels, sample_fq,
byte_p_sec, byte_p_spl, bits_p_spl))
return FALSE;
break;
case 0x40:
- if (!HandleG721(data, channels, sample_fq,
+ if (!HandleOutputG721(data, channels, sample_fq,
byte_p_sec, byte_p_spl, bits_p_spl))
return FALSE;
break;
return TRUE;
}
+wxSoundFormatBase *wxSoundWave::HandleInputPCM(wxDataOutputStream& data)
+{
+ wxUint16 format, channels, byte_p_spl, bits_p_spl;
+ wxUint32 sample_fq, byte_p_sec;
+ wxSoundFormatPcm *pcm;
+
+ pcm = (wxSoundFormatPcm *)(m_sndformat->Clone());
+
+ // Write block length
+ data.Write32(16);
+
+ sample_fq = pcm->GetSampleRate();
+ bits_p_spl = pcm->GetBPS();
+ channels = pcm->GetChannels();
+ byte_p_spl = pcm->GetBPS() / 8;
+ byte_p_sec = pcm->GetBytesFromTime(1);
+ format = 0x01;
+
+ pcm->Signed(TRUE);
+ pcm->SetOrder(wxLITTLE_ENDIAN);
+
+ data << format << channels << sample_fq
+ << byte_p_sec << byte_p_spl << bits_p_spl;
+
+ return pcm;
+}
+
+wxSoundFormatBase *wxSoundWave::HandleInputG72X(wxDataOutputStream& data)
+{
+ wxUint16 format, channels, byte_p_spl, bits_p_spl;
+ wxUint32 sample_fq, byte_p_sec;
+ wxSoundFormatG72X *g72x;
+
+ // Write block length
+ data.Write32(16);
+
+ g72x = (wxSoundFormatG72X *)(m_sndformat->Clone());
+ if (g72x->GetG72XType() != wxSOUND_G721) {
+ delete g72x;
+ return NULL;
+ }
+
+ sample_fq = g72x->GetSampleRate();
+ bits_p_spl = 4;
+ channels = 1;
+ byte_p_spl = 0;
+ byte_p_sec = g72x->GetBytesFromTime(1);
+ format = 0x40;
+ data << format << channels << sample_fq
+ << byte_p_sec << byte_p_spl << bits_p_spl;
+
+ return g72x;
+}
+
bool wxSoundWave::PrepareToRecord(unsigned long time)
{
#define WRITE_SIGNATURE(sig) \
WRITE_SIGNATURE(WAVE_SIGNATURE);
{
- wxUint16 format, channels, byte_p_spl, bits_p_spl;
- wxUint32 sample_fq, byte_p_sec;
- wxSoundFormatPcm *pcm;
+ wxSoundFormatBase *frmt;
+
+ WRITE_SIGNATURE(FMT_SIGNATURE);
- if (m_sndformat->GetType() != wxSOUND_PCM) {
+ switch (m_sndformat->GetType()) {
+ case wxSOUND_PCM:
+ frmt = HandleInputPCM(data);
+ break;
+ case wxSOUND_G72X:
+ frmt = HandleInputG72X(data);
+ break;
+ default:
m_snderror = wxSOUND_NOCODEC;
return FALSE;
}
- pcm = (wxSoundFormatPcm *)(m_sndformat->Clone());
+ FAIL_WITH(!frmt, wxSOUND_NOCODEC);
- WRITE_SIGNATURE(FMT_SIGNATURE);
- data.Write32(16);
-
- sample_fq = pcm->GetSampleRate();
- bits_p_spl = pcm->GetBPS();
- channels = pcm->GetChannels();
- byte_p_spl = pcm->GetBPS() / 8;
- byte_p_sec = pcm->GetBytesFromTime(1);
- format = 1;
- data << format << channels << sample_fq
- << byte_p_sec << byte_p_spl << bits_p_spl;
-
- pcm->Signed(TRUE);
- pcm->SetOrder(wxLITTLE_ENDIAN);
-
- if (!SetSoundFormat(*pcm)) {
- delete pcm;
+ if (!SetSoundFormat(*frmt)) {
+ delete frmt;
return FALSE;
}
- delete pcm;
+ delete frmt;
}
WRITE_SIGNATURE(DATA_SIGNATURE);
wxUint32 GetData(void *buffer, wxUint32 len);
wxUint32 PutData(const void *buffer, wxUint32 len);
- bool HandlePCM(wxDataInputStream& data, wxUint16 channels,
+ bool HandleOutputPCM(wxDataInputStream& data, wxUint16 channels,
wxUint32 sample_fq, wxUint32 byte_p_sec,
wxUint16 byte_p_spl, wxUint16 bits_p_spl);
- bool HandleG721(wxDataInputStream& data, wxUint16 channels,
+ bool HandleOutputG721(wxDataInputStream& data, wxUint16 channels,
wxUint32 sample_fq, wxUint32 byte_p_sec,
wxUint16 byte_p_spl, wxUint16 bits_p_spl);
+ wxSoundFormatBase *HandleInputPCM(wxDataOutputStream& data);
+ wxSoundFormatBase *HandleInputG72X(wxDataOutputStream& data);
};
#endif