From: John Hodge Date: Sun, 30 Oct 2011 07:44:12 +0000 (+0800) Subject: Usermode/AxWin3 - Working on IPC X-Git-Tag: rel0.14~168 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=9b2597c18780e7b9946336aa76c81c8c6106813a;p=tpg%2Facess2.git Usermode/AxWin3 - Working on IPC --- diff --git a/Usermode/Applications/axwin3_src/WM/Makefile b/Usermode/Applications/axwin3_src/WM/Makefile index 1e7b9bd7..ada8ac3e 100644 --- a/Usermode/Applications/axwin3_src/WM/Makefile +++ b/Usermode/Applications/axwin3_src/WM/Makefile @@ -6,7 +6,7 @@ CPPFLAGS += -I include/ DIR := Apps/AxWin/3.0 BIN := AxWinWM -OBJ := main.o wm.o input.o +OBJ := main.o wm.o input.o ipc.o OBJ += messageio.o OBJ += renderer_classes.o renderer_passthru.o renderer_widget.o diff --git a/Usermode/Applications/axwin3_src/WM/include/common.h b/Usermode/Applications/axwin3_src/WM/include/common.h index 5aae9273..7bc6f60c 100644 --- a/Usermode/Applications/axwin3_src/WM/include/common.h +++ b/Usermode/Applications/axwin3_src/WM/include/common.h @@ -18,7 +18,7 @@ void Input_FillSelect(int *nfds, fd_set *set); void Input_HandleSelect(fd_set *set); // --- IPC --- - int IPC_Init(void); +void IPC_Init(void); void IPC_FillSelect(int *nfds, fd_set *set); void IPC_HandleSelect(fd_set *set); diff --git a/Usermode/Applications/axwin3_src/WM/include/ipcmessages.h b/Usermode/Applications/axwin3_src/WM/include/ipcmessages.h new file mode 100644 index 00000000..e825293f --- /dev/null +++ b/Usermode/Applications/axwin3_src/WM/include/ipcmessages.h @@ -0,0 +1,34 @@ +/* + * 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; + +/** + * \name Flags for IPC Messages + * \{ + */ +//! Request a return value +#define IPCMSG_FLAG_RETURN 1 + +struct sAxWin_IPCMessage +{ + uint16_t ID; + uint16_t Flags; + char Data[]; +}; + +enum eAxWin_IPCMessageTypes +{ + IPCMSG_PING, //!< + IPCMSG_SENDMSG, //!< Send a message to another window +}; + +#endif + diff --git a/Usermode/Applications/axwin3_src/WM/include/renderer_widget.h b/Usermode/Applications/axwin3_src/WM/include/renderer_widget.h index 7187c87f..680fb4f6 100644 --- a/Usermode/Applications/axwin3_src/WM/include/renderer_widget.h +++ b/Usermode/Applications/axwin3_src/WM/include/renderer_widget.h @@ -37,6 +37,72 @@ enum eElementTypes MAX_ELETYPES = 0x100 }; +enum eElementFlags +{ + /** + * \brief Rendered + * + * If set, the element will be ignored in calculating sizes and + * rendering. + */ + ELEFLAG_NORENDER = 0x001, + /** + * \brief Element visibility + * + * If set, the element is not drawn (but still is used for size calculations) + */ + ELEFLAG_INVISIBLE = 0x002, + + /** + * \brief Position an element absulutely (ignored in size calcs) + */ + ELEFLAG_ABSOLUTEPOS = 0x004, + + /** + * \brief Fixed size element + */ + ELEFLAG_FIXEDSIZE = 0x008, + + /** + * \brief Element "orientation" + * + * Vertical means that the children of this element are stacked, + * otherwise they list horizontally + */ + ELEFLAG_VERTICAL = 0x010,// ELEFLAG_HORIZONTAL = 0x000, + /** + * \brief Action for text that overflows + */ + ELEFLAG_WRAP = 0x020,// ELEFLAG_NOWRAP = 0x000, + /** + * \brief Cross size action + * + * If this flag is set, the element will only be as large (across + * its parent) as is needed to encase the contents of the element. + * Otherwise, the element will expand to fill all avaliable space. + */ + ELEFLAG_NOEXPAND = 0x040, + + /** + * \brief With (length) size action + * If this flag is set, the element will only be as large as + * is required along it's parent + */ + ELEFLAG_NOSTRETCH = 0x080, + + /** + * \brief Center alignment + */ + ELEFLAG_ALIGN_CENTER= 0x100, + /** + * \brief Right/Bottom alignment + * + * If set, the element aligns to the end of avaliable space (instead + * of the beginning) + */ + ELEFLAG_ALIGN_END = 0x200 +}; + typedef struct { uint32_t Parent; diff --git a/Usermode/Applications/axwin3_src/WM/input.c b/Usermode/Applications/axwin3_src/WM/input.c index 9de0d42e..d72d6b68 100644 --- a/Usermode/Applications/axwin3_src/WM/input.c +++ b/Usermode/Applications/axwin3_src/WM/input.c @@ -18,6 +18,7 @@ typedef struct #define JOY_IOCTL_GETSETAXISPOSITION 7 // === IMPORTS === +extern void Video_SetCursorPos(short X, short Y); // TODO: Move out const char *gsMouseDevice; int giTerminalFD; diff --git a/Usermode/Applications/axwin3_src/WM/ipc.c b/Usermode/Applications/axwin3_src/WM/ipc.c new file mode 100644 index 00000000..01f16be0 --- /dev/null +++ b/Usermode/Applications/axwin3_src/WM/ipc.c @@ -0,0 +1,190 @@ +/* + * Acess2 GUI (AxWin) Version 3 + * - By John Hodge (thePowersGang) + * + * ipc.c + * - Interprocess communication + */ +#include +#include +#include +#include +#include + +#define AXWIN_PORT 4101 + +#define STATICBUF_SIZE 64 + +// === TYPES === +typedef struct sIPC_Type tIPC_Type; +struct sIPC_Type +{ + int (*GetIdentSize)(void *Ident); + int (*CompareIdent)(void *Ident1, void *Ident2); + void (*SendMessage)(void *Ident, size_t, void *Data); +}; + +// === PROTOTYPES === +void IPC_Init(void); +void IPC_FillSelect(int *nfds, fd_set *set); +void IPC_HandleSelect(fd_set *set); +void IPC_Handle(tIPC_Type *IPCType, void *Ident, size_t MsgLen, tAxWin_Message *Msg); +void IPC_ReturnValue(tIPC_Type *IPCType, void *Ident, int MessageID, uint32_t Value); + int IPC_Type_Datagram_GetSize(void *Ident); + int IPC_Type_Datagram_Compare(void *Ident1, void *Ident2); +void IPC_Type_Datagram_Send(void *Ident, size_t Length, void *Data); + int IPC_Type_Sys_GetSize(void *Ident); + int IPC_Type_Sys_Compare(void *Ident1, void *Ident2); +void IPC_Type_Sys_Send(void *Ident, size_t Length, void *Data); + +// === GLOBALS === + int giNetworkFileHandle = -1; + int giMessagesFileHandle = -1; +tIPC_Type gIPC_Type_Datagram = { + IPC_Type_Datagram_GetSize, + IPC_Type_Datagram_Compare, + IPC_Type_Datagram_Send +}; +tIPC_Type gIPC_Type_SysMessage = { + IPC_Type_Sys_GetSize, + IPC_Type_Sys_Compare, + IPC_Type_Sys_Send +}; + +// === CODE === +void IPC_Init(void) +{ + int tmp; + // TODO: Check this + giNetworkFileHandle = open("/Devices/ip/loop/udp", OPENFLAG_READ); + tmp = AXWIN_PORT; ioctl(giNetworkFileHandle, 4, &tmp); // TODO: Don't hard-code IOCtl number +} + +void IPC_FillSelect(int *nfds, fd_set *set) +{ + if( giNetworkFileHandle > *nfds ) *nfds = giNetworkFileHandle; + FD_SET(giNetworkFileHandle, set); +} + +void IPC_HandleSelect(fd_set *set) +{ + if( FD_ISSET(giNetworkFileHandle, set) ) + { + char staticBuf[STATICBUF_SIZE]; + int readlen, identlen; + char *msg; + + readlen = read(giNetworkFileHandle, staticBuf, sizeof(staticBuf)); + + identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] ); + msg = staticBuf + identlen; + + IPC_Handle(&gIPC_Type_Datagram, staticBuf, readlen - identlen, (void*)msg); + _SysDebug("IPC_HandleSelect: UDP handled"); + } + + while(SysGetMessage(NULL, NULL)) + { + pid_t tid; + int len = SysGetMessage(&tid, NULL); + char data[len]; + SysGetMessage(NULL, data); + + IPC_Handle(&gIPC_Type_SysMessage, &tid, len, (void*)data); + _SysDebug("IPC_HandleSelect: Message handled"); + } +} + +void IPC_Handle(tIPC_Type *IPCType, void *Ident, size_t MsgLen, tAxWin_IPCMessage *Msg) +{ + tApplication *app; + tElement *ele; + + _SysDebug("IPC_Handle: (IPCType=%p, Ident=%p, MsgLen=%i, Msg=%p)", + IPCType, Ident, MsgLen, Msg); + + if( MsgLen < sizeof(tAxWin_Message) ) + return ; + if( MsgLen < sizeof(tAxWin_Message) + Msg->Size ) + return ; + + app = AxWin_GetClient(IPCType, Ident); + + switch((enum eAxWin_IPCMessageTypes) Msg->ID) + { + // --- Ping message (reset timeout and get server version) + case IPCMSG_PING: + _SysDebug(" IPC_Handle: IPCMSG_PING"); + if( MsgLen < sizeof(tAxWin_Message) + 4 ) return; + if( Msg->Flags & IPCMSG_FLAG_RETURN ) + { + Msg->ID = IPCMSG_PING; + Msg->Size = sizeof(tIPCMsg_Return); + ((tIPCMsg_Return*)Msg->Data)->Value = AXWIN_VERSION; + IPCType->SendMessage(Ident, sizeof(tIPCMsg_Return), Msg); + } + break; + + // --- + + // --- Unknown message + default: + fprintf(stderr, "WARNING: Unknown message %i (%p)\n", Msg->ID, IPCType); + _SysDebug("WARNING: Unknown message %i (%p)\n", Msg->ID, IPCType); + break; + } +} + +void IPC_ReturnValue(tIPC_Type *IPCType, void *Ident, int MessageID, uint32_t Value) +{ + char data[sizeof(tAxWin_Message) + sizeof(tAxWin_RetMsg)]; + tAxWin_Message *msg = (void *)data; + tAxWin_RetMsg *ret_msg = (void *)msg->Data; + + msg->Source = 0; // 0 = Server + msg->ID = MSG_SRSP_RETURN; + msg->Size = sizeof(tAxWin_RetMsg); + ret_msg->ReqID = MessageID; + ret_msg->Rsvd = 0; + ret_msg->Value = Value; + + IPCType->SendMessage(Ident, sizeof(data), data); +} + +int IPC_Type_Datagram_GetSize(void *Ident) +{ + return 4 + Net_GetAddressSize( ((uint16_t*)Ident)[1] ); +} + +int IPC_Type_Datagram_Compare(void *Ident1, void *Ident2) +{ + // Pass the buck :) + // - No need to worry about mis-matching sizes, as the size is computed + // from the 3rd/4th bytes, hence it will differ before the size is hit. + return memcmp(Ident1, Ident2, IPC_Type_Datagram_GetSize(Ident1)); +} + +void IPC_Type_Datagram_Send(void *Ident, size_t Length, void *Data) +{ + int identlen = IPC_Type_Datagram_GetSize(Ident); + char tmpbuf[ identlen + Length ]; + memcpy(tmpbuf, Ident, identlen); // Header + memcpy(tmpbuf + identlen, Data, Length); // Data + // TODO: Handle fragmented packets + write(giNetworkFileHandle, tmpbuf, sizeof(tmpbuf)); +} + +int IPC_Type_Sys_GetSize(void *Ident) +{ + return sizeof(pid_t); +} + +int IPC_Type_Sys_Compare(void *Ident1, void *Ident2) +{ + return *(int*)Ident1 - *(int*)Ident2; +} + +void IPC_Type_Sys_Send(void *Ident, size_t Length, void *Data) +{ + SysSendMessage( *(tid_t*)Ident, Length, Data ); +} diff --git a/Usermode/Applications/axwin3_src/WM/messageio.c b/Usermode/Applications/axwin3_src/WM/messageio.c index b1e2aa6a..0761ac5b 100644 --- a/Usermode/Applications/axwin3_src/WM/messageio.c +++ b/Usermode/Applications/axwin3_src/WM/messageio.c @@ -13,7 +13,7 @@ // === GLOBALS === // === CODE === -void DispachMessage(tAxWin_Message *Message) +void DispachMessage(tAxWin_Message *Message, size_t Length) { switch(Message->ID) { diff --git a/Usermode/Applications/axwin3_src/WM/renderer_widget.c b/Usermode/Applications/axwin3_src/WM/renderer_widget.c index fa284e83..94840d35 100644 --- a/Usermode/Applications/axwin3_src/WM/renderer_widget.c +++ b/Usermode/Applications/axwin3_src/WM/renderer_widget.c @@ -92,7 +92,7 @@ void Renderer_Widget_Redraw(tWindow *Window) } // --- Render / Resize --- -void _UpdateDimensions(tElement *Ele) +void Widget_UpdateDimensions(tElement *Element) { tElement *child; int nChildren = 0; @@ -189,12 +189,15 @@ void _UpdateDimensions(tElement *Ele) child->CachedX = -1; // Recurse down so the child elements can be updated - _UpdateDimensions(child); + Widget_UpdateDimensions(child); } } -void _UpdatePosition(tElement *Element) +/** + * \brief Update the position of child elements + */ +void Widget_UpdatePosition(tElement *Element) { tElement *child; int x, y; @@ -236,7 +239,7 @@ void _UpdatePosition(tElement *Element) child->CachedX = newX; child->CachedY = newY; // Update child's children positions - WM_UpdatePosition(child); + Widget_UpdatePosition(child); } // Increment diff --git a/Usermode/Applications/axwin3_src/WM/video.c b/Usermode/Applications/axwin3_src/WM/video.c index 4121fbeb..99b1f9db 100644 --- a/Usermode/Applications/axwin3_src/WM/video.c +++ b/Usermode/Applications/axwin3_src/WM/video.c @@ -1,6 +1,9 @@ /* - * Acess GUI (AxWin) Version 2 - * By John Hodge (thePowersGang) + * Acess2 GUI (AxWin) Version 3 + * - By John Hodge (thePowersGang) + * + * video.c + * - Video methods */ #include "common.h" #include