Usermode/AxWin4 - Starting work on client-side library
[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         if( gIPCChannel ) {
24                 return false;
25         }
26         try {
27                 if( strncmp(URI, "ipcpipe://", 3+4+3) == 0 )
28                 {
29                         gIPCChannel = new CIPCChannel_AcessIPCPipe(URI);
30                 }
31                 else
32                 {
33                         return false;
34                 }
35         }
36         catch( const ::std::exception& e )
37         {
38                 fprintf(stderr, "AxWin4_Connect: %s\n", e.what());
39                 return false;
40         }
41         return true;
42 }
43
44 extern "C" bool AxWin4_PeekEventQueue(void)
45 {
46         return false;
47 }
48
49 extern "C" bool AxWin4_WaitEventQueue(uint64_t Timeout)
50 {
51         AxWin4_WaitEventQueueSelect(0, NULL, NULL, NULL, Timeout);
52 }
53
54 extern "C" bool AxWin4_WaitEventQueueSelect(int nFDs, fd_set *rfds, fd_set *wfds, fd_set *efds, uint64_t Timeout)
55 {
56         fd_set  local_rfds;
57         if( !rfds )
58                 rfds = &local_rfds;
59         
60         int64_t select_timeout = Timeout;
61         int64_t *select_timeout_p = (Timeout ? &select_timeout : 0);
62         
63         nFDs = ::std::max(nFDs, gIPCChannel->FillSelect(*rfds));
64         _SysSelect(nFDs, rfds, wfds, efds, select_timeout_p, 0);
65         return gIPCChannel->HandleSelect(*rfds);
66 }
67
68 void SendMessage(CSerialiser& message)
69 {
70         gIPCChannel->Send(message);
71 }
72
73 IIPCChannel::~IIPCChannel()
74 {
75 }
76
77 };      // namespace AxWin
78

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