2 * Acess GUI (AxWin) Version 2
3 * By John Hodge (thePowersGang)
8 #include <axwin/messages.h>
11 #define AXWIN_PORT 4101
13 #define STATICBUF_SIZE 64
16 typedef void tMessages_Handle_Callback(void*, size_t, void*);
19 void Messages_PollIPC();
20 void Messages_RespondIPC(void *Ident, size_t Length, void *Data);
21 void Messages_Handle(void *Ident, int MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond);
31 giIPCFileHandle = open("/Devices/ip/loop/udp", OPENFLAG_READ);
32 tmp = AXWIN_PORT; ioctl(giIPCFileHandle, 4, &tmp); // TODO: Don't hard-code IOCtl number
35 void IPC_FillSelect(int *nfds, fd_set *set)
37 if( giIPCFileHandle > *nfds ) *nfds = giIPCFileHandle;
38 FD_SET(giIPCFileHandle, set);
41 void IPC_HandleSelect(fd_set *set)
43 if( FD_ISSET(giIPCFileHandle, set) )
45 char staticBuf[STATICBUF_SIZE];
46 int readlen, identlen;
48 readlen = read(giIPCFileHandle, sizeof(staticBuf), staticBuf);
50 // Assume that all connections are from localhost
51 identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] );
52 msg = staticBuf + identlen;
54 Messages_Handle(staticBuf, readlen - identlen, (void*)msg, Messages_RespondIPC);
59 void Messages_PollIPC()
63 char staticBuf[STATICBUF_SIZE];
67 while( (len = SysGetMessage(&tid, NULL)) == 0 )
70 // Allocate the space for it
71 if( len <= STATICBUF_SIZE )
72 msg = (void*)staticBuf;
78 "ERROR - Unable to allocate message buffer, ignoring message from %i\n",
80 SysGetMessage(NULL, GETMSG_IGNORE);
86 SysGetMessage(NULL, msg);
88 Messages_Handle(msg, Messages_RespondIPC, tid);
92 void Messages_RespondIPC(void *Ident, size_t Length, void *Data)
94 SysSendMessage( *(tid_t*)Ident, Length, Data );
97 void Messages_Handle(void *Ident, int MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond)
103 Msg->ID = MSG_SRSP_VERSION;
107 *(uint16_t*)&Msg->Data[2] = -1;
108 Messages_RespondIPC(ID, sizeof(Msg->ID), Msg);
112 fprintf(stderr, "WARNING: Unknown message %i (%p)\n", Msg->ID, Respond);
113 _SysDebug("WARNING: Unknown message %i (%p)\n", Msg->ID, Respond);