added struct subsys so that we know each
authorEleni Maria Stea <elene.mst@gmail.com>
Wed, 27 Mar 2013 00:13:31 +0000 (02:13 +0200)
committerEleni Maria Stea <elene.mst@gmail.com>
Wed, 27 Mar 2013 00:13:31 +0000 (02:13 +0200)
public struct's position in the shared memory

12 files changed:
src/fbdev/gfx.cc
src/fbdev/keyboard.cc
src/fbdev/mouse.cc
src/sdl/gfx.cc
src/sdl/mouse.cc
src/shalloc.cc
src/shalloc.h
src/text.cc
src/winnie.cc
src/winnie.h
src/wm.cc
src/wm.h

index 1421348..ff86d9c 100644 (file)
@@ -36,6 +36,7 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
 
 #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) {
index d1d5077..22f129a 100644 (file)
@@ -33,6 +33,7 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
 #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;
 
index bc2f29f..1fb2d55 100644 (file)
@@ -36,6 +36,7 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
 #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;
index 74aa94d..7e098b9 100644 (file)
@@ -26,6 +26,7 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
 
 #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;
index db39d4a..3ba98a0 100644 (file)
@@ -24,8 +24,9 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
 
 #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;
 }
index 3f47995..5d4715a 100644 (file)
@@ -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;
index 0e23159..bb0daf7 100644 (file)
@@ -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_
index 7f8c067..7dbae5d 100644 (file)
@@ -25,6 +25,7 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
 #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;
index 604a5e1..ffbe94d 100644 (file)
@@ -26,12 +26,18 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
 #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;
+}
index cd2c0b0..899357c 100644 (file)
@@ -31,7 +31,7 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
 #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
index cbb5443..621a23f 100644 (file)
--- a/src/wm.cc
+++ b/src/wm.cc
@@ -27,10 +27,11 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
 #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)
index e2e2487..46f4857 100644 (file)
--- a/src/wm.h
+++ b/src/wm.h
@@ -26,6 +26,7 @@ Author: Eleni Maria Stea <elene.mst@gmail.com>
 
 #include "geom.h"
 #include "pixmap.h"
+#include "winnie.h"
 
 class Window;