+void RecvMessage(CDeserialiser& message)
+{
+ uint8_t id = message.ReadU8();
+ _SysDebug("RecvMessage: id=%i", id);
+ switch(id)
+ {
+ case IPCMSG_REPLY:
+ // Flag reply and take a copy of this message
+ if( !gSyncReplyActive )
+ {
+ _SysDebug("Unexpected reply message %i", message.ReadU8());
+ }
+ else if( gSyncReplyValid )
+ {
+ // Oh... that was unexpected
+ _SysDebug("Unexpected second reply message %i", message.ReadU8());
+ }
+ else
+ {
+ gSyncReplyValid = true;
+ gSyncReplyBuf = message;
+ }
+ break;
+ default:
+ _SysDebug("TODO: RecvMessage(%i)", id);
+ break;
+ }
+}
+
+CDeserialiser GetSyncReply(CSerialiser& request, unsigned int Message)
+{
+ ::std::lock_guard<std::mutex> lock(glSyncReply);
+ gSyncReplyActive = true;
+ gSyncReplyValid = false;
+ // Send once lock is acquired
+ SendMessage(request);
+
+ while( !gSyncReplyValid )
+ {
+ // Tick along
+ if( !AxWin4_WaitEventQueue(0) )
+ throw ::std::runtime_error("Connection dropped while waiting for reply");
+ }
+ gSyncReplyActive = false;
+
+ uint8_t id = gSyncReplyBuf.ReadU8();
+ if( id != Message )
+ {
+ _SysDebug("Unexpected reply message id=%i, expected %i",
+ id, Message);
+ throw ::std::runtime_error("Sequencing error, unexpected reply");
+ }
+
+ // Use move to avoid copying
+ return ::std::move(gSyncReplyBuf);
+}
+
+extern "C" void AxWin4_GetScreenDimensions(unsigned int ScreenIndex, unsigned int *Width, unsigned int *Height)
+{
+ CSerialiser req;
+ req.WriteU8(IPCMSG_GETGLOBAL);
+ req.WriteU16(IPC_GLOBATTR_SCREENDIMS);
+ req.WriteU8(ScreenIndex);
+
+ CDeserialiser response = GetSyncReply(req, IPCMSG_GETGLOBAL);
+ if( response.ReadU16() != IPC_GLOBATTR_SCREENDIMS ) {
+
+ }
+
+ *Width = response.ReadU16();
+ *Height = response.ReadU16();
+
+ _SysDebug("AxWin4_GetScreenDimensions: %i = %ix%i", ScreenIndex, *Width, *Height);
+}