From: John Hodge Date: Wed, 2 Nov 2011 13:08:57 +0000 (+0800) Subject: Usermode/AxWin3 - Working on interface library X-Git-Tag: rel0.14~163 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=015bc57d9df5f9d073950a4cdfd1100c3ce6f954;p=tpg%2Facess2.git Usermode/AxWin3 - Working on interface library --- diff --git a/Usermode/Libraries/libaxwin3.so_src/include/internal.h b/Usermode/Libraries/libaxwin3.so_src/include/internal.h new file mode 100644 index 00000000..ae47408c --- /dev/null +++ b/Usermode/Libraries/libaxwin3.so_src/include/internal.h @@ -0,0 +1,20 @@ +/* + * Acess2 Window Manager v3 + * - By John Hodge (thePowersGang) + * + * internal.h + * - Internal definitions + */ +#ifndef _INTERNAL_H_ +#define _INTERNAL_H_ + +struct sAxWin3_Window +{ + uint32_t ServerID; + tAxWin3_WindowMessageHandler Handler; + + char Data[]; +}; + +#endif + diff --git a/Usermode/Libraries/libaxwin3.so_src/include/ipc.h b/Usermode/Libraries/libaxwin3.so_src/include/ipc.h index d8df229e..a2533ead 100644 --- a/Usermode/Libraries/libaxwin3.so_src/include/ipc.h +++ b/Usermode/Libraries/libaxwin3.so_src/include/ipc.h @@ -10,7 +10,7 @@ typedef struct sAxWin_IPCMessage tAxWin_IPCMessage; typedef struct sIPCMsg_Return tIPCMsg_Return; -typedef struct sIPCMsg_CreateWin sIPCMsg_CreateWin; +typedef struct sIPCMsg_CreateWin tIPCMsg_CreateWin; /** * \name Flags for IPC Messages @@ -50,5 +50,8 @@ enum eAxWin_IPCMessageTypes IPCMSG_CREATEWIN, //!< Create a window }; +extern tAxWin_IPCMessage *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int Flags, int ExtraBytes); +extern void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg); + #endif diff --git a/Usermode/Libraries/libaxwin3.so_src/msg.c b/Usermode/Libraries/libaxwin3.so_src/msg.c index 35057a82..5871331f 100644 --- a/Usermode/Libraries/libaxwin3.so_src/msg.c +++ b/Usermode/Libraries/libaxwin3.so_src/msg.c @@ -66,6 +66,18 @@ tAxWin3_MessageCallback AxWin3_SetMessageCallback(tAxWin3_MessageCallback Callba return old; } +tAxWin_IPCMessage *AxWin3_int_AllocateIPCMessage(tHWND Window, int Message, int Flags, int ExtraBytes) +{ + tAxWin_IPCMessage *ret; + + ret = malloc( sizeof(tAxWin_IPCMessage) + ExtraBytes ); + ret->Flags = Flags; + ret->ID = Message; + ret->Window = Window; + ret->Size = ExtraBytes; + return ret; +} + void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg) { int size = sizeof(tAxWin_IPCMessage) + Msg->Size; diff --git a/Usermode/Libraries/libaxwin3.so_src/wm.c b/Usermode/Libraries/libaxwin3.so_src/wm.c index 8764cd97..7315c05a 100644 --- a/Usermode/Libraries/libaxwin3.so_src/wm.c +++ b/Usermode/Libraries/libaxwin3.so_src/wm.c @@ -7,27 +7,98 @@ */ #include #include +#include +#include "include/ipc.h" +#include "include/internal.h" + +#define WINDOWS_PER_ALLOC (63) + +typedef struct sWindowBlock tWindowBlock; + +typedef struct sAxWin3_Window tWindow; + +// === STRUCTURES === +struct sWindowBlock +{ + tWindowBlock *Next; + tWindow *Windows[WINDOWS_PER_ALLOC]; +}; + +// === GLOBALS === + int giAxWin3_LowestFreeWinID; + int giAxWin3_HighestUsedWinID; +tWindowBlock gAxWin3_WindowList; // === CODE === -tHWND AxWin3_CreateWindow(tHWND Parent, const char *Renderer, int Flags) +tWindow *AxWin3_int_CreateWindowStruct(uint32_t ServerID, int ExtraBytes) +{ + tWindow *ret; + + ret = calloc(sizeof(tWindow) + ExtraBytes, 1); + ret->ServerID = ServerID; + + return ret; +} + +tHWND AxWin3_CreateWindow(tHWND Parent, const char *Renderer, int Flags, int DataBytes, void **DataPtr) { + tWindow *ret; + int newWinID; int dataSize = sizeof(tIPCMsg_CreateWin) + strlen(Renderer) + 1; tAxWin_IPCMessage *msg; tIPCMsg_CreateWin *create_win; - msg = alloca( sizeof(tAxWin_IPCMessage) + dataSize ); - create_win = msg->Data; + // TODO: Validate `Parent` - msg->ID = IPCMSG_CREATEWIN; - msg->Flags = 0; - msg->Window = Parent; // TODO: Validation - msg->Size = dataSize; + // Allocate a window ID + { + int idx; + tWindowBlock *block, *prev; + block = &gAxWin3_WindowList; + newWinID = giAxWin3_LowestFreeWinID; + for( idx = 0; block; newWinID ++ ) + { + if( block->Windows[idx] == NULL ) + break; + idx ++; + if(idx == WINDOWS_PER_ALLOC) { + prev = block; + block = block->Next; + idx = 0; + } + } + + if( !block ) + { + block = calloc(sizeof(tWindowBlock), 1); + prev->Next = block; + idx = 0; + } + + ret = block->Windows[idx] = AxWin3_int_CreateWindowStruct(newWinID, DataBytes); - create_win->NewWinID = AxWin3_int_AllocateWindowID(); + if(newWinID > giAxWin3_HighestUsedWinID) + giAxWin3_HighestUsedWinID = newWinID; + if(newWinID == giAxWin3_LowestFreeWinID) + giAxWin3_HighestUsedWinID ++; + } + + // Create message + msg = AxWin3_int_AllocateIPCMessage(Parent, IPCMSG_CREATEWIN, 0, dataSize); + create_win = (void*)msg->Data; + create_win->NewWinID = newWinID; create_win->Flags = Flags; strcpy(create_win->Renderer, Renderer); - return NULL; + // Send and clean up + AxWin3_int_SendIPCMessage(msg); + free(msg); + + // TODO: Detect errors in AxWin3_CreateWindow + + // Return success + if(DataPtr) *DataPtr = ret->Data; + return ret; } void AxWin3_DestroyWindow(tHWND Window) diff --git a/Usermode/include/axwin3/axwin.h b/Usermode/include/axwin3/axwin.h index e7ad5800..2c852437 100644 --- a/Usermode/include/axwin3/axwin.h +++ b/Usermode/include/axwin3/axwin.h @@ -8,14 +8,16 @@ #ifndef _AXWIN3_AXWIN_H_ #define _AXWIN3_AXWIN_H_ -typedef void *tHWND; +typedef struct sAxWin3_Window *tHWND; typedef void (*tAxWin3_MessageCallback)(int SourceTID, int Length); +typedef int (*tAxWin3_WindowMessageHandler)(tHWND Window, int Length, void *Data); + 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 tHWND AxWin3_CreateWindow(tHWND Parent, const char *Renderer, int Flags, int DataBytes, void **DataPtr); extern void AxWin3_DestroyWindow(tHWND Window); extern void AxWin3_SendMessage(tHWND Window, int Length, void *Data);