]> git.saurik.com Git - wxWidgets.git/blame - src/os2/gsockpm.cpp
fixed bug with lower-case colours in wxColourDatabase::AddColour() (patch 1074865)
[wxWidgets.git] / src / os2 / gsockpm.cpp
CommitLineData
05a019a2
DE
1/* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
3 * Name: gsockpm.c
4 * Purpose: GSocket: PM part
65571936 5 * Licence: The wxWindows licence
05a019a2
DE
6 * CVSID: $Id$
7 * ------------------------------------------------------------------------- */
8
9#include "wx/setup.h"
10
11#if wxUSE_SOCKETS
12
13#include <stdlib.h>
14#include "wx/unix/gsockunx.h"
15#include "wx/gsocket.h"
621b4574 16#include "wx/app.h"
05a019a2
DE
17
18#define wxSockReadMask 0x01
19#define wxSockWriteMask 0x02
20
21static void _GSocket_PM_Input(void *data)
22{
23 GSocket *socket = (GSocket *) data;
a1ad0f6b 24 socket->Detected_Read();
05a019a2
DE
25}
26
27static void _GSocket_PM_Output(void *data)
28{
29 GSocket *socket = (GSocket *) data;
a1ad0f6b 30 socket->Detected_Write();
05a019a2
DE
31}
32
a1ad0f6b
DE
33bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
34{ return true; }
35
36bool GSocketGUIFunctionsTableConcrete::OnInit(void)
05a019a2
DE
37{
38 return 1;
39}
40
a1ad0f6b 41void GSocketGUIFunctionsTableConcrete::OnExit(void)
05a019a2
DE
42{
43}
44
a1ad0f6b 45bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket *socket)
05a019a2
DE
46{
47 int *m_id;
48 socket->m_gui_dependent = (char *)malloc(sizeof(int)*2);
49 m_id = (int *)(socket->m_gui_dependent);
50
51 m_id[0] = -1;
52 m_id[1] = -1;
948c96ef 53 return true;
05a019a2
DE
54}
55
a1ad0f6b 56void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket *socket)
05a019a2
DE
57{
58 free(socket->m_gui_dependent);
59}
60
a1ad0f6b 61void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket *socket, GSocketEvent event)
05a019a2
DE
62{
63 int *m_id = (int *)(socket->m_gui_dependent);
64 int c;
65
66 if (socket->m_fd == -1)
67 return;
68
69 switch (event)
70 {
71 case GSOCK_LOST: /* fall-through */
72 case GSOCK_INPUT: c = 0; break;
73 case GSOCK_OUTPUT: c = 1; break;
74 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
75 default: return;
76 }
77
78 if (m_id[c] != -1)
621b4574 79 wxTheApp->RemoveSocketHandler(m_id[c]);
05a019a2
DE
80
81 if (c == 0)
82 {
621b4574
SN
83 m_id[0] = wxTheApp->AddSocketHandler(socket->m_fd, wxSockReadMask,
84 _GSocket_PM_Input, (void *)socket);
05a019a2
DE
85 }
86 else
87 {
621b4574
SN
88 m_id[1] = wxTheApp->AddSocketHandler(socket->m_fd, wxSockWriteMask,
89 _GSocket_PM_Output, (void *)socket);
05a019a2
DE
90 }
91}
92
a1ad0f6b 93void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket *socket, GSocketEvent event)
05a019a2
DE
94{
95 int *m_id = (int *)(socket->m_gui_dependent);
96 int c;
97 switch (event)
98 {
99 case GSOCK_LOST: /* fall-through */
100 case GSOCK_INPUT: c = 0; break;
101 case GSOCK_OUTPUT: c = 1; break;
102 case GSOCK_CONNECTION: c = ((socket->m_server) ? 0 : 1); break;
103 default: return;
104 }
105 if (m_id[c] != -1)
621b4574 106 wxTheApp->RemoveSocketHandler(m_id[c]);
05a019a2
DE
107
108 m_id[c] = -1;
109}
110
a1ad0f6b 111void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket *socket)
05a019a2 112{
a1ad0f6b
DE
113 Install_Callback(socket, GSOCK_INPUT);
114 Install_Callback(socket, GSOCK_OUTPUT);
05a019a2
DE
115}
116
a1ad0f6b 117void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket *socket)
05a019a2 118{
a1ad0f6b
DE
119 Uninstall_Callback(socket, GSOCK_INPUT);
120 Uninstall_Callback(socket, GSOCK_OUTPUT);
05a019a2
DE
121}
122
123#else /* !wxUSE_SOCKETS */
124
125/* some compilers don't like having empty source files */
126static int wxDummyGsockVar = 0;
127
128#endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */