Author: abroekhuis
Date: Tue Oct 18 11:44:15 2011
New Revision: 1185587

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

Modified:
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/include/circle_shape.h
    
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/src/activator.c
    
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/private/src/paint_frame.c

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/include/circle_shape.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/include/circle_shape.h?rev=1185587&r1=1185586&r2=1185587&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/include/circle_shape.h
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/include/circle_shape.h
 Tue Oct 18 11:44:15 2011
@@ -2,13 +2,13 @@
  * default_shape.h
  *
  *  Created on: Aug 22, 2011
- *      Author: operator
  */
 
 #ifndef CIRCLE_SHAPE_H_
 #define CIRCLE_SHAPE_H_
 
+#include "celix_errno.h"
 
-extern SIMPLE_SHAPE circleShape_create(BUNDLE_CONTEXT context);
+celix_status_t circleShape_create(BUNDLE_CONTEXT context, SIMPLE_SHAPE *shape);
 
 #endif /* CIRCLE_SHAPE_H_ */

Modified: 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/src/activator.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/src/activator.c?rev=1185587&r1=1185586&r2=1185587&view=diff
==============================================================================
--- 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/src/activator.c
 (original)
+++ 
incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/circle/private/src/activator.c
 Tue Oct 18 11:44:15 2011
@@ -24,45 +24,48 @@
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 
+#include "service_registration.h"
 #include "bundle_activator.h"
 #include "bundle_context.h"
 #include "simple_shape.h"
 #include "circle_shape.h"
 #include "simple_shape.h"
 
-struct greetingActivator {
+struct activator {
        SERVICE_REGISTRATION reg;
        apr_pool_t *pool;
 };
 
-typedef struct greetingActivator *GREETING_ACTIVATOR;
-
 celix_status_t bundleActivator_create(BUNDLE_CONTEXT context, void **userData) 
{
        apr_pool_t *pool;
-       GREETING_ACTIVATOR activator;
+       struct activator *activator;
        celix_status_t status = bundleContext_getMemoryPool(context, &pool);
        if (status == CELIX_SUCCESS) {
-               *userData = apr_palloc(pool, sizeof(struct greetingActivator));
+               *userData = apr_palloc(pool, sizeof(struct activator));
                activator = *userData;
                activator->reg = NULL;
                activator->pool = pool;
        }
-       printf("Circle created %d\n", status);
        return status;
 }
 
 celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT ctx) {
-       struct greetingActivator * act = (struct greetingActivator *) userData;
+       struct activator * act = (struct activator *) userData;
        celix_status_t status = CELIX_SUCCESS;
-       SIMPLE_SHAPE es = circleShape_create(ctx);
+       SIMPLE_SHAPE es = NULL;
+       circleShape_create(ctx, &es);
        PROPERTIES props = properties_create();
        properties_set(props, "name", "circle");
     status = bundleContext_registerService(ctx, SIMPLE_SHAPE_SERVICE_NAME, es, 
props, &act->reg);
-       printf("Circle activated %d\n", status);
        return status;
 }
 
 celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+       celix_status_t status = CELIX_SUCCESS;
+       struct activator * act = (struct activator *) userData;
+
+       status = serviceRegistration_unregister(act->reg);
+
        return CELIX_SUCCESS;
 }
 

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=1185587&r1=1185586&r2=1185587&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
 Tue Oct 18 11:44:15 2011
@@ -23,21 +23,35 @@
 
 void circleShape_draw(SIMPLE_SHAPE shape, GdkPixmap *pixMap, GtkWidget 
*widget, gdouble x, gdouble y);
 
-SIMPLE_SHAPE circleShape_create(BUNDLE_CONTEXT context) {
+celix_status_t circleShape_create(BUNDLE_CONTEXT context, SIMPLE_SHAPE *shape) 
{
+       celix_status_t status = CELIX_SUCCESS;
+
        BUNDLE bundle;
        apr_pool_t *pool;
-       SIMPLE_SHAPE shape = (SIMPLE_SHAPE) malloc(sizeof(*shape));
-       bundleContext_getBundle(context, &bundle);
-       bundleContext_getMemoryPool(context, &pool);
-       shape->icon_path = NULL;
-       celix_status_t status = bundle_getEntry(bundle, CIRCLE_FILE, pool, 
&shape->icon_path);
-       shape->simpleShape_draw = circleShape_draw;
-       if (status == CELIX_SUCCESS) {
-               // no error
+
+       if (*shape != NULL || context == NULL) {
+               status = CELIX_ILLEGAL_ARGUMENT;
        } else {
-               printf("Could not find resource %s\n", CIRCLE_FILE);
+               status = bundleContext_getBundle(context, &bundle);
+               if (status == CELIX_SUCCESS) {
+                       status = bundleContext_getMemoryPool(context, &pool);
+                       if (status == CELIX_SUCCESS) {
+                               *shape = (SIMPLE_SHAPE) apr_palloc(pool, 
sizeof(**shape));
+                               if (!*shape) {
+                                       status = CELIX_ENOMEM;
+                               } else {
+                                       (*shape)->icon_path = NULL;
+                                       celix_status_t status = 
bundle_getEntry(bundle, CIRCLE_FILE, pool, &(*shape)->icon_path);
+                                       if (status == CELIX_SUCCESS) {
+                                               (*shape)->simpleShape_draw = 
circleShape_draw;
+                                       } else {
+                                               printf("Could not find resource 
%s\n", CIRCLE_FILE);
+                                       }
+                               }
+                       }
+               }
        }
-       return shape;
+       return status;
 }
 
 void circleShape_draw(SIMPLE_SHAPE shape, GdkPixmap *pixMap, GtkWidget 
*widget, gdouble x, gdouble y){

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=1185587&r1=1185586&r2=1185587&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
 Tue Oct 18 11:44:15 2011
@@ -117,7 +117,6 @@ motion_notify_event( GtkWidget *widget, 
 {
   int x, y;
   GdkModifierType state;
-  printf("motion notify event\n");
   if (event->is_hint) {
     gdk_window_get_pointer (event->window, &x, &y, &state);
   } else {
@@ -132,7 +131,6 @@ motion_notify_event( GtkWidget *widget, 
 static gboolean
 expose_event( GtkWidget *widget, GdkEventExpose *event )
 {
-       printf("expose event\n");
        gdk_draw_drawable(widget->window,
                        widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
                        this->m_pixMap,
@@ -145,7 +143,6 @@ expose_event( GtkWidget *widget, GdkEven
 static gboolean
 configure_event( GtkWidget *widget, GdkEventConfigure *event )
 {
-  printf("configure event\n");
   if (this->m_pixMap) {
     g_object_unref(this->m_pixMap);
   }
@@ -314,7 +311,7 @@ PAINT_FRAME paintFrame_create(BUNDLE_CON
                        | GDK_POINTER_MOTION_MASK
                        | GDK_POINTER_MOTION_HINT_MASK);
 
-       gtk_drawing_area_size(this->m_drawingArea, 200, 200);
+       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);


Reply via email to