celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1667603 - in /celix/trunk: dependency_manager_2/private/include/ dependency_manager_2/private/src/ dependency_manager_2/public/include/ examples/whiteboard/publisherA/private/src/ examples/whiteboard/publisherB/private/src/ examples/whiteb...
Date Wed, 18 Mar 2015 19:29:50 GMT
Author: abroekhuis
Date: Wed Mar 18 19:29:49 2015
New Revision: 1667603

URL: http://svn.apache.org/r1667603
Log:
Added dependency injection to the dependency manager.

Modified:
    celix/trunk/dependency_manager_2/private/include/dm_event.h
    celix/trunk/dependency_manager_2/private/include/dm_service_dependency_impl.h
    celix/trunk/dependency_manager_2/private/src/dm_component_impl.c
    celix/trunk/dependency_manager_2/private/src/dm_event.c
    celix/trunk/dependency_manager_2/private/src/dm_service_dependency.c
    celix/trunk/dependency_manager_2/public/include/dm_service_dependency.h
    celix/trunk/examples/whiteboard/publisherA/private/src/activator.c
    celix/trunk/examples/whiteboard/publisherB/private/src/activator.c
    celix/trunk/examples/whiteboard/tracker/private/src/activator.c
    celix/trunk/examples/whiteboard/tracker_depman/private/include/tracker.h
    celix/trunk/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
    celix/trunk/examples/whiteboard/tracker_depman/private/src/tracker.c

Modified: celix/trunk/dependency_manager_2/private/include/dm_event.h
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/private/include/dm_event.h?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/private/include/dm_event.h (original)
+++ celix/trunk/dependency_manager_2/private/include/dm_event.h Wed Mar 18 19:29:49 2015
@@ -56,5 +56,8 @@ celix_status_t event_destroy(dm_event_pt
 
 celix_status_t event_equals(void *a, void *b, bool *equals);
 
+celix_status_t event_getService(dm_event_pt event, void **service);
+celix_status_t event_compareTo(dm_event_pt event, dm_event_pt compareTo, int *compare);
+
 
 #endif /* DM_EVENT_H_ */

Modified: celix/trunk/dependency_manager_2/private/include/dm_service_dependency_impl.h
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/private/include/dm_service_dependency_impl.h?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/private/include/dm_service_dependency_impl.h (original)
+++ celix/trunk/dependency_manager_2/private/include/dm_service_dependency_impl.h Wed Mar
18 19:29:49 2015
@@ -47,6 +47,7 @@ struct dm_service_dependency {
 	service_swap_fpt swap;
 
 	void **autoConfigure;
+	celix_thread_mutex_t lock;
 
 	bool isStarted;
 
@@ -61,6 +62,7 @@ struct dm_service_dependency {
 celix_status_t serviceDependency_start(dm_service_dependency_pt dependency);
 celix_status_t serviceDependency_stop(dm_service_dependency_pt dependency);
 celix_status_t serviceDependency_setInstanceBound(dm_service_dependency_pt dependency, bool
instanceBound);
+celix_status_t serviceDependency_setAutoConfig(dm_service_dependency_pt dependency, void
**autoConfigure);
 celix_status_t serviceDependency_setAvailable(dm_service_dependency_pt dependency, bool available);
 
 celix_status_t serviceDependency_setComponent(dm_service_dependency_pt dependency, dm_component_pt
component);
@@ -73,6 +75,11 @@ celix_status_t serviceDependency_invokeS
 celix_status_t serviceDependency_isAvailable(dm_service_dependency_pt dependency, bool *available);
 celix_status_t serviceDependency_isRequired(dm_service_dependency_pt dependency, bool *required);
 celix_status_t serviceDependency_isInstanceBound(dm_service_dependency_pt dependency, bool
*instanceBound);
+celix_status_t serviceDependency_isAutoConfig(dm_service_dependency_pt dependency, bool *autoConfig);
+
+celix_status_t serviceDependency_getAutoConfig(dm_service_dependency_pt dependency, void
***autoConfigure);
+celix_status_t serviceDependency_unlock(dm_service_dependency_pt dependency);
+celix_status_t serviceDependency_lock(dm_service_dependency_pt dependency);
 
 
 #endif /* DM_SERVICE_DEPENDENCY_IMPL_H_ */

Modified: celix/trunk/dependency_manager_2/private/src/dm_component_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/private/src/dm_component_impl.c?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/private/src/dm_component_impl.c (original)
+++ celix/trunk/dependency_manager_2/private/src/dm_component_impl.c Wed Mar 18 19:29:49 2015
@@ -1,4 +1,4 @@
-#include <sys/cdefs.h>/**
+/**
  *Licensed to the Apache Software Foundation (ASF) under one
  *or more contributor license agreements.  See the NOTICE file
  *distributed with this work for additional information
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 
 #include "dm_component_impl.h"
+#include "../../../framework/private/include/framework_private.h"
 
 struct dm_executor {
     pthread_t runningThread;
@@ -67,12 +68,17 @@ static celix_status_t component_unregist
 static celix_status_t component_invokeAddOptionalDependencies(dm_component_pt component);
 static celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt
component);
 static celix_status_t component_invokeAddRequiredDependencies(dm_component_pt component);
+static celix_status_t component_invokeAutoConfigInstanceBoundDependencies(dm_component_pt
component);
+static celix_status_t component_invokeAutoConfigDependencies(dm_component_pt component);
+static celix_status_t component_configureImplementation(dm_component_pt component, dm_service_dependency_pt
dependency);
 static celix_status_t component_allInstanceBoundAvailable(dm_component_pt component, bool
*available);
 static celix_status_t component_allRequiredAvailable(dm_component_pt component, bool *available);
 static celix_status_t component_performTransition(dm_component_pt component, dm_component_state_pt
oldState, dm_component_state_pt newState, bool *transition);
 static celix_status_t component_calculateNewState(dm_component_pt component, dm_component_state_pt
currentState, dm_component_state_pt *newState);
 static celix_status_t component_handleChange(dm_component_pt component);
 static celix_status_t component_startDependencies(dm_component_pt component __attribute__((unused)),
array_list_pt dependencies);
+static celix_status_t component_getDependencyEvent(dm_component_pt component, dm_service_dependency_pt
dependency, dm_event_pt *event_pptr);
+static celix_status_t component_updateInstance(dm_component_pt component, dm_service_dependency_pt
dependency, dm_event_pt event, bool update, bool add);
 
 static celix_status_t component_addTask(dm_component_pt component, array_list_pt dependencies);
 static celix_status_t component_startTask(dm_component_pt component, void * data __attribute__((unused)));
@@ -352,7 +358,9 @@ celix_status_t component_handleAdded(dm_
                 if (required) {
                     serviceDependency_invokeAdd(dependency, event);
                 }
-                // updateInstance
+                dm_event_pt event = NULL;
+                component_getDependencyEvent(component, dependency, &event);
+                component_updateInstance(component, dependency, event, false, true);
             } else {
                 bool required = false;
                 serviceDependency_isRequired(dependency, &required);
@@ -364,7 +372,9 @@ celix_status_t component_handleAdded(dm_
         }
         case DM_CMP_STATE_TRACKING_OPTIONAL:
             serviceDependency_invokeAdd(dependency, event);
-            // updateInstance
+            dm_event_pt event = NULL;
+            component_getDependencyEvent(component, dependency, &event);
+            component_updateInstance(component, dependency, event, false, true);
             break;
         default:
             break;
@@ -389,14 +399,18 @@ celix_status_t component_handleChanged(d
         switch (component->state) {
             case DM_CMP_STATE_TRACKING_OPTIONAL:
                 serviceDependency_invokeChange(dependency, event);
-                // updateInstance
+                dm_event_pt hevent = NULL;
+                component_getDependencyEvent(component, dependency, &hevent);
+                component_updateInstance(component, dependency, hevent, true, false);
                 break;
             case DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED: {
                 bool instanceBound = false;
                 serviceDependency_isInstanceBound(dependency, &instanceBound);
                 if (!instanceBound) {
                     serviceDependency_invokeChange(dependency, event);
-                    // updateInstance
+                    dm_event_pt hevent = NULL;
+                    component_getDependencyEvent(component, dependency, &hevent);
+                    component_updateInstance(component, dependency, hevent, true, false);
                 }
                 break;
             }
@@ -441,13 +455,17 @@ celix_status_t component_handleRemoved(d
                     if (required) {
                         serviceDependency_invokeRemove(dependency, event);
                     }
-                    // updateInstance
+                    dm_event_pt hevent = NULL;
+                    component_getDependencyEvent(component, dependency, &hevent);
+                    component_updateInstance(component, dependency, hevent, false, false);
                 }
                 break;
             }
             case DM_CMP_STATE_TRACKING_OPTIONAL:
                 serviceDependency_invokeRemove(dependency, event);
-                // updateInstance
+                dm_event_pt hevent = NULL;
+                component_getDependencyEvent(component, dependency, &hevent);
+                component_updateInstance(component, dependency, hevent, false, false);
                 break;
             default:
                 break;
@@ -506,6 +524,29 @@ celix_status_t component_handleSwapped(d
     return status;
 }
 
+celix_status_t component_updateInstance(dm_component_pt component, dm_service_dependency_pt
dependency, dm_event_pt event, bool update, bool add) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    bool autoConfig = false;
+
+    serviceDependency_isAutoConfig(dependency, &autoConfig);
+
+    if (autoConfig) {
+        void *service = NULL;
+        void **field = NULL;
+
+        if (event != NULL) {
+            event_getService(event, &service);
+        }
+        serviceDependency_getAutoConfig(dependency, &field);
+        serviceDependency_lock(dependency);
+        *field = service;
+        serviceDependency_unlock(dependency);
+    }
+
+    return status;
+}
+
 celix_status_t component_startDependencies(dm_component_pt component __attribute__((unused)),
array_list_pt dependencies) {
     celix_status_t status = CELIX_SUCCESS;
     array_list_pt required_dependencies = NULL;
@@ -643,7 +684,7 @@ celix_status_t component_performTransiti
         // #TODO Remove
 //        component_instantiateComponent(component);
         component_invokeAddRequiredDependencies(component);
-//        component_invokeAutoConfigDependencies(component);
+        component_invokeAutoConfigDependencies(component);
         dm_component_state_pt stateBeforeCallingInit = component->state;
         if (component->callbackInit) {
         	component->callbackInit(component->implementation);
@@ -658,7 +699,7 @@ celix_status_t component_performTransiti
 
     if (oldState == DM_CMP_STATE_INSTANTIATED_AND_WAITING_FOR_REQUIRED && newState
== DM_CMP_STATE_TRACKING_OPTIONAL) {
         component_invokeAddRequiredInstanceBoundDependencies(component);
-//        component_invokeAutoConfigInstanceBoundDependencies(component);
+        component_invokeAutoConfigInstanceBoundDependencies(component);
         if (component->callbackStart) {
         	component->callbackStart(component->implementation);
         }
@@ -793,6 +834,50 @@ celix_status_t component_invokeAddRequir
     return status;
 }
 
+celix_status_t component_invokeAutoConfigDependencies(dm_component_pt component) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    pthread_mutex_lock(&component->mutex);
+    for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+        dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+        bool autoConfig = false;
+        bool instanceBound = false;
+
+        serviceDependency_isAutoConfig(dependency, &autoConfig);
+        serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+        if (autoConfig && !instanceBound) {
+            component_configureImplementation(component, dependency);
+        }
+    }
+    pthread_mutex_unlock(&component->mutex);
+
+    return status;
+}
+
+celix_status_t component_invokeAutoConfigInstanceBoundDependencies(dm_component_pt component)
{
+    celix_status_t status = CELIX_SUCCESS;
+
+    pthread_mutex_lock(&component->mutex);
+    for (unsigned int i = 0; i < arrayList_size(component->dependencies); i++) {
+        dm_service_dependency_pt dependency = arrayList_get(component->dependencies, i);
+
+        bool autoConfig = false;
+        bool instanceBound = false;
+
+        serviceDependency_isAutoConfig(dependency, &autoConfig);
+        serviceDependency_isInstanceBound(dependency, &instanceBound);
+
+        if (autoConfig && instanceBound) {
+            component_configureImplementation(component, dependency);
+        }
+    }
+    pthread_mutex_unlock(&component->mutex);
+
+    return status;
+}
+
 celix_status_t component_invokeAddRequiredInstanceBoundDependencies(dm_component_pt component)
{
     celix_status_t status = CELIX_SUCCESS;
 
@@ -926,6 +1011,52 @@ celix_status_t component_invokeRemoveReq
 
     return status;
 }
+
+celix_status_t component_getDependencyEvent(dm_component_pt component, dm_service_dependency_pt
dependency, dm_event_pt *event_pptr) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+    *event_pptr = NULL;
+
+    if (events) {
+        for (unsigned int j = 0; j < arrayList_size(events); j++) {
+            dm_event_pt event_ptr = arrayList_get(events, j);
+            if (*event_pptr != NULL) {
+                int compare = 0;
+                event_compareTo(event_ptr, *event_pptr, &compare);
+                if (compare > 0) {
+                    *event_pptr = event_ptr;
+                }
+            } else {
+                *event_pptr = event_ptr;
+            }
+        }
+    }
+
+    return status;
+}
+
+celix_status_t component_configureImplementation(dm_component_pt component, dm_service_dependency_pt
dependency) {
+    celix_status_t status = CELIX_SUCCESS;
+
+    void **field = NULL;
+
+    array_list_pt events = hashMap_get(component->dependencyEvents, dependency);
+    if (events) {
+        void *service = NULL;
+        dm_event_pt event = NULL;
+        component_getDependencyEvent(component, dependency, &event);
+        if (event != NULL) {
+            event_getService(event, &service);
+            serviceDependency_getAutoConfig(dependency, &field);
+            serviceDependency_lock(dependency);
+            *field = service;
+            serviceDependency_unlock(dependency);
+        }
+    }
+
+    return status;
+}
 
 celix_status_t component_destroyComponent(dm_component_pt component) {
     celix_status_t status = CELIX_SUCCESS;

Modified: celix/trunk/dependency_manager_2/private/src/dm_event.c
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/private/src/dm_event.c?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/private/src/dm_event.c (original)
+++ celix/trunk/dependency_manager_2/private/src/dm_event.c Wed Mar 18 19:29:49 2015
@@ -76,5 +76,17 @@ celix_status_t event_equals(void *a, voi
 	}
 
 	return status;
+}
+
+celix_status_t event_compareTo(dm_event_pt event, dm_event_pt compareTo, int *compare) {
+	celix_status_t status;
+
+	status = serviceReference_compareTo(event->reference, compareTo->reference, compare);
+
+	return status;
+}
 
+celix_status_t event_getService(dm_event_pt event, void **service) {
+	*service = event->service;
+	return CELIX_SUCCESS;
 }

Modified: celix/trunk/dependency_manager_2/private/src/dm_service_dependency.c
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/private/src/dm_service_dependency.c?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/private/src/dm_service_dependency.c (original)
+++ celix/trunk/dependency_manager_2/private/src/dm_service_dependency.c Wed Mar 18 19:29:49
2015
@@ -52,7 +52,7 @@ celix_status_t serviceDependency_create(
 		(*dependency_ptr)->change = NULL;
 		(*dependency_ptr)->remove = NULL;
 
-		(*dependency_ptr)->autoConfigure = false;
+		(*dependency_ptr)->autoConfigure = NULL;
 
 		(*dependency_ptr)->isStarted = false;
 
@@ -85,6 +85,16 @@ celix_status_t serviceDependency_destroy
 	return status;
 }
 
+celix_status_t serviceDependency_lock(dm_service_dependency_pt dependency) {
+	celixThreadMutex_lock(&dependency->lock);
+	return CELIX_SUCCESS;
+}
+
+celix_status_t serviceDependency_unlock(dm_service_dependency_pt dependency) {
+	celixThreadMutex_unlock(&dependency->lock);
+	return CELIX_SUCCESS;
+}
+
 celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required)
{
 	celix_status_t status = CELIX_SUCCESS;
 
@@ -146,15 +156,20 @@ celix_status_t serviceDependency_setCall
 	return status;
 }
 
-celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, void
**field) {
+celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t
*service_lock, void **field) {
 	celix_status_t status = CELIX_SUCCESS;
 
+	celix_thread_mutex_t lock;
+
 	if (!dependency) {
 		status = CELIX_ILLEGAL_ARGUMENT;
 	}
 
 	if (status == CELIX_SUCCESS) {
 		dependency->autoConfigure = field;
+		celixThreadMutex_create(&lock, NULL);
+		*service_lock = lock;
+		dependency->lock = lock;
 	}
 
 	return status;
@@ -278,7 +293,9 @@ celix_status_t serviceDependency_invokeA
 	}
 
 	if (status == CELIX_SUCCESS) {
-		dependency->add(dependency->component->implementation, event->reference, event->service);
+		if (dependency->add) {
+			dependency->add(dependency->component->implementation, event->reference, event->service);
+		}
 	}
 
 	return status;
@@ -292,7 +309,9 @@ celix_status_t serviceDependency_invokeC
 	}
 
 	if (status == CELIX_SUCCESS) {
-		dependency->change(dependency->component->implementation, event->reference,
event->service);
+		if (dependency->change) {
+			dependency->change(dependency->component->implementation, event->reference,
event->service);
+		}
 	}
 
 	return status;
@@ -306,7 +325,9 @@ celix_status_t serviceDependency_invokeR
 	}
 
 	if (status == CELIX_SUCCESS) {
-		dependency->remove(dependency->component->implementation, event->reference,
event->service);
+		if (dependency->remove) {
+			dependency->remove(dependency->component->implementation, event->reference,
event->service);
+		}
 	}
 
 	return status;
@@ -320,7 +341,11 @@ celix_status_t serviceDependency_invokeS
 	}
 
 	if (status == CELIX_SUCCESS) {
-		dependency->swap(dependency->component->implementation, event->reference, event->service,
newEvent->reference, newEvent->service);
+		if (dependency->swap) {
+			dependency
+					->swap(dependency->component->implementation, event->reference, event->service,
newEvent->reference,
+							newEvent->service);
+		}
 	}
 
 	return status;
@@ -366,6 +391,34 @@ celix_status_t serviceDependency_isInsta
 	}
 
 	return status;
+}
+
+celix_status_t serviceDependency_isAutoConfig(dm_service_dependency_pt dependency, bool *autoConfig)
{
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (!dependency) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	}
+
+	if (status == CELIX_SUCCESS) {
+		*autoConfig = dependency->autoConfigure != NULL;
+	}
+
+	return status;
+}
+
+celix_status_t serviceDependency_getAutoConfig(dm_service_dependency_pt dependency, void
***autoConfigure) {
+	celix_status_t status = CELIX_SUCCESS;
+
+	if (!dependency) {
+		status = CELIX_ILLEGAL_ARGUMENT;
+	}
+
+	if (status == CELIX_SUCCESS) {
+		*autoConfigure = dependency->autoConfigure;
+	}
+
+	return status;
 }
 
 celix_status_t serviceDependency_addedService(void *_ptr, service_reference_pt reference,
void *service) {

Modified: celix/trunk/dependency_manager_2/public/include/dm_service_dependency.h
URL: http://svn.apache.org/viewvc/celix/trunk/dependency_manager_2/public/include/dm_service_dependency.h?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/dependency_manager_2/public/include/dm_service_dependency.h (original)
+++ celix/trunk/dependency_manager_2/public/include/dm_service_dependency.h Wed Mar 18 19:29:49
2015
@@ -44,6 +44,6 @@ celix_status_t serviceDependency_destroy
 celix_status_t serviceDependency_setRequired(dm_service_dependency_pt dependency, bool required);
 celix_status_t serviceDependency_setService(dm_service_dependency_pt dependency, char *serviceName,
char *filter);
 celix_status_t serviceDependency_setCallbacks(dm_service_dependency_pt dependency, service_add_fpt
add, service_change_fpt change, service_remove_fpt remove, service_swap_fpt swap);
-celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, void
**field);
+celix_status_t serviceDependency_setAutoConfigure(dm_service_dependency_pt dependency, celix_thread_mutex_t
*service_lock, void **field);
 
 #endif /* DM_SERVICE_DEPENDENCY_H_ */

Modified: celix/trunk/examples/whiteboard/publisherA/private/src/activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/examples/whiteboard/publisherA/private/src/activator.c?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/examples/whiteboard/publisherA/private/src/activator.c (original)
+++ celix/trunk/examples/whiteboard/publisherA/private/src/activator.c Wed Mar 18 19:29:49
2015
@@ -26,10 +26,7 @@
 #include <stdlib.h>
 
 #include "bundle_activator.h"
-#include "bundle_context.h"
 #include "publisher_private.h"
-#include "celix_errno.h"
-#include "service_registration.h"
 
 struct activatorData {
     publisher_service_pt ps;

Modified: celix/trunk/examples/whiteboard/publisherB/private/src/activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/examples/whiteboard/publisherB/private/src/activator.c?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/examples/whiteboard/publisherB/private/src/activator.c (original)
+++ celix/trunk/examples/whiteboard/publisherB/private/src/activator.c Wed Mar 18 19:29:49
2015
@@ -26,9 +26,7 @@
 #include <stdlib.h>
 
 #include "bundle_activator.h"
-#include "bundle_context.h"
 #include "publisher_private.h"
-#include "service_registration.h"
 
 struct activatorData {
 	publisher_service_pt ps;

Modified: celix/trunk/examples/whiteboard/tracker/private/src/activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/examples/whiteboard/tracker/private/src/activator.c?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/examples/whiteboard/tracker/private/src/activator.c (original)
+++ celix/trunk/examples/whiteboard/tracker/private/src/activator.c Wed Mar 18 19:29:49 2015
@@ -31,7 +31,6 @@
 #include "bundle_activator.h"
 #include "publisher.h"
 #include "service_tracker.h"
-#include "bundle_context.h"
 
 struct data {
 	bundle_context_pt context;
@@ -84,38 +83,24 @@ celix_status_t removedServ(void * handle
 }
 
 celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) {
-    celix_status_t status = CELIX_SUCCESS;
-    if (status == CELIX_SUCCESS) {
-        *userData = calloc(1, sizeof(struct data));
-        ((struct data *) (*userData))->publishers = NULL;
-        arrayList_create(&((struct data *) (*userData))->publishers);
-    } else {
-        status = CELIX_START_ERROR;
-    }
+    *userData = calloc(1, sizeof(struct data));
+    ((struct data *) (*userData))->publishers = NULL;
+    arrayList_create(&((struct data *) (*userData))->publishers);
     return CELIX_SUCCESS;
 }
 
 celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
     celix_status_t status = CELIX_SUCCESS;
-    if (status == CELIX_SUCCESS) {
-        struct data * data = (struct data *) userData;
-		service_tracker_customizer_pt cust = NULL;
-		service_tracker_pt tracker = NULL;
-        
-		data->context = context;
-
-        serviceTrackerCustomizer_create(data, addingServ, addedServ, modifiedServ, removedServ,
&cust);
-        serviceTracker_create(context, (char *) PUBLISHER_NAME, cust, &tracker);
-
-        data->tracker = tracker;
-
-        serviceTracker_open(tracker);
-
-        data->running = true;
-        pthread_create(&data->sender, NULL, trk_send, data);
-    } else {
-        status = CELIX_START_ERROR;
-    }
+    struct data * data = (struct data *) userData;
+    service_tracker_customizer_pt cust = NULL;
+    service_tracker_pt tracker = NULL;
+    data->context = context;
+    serviceTrackerCustomizer_create(data, addingServ, addedServ, modifiedServ, removedServ,
&cust);
+    serviceTracker_create(context, (char *) PUBLISHER_NAME, cust, &tracker);
+    data->tracker = tracker;
+    serviceTracker_open(tracker);
+    data->running = true;
+    pthread_create(&data->sender, NULL, trk_send, data);
     return status;
 }
 

Modified: celix/trunk/examples/whiteboard/tracker_depman/private/include/tracker.h
URL: http://svn.apache.org/viewvc/celix/trunk/examples/whiteboard/tracker_depman/private/include/tracker.h?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/examples/whiteboard/tracker_depman/private/include/tracker.h (original)
+++ celix/trunk/examples/whiteboard/tracker_depman/private/include/tracker.h Wed Mar 18 19:29:49
2015
@@ -39,6 +39,9 @@ struct data {
 	pthread_t sender;
 	bool running;
 	log_service_pt logger;
+
+	celix_thread_mutex_t logger_lock;
+	celix_thread_mutex_t publisher_lock;
 };
 
 celix_status_t tracker_addedServ(void * handle, service_reference_pt ref, void * service);

Modified: celix/trunk/examples/whiteboard/tracker_depman/private/src/dependency_activator.c
URL: http://svn.apache.org/viewvc/celix/trunk/examples/whiteboard/tracker_depman/private/src/dependency_activator.c?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/examples/whiteboard/tracker_depman/private/src/dependency_activator.c (original)
+++ celix/trunk/examples/whiteboard/tracker_depman/private/src/dependency_activator.c Wed
Mar 18 19:29:49 2015
@@ -28,12 +28,8 @@
 #include "celixbool.h"
 
 #include "dm_activator_base.h"
-#include "dm_service_dependency.h"
-#include "dm_component.h"
 #include "publisher.h"
 #include "tracker.h"
-#include "log_service.h"
-#include "bundle_context.h"
 
 celix_status_t dm_create(bundle_context_pt context, void **userData) {
 	printf("Create\n");
@@ -71,7 +67,8 @@ celix_status_t dm_init(void * userData,
 	serviceDependency_create(&dep2);
     serviceDependency_setRequired(dep2, false);
     serviceDependency_setService(dep2, (char *) OSGI_LOGSERVICE_NAME, NULL);
-    serviceDependency_setCallbacks(dep2, tracker_addLog, tracker_modifiedLog, tracker_removeLog,
NULL);
+//    serviceDependency_setCallbacks(dep2, tracker_addLog, tracker_modifiedLog, tracker_removeLog,
NULL);
+	serviceDependency_setAutoConfigure(dep2, &data->logger_lock, (void **) &data->logger);
     component_addServiceDependency(service, dep2, NULL);
 
 	data->service = service;
@@ -102,3 +99,27 @@ celix_status_t dm_destroy(void * userDat
 	return CELIX_SUCCESS;
 }
 
+//int count;
+//
+//void lock(int state) {
+//	pthread_mutex_t lock;
+//	if (state == 1) {
+//		if (count > 0) {
+//			count++;
+//		} else {
+//			pthread_mutex_lock(&lock);
+//		}
+//	} else {
+//		pthread_mutex_lock(&lock);
+//	}
+//}
+//
+//void unlcok(int state) {
+//	if (state == 1) {
+//		if (count-- == 0) {
+//			pthread_mutex_unlock(&lock);
+//		}
+//	} else {
+//		pthread_mutex_unlock(&lock);
+//	}
+//}
\ No newline at end of file

Modified: celix/trunk/examples/whiteboard/tracker_depman/private/src/tracker.c
URL: http://svn.apache.org/viewvc/celix/trunk/examples/whiteboard/tracker_depman/private/src/tracker.c?rev=1667603&r1=1667602&r2=1667603&view=diff
==============================================================================
--- celix/trunk/examples/whiteboard/tracker_depman/private/src/tracker.c (original)
+++ celix/trunk/examples/whiteboard/tracker_depman/private/src/tracker.c Wed Mar 18 19:29:49
2015
@@ -31,20 +31,24 @@
 
 #include "publisher.h"
 #include "tracker.h"
-#include "log_service.h"
 
 static void *dp_send(void *handle) {
 	struct data * data = (struct data *) handle;
 	while (data->running) {
 		printf("Running\n");
 		int i;
+		// lock
 		for (i = 0; i < arrayList_size(data->publishers); i++) {
 			publisher_service_pt pub = (publisher_service_pt) arrayList_get(data->publishers, i);
 			pub->invoke(pub->publisher, "Tracker message");
+			celixThreadMutex_lock(&data->logger_lock);
+			printf("%p\n", data->logger);
 			if (data->logger != NULL) {
 				data->logger->log(data->logger->logger, OSGI_LOGSERVICE_INFO, "Sending message
to publisher");
 			}
+			celixThreadMutex_unlock(&data->logger_lock);
 		}
+		// lock
 		usleep(1000000);
 	}
 	pthread_exit(NULL);
@@ -82,8 +86,7 @@ celix_status_t tracker_addedServ(void *
 }
 
 celix_status_t tracker_modifiedServ(void * handle, service_reference_pt ref, void * service)
{
-	struct data * data = (struct data *) handle;
-	printf("Service Changed\n");
+    printf("Service Changed\n");
 	return CELIX_SUCCESS;
 }
 
@@ -94,25 +97,25 @@ celix_status_t tracker_removedServ(void
 	return CELIX_SUCCESS;
 }
 
-celix_status_t tracker_addLog(void *handle, service_reference_pt ref, void *service) {
-    struct data * data = (struct data *) handle;
-    printf("Add log\n");
-    data->logger = service;
-    ((log_service_pt) service)->log(((log_service_pt) service)->logger, OSGI_LOGSERVICE_DEBUG,
"test");
-    return CELIX_SUCCESS;
-}
-
-celix_status_t tracker_modifiedLog(void *handle, service_reference_pt ref, void *service)
{
-    struct data * data = (struct data *) handle;
-    printf("Modify log\n");
-    data->logger = service;
-    ((log_service_pt) service)->log(((log_service_pt) service)->logger, OSGI_LOGSERVICE_DEBUG,
"test");
-    return CELIX_SUCCESS;
-}
-
-celix_status_t tracker_removeLog(void *handle, service_reference_pt ref, void *service) {
-    struct data * data = (struct data *) handle;
-    data->logger = NULL;
-    printf("Remove log\n");
-    return CELIX_SUCCESS;
-}
+//celix_status_t tracker_addLog(void *handle, service_reference_pt ref, void *service) {
+//    struct data * data = (struct data *) handle;
+//    printf("Add log\n");
+//    data->logger = service;
+//    ((log_service_pt) service)->log(((log_service_pt) service)->logger, OSGI_LOGSERVICE_DEBUG,
"test");
+//    return CELIX_SUCCESS;
+//}
+//
+//celix_status_t tracker_modifiedLog(void *handle, service_reference_pt ref, void *service)
{
+//    struct data * data = (struct data *) handle;
+//    printf("Modify log\n");
+//    data->logger = service;
+//    ((log_service_pt) service)->log(((log_service_pt) service)->logger, OSGI_LOGSERVICE_DEBUG,
"test");
+//    return CELIX_SUCCESS;
+//}
+//
+//celix_status_t tracker_removeLog(void *handle, service_reference_pt ref, void *service)
{
+//    struct data * data = (struct data *) handle;
+//    data->logger = NULL;
+//    printf("Remove log\n");
+//    return CELIX_SUCCESS;
+//}



Mime
View raw message