Added: 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=1177194&view=auto ============================================================================== --- incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/square/private/src/square_shape.c (added) +++ incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/square/private/src/square_shape.c Thu Sep 29 07:44:24 2011 @@ -0,0 +1,76 @@ +/* + * simple_shape.c + * + * Created on: Aug 22, 2011 + * Author: operator + */ + + +#include <stdio.h> +#include <string.h> +#include <stdbool.h> +#include <stdlib.h> +#include <glib.h> +#include <gtk/gtk.h> +#include <gdk/gdk.h> +#include "bundle_context.h" +#include "bundle.h" +#include "hash_map.h" +#include "simple_shape.h" +#include "square_shape.h" +#define SQUARE_FILE "square.png" + +void squareShape_draw(SIMPLE_SHAPE shape, GdkPixmap *pixMap, GtkWidget *widget, gdouble x, gdouble y); + +SIMPLE_SHAPE squareShape_create(BUNDLE_CONTEXT context) { + 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, SQUARE_FILE, pool, &shape->icon_path); + shape->simpleShape_draw = squareShape_draw; + if (status == CELIX_SUCCESS) { + // no error + } else { + printf("Could not find resource %s\n", SQUARE_FILE); + } + return shape; +} + +void squareShape_draw(SIMPLE_SHAPE shape, GdkPixmap *pixMap, GtkWidget *widget, gdouble x, gdouble y){ + GdkRectangle update_rect; + GdkPixbuf *curr_pix_buf; + GError *gerror = NULL; + gsize rd = 0, wr = 0; + if (shape->icon_path == NULL){ + printf("no icon path\n"); + } else { + gchar *gfn = g_locale_to_utf8(shape->icon_path, strlen(shape->icon_path), &rd, &wr, &gerror); + curr_pix_buf = gdk_pixbuf_new_from_file(gfn, &gerror); + if(!curr_pix_buf) { + g_printerr("error message: %s\n", (gchar *) gerror->message); + } + update_rect.x = x - 5; + update_rect.y = y - 5; + update_rect.width = gdk_pixbuf_get_width(curr_pix_buf); + update_rect.height = gdk_pixbuf_get_height(curr_pix_buf); + gdk_pixbuf_render_to_drawable( + curr_pix_buf, + pixMap, + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + 0, 0, + update_rect.x, update_rect.y, + update_rect.width, + update_rect.height, + GDK_RGB_DITHER_NONE, + 0, 0); + gtk_widget_queue_draw_area (widget, + update_rect.x, update_rect.y, + update_rect.width, update_rect.height); + } +} + + +
Copied: incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/CMakeLists.txt (from r1177180, incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/CMakeLists.txt) URL: http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/CMakeLists.txt?p2=incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/CMakeLists.txt&p1=incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/CMakeLists.txt&r1=1177180&r2=1177194&rev=1177194&view=diff ============================================================================== --- incubator/celix/trunk/examples/osgi-in-action/chapter04-correct-listener/CMakeLists.txt (original) +++ incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/CMakeLists.txt Thu Sep 29 07:44:24 2011 @@ -14,10 +14,31 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +cmake_minimum_required(VERSION 2.8) +INCLUDE(FindPkgConfig) +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) +include_directories( + private/include + public/include + ../simple/public/include +) +include_directories(${GTK_INCLUDE_DIRS}) +include_directories(${GLIB_INCLUDE_DIRS}) +include_directories(${GTHR_INCLUDE_DIRS}) -add_library(chapter04-correct-listener SHARED private/src/activator) +link_directories(${GTK_LIBRARY_DIRS}) +link_directories(${GLIB_LIBRARY_DIRS}) +link_directories(${GTHR_LIBRARY_DIRS}) + +add_library(triangle SHARED + private/src/activator + private/src/triangle_shape + ) include_directories("${PROJECT_SOURCE_DIR}/utils/public/include") include_directories("${PROJECT_SOURCE_DIR}/log_service/public/include") -target_link_libraries(chapter04-correct-listener framework) +target_link_libraries(triangle framework ${GLIB_LIBRARIES} ${GTK_LIBRARIES} ${GTHR_LIBRARIES}) -bundle(chapter04-correct-listener) +bundle(triangle FILES private/src/triangle.png) Added: incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/MANIFEST/MANIFEST.MF URL: http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/MANIFEST/MANIFEST.MF?rev=1177194&view=auto ============================================================================== --- incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/MANIFEST/MANIFEST.MF (added) +++ incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/MANIFEST/MANIFEST.MF Thu Sep 29 07:44:24 2011 @@ -0,0 +1,7 @@ +Bundle-SymbolicName: triangle +Bundle-Version: 1.0.0 +library: triangle +Export-Service: simple_shape +Import-Service: simple_shape + + Added: incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/include/triangle_shape.h URL: http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/include/triangle_shape.h?rev=1177194&view=auto ============================================================================== --- incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/include/triangle_shape.h (added) +++ incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/include/triangle_shape.h Thu Sep 29 07:44:24 2011 @@ -0,0 +1,13 @@ +/* + * default_shape.h + * + * Created on: Aug 22, 2011 + * Author: operator + */ + +#ifndef TRIANGLE_SHAPE_H_ +#define TRIANGLE_SHAPE_H_ + +extern SIMPLE_SHAPE triangleShape_create(BUNDLE_CONTEXT ctx); + +#endif /* TRIANGLE_SHAPE_H_ */ Copied: incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/activator.c (from r1177180, incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/activator.c) URL: http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/activator.c?p2=incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/activator.c&p1=incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/activator.c&r1=1177180&r2=1177194&rev=1177194&view=diff ============================================================================== --- incubator/celix/trunk/examples/osgi-in-action/chapter01-greeting-example/greeting/private/src/activator.c (original) +++ incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/activator.c Thu Sep 29 07:44:24 2011 @@ -20,12 +20,15 @@ #include <stdlib.h> #include <stdio.h> #include <apr_general.h> +#include <glib.h> +#include <gtk/gtk.h> +#include <gdk/gdk.h> #include "bundle_activator.h" #include "bundle_context.h" -#include "greeting_impl.h" -#include "greeting_service.h" -#include "service_registration.h" +#include "simple_shape.h" +#include "triangle_shape.h" +#include "simple_shape.h" struct greetingActivator { SERVICE_REGISTRATION reg; @@ -44,31 +47,25 @@ celix_status_t bundleActivator_create(BU activator->reg = NULL; activator->pool = pool; } + printf("Triangle created %d\n", status); return status; } -celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT context) { +celix_status_t bundleActivator_start(void * userData, BUNDLE_CONTEXT ctx) { struct greetingActivator * act = (struct greetingActivator *) userData; celix_status_t status = CELIX_SUCCESS; - GREETING_SERVICE es = apr_palloc(act->pool, sizeof(*es)); - es->instance = apr_palloc(act->pool, sizeof(*es->instance)); - es->instance->name = GREETING_SERVICE_NAME; - es->greeting_sayHello = greeting_sayHello; - - status = bundleContext_registerService(context, GREETING_SERVICE_NAME, es, NULL, &act->reg); + SIMPLE_SHAPE es = triangleShape_create(ctx); + PROPERTIES props = properties_create(); + properties_set(props, "name", "triangle"); + status = bundleContext_registerService(ctx, SIMPLE_SHAPE_SERVICE_NAME, es, props, &act->reg); + printf("Triangle activated %d\n", status); return status; } celix_status_t bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) { - celix_status_t status = CELIX_SUCCESS; - struct greetingActivator * act = (struct greetingActivator *) userData; - serviceRegistration_unregister(act->reg); - act->reg = NULL; return CELIX_SUCCESS; } celix_status_t bundleActivator_destroy(void * userData, BUNDLE_CONTEXT context) { - struct greetingActivator * act = (struct greetingActivator *) userData; - act->reg = NULL; return CELIX_SUCCESS; } Added: incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle.png URL: http://svn.apache.org/viewvc/incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle.png?rev=1177194&view=auto ============================================================================== Files incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle.png (added) and incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle.png Thu Sep 29 07:44:24 2011 differ Added: 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=1177194&view=auto ============================================================================== --- incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle_shape.c (added) +++ incubator/celix/trunk/examples/osgi-in-action/chapter04-paint-example/triangle/private/src/triangle_shape.c Thu Sep 29 07:44:24 2011 @@ -0,0 +1,76 @@ +/* + * simple_shape.c + * + * Created on: Aug 22, 2011 + * Author: operator + */ + + +#include <stdio.h> +#include <string.h> +#include <stdbool.h> +#include <stdlib.h> +#include <glib.h> +#include <gtk/gtk.h> +#include <gdk/gdk.h> +#include "bundle_context.h" +#include "bundle.h" +#include "hash_map.h" +#include "simple_shape.h" +#include "triangle_shape.h" +#define TRIANGLE_FILE "triangle.png" + +void triangleShape_draw(SIMPLE_SHAPE shape, GdkPixmap *pixMap, GtkWidget *widget, gdouble x, gdouble y); + +SIMPLE_SHAPE triangleShape_create(BUNDLE_CONTEXT context) { + 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, TRIANGLE_FILE, pool, &shape->icon_path); + shape->simpleShape_draw = triangleShape_draw; + if (status == CELIX_SUCCESS){ + // no error + } else { + printf("Could not find resource %s\n", TRIANGLE_FILE); + } + return shape; +} + +void triangleShape_draw(SIMPLE_SHAPE shape, GdkPixmap *pixMap, GtkWidget *widget, gdouble x, gdouble y){ + GdkRectangle update_rect; + GdkPixbuf *curr_pix_buf; + GError *gerror = NULL; + gsize rd = 0, wr = 0; + if (shape->icon_path == NULL) { + printf("error message: icon path unknown\n"); + } else { + gchar *gfn = g_locale_to_utf8(shape->icon_path, strlen(shape->icon_path), &rd, &wr, &gerror); + curr_pix_buf = gdk_pixbuf_new_from_file(gfn, &gerror); + if(!curr_pix_buf) { + g_printerr("error message: %s\n", (gchar *) gerror->message); + } + update_rect.x = x - 5; + update_rect.y = y - 5; + update_rect.width = gdk_pixbuf_get_width(curr_pix_buf); + update_rect.height = gdk_pixbuf_get_height(curr_pix_buf); + gdk_pixbuf_render_to_drawable( + curr_pix_buf, + pixMap, + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + 0, 0, + update_rect.x, update_rect.y, + update_rect.width, + update_rect.height, + GDK_RGB_DITHER_NONE, + 0, 0); + gtk_widget_queue_draw_area (widget, + update_rect.x, update_rect.y, + update_rect.width, update_rect.height); + } +} + + +
