Usermode/AxWin3 - Working on interface library
authorJohn Hodge <[email protected]>
Mon, 31 Oct 2011 14:02:26 +0000 (22:02 +0800)
committerJohn Hodge <[email protected]>
Mon, 31 Oct 2011 14:02:26 +0000 (22:02 +0800)
Usermode/Libraries/Makefile.cfg
Usermode/Libraries/libaxwin3.so_src/include/ipc.h [new file with mode: 0644]
Usermode/Libraries/libaxwin3.so_src/main.c
Usermode/Libraries/libaxwin3.so_src/msg.c
Usermode/include/axwin3/axwin.h

index a9b0191..9463028 100644 (file)
@@ -8,4 +8,4 @@ MAKEDEP  = $(CC) -M
 ASFLAGS  += -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1
 CPPFLAGS := -I$(ACESSDIR)/Usermode/include/ -DARCHDIR=$(ARCHDIR) -DARCHDIR_is_$(ARCHDIR)=1
 CFLAGS   := -g -Wall -fPIC -fno-builtin -fno-stack-protector $(CPPFLAGS)
-LDFLAGS  := -g -nostdlib -shared -I/Acess/Libs/ld-acess.so -e SoMain -x -L$(OUTPUTDIR)Libs/
+LDFLAGS  := -g -nostdlib -shared -I/Acess/Libs/ld-acess.so -e SoMain -x -L$(OUTPUTDIR)Libs/ -Wl,--no-undefined
diff --git a/Usermode/Libraries/libaxwin3.so_src/include/ipc.h b/Usermode/Libraries/libaxwin3.so_src/include/ipc.h
new file mode 100644 (file)
index 0000000..d9d7ee8
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Acess2 Window Manager v3
+ * - By John Hodge (thePowersGang)
+ *
+ * ipcmessages.h
+ * - IPC Message format definition
+ */
+#ifndef _IPCMESSAGES_H_
+#define _IPCMESSAGES_H_
+
+typedef struct sAxWin_IPCMessage       tAxWin_IPCMessage;
+typedef struct sIPCMsg_Return  tIPCMsg_Return;
+
+/**
+ * \name Flags for IPC Messages
+ * \{
+ */
+//! Request a return value
+#define IPCMSG_FLAG_RETURN     0x01
+
+struct sAxWin_IPCMessage
+{
+        uint8_t        ID;
+        uint8_t        Flags;
+       uint16_t        Size;
+       uint32_t        Window;
+       char    Data[];
+};
+
+struct sIPCMsg_Return
+{
+       uint32_t        Value;
+};
+
+enum eAxWin_IPCMessageTypes
+{
+       IPCMSG_PING,    //!< 
+       IPCMSG_SENDMSG, //!< Send a message to another window
+};
+
+#endif
+
index a71a662..0ee81ce 100644 (file)
@@ -14,7 +14,3 @@ int SoMain(void *Base, int argc, const char *argv[], const char **envp)
        return 0;
 }
 
-void AxWin3_Connect(const char *ServerDesc)
-{
-       // TODO: Handle Message passing, Local UDP and TCP streams
-}
index e69de29..35057a8 100644 (file)
@@ -0,0 +1,136 @@
+/*
+ * AxWin3 Interface Library
+ * - By John Hodge (thePowersGang)
+ *
+ * msg.c
+ * - Message handling / IPC
+ */
+#include <axwin3/axwin.h>
+#include <acess/sys.h>
+#include <string.h>
+#include <stdlib.h>
+#include "include/ipc.h"
+
+// === CONSTANTS ===
+enum eConnectionType
+{
+       CONNTYPE_SENDMESSAGE,
+       CONNTYPE_UDP,
+       CONNTYPE_TCP
+};
+
+// === GLOBALS ===
+enum eConnectionType   giConnectionType;
+int    giConnectionNum;        // FD or PID
+char   gaAxWin3_int_UDPHeader[] = {5,16,0,0};  // Port 4101
+ int   giAxWin3_int_UDPHeaderLen = sizeof(gaAxWin3_int_UDPHeader);
+const char     *gsAxWin3_int_ServerDesc;
+tAxWin3_MessageCallback        gAxWin3_MessageCallback;
+
+// === CODE ===
+void AxWin3_Connect(const char *ServerDesc)
+{
+       if( !ServerDesc )
+       {
+               ServerDesc = gsAxWin3_int_ServerDesc;
+       }
+       if( !ServerDesc )
+       {
+               // TODO: Error out
+               return ;
+       }
+       switch(ServerDesc[0])
+       {
+       case '1': case '2': case '3': case '4': case '5':
+       case '6': case '7': case '8': case '9': case '0':
+               giConnectionType = CONNTYPE_SENDMESSAGE;
+               giConnectionNum = atoi(ServerDesc);
+               break;
+       case 'u':
+               while(*ServerDesc && *ServerDesc != ':')        ServerDesc ++;
+               ServerDesc ++;
+               // TODO: Open socket and create UDP header
+               break;
+       case 't':
+               while(*ServerDesc && *ServerDesc != ':')        ServerDesc ++;
+               ServerDesc ++;
+               // TODO: Open socket
+               break;
+       }
+}
+
+tAxWin3_MessageCallback AxWin3_SetMessageCallback(tAxWin3_MessageCallback Callback)
+{
+       tAxWin3_MessageCallback old = gAxWin3_MessageCallback;
+       gAxWin3_MessageCallback = Callback;
+       return old;
+}
+
+void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg)
+{
+        int    size = sizeof(tAxWin_IPCMessage) + Msg->Size;
+       switch(giConnectionType)
+       {
+       case CONNTYPE_SENDMESSAGE:
+               SysSendMessage(giConnectionNum, size, Msg);
+               break;
+       case CONNTYPE_UDP: {
+               // Create UDP header
+               char    tmpbuf[giAxWin3_int_UDPHeaderLen + size];
+               memcpy(tmpbuf, gaAxWin3_int_UDPHeader, giAxWin3_int_UDPHeaderLen);
+               memcpy(tmpbuf + giAxWin3_int_UDPHeaderLen, Msg, size);
+               write(giConnectionNum, tmpbuf, sizeof(tmpbuf));
+               }
+               break;
+       case CONNTYPE_TCP:
+               write(giConnectionNum, Msg, size);
+               break;
+       default:
+               break;
+       }
+}
+
+tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(void)
+{
+        int    len;
+       tAxWin_IPCMessage       *ret = NULL;
+       switch(giConnectionType)
+       {
+       case CONNTYPE_SENDMESSAGE:
+               while(SysGetMessage(NULL, NULL))
+               {
+                       pid_t   tid;
+                       len = SysGetMessage(&tid, NULL);
+                       // Check if the message came from the server
+                       if(tid != giConnectionNum)
+                       {
+                               // If not, pass the buck (or ignore)
+                               if( gAxWin3_MessageCallback )
+                                       gAxWin3_MessageCallback(tid, len);
+                               else
+                                       SysGetMessage(NULL, GETMSG_IGNORE);
+                               continue ;
+                       }
+                       
+                       // If it's from the server, allocate a buffer and return it
+                       ret = malloc(len);
+                       if(ret == NULL) return NULL;
+                       SysGetMessage(NULL, ret);
+                       break;
+               }
+               break;
+       default:
+               // TODO: Implement
+               _SysDebug("TODO: Implement AxWin3_int_GetIPCMessage for TCP/UDP");
+               break;
+       }
+
+       // No message?
+       if( ret == NULL )
+               return NULL;
+
+       // TODO: Sanity checks, so a stupid server can't crash us
+
+       return ret;
+}
+
index 359f4e6..e7ad580 100644 (file)
 
 typedef void   *tHWND;
 
+typedef void   (*tAxWin3_MessageCallback)(int SourceTID, int Length);
+
 extern void    AxWin3_Connect(const char *ServerDesc);
+extern tAxWin3_MessageCallback AxWin3_SetMessageCallback(tAxWin3_MessageCallback Callback);
 
 extern tHWND   AxWin3_CreateWindow(tHWND Parent, const char *Renderer, int Flags);
 extern void    AxWin3_DestroyWindow(tHWND Window);

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