From: John Hodge Date: Mon, 31 Oct 2011 14:02:26 +0000 (+0800) Subject: Usermode/AxWin3 - Working on interface library X-Git-Tag: rel0.14~165 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3de54cd41d780eb284a56a761ef84faaa620d88b;p=tpg%2Facess2.git Usermode/AxWin3 - Working on interface library --- diff --git a/Usermode/Libraries/Makefile.cfg b/Usermode/Libraries/Makefile.cfg index a9b01919..94630280 100644 --- a/Usermode/Libraries/Makefile.cfg +++ b/Usermode/Libraries/Makefile.cfg @@ -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 index 00000000..d9d7ee83 --- /dev/null +++ b/Usermode/Libraries/libaxwin3.so_src/include/ipc.h @@ -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 + diff --git a/Usermode/Libraries/libaxwin3.so_src/main.c b/Usermode/Libraries/libaxwin3.so_src/main.c index a71a662b..0ee81ceb 100644 --- a/Usermode/Libraries/libaxwin3.so_src/main.c +++ b/Usermode/Libraries/libaxwin3.so_src/main.c @@ -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 -} diff --git a/Usermode/Libraries/libaxwin3.so_src/msg.c b/Usermode/Libraries/libaxwin3.so_src/msg.c index e69de29b..35057a82 100644 --- a/Usermode/Libraries/libaxwin3.so_src/msg.c +++ b/Usermode/Libraries/libaxwin3.so_src/msg.c @@ -0,0 +1,136 @@ +/* + * AxWin3 Interface Library + * - By John Hodge (thePowersGang) + * + * msg.c + * - Message handling / IPC + */ +#include +#include +#include +#include +#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; +} + diff --git a/Usermode/include/axwin3/axwin.h b/Usermode/include/axwin3/axwin.h index 359f4e6b..e7ad5800 100644 --- a/Usermode/include/axwin3/axwin.h +++ b/Usermode/include/axwin3/axwin.h @@ -10,7 +10,10 @@ 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);