More work on TCP, splitted UDI arch dependent out of udi.h, slight work on AxWin
[tpg/acess2.git] / Usermode / Applications / axwin2_src / WM / messages.c
1 /*
2  * Acess GUI (AxWin) Version 2
3  * By John Hodge (thePowersGang)
4  */
5 #include "common.h"
6 #include <acess/sys.h>
7 #include <axwin/messages.h>
8
9 #define STATICBUF_SIZE  64
10
11 // === TYPES ===
12 typedef void tMessages_Handle_Callback(int, size_t,void*);
13
14 // === PROTOTYPES ===
15 void    Messages_PollIPC();
16 void    Messages_RespondIPC(int ID, size_t Length, void *Data);
17 void    Messages_Handle(tAxWin_Message *Msg, tMessages_Handle_Callback *Respond, int ID);
18
19 // === GLOBALS ===
20
21 // === CODE ===
22 void Messages_PollIPC()
23 {
24          int    len;
25          int    tid = 0;
26         char    staticBuf[STATICBUF_SIZE];
27         tAxWin_Message  *msg;
28         
29         // Wait for a message
30         while( (len = SysGetMessage(&tid, NULL)) )
31                 yield();
32         
33         // Allocate the space for it
34         if( len <= STATICBUF_SIZE )
35                 msg = (void*)staticBuf;
36         else {
37                 msg = malloc( len );
38                 if(!msg) {
39                         fprintf(
40                                 stderr,
41                                 "ERROR - Unable to allocate message buffer, ignoring message from %i\n",
42                                 tid);
43                         SysGetMessage(NULL, GETMSG_IGNORE);
44                         return ;
45                 }
46         }
47         
48         // Get message data
49         SysGetMessage(NULL, msg);
50         
51         Messages_Handle(msg, Messages_RespondIPC, tid);
52 }
53
54 void Messages_RespondIPC(int ID, size_t Length, void *Data)
55 {
56         SysSendMessage(ID, Length, Data);
57 }
58
59 void Messages_Handle(tAxWin_Message *Msg, tMessages_Handle_Callback *Respond, int ID)
60 {
61         switch(Msg->ID)
62         {
63         case MSG_SREQ_PING:
64                 Msg->ID = MSG_SRSP_PONG;
65                 Respond(ID, sizeof(Msg->ID), Msg);
66                 break;
67         default:
68                 fprintf(stderr, "WARNING: Unknown message %i from %i (%p)\n", Msg->ID, ID, Respond);
69                 _SysDebug("WARNING: Unknown message %i from %i (%p)\n", Msg->ID, ID, Respond);
70                 break;
71         }
72 }
73

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