+
+int (*gIPC_MessageHandlers[])(tIPC_Client *Client, tAxWin_IPCMessage *Msg) = {
+ IPC_Msg_Ping,
+ IPC_Msg_GetDisplayCount,
+ IPC_Msg_GetDisplayDims,
+ IPC_Msg_SendMsg,
+ IPC_Msg_CreateWin,
+ IPC_Msg_DestroyWin, // Destroy window
+ IPC_Msg_SetWindowTitle,
+ IPC_Msg_ShowWindow,
+ IPC_Msg_DecorateWindow,
+ IPC_Msg_FocusWindow,
+ IPC_Msg_SetWinPos,
+ IPC_Msg_RegisterAction
+};
+const int giIPC_NumMessageHandlers = sizeof(gIPC_MessageHandlers)/sizeof(gIPC_MessageHandlers[0]);
+
+void IPC_Handle(tIPC_Client *Client, size_t MsgLen, tAxWin_IPCMessage *Msg)
+{
+ int rv = 0;
+
+// _SysDebug("IPC_Handle: (IPCType=%p, Ident=%p, MsgLen=%i, Msg=%p)",
+// IPCType, Ident, MsgLen, Msg);
+
+ if( MsgLen < sizeof(*Msg) ) {
+ _SysDebug("IPC_Handle: %p Dropped full undersize message (%i < %i)",
+ Client, MsgLen, sizeof(*Msg));
+ return ;
+ }
+ if( MsgLen < sizeof(*Msg) + Msg->Size ) {
+ _SysDebug("IPC_Handle: %p Dropped undersize message (%i < %i+%i)",
+ Client, MsgLen, sizeof(*Msg), Msg->Size);
+ return ;
+ }
+
+ if( Msg->Flags & IPCMSG_FLAG_RENDERER )
+ {
+ tWindow *win = IPC_int_GetWindow(Client, Msg->Window);
+ if( !win ) {
+ _SysDebug("WARNING: NULL window in message %i (%x)", Msg->ID, Msg->Window);
+ return ;
+ }
+ tWMRenderer *renderer = win->Renderer;
+ if( Msg->ID >= renderer->nIPCHandlers ) {
+ _SysDebug("WARNING: Message %i out of range in %s", Msg->ID, renderer->Name);
+ return ;
+ }
+ if( !renderer->IPCHandlers[Msg->ID] ) {
+ _SysDebug("WARNING: Message %i has no handler in %s", Msg->ID, renderer->Name);
+ return ;
+ }
+ _SysDebug("IPC_Handle: Call %s-%i %ib", renderer->Name, Msg->ID, Msg->Size);
+ rv = renderer->IPCHandlers[Msg->ID](win, Msg->Size, Msg->Data);
+ if( rv )
+ _SysDebug("IPC_Handle: rv != 0 (%i)", rv);
+ }
+ else
+ {
+ if( Msg->ID >= giIPC_NumMessageHandlers ) {
+ fprintf(stderr, "WARNING: Unknown message %i (%p)\n", Msg->ID, Client);
+ _SysDebug("WARNING: Unknown message %i (%p)", Msg->ID, Client);
+ return ;
+ }
+
+ if( !gIPC_MessageHandlers[ Msg->ID ] ) {
+ fprintf(stderr, "WARNING: Message %i does not have a handler\n", Msg->ID);
+ _SysDebug("WARNING: Message %i does not have a handler", Msg->ID);
+ return ;
+ }
+
+ _SysDebug("IPC_Handle: Call WM-%i %ib", Msg->ID, Msg->Size);
+ rv = gIPC_MessageHandlers[Msg->ID](Client, Msg);
+ if( rv )
+ _SysDebug("IPC_Handle: rv != 0 (%i)", rv);
+ }
+}
+
+// Dispatch a message to the client
+void IPC_SendWMMessage(tIPC_Client *Client, uint32_t Src, uint32_t Dst, int MsgID, int Len, void *Data)
+{
+ tAxWin_IPCMessage *hdr;
+ tIPCMsg_SendMsg *msg;
+ char buf[sizeof(*hdr)+sizeof(*msg)+Len];
+
+ hdr = (void*)buf;
+ msg = (void*)hdr->Data;
+
+ hdr->ID = IPCMSG_SENDMSG;
+ hdr->Flags = 0;
+ hdr->Size = sizeof(*msg) + Len;
+ hdr->Window = Dst;
+
+ msg->Remote = Src;
+ msg->ID = MsgID;
+ msg->Length = Len;
+ memcpy(msg->Data, Data, Len);
+
+ Client->IPCType->SendMessage(Client->Ident, sizeof(buf), buf);
+}
+
+// --- Server->Client replies
+void IPC_SendReply(tIPC_Client *Client, uint32_t WinID, int MsgID, size_t Len, const void *Data)
+{
+ tAxWin_IPCMessage *hdr;
+ char buf[sizeof(*hdr)+Len];
+
+ hdr = (void*)buf;
+
+ hdr->ID = MsgID;
+ hdr->Flags = IPCMSG_FLAG_RENDERER;
+ hdr->Size = Len;
+ hdr->Window = WinID;
+
+ memcpy(hdr->Data, Data, Len);
+ Client->IPCType->SendMessage(Client->Ident, sizeof(buf), buf);
+}
+