From 9261ecb0ad85bdf8b21e17b7309ddaeb76a57d96 Mon Sep 17 00:00:00 2001 From: Eleni Maria Stea Date: Wed, 27 Mar 2013 02:13:31 +0200 Subject: [PATCH] added struct subsys so that we know each public struct's position in the shared memory --- src/fbdev/gfx.cc | 3 +++ src/fbdev/keyboard.cc | 3 +++ src/fbdev/mouse.cc | 2 ++ src/sdl/gfx.cc | 3 +++ src/sdl/mouse.cc | 5 ++++- src/shalloc.cc | 5 +++++ src/shalloc.h | 2 ++ src/text.cc | 3 +++ src/winnie.cc | 14 ++++++++++++++ src/winnie.h | 4 +++- src/wm.cc | 13 ++++++++++--- src/wm.h | 1 + 12 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/fbdev/gfx.cc b/src/fbdev/gfx.cc index 1421348..ff86d9c 100644 --- a/src/fbdev/gfx.cc +++ b/src/fbdev/gfx.cc @@ -36,6 +36,7 @@ Author: Eleni Maria Stea #include "gfx.h" #include "shalloc.h" +#include "winnie.h" #define FRAMEBUFFER_SIZE(xsz, ysz, bpp) ((xsz) * (ysz) * (bpp) / CHAR_BIT) @@ -58,6 +59,8 @@ bool init_gfx() return false; } + get_subsys()->graphics_offset = (int)((char*)gfx - (char*)get_pool()); + dev_fd = -1; if((dev_fd = open("/dev/fb0", O_RDWR)) == -1) { diff --git a/src/fbdev/keyboard.cc b/src/fbdev/keyboard.cc index d1d5077..22f129a 100644 --- a/src/fbdev/keyboard.cc +++ b/src/fbdev/keyboard.cc @@ -33,6 +33,7 @@ Author: Eleni Maria Stea #include "keyboard.h" #include "shalloc.h" #include "window.h" +#include "winnie.h" #include "wm.h" struct Keyboard { @@ -48,6 +49,8 @@ bool init_keyboard() return false; } + get_subsys()->keyboard_offset = (int)((char*)keyboard - (char*)get_pool()); + keyboard->ttystate = keyboard->CANONICAL; keyboard->dev_fd = -1; diff --git a/src/fbdev/mouse.cc b/src/fbdev/mouse.cc index bc2f29f..1fb2d55 100644 --- a/src/fbdev/mouse.cc +++ b/src/fbdev/mouse.cc @@ -36,6 +36,7 @@ Author: Eleni Maria Stea #include "mouse.h" #include "shalloc.h" #include "window.h" +#include "winnie.h" #include "wm.h" #define BN_LEFT 1 @@ -59,6 +60,7 @@ bool init_mouse() if(!(mouse = (Mouse*)sh_malloc(sizeof *mouse))) { return false; } + get_subsys()->mouse_offset = (int)((char*)mouse - (char*)get_pool()); memset(mouse, 0, sizeof *mouse); mouse->dev_fd = -1; diff --git a/src/sdl/gfx.cc b/src/sdl/gfx.cc index 74aa94d..7e098b9 100644 --- a/src/sdl/gfx.cc +++ b/src/sdl/gfx.cc @@ -26,6 +26,7 @@ Author: Eleni Maria Stea #include "gfx.h" #include "shalloc.h" +#include "winnie.h" static SDL_Surface *fbsurf; @@ -49,6 +50,8 @@ bool init_gfx() return false; } + get_subsys()->graphics_offset = (int)((char*)gfx - (char*)get_pool()); + Rect scr_rect(0, 0, 1024, 768); gfx->screen_rect = scr_rect; gfx->color_depth = 32; diff --git a/src/sdl/mouse.cc b/src/sdl/mouse.cc index db39d4a..3ba98a0 100644 --- a/src/sdl/mouse.cc +++ b/src/sdl/mouse.cc @@ -24,8 +24,9 @@ Author: Eleni Maria Stea #include "mouse.h" #include "shalloc.h" -#include "window.h" #include "wm.h" +#include "window.h" +#include "winnie.h" extern SDL_Event sdl_event; @@ -42,6 +43,8 @@ bool init_mouse() if(!(mouse = (Mouse*)sh_malloc(sizeof *mouse))) { return false; } + get_subsys()->mouse_offset = (int)((char*)mouse - (char*)get_pool()); + memset(mouse, 0, sizeof *mouse); return true; } diff --git a/src/shalloc.cc b/src/shalloc.cc index 3f47995..5d4715a 100644 --- a/src/shalloc.cc +++ b/src/shalloc.cc @@ -144,6 +144,11 @@ void sh_free(void *ptr) } } +void *get_pool() +{ + return (void*)pool; +} + static bool is_allocated(int block_number) { int idx = block_number / 32; diff --git a/src/shalloc.h b/src/shalloc.h index 0e23159..bb0daf7 100644 --- a/src/shalloc.h +++ b/src/shalloc.h @@ -30,4 +30,6 @@ void destroy_shared_memory(); void *sh_malloc(size_t bytes); void sh_free(void *ptr); +void *get_pool(); + #endif // SHALLOC_H_ diff --git a/src/text.cc b/src/text.cc index 7f8c067..7dbae5d 100644 --- a/src/text.cc +++ b/src/text.cc @@ -25,6 +25,7 @@ Author: Eleni Maria Stea #include "gfx.h" #include "shalloc.h" #include "text.h" +#include "winnie.h" #define DPI 72 #define FONT_PATH "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf" @@ -47,6 +48,8 @@ bool init_text() return false; } + get_subsys()->text_offset = (int)((char*)text - (char*)get_pool()); + if(FT_Init_FreeType(&text->ft_lib)) { fprintf(stderr, "Failed to initialize the FreeType library!\n"); return false; diff --git a/src/winnie.cc b/src/winnie.cc index 604a5e1..ffbe94d 100644 --- a/src/winnie.cc +++ b/src/winnie.cc @@ -26,12 +26,18 @@ Author: Eleni Maria Stea #include "shalloc.h" #include "winnie.h" +static Subsys *subsys; + bool winnie_init() { if(!init_shared_memory()) { return false; } + if(!(subsys = (Subsys*)sh_malloc(sizeof *subsys))) { + return false; + } + if(!init_gfx()) { return false; } @@ -62,6 +68,9 @@ void winnie_shutdown() destroy_keyboard(); destroy_mouse(); destroy_text(); + destroy_window_manager(); + + sh_free(subsys); destroy_shared_memory(); } @@ -80,3 +89,8 @@ long winnie_get_time() return (tv.tv_usec - init_tv.tv_usec) / 1000 + (tv.tv_sec - init_tv.tv_sec) * 1000; } + +Subsys *get_subsys() +{ + return subsys; +} diff --git a/src/winnie.h b/src/winnie.h index cd2c0b0..899357c 100644 --- a/src/winnie.h +++ b/src/winnie.h @@ -31,7 +31,7 @@ Author: Eleni Maria Stea #include "window.h" #include "wm.h" -struct subsys { +struct Subsys { int graphics_offset; int keyboard_offset; int mouse_offset; @@ -44,4 +44,6 @@ void winnie_shutdown(); long winnie_get_time(); +Subsys *get_subsys(); + #endif diff --git a/src/wm.cc b/src/wm.cc index cbb5443..621a23f 100644 --- a/src/wm.cc +++ b/src/wm.cc @@ -27,10 +27,11 @@ Author: Eleni Maria Stea #include "gfx.h" #include "mouse.h" #include "mouse_cursor.h" +#include "shalloc.h" #include "text.h" -#include "wm.h" #include "window.h" #include "winnie.h" +#include "wm.h" #define DCLICK_INTERVAL 400 @@ -42,16 +43,22 @@ static void motion(Window *win, int x, int y); bool init_window_manager() { - if(!(wm = new WindowManager)) { + void *wm_mem; + if(!(wm_mem = sh_malloc(sizeof *wm))) { return false; } + wm = new (wm_mem) WindowManager; + + get_subsys()->wm_offset = (int)((char*)wm - (char*)get_pool()); + return true; } void destroy_window_manager() { - delete wm; + wm->~WindowManager(); + sh_free(wm); } void WindowManager::create_frame(Window *win) diff --git a/src/wm.h b/src/wm.h index e2e2487..46f4857 100644 --- a/src/wm.h +++ b/src/wm.h @@ -26,6 +26,7 @@ Author: Eleni Maria Stea #include "geom.h" #include "pixmap.h" +#include "winnie.h" class Window; -- 1.7.10.4