Usermode/AxWin4 - Starting work on client-side library
[tpg/acess2.git] / Usermode / Libraries / libaxwin4.so_src / ipc.cpp
diff --git a/Usermode/Libraries/libaxwin4.so_src/ipc.cpp b/Usermode/Libraries/libaxwin4.so_src/ipc.cpp
new file mode 100644 (file)
index 0000000..c7a2455
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * AxWin4 Interface Library
+ * - By John Hodge (thePowersGang)
+ *
+ * ipc.c
+ * - IPC Abstraction
+ */
+#include <axwin4/axwin.h>
+#include "include/common.hpp"
+#include "include/IIPCChannel.hpp"
+#include "include/CIPCChannel_AcessIPCPipe.hpp"
+#include <algorithm>
+
+#include <cstring>
+#include <cstdio>
+
+namespace AxWin {
+
+IIPCChannel*   gIPCChannel;
+
+extern "C" bool AxWin4_Connect(const char *URI)
+{
+       if( gIPCChannel ) {
+               return false;
+       }
+       try {
+               if( strncmp(URI, "ipcpipe://", 3+4+3) == 0 )
+               {
+                       gIPCChannel = new CIPCChannel_AcessIPCPipe(URI);
+               }
+               else
+               {
+                       return false;
+               }
+       }
+       catch( const ::std::exception& e )
+       {
+               fprintf(stderr, "AxWin4_Connect: %s\n", e.what());
+               return false;
+       }
+       return true;
+}
+
+extern "C" bool AxWin4_PeekEventQueue(void)
+{
+       return false;
+}
+
+extern "C" bool AxWin4_WaitEventQueue(uint64_t Timeout)
+{
+       AxWin4_WaitEventQueueSelect(0, NULL, NULL, NULL, Timeout);
+}
+
+extern "C" bool AxWin4_WaitEventQueueSelect(int nFDs, fd_set *rfds, fd_set *wfds, fd_set *efds, uint64_t Timeout)
+{
+       fd_set  local_rfds;
+       if( !rfds )
+               rfds = &local_rfds;
+       
+       int64_t select_timeout = Timeout;
+       int64_t *select_timeout_p = (Timeout ? &select_timeout : 0);
+       
+       nFDs = ::std::max(nFDs, gIPCChannel->FillSelect(*rfds));
+       _SysSelect(nFDs, rfds, wfds, efds, select_timeout_p, 0);
+       return gIPCChannel->HandleSelect(*rfds);
+}
+
+void SendMessage(CSerialiser& message)
+{
+       gIPCChannel->Send(message);
+}
+
+IIPCChannel::~IIPCChannel()
+{
+}
+
+};     // namespace AxWin
+

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