]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/gsockpm.cpp
1 /* -------------------------------------------------------------------------
2 * Project: GSocket (Generic Socket) for WX
4 * Purpose: GSocket: PM part
5 * Licence: The wxWindows licence
7 * ------------------------------------------------------------------------- */
14 #include "wx/unix/gsockunx.h"
15 #include "wx/gsocket.h"
17 extern int wxAppAddSocketHandler(int handle
, int mask
,
18 void (*callback
)(void*), void * gsock
);
20 extern void wxAppRemoveSocketHandler(int handle
);
22 #define wxSockReadMask 0x01
23 #define wxSockWriteMask 0x02
25 static void _GSocket_PM_Input(void *data
)
27 GSocket
*socket
= (GSocket
*) data
;
28 socket
->Detected_Read();
31 static void _GSocket_PM_Output(void *data
)
33 GSocket
*socket
= (GSocket
*) data
;
34 socket
->Detected_Write();
37 bool GSocketGUIFunctionsTableConcrete::CanUseEventLoop()
40 bool GSocketGUIFunctionsTableConcrete::OnInit(void)
45 void GSocketGUIFunctionsTableConcrete::OnExit(void)
49 bool GSocketGUIFunctionsTableConcrete::Init_Socket(GSocket
*socket
)
52 socket
->m_gui_dependent
= (char *)malloc(sizeof(int)*2);
53 m_id
= (int *)(socket
->m_gui_dependent
);
60 void GSocketGUIFunctionsTableConcrete::Destroy_Socket(GSocket
*socket
)
62 free(socket
->m_gui_dependent
);
65 void GSocketGUIFunctionsTableConcrete::Install_Callback(GSocket
*socket
, GSocketEvent event
)
67 int *m_id
= (int *)(socket
->m_gui_dependent
);
70 if (socket
->m_fd
== -1)
75 case GSOCK_LOST
: /* fall-through */
76 case GSOCK_INPUT
: c
= 0; break;
77 case GSOCK_OUTPUT
: c
= 1; break;
78 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
83 wxAppRemoveSocketHandler(m_id
[c
]);
87 m_id
[0] = wxAppAddSocketHandler(socket
->m_fd
, wxSockReadMask
,
88 _GSocket_PM_Input
, (void *)socket
);
92 m_id
[1] = wxAppAddSocketHandler(socket
->m_fd
, wxSockWriteMask
,
93 _GSocket_PM_Output
, (void *)socket
);
97 void GSocketGUIFunctionsTableConcrete::Uninstall_Callback(GSocket
*socket
, GSocketEvent event
)
99 int *m_id
= (int *)(socket
->m_gui_dependent
);
103 case GSOCK_LOST
: /* fall-through */
104 case GSOCK_INPUT
: c
= 0; break;
105 case GSOCK_OUTPUT
: c
= 1; break;
106 case GSOCK_CONNECTION
: c
= ((socket
->m_server
) ? 0 : 1); break;
110 wxAppRemoveSocketHandler(m_id
[c
]);
115 void GSocketGUIFunctionsTableConcrete::Enable_Events(GSocket
*socket
)
117 Install_Callback(socket
, GSOCK_INPUT
);
118 Install_Callback(socket
, GSOCK_OUTPUT
);
121 void GSocketGUIFunctionsTableConcrete::Disable_Events(GSocket
*socket
)
123 Uninstall_Callback(socket
, GSOCK_INPUT
);
124 Uninstall_Callback(socket
, GSOCK_OUTPUT
);
127 #else /* !wxUSE_SOCKETS */
129 /* some compilers don't like having empty source files */
130 static int wxDummyGsockVar
= 0;
132 #endif /* wxUSE_SOCKETS/!wxUSE_SOCKETS */