Author: abroekhuis
Date: Thu Nov  3 11:01:50 2011
New Revision: 1197062

URL: http://svn.apache.org/viewvc?rev=1197062&view=rev
Log:
Updated Paint example

Disabled assignable check due to module and service layer mixup in Celix

Added:
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/gtktest.glade
Modified:
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/src/circle_shape.c
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/CMakeLists.txt
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/MANIFEST/MANIFEST.MF
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/default_shape.h
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/paint_frame.h
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/shape_component.h
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/activator.c
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/paint_frame.c
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/shape_component.c
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/square/private/src/square_shape.c
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle_shape.c
    incubator/celix/trunk/framework/private/src/service_reference.c

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/src/circle_shape.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/src/circle_shape.c?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/src/circle_shape.c
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/src/circle_shape.c
 Thu Nov  3 11:01:50 2011
@@ -40,6 +40,7 @@ celix_status_t circleShape_create(BUNDLE
                                if (!*shape) {
                                        status = CELIX_ENOMEM;
                                } else {
+                                       (*shape)->name = "Circle";
                                        (*shape)->icon_path = NULL;
                                        celix_status_t status = 
bundle_getEntry(bundle, CIRCLE_FILE, pool, &(*shape)->icon_path);
                                        if (status == CELIX_SUCCESS) {

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/CMakeLists.txt
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/CMakeLists.txt?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/CMakeLists.txt
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/CMakeLists.txt
 Thu Nov  3 11:01:50 2011
@@ -20,6 +20,7 @@ cmake_policy(SET CMP0014 NEW)
 pkg_search_module (GLIB  REQUIRED glib-2.0)
 pkg_search_module (GTHR  REQUIRED gthread-2.0)
 pkg_search_module (GTK   REQUIRED gtk+-2.0)
+pkg_search_module (GMODULE   REQUIRED gmodule-2.0)
 include_directories(
        ../circle/public/include
        ../square/public/include
@@ -32,19 +33,21 @@ include_directories(
 include_directories(${GTK_INCLUDE_DIRS})
 include_directories(${GLIB_INCLUDE_DIRS})
 include_directories(${GTHR_INCLUDE_DIRS})
+include_directories(${GMODULE_INCLUDE_DIRS})
 
 link_directories(${GTK_LIBRARY_DIRS})
 link_directories(${GLIB_LIBRARY_DIRS})
 link_directories(${GTHR_LIBRARY_DIRS})
+link_directories(${GMODULE_LIBRARY_DIRS})
 
 add_library(chapter04-paint-example SHARED 
        private/src/activator
        private/src/default_shape
-       private/src/paint_frame
        private/src/shape_component
+       private/src/paint_frame
  )
 include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
 include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include")
-target_link_libraries(chapter04-paint-example framework ${GLIB_LIBRARIES} 
${GTK_LIBRARIES} ${GTHR_LIBRARIES})
+target_link_libraries(chapter04-paint-example framework ${MODULE_LIBRARIES} 
${GLIB_LIBRARIES} ${GTK_LIBRARIES} ${GTHR_LIBRARIES})
 
-bundle(chapter04-paint-example FILES private/src/underc.png)
+bundle(chapter04-paint-example FILES private/src/underc.png gtktest.glade)

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/MANIFEST/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/MANIFEST/MANIFEST.MF?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/MANIFEST/MANIFEST.MF
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/MANIFEST/MANIFEST.MF
 Thu Nov  3 11:01:50 2011
@@ -1,6 +1,3 @@
 Bundle-SymbolicName: chapter04-paint-example
 Bundle-Version: 1.0.0
 library: chapter04-paint-example
-Import-Service: simple_shape
-
-

Added: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/gtktest.glade
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/gtktest.glade?rev=1197062&view=auto
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/gtktest.glade
 (added)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/gtktest.glade
 Thu Nov  3 11:01:50 2011
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="2.24"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">600</property>
+    <property name="height_request">400</property>
+    <property name="can_focus">False</property>
+    <signal name="destroy" handler="on_window1_destroy" swapped="no"/>
+    <child>
+      <object class="GtkVBox" id="vbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <child>
+          <object class="GtkToolbar" id="toolbar1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkDrawingArea" id="drawingarea1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="events">GDK_EXPOSURE_MASK | 
GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK 
| GDK_STRUCTURE_MASK</property>
+            <signal name="button-press-event" handler="newFrame_mousePressed" 
after="yes" swapped="no"/>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/default_shape.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/default_shape.h?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/default_shape.h
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/default_shape.h
 Thu Nov  3 11:01:50 2011
@@ -8,8 +8,6 @@
 #ifndef DEFAULT_SHAPE_H_
 #define DEFAULT_SHAPE_H_
 
-#define PAINT_FRAME_SERVICE_NAME "paint"
-
 extern SIMPLE_SHAPE defaultShape_create(BUNDLE_CONTEXT context);
 
 #endif /* DEFAULT_SHAPE_H_ */

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/paint_frame.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/paint_frame.h?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/paint_frame.h
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/paint_frame.h
 Thu Nov  3 11:01:50 2011
@@ -8,33 +8,32 @@
 #ifndef PAINT_FRAME_H_
 #define PAINT_FRAME_H_
 
-static const int BOX = 54;
-
 #define PAINT_FRAME_SERVICE_NAME "paint"
 
 struct paint_frame {
-       GtkWidget *m_toolBar;
+       apr_pool_t *pool;
+       GtkWidget *window;
+       GtkWidget *drawingArea;
+       GtkWidget *toolbar;
+       GdkPixmap *pixMap;
+       bool showing;
+
        char *m_selected;
-       GtkWidget *m_mainPanel, *m_window, *m_drawingArea;
-       GdkPixmap *m_pixMap;
-       //SHAPE_COMPONENT *m_selectedComponent;
        HASH_MAP m_shapes;
-       //private ActionListener m_reusableActionListener = new 
ShapeActionListener();
        SIMPLE_SHAPE m_defaultShape;
        LINKED_LIST m_shapeComponents;
-       /* methods */
-       void (*paintFrame_show)(void);
-       void (*paintFrame_selectShape)(char *name);
-       SIMPLE_SHAPE (*paintFrame_getShape)(char *name);
-       void (*paintFrame_addShape)(BUNDLE_CONTEXT context, char* name, void 
*icon, SIMPLE_SHAPE shape);
-       void (*paintFrame_removeShape)(char *name);
+       BUNDLE_CONTEXT context;
+       GThread *main;
 };
 
 
 typedef struct paint_frame *PAINT_FRAME;
-extern PAINT_FRAME paintFrame_create(BUNDLE_CONTEXT context, apr_pool_t *pool);
-
+celix_status_t paintFrame_create(BUNDLE_CONTEXT context, apr_pool_t *pool, 
PAINT_FRAME *frame);
+celix_status_t paintFrame_exit(PAINT_FRAME frame);
 
+SIMPLE_SHAPE paintFrame_getShape(PAINT_FRAME frame, char *name);
+celix_status_t paintFrame_addShape(PAINT_FRAME frame, BUNDLE_CONTEXT context, 
SIMPLE_SHAPE shape);
+celix_status_t paintFrame_removeShape(PAINT_FRAME frame, SIMPLE_SHAPE sshape);
 
 
 #endif /* PAINT_FRAME_H_ */

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/shape_component.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/shape_component.h?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/shape_component.h
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/include/shape_component.h
 Thu Nov  3 11:01:50 2011
@@ -7,17 +7,20 @@
 
 #ifndef SHAPE_COMPONENT_H_
 #define SHAPE_COMPONENT_H_
+
+#include "paint_frame.h"
+
 typedef struct shape_component *SHAPE_COMPONENT;
 
 struct shape_component {
-       char shapeName[30];
+       char *shapeName;
        PAINT_FRAME m_frame;
        gdouble x, y, w, h;
        void (*shapeComponent_paintComponent)(SHAPE_COMPONENT shapeComponent, 
PAINT_FRAME frame,
                        GdkPixmap *pixMap, GtkWidget *widget);
 };
 
-extern SHAPE_COMPONENT shapeComponent_create(PAINT_FRAME frame, char 
*shapeName,
+extern SHAPE_COMPONENT shapeComponent_create(PAINT_FRAME frame, SIMPLE_SHAPE 
sshape,
                gdouble x, gdouble y);
 
 #endif /* SHAPE_COMPONENT_H_ */

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/activator.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/activator.c?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/activator.c
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/activator.c
 Thu Nov  3 11:01:50 2011
@@ -56,7 +56,8 @@ celix_status_t bundleActivator_create(BU
                activator->reg = NULL;
                activator->pool = pool;
                activator->context = context;
-               activator->paint_frame = paintFrame_create(context, pool);
+               activator->paint_frame = NULL;
+               status = paintFrame_create(context, pool, 
&activator->paint_frame);
         cust = (SERVICE_TRACKER_CUSTOMIZER) apr_palloc(pool, sizeof(*cust));
         cust->handle = activator;
         cust->addedService = addedServ;
@@ -65,6 +66,7 @@ celix_status_t bundleActivator_create(BU
         cust->removedService = removedServ;
         serviceTracker_create(context, SIMPLE_SHAPE_SERVICE_NAME, cust, 
&activator->tracker);
                serviceTracker_open(activator->tracker);
+
        }
        return status;
 }
@@ -72,14 +74,13 @@ celix_status_t bundleActivator_create(BU
 celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT ctx) {
        struct paintFrameActivatorData * act = (struct paintFrameActivatorData 
*) userData;
        celix_status_t status = CELIX_SUCCESS;
-    status = bundleContext_registerService(ctx, PAINT_FRAME_SERVICE_NAME,
-               act->paint_frame, NULL, &act->reg);
        return status;
 }
 
 celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
        struct paintFrameActivatorData * act = (struct paintFrameActivatorData 
*) userData;
        serviceTracker_close(act->tracker);
+       paintFrame_exit(act->paint_frame);
        return CELIX_SUCCESS;
 }
 
@@ -97,7 +98,7 @@ celix_status_t addingServ(void * handle,
 celix_status_t addedServ(void * handle, SERVICE_REFERENCE ref, void * service) 
{
        struct paintFrameActivatorData * data = (struct paintFrameActivatorData 
*) handle;
        char * serviceName = properties_get(ref->registration->properties, 
"name");
-       data->paint_frame->paintFrame_addShape(data->context, serviceName, 
NULL, service);
+       paintFrame_addShape(data->paint_frame, data->context, service);
        return CELIX_SUCCESS;
  }
 
@@ -110,6 +111,6 @@ celix_status_t modifiedServ(void * handl
 celix_status_t removedServ(void * handle, SERVICE_REFERENCE ref, void * 
service) {
        struct paintFrameActivatorData * data = (struct paintFrameActivatorData 
*) handle;
        char * serviceName = properties_get(ref->registration->properties, 
"name");
-       data->paint_frame->paintFrame_removeShape(serviceName);
+       paintFrame_removeShape(data->paint_frame, service);
        return CELIX_SUCCESS;
 }

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/paint_frame.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/paint_frame.c?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/paint_frame.c
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/paint_frame.c
 Thu Nov  3 11:01:50 2011
@@ -15,12 +15,13 @@
  **/
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <gtk/gtk.h>
 #include <string.h>
 #include <stdbool.h>
-#include <stdlib.h>
 #include <glib.h>
-#include <gtk/gtk.h>
 #include <gdk/gdk.h>
+#include "headers.h"
 #include "bundle_context.h"
 #include "bundle.h"
 #include "utils.h"
@@ -31,156 +32,181 @@
 #include "paint_frame.h"
 #include "shape_component.h"
 #include "default_shape.h"
+#include "celix_errno.h"
 
 static PAINT_FRAME this = NULL;
 
-struct gtk_thread_data {
-       apr_pool_t *pool;
-       BUNDLE_CONTEXT context;
-};
 struct shape_info {
        char *name;
-       SIMPLE_SHAPE m_shape;
+       SIMPLE_SHAPE shape;
        GtkWidget *button;
 };
 
-typedef struct shape_info *SHAPE_INFO;
+typedef struct shape_info *shape_info_t;
+static celix_status_t paintFrame_redraw(PAINT_FRAME frame, GdkModifierType 
state);
+static celix_status_t paintFrame_show(PAINT_FRAME frame);
+static void paintFrame_destroy(GtkWidget *widget, gpointer data);
+static void paintFrame_expose(GtkWidget *widget, GdkEventExpose *event, 
gpointer data);
+static void paintFrame_configure(GtkWidget *widget, GdkEventConfigure *event, 
gpointer data);
+static void paintFrame_buttonClicked(GtkWidget *button, gpointer data);
+static gboolean paintFrame_mousePressed( GtkWidget *widget, GdkEventButton 
*event, gpointer data);
+static gpointer paintFrame_gtkmain(gpointer a_data);
+static void paintFrame_destroyWidgets(PAINT_FRAME frame);
 
+/**
+ * Default constructor that populates the main window.
+ **/
+celix_status_t paintFrame_create(BUNDLE_CONTEXT context, apr_pool_t *pool, 
PAINT_FRAME *frame) {
+       celix_status_t status = CELIX_SUCCESS;
+       apr_pool_t *mypool = NULL;
+       apr_pool_create(&mypool, pool);
+       this = malloc(sizeof(*this));
+       if (!this) {
+               this = NULL;
+               status = CELIX_ENOMEM;
+       } else {
+               *frame = this;
+               GtkBuilder *builder;
+               char *builderFile;
+               BUNDLE bundle;
+               GError *error = NULL;
+
+               (*frame)->showing = false;
+               (*frame)->pool = mypool;
+               (*frame)->pixMap = NULL;
+               (*frame)->m_selected = NULL;
+               (*frame)->context = context;
+               (*frame)->m_shapes = hashMap_create(string_hash, NULL, 
string_equals, NULL);
+               (*frame)->m_defaultShape = 
defaultShape_create((*frame)->context);
+               linkedList_create((*frame)->pool, &(*frame)->m_shapeComponents);
+
+
+               status = bundleContext_getBundle(context, &bundle);
+               if (status == CELIX_SUCCESS) {
+                       status = bundle_getEntry(bundle, "gtktest.glade", 
mypool, &builderFile);
+                       if (status == CELIX_SUCCESS) {
+                               g_thread_init(NULL);
+                               gdk_threads_init();
+                               gtk_init(NULL, NULL);
+
+                               builder = gtk_builder_new();
+                               gtk_builder_add_from_file(builder, builderFile, 
NULL);
+
+                               (*frame)->window = 
GTK_WIDGET(gtk_builder_get_object (builder, "window1"));
+                               (*frame)->toolbar = 
GTK_WIDGET(gtk_builder_get_object (builder, "toolbar1"));
+                               (*frame)->drawingArea = 
GTK_WIDGET(gtk_builder_get_object (builder, "drawingarea1"));
+                               g_object_unref(G_OBJECT(builder));
+
+                               
gtk_window_set_title(GTK_WINDOW((*frame)->window), "OSGi in Action, 
Paint-Example");
+
+                               gtk_widget_set_events ((*frame)->drawingArea, 
GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
+
+                               g_signal_connect(G_OBJECT((*frame)->window), 
"destroy", G_CALLBACK(paintFrame_destroy), (*frame));
+                               
g_signal_connect(G_OBJECT((*frame)->drawingArea), "expose_event", 
G_CALLBACK(paintFrame_expose), (*frame));
+                               
g_signal_connect(G_OBJECT((*frame)->drawingArea), "configure_event", 
G_CALLBACK(paintFrame_configure), (*frame));
+                               
g_signal_connect(G_OBJECT((*frame)->drawingArea), "button_press_event", 
G_CALLBACK(paintFrame_mousePressed), (*frame));
+
+
+                               paintFrame_show((*frame));
+                               (*frame)->showing = true;
+
+                               if( g_thread_supported()) {
+                                       (*frame)->main = 
g_thread_create(paintFrame_gtkmain, (*frame), TRUE, &error);
+                                       if ((*frame)->main == NULL){
+                                               g_printerr ("Failed to create 
thread: %s\n", error->message);
+                                               status = CELIX_BUNDLE_EXCEPTION;
+                                       }
+                               } else {
+                                       g_printerr("g_thread NOT supported\n");
+                               }
+                       }
+               }
+       }
 
-static SHAPE_INFO shapeInfo_create(char* name, GtkWidget *button, SIMPLE_SHAPE 
shape){
-       SHAPE_INFO info = malloc(sizeof(*info));
-       info->m_shape = shape;
-       info->name = name;
-       info->button = button;
-       return info;
-}
-static void paintFrame_show() {
-       gtk_widget_show (this->m_drawingArea);
-       gtk_widget_show (this->m_mainPanel);
-       gtk_widget_show (this->m_toolBar);
-       gtk_widget_show (this->m_window);
+       return status;
 }
 
-/* main function */
-static gpointer _gtkthread(gpointer a_data) {
+celix_status_t paintFrame_exit(PAINT_FRAME frame) {
+       frame->showing = false;
+
+       paintFrame_destroyWidgets(frame);
+
        gdk_threads_enter();
-       gtk_main ();
+
+       gtk_main_quit();
+
        gdk_threads_leave();
-       return NULL;
-}
 
-static void redraw(GtkWidget *widget, GdkModifierType state){
-       if (this->m_pixMap != NULL) {
-               GdkRectangle update_rect;
+       g_thread_join(frame->main);
 
-               update_rect.x = 0;
-               update_rect.y = 0;
-               update_rect.width = widget->allocation.width;
-               update_rect.height = widget->allocation.height;
-               gdk_draw_rectangle (this->m_pixMap,
-                               widget->style->white_gc,
-                               TRUE,
-                               update_rect.x, update_rect.y,
-                               update_rect.width, update_rect.height);
-               gtk_widget_draw(widget, &update_rect);
-               LINKED_LIST_ITERATOR it = 
linkedListIterator_create(this->m_shapeComponents, 0);
-               while (linkedListIterator_hasNext(it)){
-                       SHAPE_COMPONENT sc = linkedListIterator_next(it);
-                       (*sc->shapeComponent_paintComponent)(sc, this, 
this->m_pixMap, widget);
-               }
-       }
+       return CELIX_SUCCESS;
 }
 
+static celix_status_t shapeInfo_create(PAINT_FRAME frame, char* name, 
GtkWidget *button, SIMPLE_SHAPE shape, shape_info_t *info){
+       *info = malloc(sizeof(**info));
+       (*info)->shape = shape;
+       (*info)->name = name;
+       (*info)->button = button;
+       return CELIX_SUCCESS;
+}
+static celix_status_t paintFrame_show(PAINT_FRAME frame) {
+       gtk_widget_show(frame->drawingArea);
+       gtk_widget_show(frame->toolbar);
+       gtk_widget_show(frame->window);
 
-static void button_handler( GtkWidget *widget,
-                          gpointer   data )
-{
-    this->m_selected = (gchar *) data;
-}
-static void destroy( GtkWidget *widget,
-                     gpointer   data )
-{
-    gtk_main_quit ();
-}
-static gboolean delete(GtkWidget *widget,
-                     gpointer   data )
-{
-    gtk_main_quit ();
-    return TRUE;
+       return CELIX_SUCCESS;
 }
-/******************************** mouse event handler *******************/
+
 /**
- * notification of a mouse motion
- */
-static gboolean
-motion_notify_event( GtkWidget *widget, GdkEventMotion *event )
-{
-  int x, y;
-  GdkModifierType state;
-  if (event->is_hint) {
-    gdk_window_get_pointer (event->window, &x, &y, &state);
-  } else {
-      x = event->x;
-      y = event->y;
-      state = event->state;
-    }
-  return TRUE;
-}
-/******************************** drawable event handler *******************/
-/* Redraw the screen from the backing pixmap */
-static gboolean
-expose_event( GtkWidget *widget, GdkEventExpose *event )
-{
-       gdk_draw_drawable(widget->window,
-                       widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
-                       this->m_pixMap,
-                       event->area.x, event->area.y,
-                       event->area.x, event->area.y,
-                       event->area.width, event->area.height);
-       return TRUE;
-}
-/* configuration events  */
-static gboolean
-configure_event( GtkWidget *widget, GdkEventConfigure *event )
-{
-  if (this->m_pixMap) {
-    g_object_unref(this->m_pixMap);
-  }
-
-  this->m_pixMap = gdk_pixmap_new(widget->window,
-              widget->allocation.width,
-              widget->allocation.height,
-              -1);
-  redraw(widget, 0);
-  return TRUE;
-}
-
-static gboolean
-button_press_event( GtkWidget *widget, GdkEventButton *event )
-{
-  if (event->button == 1 && this->m_pixMap != NULL) {
-         if (this->m_selected == NULL){
-                printf("no button selected yet\n");
-         } else {
-           SHAPE_COMPONENT sc = shapeComponent_create(this, this->m_selected, 
event->x, event->y);
-           linkedList_addFirst(this->m_shapeComponents, sc);
-           (*sc->shapeComponent_paintComponent)(sc, this, this->m_pixMap, 
widget);
-         }
-  }
-  return TRUE;
-}
+ * Injects an available <tt>SimpleShape</tt> into the drawing frame.
+ *
+ * @param name The name of the injected <tt>SimpleShape</tt>.
+ * @param icon The icon associated with the injected <tt>SimpleShape</tt>.
+ * @param shape The injected <tt>SimpleShape</tt> instance.
+ **/
+celix_status_t paintFrame_addShape(PAINT_FRAME frame, BUNDLE_CONTEXT context, 
SIMPLE_SHAPE shape) {
+       celix_status_t status = CELIX_SUCCESS;
 
+       gdk_threads_enter();
+       GError *gerror = NULL;
+       GtkWidget *button = gtk_button_new();
+       gtk_widget_set_name((GtkWidget *) button, shape->name);
+       GtkWidget *im = gtk_image_new_from_file(shape->icon_path);
+       gtk_button_set_image((GtkButton *) button, im);
+       gtk_toolbar_append_widget((GtkToolbar *) frame->toolbar, (GtkWidget *) 
button, "", "");
+       g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK 
(paintFrame_buttonClicked), frame);
+       gtk_widget_show(button);
+       if (hashMap_get(frame->m_shapes, shape->name) == NULL) {
+               shape_info_t info = NULL;
+               shapeInfo_create(frame, shape->name, button, shape, &info);
+               hashMap_put(frame->m_shapes, shape->name, info);
+       }
+       paintFrame_redraw(frame, 0);
+       paintFrame_show(frame);
+       gdk_threads_leave();
+
+       return status;
+}
 
 /**
- * This method sets the currently selected shape to be used for drawing on the
- * canvas.
+ * Removes a no longer available <tt>SimpleShape</tt> from the drawing frame.
  *
- * @param name The name of the shape to use for drawing on the canvas.
+ * @param name The name of the <tt>SimpleShape</tt> to remove.
  **/
-void paintFrame_selectShape(char *name) {
+celix_status_t paintFrame_removeShape(PAINT_FRAME frame, SIMPLE_SHAPE sshape) {
+       celix_status_t status = CELIX_SUCCESS;
        gdk_threads_enter();
-       this->m_selected = name;
+       shape_info_t shape = (shape_info_t) hashMap_remove(this->m_shapes, 
sshape->name);
+       if (shape != NULL) {
+               this->m_selected = NULL;
+               gtk_widget_destroy(GTK_WIDGET(shape->button));
+               gtk_widget_show_all(this->toolbar);
+               paintFrame_redraw(this, 0);
+               paintFrame_show(this);
+       }
        gdk_threads_leave();
+
+       return status;
 }
 
 /**
@@ -191,147 +217,112 @@ void paintFrame_selectShape(char *name) 
  * @return The corresponding <tt>SimpleShape</tt> instance if available or
  *         <tt>null</tt>.
  **/
-SIMPLE_SHAPE paintFrame_getShape(char *name) {
-       SHAPE_INFO info = (SHAPE_INFO) hashMap_get(this->m_shapes, name);
+SIMPLE_SHAPE paintFrame_getShape(PAINT_FRAME frame, char *name) {
+       shape_info_t info = (shape_info_t) hashMap_get(frame->m_shapes, name);
        if (info == NULL) {
-               return this->m_defaultShape;
+               return frame->m_defaultShape;
        } else {
-               return info->m_shape;
+               return info->shape;
        }
 }
 
-/**
- * Injects an available <tt>SimpleShape</tt> into the drawing frame.
- *
- * @param name The name of the injected <tt>SimpleShape</tt>.
- * @param icon The icon associated with the injected <tt>SimpleShape</tt>.
- * @param shape The injected <tt>SimpleShape</tt> instance.
- **/
-void paintFrame_addShape(BUNDLE_CONTEXT context, char* name, void *icon, 
SIMPLE_SHAPE shape) {
+static void paintFrame_destroy(GtkWidget *widget, gpointer data) {
+       PAINT_FRAME frame = data;
+       BUNDLE bundle = NULL;
+
+       frame->showing = false;
+
+       bundleContext_getBundleById(frame->context, 0, &bundle);
+       bundle_stop(bundle, 0);
+}
+
+static void paintFrame_destroyWidgets(PAINT_FRAME frame) {
        gdk_threads_enter();
-       char png_file[30], *path;
-       GError *gerror = NULL;
-       BUNDLE bundle;
-       apr_pool_t *pool;
-       /* Add the buttons to the graph navigation panel. */
-       GtkWidget *button = gtk_button_new();
-       sprintf(png_file, "%s.png", name);
-       bundleContext_getBundle(context, &bundle);
-       bundleContext_getMemoryPool(context, &pool);
-       celix_status_t status = bundle_getEntry(bundle, png_file, pool, &path);
-       if (status == CELIX_SUCCESS) {
-               GtkWidget *im = gtk_image_new_from_file(path);
-               gtk_button_set_image((GtkButton *) button, im);
-               gsize rd = 0, wr = 0;
-               gchar *gfn = g_locale_to_utf8(name, strlen(name), &rd, &wr, 
&gerror);
-               //gtk_widget_set_size_request(button, 10, 10);
-               gtk_button_set_label((GtkButton *) button, gfn);
-               gtk_box_pack_start (GTK_BOX(this->m_toolBar), button, TRUE, 
TRUE, 0);
-       } else {
-               printf("Cannot find resource %s\n", png_file);
+
+       if (frame->pixMap != NULL) {
+               gdk_pixmap_unref(frame->pixMap);
        }
-       g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK 
(button_handler), name);
-       gtk_widget_show(button);
-       if (hashMap_get(this->m_shapes, name) == NULL) {
-               hashMap_put(this->m_shapes, name, shapeInfo_create(name, 
button, shape));
+       if (frame->toolbar != NULL) {
+               gtk_widget_destroy(frame->toolbar);
+       }
+       if (frame->drawingArea != NULL) {
+               gtk_widget_destroy(frame->drawingArea);
        }
-       redraw(this->m_drawingArea, 0);
-       paintFrame_show();
+       if (frame->window != NULL) {
+               gtk_widget_destroy(frame->window);
+       }
+
+       frame->pixMap = NULL;
+       frame->toolbar = NULL;
+       frame->window = NULL;
+       frame->drawingArea = NULL;
+
        gdk_threads_leave();
 }
 
-/**
- * Removes a no longer available <tt>SimpleShape</tt> from the drawing frame.
- *
- * @param name The name of the <tt>SimpleShape</tt> to remove.
- **/
-void paintFrame_removeShape(char *name) {
-       gdk_threads_enter();
-       SHAPE_INFO shape = (SHAPE_INFO) hashMap_remove(this->m_shapes, name);
-       this->m_selected = NULL;
-       gtk_container_remove(GTK_CONTAINER(this->m_toolBar), shape->button);
-       gtk_widget_show_all(this->m_toolBar);
-       redraw(this->m_drawingArea, 0);
-       paintFrame_show();
-       gdk_threads_leave();
+static void paintFrame_configure(GtkWidget *widget, GdkEventConfigure *event, 
gpointer data) {
+       PAINT_FRAME frame = data;
+       if (frame->pixMap != NULL) {
+               gdk_pixmap_unref(frame->pixMap);
+       }
+
+       frame->pixMap = gdk_pixmap_new(widget->window, 
widget->allocation.width, widget->allocation.height, -1);
+       paintFrame_redraw(frame, 0);
 }
 
+static void paintFrame_expose(GtkWidget *widget, GdkEventExpose *event, 
gpointer data) {
+       PAINT_FRAME frame = data;
+       gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE 
(widget)], frame->pixMap,
+                       event->area.x, event->area.y, event->area.x, 
event->area.y, event->area.width, event->area.height);
+}
+
+static void paintFrame_buttonClicked(GtkWidget *button, gpointer data) {
+       PAINT_FRAME frame = data;
+       frame->m_selected = (char *) gtk_widget_get_name(button);
+}
+
+static gboolean paintFrame_mousePressed( GtkWidget *widget, GdkEventButton 
*event, gpointer data) {
+       PAINT_FRAME frame = data;
+       if (event->button == 1 && frame->pixMap != NULL) {
+               if (frame->m_selected == NULL){
+                       printf("no button selected yet\n");
+               } else {
+                       SHAPE_COMPONENT sc = shapeComponent_create(frame, 
paintFrame_getShape(frame, frame->m_selected), event->x, event->y);
+                       linkedList_addFirst(frame->m_shapeComponents, sc);
+                       (*sc->shapeComponent_paintComponent)(sc, frame, 
frame->pixMap, widget);
+               }
+       }
+       return TRUE;
+}
 
-/**
- * Default constructor that populates the main window.
- **/
-PAINT_FRAME paintFrame_create(BUNDLE_CONTEXT context, apr_pool_t *pool) {
-       GError *error = NULL;
-       GThread *l_th;
-       struct gtk_thread_data *data = apr_palloc(pool, sizeof(*data));
-       data->pool = pool;
-       data->context = context;
-       this = malloc(sizeof(*this));
-       /* set the methods */
-       this->paintFrame_addShape = paintFrame_addShape;
-       this->paintFrame_getShape = paintFrame_getShape;
-       this->paintFrame_removeShape = paintFrame_removeShape;
-       this->paintFrame_selectShape = paintFrame_selectShape;
-       this->paintFrame_show = paintFrame_show;
-       this->m_selected = NULL;
-       this->m_pixMap = NULL;
-       g_thread_init(NULL);
-       gdk_threads_init();
-       gtk_init(NULL, NULL);
-       this->m_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-       gtk_container_set_border_width (GTK_CONTAINER (this->m_window), 10);
-       gtk_window_set_title (GTK_WINDOW (this->m_window), "OSGi in Action, 
Paint-Example");
-
-       g_signal_connect (G_OBJECT (this->m_window), "delete_event",
-                       G_CALLBACK (delete), NULL);
-
-       g_signal_connect (G_OBJECT (this->m_window), "destroy",
-                       G_CALLBACK (destroy), NULL);
-       /* Create the graph navigation panel and add it to the window. */
-       this->m_toolBar = gtk_hbox_new (FALSE, 0);
-       this->m_mainPanel = gtk_vbox_new(FALSE, 0);
-
-       gtk_container_add  (GTK_CONTAINER (this->m_window), this->m_mainPanel);
-
-
-       this->m_drawingArea = gtk_drawing_area_new();
-
-       gtk_signal_connect (GTK_OBJECT (this->m_drawingArea), "expose_event",
-                       (GtkSignalFunc) expose_event, NULL);
-       gtk_signal_connect (GTK_OBJECT(this->m_drawingArea),"configure_event",
-                       (GtkSignalFunc) configure_event, NULL);
-       gtk_signal_connect (GTK_OBJECT (this->m_drawingArea), 
"motion_notify_event",
-                       (GtkSignalFunc) motion_notify_event, NULL);
-       gtk_signal_connect (GTK_OBJECT (this->m_drawingArea), 
"button_press_event",
-                       (GtkSignalFunc) button_press_event, NULL);
-
-       gtk_widget_set_events (this->m_drawingArea, GDK_EXPOSURE_MASK
-                       | GDK_LEAVE_NOTIFY_MASK
-                       | GDK_BUTTON_PRESS_MASK
-                       | GDK_POINTER_MOTION_MASK
-                       | GDK_POINTER_MOTION_HINT_MASK);
-
-       gtk_widget_set_size_request(this->m_drawingArea, 200, 200);
-
-       /*Add the graph navigation panel to the main panel. */
-       gtk_box_pack_start (GTK_BOX(this->m_mainPanel), this->m_toolBar, TRUE, 
TRUE, 0);
-       /* Add the draw-able area to the main panel. */
-       gtk_box_pack_start (GTK_BOX(this->m_mainPanel), this->m_drawingArea, 
TRUE, TRUE, 0);
-
-       this->m_shapes = hashMap_create(string_hash, NULL, string_equals, NULL);
-       linkedList_create(data->pool, &this->m_shapeComponents);
-       this->m_defaultShape = defaultShape_create(data->context);
-       paintFrame_show();
-       if( g_thread_supported()) {
-               l_th = g_thread_create(_gtkthread, data, TRUE, &error);
-               if (l_th == NULL){
-                       g_printerr ("Failed to create thread: %s\n", 
error->message);
-                       return NULL;
+static celix_status_t paintFrame_redraw(PAINT_FRAME frame, GdkModifierType 
state) {
+       if (frame->pixMap != NULL && frame->showing) {
+               GdkRectangle update_rect;
+
+               update_rect.x = 0;
+               update_rect.y = 0;
+               update_rect.width = frame->drawingArea->allocation.width;
+               update_rect.height = frame->drawingArea->allocation.height;
+               gdk_draw_rectangle (this->pixMap,
+                               frame->drawingArea->style->white_gc,
+                               TRUE,
+                               update_rect.x, update_rect.y,
+                               update_rect.width, update_rect.height);
+               gtk_widget_draw(frame->drawingArea, &update_rect);
+               LINKED_LIST_ITERATOR it = 
linkedListIterator_create(this->m_shapeComponents, 0);
+               while (linkedListIterator_hasNext(it)) {
+                       SHAPE_COMPONENT sc = linkedListIterator_next(it);
+                       (*sc->shapeComponent_paintComponent)(sc, this, 
this->pixMap, frame->drawingArea);
                }
-       } else {
-               g_printerr("g_thread NOT supported\n");
        }
-       return this;
+
+       return CELIX_SUCCESS;
 }
 
+static gpointer paintFrame_gtkmain(gpointer a_data) {
+       gdk_threads_enter();
+       gtk_main();
+       gdk_threads_leave();
 
+       return NULL;
+}

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/shape_component.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/shape_component.c?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/shape_component.c
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/paint/private/src/shape_component.c
 Thu Nov  3 11:01:50 2011
@@ -18,17 +18,18 @@
 #include "linkedlist.h"
 #include "hash_map.h"
 #include "simple_shape.h"
-#include "paint_frame.h"
 #include "shape_component.h"
 
+static const int BOX = 54;
+
 extern void shapeComponent_paintComponent(SHAPE_COMPONENT shapeComponent, 
PAINT_FRAME frame,
                GdkPixmap *pixMap, GtkWidget *widget);
 
-SHAPE_COMPONENT shapeComponent_create(PAINT_FRAME frame, char *shapeName,
+SHAPE_COMPONENT shapeComponent_create(PAINT_FRAME frame, SIMPLE_SHAPE sshape,
                gdouble x, gdouble y) {
        SHAPE_COMPONENT shape = malloc(sizeof(*shape));
        shape->m_frame = frame;
-       strcpy(shape->shapeName, shapeName);
+       shape->shapeName = strdup(sshape->name);
        shape->x = x - BOX /2;
        shape->y = y - BOX /2;
        shape->w = BOX;
@@ -40,7 +41,7 @@ SHAPE_COMPONENT shapeComponent_create(PA
 
 void shapeComponent_paintComponent(SHAPE_COMPONENT shapeComponent, PAINT_FRAME 
frame,
                GdkPixmap *pixMap, GtkWidget *widget) {
-       SIMPLE_SHAPE shape = 
frame->paintFrame_getShape(shapeComponent->shapeName);
+       SIMPLE_SHAPE shape = paintFrame_getShape(frame, 
shapeComponent->shapeName);
        if (shape == NULL) {
                g_printerr("cannot find shape %s\n", shapeComponent->shapeName);
        } else {

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/square/private/src/square_shape.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/square/private/src/square_shape.c?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/square/private/src/square_shape.c
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/square/private/src/square_shape.c
 Thu Nov  3 11:01:50 2011
@@ -28,6 +28,7 @@ SIMPLE_SHAPE squareShape_create(BUNDLE_C
        SIMPLE_SHAPE shape = (SIMPLE_SHAPE) malloc(sizeof(*shape));
        bundleContext_getBundle(context, &bundle);
        bundleContext_getMemoryPool(context, &pool);
+       shape->name = "Square";
        shape->icon_path = NULL;
        celix_status_t status = bundle_getEntry(bundle, SQUARE_FILE, pool, 
&shape->icon_path);
        shape->simpleShape_draw = squareShape_draw;

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle_shape.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle_shape.c?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle_shape.c
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle_shape.c
 Thu Nov  3 11:01:50 2011
@@ -28,6 +28,7 @@ SIMPLE_SHAPE triangleShape_create(BUNDLE
        SIMPLE_SHAPE shape = (SIMPLE_SHAPE) malloc(sizeof(*shape));
        bundleContext_getBundle(context, &bundle);
        bundleContext_getMemoryPool(context, &pool);
+       shape->name = "Triangle";
        shape->icon_path = NULL;
        celix_status_t status = bundle_getEntry(bundle, TRIANGLE_FILE, pool, 
&shape->icon_path);
        shape->simpleShape_draw = triangleShape_draw;

Modified: incubator/celix/trunk/framework/private/src/service_reference.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/service_reference.c?rev=1197062&r1=1197061&r2=1197062&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/service_reference.c (original)
+++ incubator/celix/trunk/framework/private/src/service_reference.c Thu Nov  3 
11:01:50 2011
@@ -36,18 +36,18 @@ bool serviceReference_isAssignableTo(SER
                return allow;
        }
 
-       WIRE providerWire = module_getWire(bundle_getCurrentModule(provider), 
serviceName);
-       WIRE requesterWire = module_getWire(bundle_getCurrentModule(requester), 
serviceName);
-
-       if (providerWire == NULL && requesterWire != NULL) {
-               allow = (bundle_getCurrentModule(provider) == 
wire_getExporter(requesterWire));
-       } else if (providerWire != NULL && requesterWire != NULL) {
-               allow = (wire_getExporter(providerWire) == 
wire_getExporter(requesterWire));
-       } else if (providerWire != NULL && requesterWire == NULL) {
-               allow = (wire_getExporter(providerWire) == 
bundle_getCurrentModule(requester));
-       } else {
-               allow = false;
-       }
+//     WIRE providerWire = module_getWire(bundle_getCurrentModule(provider), 
serviceName);
+//     WIRE requesterWire = module_getWire(bundle_getCurrentModule(requester), 
serviceName);
+//
+//     if (providerWire == NULL && requesterWire != NULL) {
+//             allow = (bundle_getCurrentModule(provider) == 
wire_getExporter(requesterWire));
+//     } else if (providerWire != NULL && requesterWire != NULL) {
+//             allow = (wire_getExporter(providerWire) == 
wire_getExporter(requesterWire));
+//     } else if (providerWire != NULL && requesterWire == NULL) {
+//             allow = (wire_getExporter(providerWire) == 
bundle_getCurrentModule(requester));
+//     } else {
+//             allow = false;
+//     }
 
        return allow;
 }


Reply via email to