AxWin2 - Working in UDP based IPC, select() for input
authorJohn Hodge <[email protected]>
Sun, 29 May 2011 09:48:55 +0000 (17:48 +0800)
committerJohn Hodge <[email protected]>
Sun, 29 May 2011 09:48:55 +0000 (17:48 +0800)
Usermode/Applications/axwin2_src/WM/Makefile
Usermode/Applications/axwin2_src/WM/input.c [new file with mode: 0644]
Usermode/Applications/axwin2_src/WM/main.c
Usermode/Applications/axwin2_src/WM/messages.c

index d740d1c..032eb8f 100644 (file)
@@ -6,11 +6,11 @@ CPPFLAGS += -I../include
 
 DIR := Apps/AxWin/1.0
 BIN := AxWinWM
-OBJ := main.o helpers.o commandline.o video.o video_text.o
+OBJ := main.o helpers.o commandline.o video.o input.o video_text.o
 OBJ += messages.o interface.o wm.o decorator.o
 OBJ += image.o
 
-LDFLAGS += -limage_sif -luri
+LDFLAGS += -limage_sif -luri -lnet
 
 -include ../../Makefile.tpl
 
diff --git a/Usermode/Applications/axwin2_src/WM/input.c b/Usermode/Applications/axwin2_src/WM/input.c
new file mode 100644 (file)
index 0000000..f69e056
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Acess GUI (AxWin) Version 2
+ * By John Hodge (thePowersGang)
+ */
+#include "common.h"
+
+// === CODE ===
+void Input_FillSelect(int *nfds, fd_set *set)
+{
+       if(*nfds < giTerminalFD)        *nfds = giTerminalFD;
+       if(*nfds < giMouseFD)   *nfds = giMouseFD;
+       FD_SET(giTerminalFD, set);
+       FD_SET(giMouseFD, set);
+}
+
+void Input_HandleSelect(fd_set *set)
+{
+       if(FD_ISSET(giTerminalFD, set))
+       {
+               
+       }
+}
index 67ceb63..dd80296 100644 (file)
@@ -58,7 +58,8 @@ int main(int argc, char *argv[])
        
                Input_FillSelect(&nfds, &fds);
                IPC_FillSelect(&nfds, &fds);
-
+               
+               nfds ++;
                select(nfds, &fds, NULL, NULL, NULL);
 
                Input_HandleSelect(&fds);
index c4bed7a..61e3357 100644 (file)
@@ -6,16 +6,19 @@
 #include <acess/sys.h>
 #include <net.h>
 #include <axwin/messages.h>
+//#include <select.h>
+
+#define AXWIN_PORT     4101
 
 #define STATICBUF_SIZE 64
 
 // === TYPES ===
-typedef void tMessages_Handle_Callback(int, size_t,void*);
+typedef void tMessages_Handle_Callback(void*, size_t, void*);
 
 // === PROTOTYPES ===
 void   Messages_PollIPC();
-void   Messages_RespondIPC(int ID, size_t Length, void *Data);
-void   Messages_Handle(tAxWin_Message *Msg, tMessages_Handle_Callback *Respond, int ID);
+void   Messages_RespondIPC(void *Ident, size_t Length, void *Data);
+void   Messages_Handle(void *Ident, int MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond);
 
 // === GLOBALS ===
  int   giIPCFileHandle;
@@ -23,11 +26,36 @@ void        Messages_Handle(tAxWin_Message *Msg, tMessages_Handle_Callback *Respond, in
 // === CODE ===
 void IPC_Init(void)
 {
+        int    tmp;
        // TODO: Check this
-       giIPCFileHandle = open("/Devices/ip/loop/udpc", OPENFLAG_READ|OPENFLAG_EXEC);
-//     ioctl(giIPCFileHandle, );
+       giIPCFileHandle = open("/Devices/ip/loop/udp", OPENFLAG_READ);
+       tmp = AXWIN_PORT;       ioctl(giIPCFileHandle, 4, &tmp);        // TODO: Don't hard-code IOCtl number
+}
+
+void IPC_FillSelect(int *nfds, fd_set *set)
+{
+       if( giIPCFileHandle > *nfds )   *nfds = giIPCFileHandle;
+       FD_SET(giIPCFileHandle, set);
+}
+
+void IPC_HandleSelect(fd_set *set)
+{
+       if( FD_ISSET(giIPCFileHandle, set) )
+       {
+               char    staticBuf[STATICBUF_SIZE];
+                int    readlen, identlen;
+               char    *msg;
+               readlen = read(giIPCFileHandle, sizeof(staticBuf), staticBuf);
+               
+               // Assume that all connections are from localhost
+               identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] );
+               msg = staticBuf + identlen;
+
+               Messages_Handle(staticBuf, readlen - identlen, (void*)msg, Messages_RespondIPC);
+       }
 }
 
+#if 0
 void Messages_PollIPC()
 {
         int    len;
@@ -59,13 +87,14 @@ void Messages_PollIPC()
        
        Messages_Handle(msg, Messages_RespondIPC, tid);
 }
+#endif
 
-void Messages_RespondIPC(int ID, size_t Length, void *Data)
+void Messages_RespondIPC(void *Ident, size_t Length, void *Data)
 {
-       SysSendMessage(ID, Length, Data);
+       SysSendMessage( *(tid_t*)Ident, Length, Data );
 }
 
-void Messages_Handle(tAxWin_Message *Msg, tMessages_Handle_Callback *Respond, int ID)
+void Messages_Handle(void *Ident, int MsgLen, tAxWin_Message *Msg, tMessages_Handle_Callback *Respond)
 {
        switch(Msg->ID)
        {
@@ -80,8 +109,8 @@ void Messages_Handle(tAxWin_Message *Msg, tMessages_Handle_Callback *Respond, in
                break;
        #endif
        default:
-               fprintf(stderr, "WARNING: Unknown message %i from %i (%p)\n", Msg->ID, ID, Respond);
-               _SysDebug("WARNING: Unknown message %i from %i (%p)\n", Msg->ID, ID, Respond);
+               fprintf(stderr, "WARNING: Unknown message %i (%p)\n", Msg->ID, Respond);
+               _SysDebug("WARNING: Unknown message %i (%p)\n", Msg->ID, Respond);
                break;
        }
 }

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