Usermode/libaxwin4 - Implementation and debug
[tpg/acess2.git] / Usermode / Libraries / libaxwin4.so_src / ipc.cpp
1 /*
2  * AxWin4 Interface Library
3  * - By John Hodge (thePowersGang)
4  *
5  * ipc.c
6  * - IPC Abstraction
7  */
8 #include <axwin4/axwin.h>
9 #include "include/common.hpp"
10 #include "include/IIPCChannel.hpp"
11 #include "include/CIPCChannel_AcessIPCPipe.hpp"
12 #include <algorithm>
13
14 #include <cstring>
15 #include <cstdio>
16
17 namespace AxWin {
18
19 IIPCChannel*    gIPCChannel;
20
21 extern "C" bool AxWin4_Connect(const char *URI)
22 {
23         _SysDebug("AxWin4_Connect('%s')", URI);
24         if( gIPCChannel ) {
25                 return false;
26         }
27         try {
28                 if( strncmp(URI, "ipcpipe://", 3+4+3) == 0 )
29                 {
30                         gIPCChannel = new CIPCChannel_AcessIPCPipe(URI+3+4+3);
31                 }
32                 else
33                 {
34                         _SysDebug("Unknown protocol");
35                         return false;
36                 }
37         }
38         catch( const ::std::exception& e )
39         {
40                 fprintf(stderr, "AxWin4_Connect: %s\n", e.what());
41                 return false;
42         }
43         return true;
44 }
45
46 extern "C" bool AxWin4_PeekEventQueue(void)
47 {
48         return false;
49 }
50
51 extern "C" bool AxWin4_WaitEventQueue(uint64_t Timeout)
52 {
53         AxWin4_WaitEventQueueSelect(0, NULL, NULL, NULL, Timeout);
54 }
55
56 extern "C" bool AxWin4_WaitEventQueueSelect(int nFDs, fd_set *rfds, fd_set *wfds, fd_set *efds, uint64_t Timeout)
57 {
58         fd_set  local_rfds;
59         if( !rfds ) {
60                 FD_ZERO(&local_rfds);
61                 rfds = &local_rfds;
62         }
63         
64         int64_t select_timeout = Timeout;
65         int64_t *select_timeout_p = (Timeout ? &select_timeout : 0);
66         
67         nFDs = ::std::max(nFDs, gIPCChannel->FillSelect(*rfds));
68         _SysSelect(nFDs, rfds, wfds, efds, select_timeout_p, 0);
69         return gIPCChannel->HandleSelect(*rfds);
70 }
71
72 void SendMessage(CSerialiser& message)
73 {
74         gIPCChannel->Send(message);
75 }
76
77 IIPCChannel::~IIPCChannel()
78 {
79 }
80
81 };      // namespace AxWin
82

UCC git Repository :: git.ucc.asn.au