celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1043909 - in /incubator/celix/trunk: dependency_manager/ hello_world/ hello_world/MANIFEST/
Date Thu, 09 Dec 2010 11:54:50 GMT
Author: abroekhuis
Date: Thu Dec  9 11:54:50 2010
New Revision: 1043909

URL: http://svn.apache.org/viewvc?rev=1043909&view=rev
Log:
CELIX-1 initial code import

Added:
    incubator/celix/trunk/dependency_manager/
    incubator/celix/trunk/dependency_manager/CMakeLists.txt
    incubator/celix/trunk/dependency_manager/dependency_activator_base.c
    incubator/celix/trunk/dependency_manager/dependency_activator_base.h
    incubator/celix/trunk/dependency_manager/dependency_manager.c
    incubator/celix/trunk/dependency_manager/dependency_manager.h
    incubator/celix/trunk/dependency_manager/service.h
    incubator/celix/trunk/dependency_manager/service_component.c
    incubator/celix/trunk/dependency_manager/service_component.h
    incubator/celix/trunk/dependency_manager/service_component_private.h
    incubator/celix/trunk/dependency_manager/service_dependency.c
    incubator/celix/trunk/dependency_manager/service_dependency.h
    incubator/celix/trunk/hello_world/
    incubator/celix/trunk/hello_world/CMakeLists.txt
    incubator/celix/trunk/hello_world/MANIFEST/
    incubator/celix/trunk/hello_world/MANIFEST/MANIFEST.MF
    incubator/celix/trunk/hello_world/activator.c

Added: incubator/celix/trunk/dependency_manager/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/CMakeLists.txt?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/CMakeLists.txt (added)
+++ incubator/celix/trunk/dependency_manager/CMakeLists.txt Thu Dec  9 11:54:50 2010
@@ -0,0 +1,4 @@
+add_library(dependency_manager STATIC dependency_manager.c dependency_activator_base.c service_component.c
service_dependency.c)
+
+include_directories("${PROJECT_SOURCE_DIR}/celix")
+target_link_libraries(dependency_manager framework)
\ No newline at end of file

Added: incubator/celix/trunk/dependency_manager/dependency_activator_base.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/dependency_activator_base.c?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/dependency_activator_base.c (added)
+++ incubator/celix/trunk/dependency_manager/dependency_activator_base.c Thu Dec  9 11:54:50
2010
@@ -0,0 +1,58 @@
+/*
+ * dependency_activator_base.c
+ *
+ *  Created on: Aug 8, 2010
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+
+#include "bundle_activator.h"
+#include "dependency_manager.h"
+#include "service_component_private.h"
+#include "dependency_activator_base.h"
+
+DEPENDENCY_MANAGER m_manager;
+BUNDLE_CONTEXT m_context;
+
+struct dependencyActivatorBase {
+	DEPENDENCY_MANAGER manager;
+	BUNDLE_CONTEXT context;
+	void * userData;
+};
+
+typedef struct dependencyActivatorBase * DEPENDENCY_ACTIVATOR_BASE;
+
+void * bundleActivator_create() {
+	DEPENDENCY_ACTIVATOR_BASE data = (DEPENDENCY_ACTIVATOR_BASE) malloc(sizeof(*data));
+	void * userData = dm_create();
+	data->userData = userData;
+
+	return data;
+}
+
+void bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+	DEPENDENCY_ACTIVATOR_BASE data = (DEPENDENCY_ACTIVATOR_BASE) userData;
+	data->manager = dependencyManager_create(context);
+	data->context = context;
+	dm_init(data->userData, data->context, data->manager);
+}
+
+void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+	DEPENDENCY_ACTIVATOR_BASE data = (DEPENDENCY_ACTIVATOR_BASE) userData;
+	dm_destroy(data->userData, data->context, data->manager);
+	m_manager = NULL;
+	m_context = NULL;
+}
+
+void bundleActivator_destroy(void * userData) {
+
+}
+
+SERVICE dependencyActivatorBase_createService(DEPENDENCY_MANAGER manager) {
+	return serviceComponent_create(manager->context, manager);
+}
+
+SERVICE_DEPENDENCY dependencyActivatorBase_createServiceDependency(DEPENDENCY_MANAGER manager)
{
+	return serviceDependency_create(manager->context);
+}
+

Added: incubator/celix/trunk/dependency_manager/dependency_activator_base.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/dependency_activator_base.h?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/dependency_activator_base.h (added)
+++ incubator/celix/trunk/dependency_manager/dependency_activator_base.h Thu Dec  9 11:54:50
2010
@@ -0,0 +1,22 @@
+/*
+ * dependency_activator_base.h
+ *
+ *  Created on: May 12, 2010
+ *      Author: dk489
+ */
+
+#ifndef DEPENDENCY_ACTIVATOR_BASE_H_
+#define DEPENDENCY_ACTIVATOR_BASE_H_
+
+#include "headers.h"
+#include "dependency_manager.h"
+#include "service_dependency.h"
+
+void * dm_create();
+void dm_init(void * userData, BUNDLE_CONTEXT context, DEPENDENCY_MANAGER manager);
+void dm_destroy(void * userData, BUNDLE_CONTEXT context, DEPENDENCY_MANAGER manager);
+
+SERVICE dependencyActivatorBase_createService();
+SERVICE_DEPENDENCY dependencyActivatorBase_createServiceDependency(DEPENDENCY_MANAGER manager);
+
+#endif /* DEPENDENCY_ACTIVATOR_BASE_H_ */

Added: incubator/celix/trunk/dependency_manager/dependency_manager.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/dependency_manager.c?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/dependency_manager.c (added)
+++ incubator/celix/trunk/dependency_manager/dependency_manager.c Thu Dec  9 11:54:50 2010
@@ -0,0 +1,38 @@
+/*
+ * dependency_manager.c
+ *
+ *  Created on: May 12, 2010
+ *      Author: dk489
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "dependency_manager.h"
+#include "dependency_activator_base.h"
+#include "bundle_context.h"
+#include "service_component_private.h"
+
+DEPENDENCY_MANAGER dependencyManager_create(BUNDLE_CONTEXT context) {
+	DEPENDENCY_MANAGER manager = (DEPENDENCY_MANAGER) malloc(sizeof(*manager));
+	manager->context = context;
+	manager->services = arrayList_create();
+	return manager;
+}
+
+void dependencyManager_add(DEPENDENCY_MANAGER manager, SERVICE service) {
+	arrayList_add(manager->services, service);
+	serviceComponent_start(service);
+}
+
+void dependencyManager_remove(DEPENDENCY_MANAGER manager, SERVICE service) {
+	serviceComponent_stop(service);
+	arrayList_removeElement(manager->services, service);
+}
+
+SERVICE dependencyManager_createService(DEPENDENCY_MANAGER manager) {
+	return serviceComponent_create(manager->context, manager);
+}
+
+SERVICE_DEPENDENCY dependencyManager_createServiceDependency(DEPENDENCY_MANAGER manager)
{
+	return serviceDependency_create(manager->context);
+}

Added: incubator/celix/trunk/dependency_manager/dependency_manager.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/dependency_manager.h?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/dependency_manager.h (added)
+++ incubator/celix/trunk/dependency_manager/dependency_manager.h Thu Dec  9 11:54:50 2010
@@ -0,0 +1,28 @@
+/*
+ * dependency_manager.h
+ *
+ *  Created on: May 12, 2010
+ *      Author: dk489
+ */
+
+#ifndef DEPENDENCY_MANAGER_H_
+#define DEPENDENCY_MANAGER_H_
+
+#include "headers.h"
+#include "service_component.h"
+
+struct dependencyManager {
+	BUNDLE_CONTEXT context;
+	ARRAY_LIST services;
+};
+
+typedef struct dependencyManager * DEPENDENCY_MANAGER;
+
+DEPENDENCY_MANAGER dependencyManager_create(BUNDLE_CONTEXT context);
+void dependencyManager_add(DEPENDENCY_MANAGER manager, SERVICE service);
+void dependencyManager_remove(DEPENDENCY_MANAGER manager, SERVICE service);
+
+void dm_startService(SERVICE service);
+void dm_stopService(SERVICE service);
+
+#endif /* DEPENDENCY_MANAGER_H_ */

Added: incubator/celix/trunk/dependency_manager/service.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service.h?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/service.h (added)
+++ incubator/celix/trunk/dependency_manager/service.h Thu Dec  9 11:54:50 2010
@@ -0,0 +1,16 @@
+/*
+ * service.h
+ *
+ *  Created on: May 12, 2010
+ *      Author: dk489
+ */
+
+#ifndef SERVICE_H_
+#define SERVICE_H_
+
+void service_init(void * userData);
+void service_start(void * userData);
+void service_stop(void * userData);
+void service_destroy(void * userData);
+
+#endif /* SERVICE_H_ */

Added: incubator/celix/trunk/dependency_manager/service_component.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service_component.c?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_component.c (added)
+++ incubator/celix/trunk/dependency_manager/service_component.c Thu Dec  9 11:54:50 2010
@@ -0,0 +1,390 @@
+/*
+ * service_component.c
+ *
+ *  Created on: Aug 8, 2010
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+
+#include "headers.h"
+#include "dependency_manager.h"
+#include "service_component.h"
+#include "service_component_private.h"
+#include "service.h"
+#include "bundle_context.h"
+#include "bundle.h"
+#include "array_list.h"
+#include "service_registration.h"
+
+typedef enum state_state {
+	STATE_INACTIVE = 1,
+	STATE_WAITING_FOR_REQUIRED,
+	STATE_TRACKING_OPTIONAL,
+} STATE_STATE;
+
+struct state {
+	ARRAY_LIST dependencies;
+	STATE_STATE state;
+};
+
+struct executorEntry {
+	SERVICE service;
+	void (*function)(void *, void*);
+	void * argument;
+};
+
+struct executor {
+	struct executorEntry * active;
+	LINKED_LIST workQueue;
+
+	pthread_mutex_t mutex;
+};
+
+SERVICE serviceComponent_create(BUNDLE_CONTEXT context, DEPENDENCY_MANAGER manager) {
+	SERVICE service = (SERVICE) malloc(sizeof(*service));
+
+	service->impl = NULL;
+	service->serviceName = NULL;
+	service->dependencies = arrayList_create();
+
+	service->init = service_init;
+	service->start= service_start;
+	service->stop = service_stop;
+	service->destroy = service_destroy;
+
+	service->context = context;
+	service->manager = manager;
+	service->state = state_create(arrayList_clone(service->dependencies), false);
+	service->executor = executor_create();
+
+	pthread_mutex_init(&service->mutex, NULL);
+
+	return service;
+}
+
+void serviceComponent_calculateStateChanges(SERVICE service, const STATE old, const STATE
new) {
+	if (state_isWaitingForRequired(old) && state_isTrackingOptional(new)) {
+		executor_enqueue(service->executor, service, serviceComponent_activateService, new);
+	}
+	if (state_isTrackingOptional(old) && state_isWaitingForRequired(new)) {
+		executor_enqueue(service->executor, service, serviceComponent_deactivateService, old);
+	}
+	if (state_isInactive(old) && state_isTrackingOptional(new)) {
+		executor_enqueue(service->executor, service, serviceComponent_activateService, new);
+	}
+	if (state_isInactive(old) && state_isWaitingForRequired(new)) {
+		executor_enqueue(service->executor, service, serviceComponent_startTrackingRequired,
new);
+	}
+	if (state_isWaitingForRequired(old) && state_isInactive(new)) {
+		executor_enqueue(service->executor, service, serviceComponent_stopTrackingRequired,
old);
+	}
+	if (state_isTrackingOptional(old) && state_isInactive(new)) {
+		executor_enqueue(service->executor, service, serviceComponent_deactivateService, old);
+		executor_enqueue(service->executor, service, serviceComponent_stopTrackingRequired,
old);
+	}
+	executor_execute(service->executor);
+}
+
+SERVICE serviceComponent_addServiceDependency(SERVICE service, SERVICE_DEPENDENCY dependency)
{
+	STATE old, new;
+	pthread_mutex_lock(&service->mutex);
+	old = service->state;
+	arrayList_add(service->dependencies, dependency);
+	pthread_mutex_unlock(&service->mutex);
+
+	if (state_isTrackingOptional(old) || ( state_isWaitingForRequired(old) && dependency->required))
{
+		serviceDependency_start(dependency, service);
+	}
+
+	pthread_mutex_lock(&service->mutex);
+	new = state_create(arrayList_clone(service->dependencies), !state_isInactive(old));
+	service->state = new;
+	pthread_mutex_unlock(&service->mutex);
+	serviceComponent_calculateStateChanges(service, old, new);
+
+	return service;
+}
+
+SERVICE serviceComponent_removeServiceDependency(SERVICE service, SERVICE_DEPENDENCY dependency)
{
+	STATE old, new;
+	pthread_mutex_lock(&service->mutex);
+	old = service->state;
+	arrayList_removeElement(service->dependencies, dependency);
+	pthread_mutex_unlock(&service->mutex);
+
+	if (state_isTrackingOptional(old) || ( state_isWaitingForRequired(old) && dependency->required))
{
+		serviceDependency_stop(dependency, service);
+	}
+
+	pthread_mutex_lock(&service->mutex);
+	new = state_create(arrayList_clone(service->dependencies), !state_isInactive(old));
+	service->state = new;
+	pthread_mutex_unlock(&service->mutex);
+	serviceComponent_calculateStateChanges(service, old, new);
+
+	return service;
+}
+
+void serviceComponent_dependencyAvailable(SERVICE service, SERVICE_DEPENDENCY dependency)
{
+	STATE old, new;
+	pthread_mutex_lock(&service->mutex);
+	old = service->state;
+	new = state_create(arrayList_clone(service->dependencies), !state_isInactive(old));
+	service->state = new;
+	pthread_mutex_unlock(&service->mutex);
+	serviceComponent_calculateStateChanges(service, old, new);
+	if (state_isTrackingOptional(new)) {
+		executor_enqueue(service->executor, service, serviceComponent_updateInstance, dependency);
+		executor_execute(service->executor);
+	}
+}
+
+void serviceComponent_dependencyChanged(SERVICE service, SERVICE_DEPENDENCY dependency) {
+	STATE state;
+	pthread_mutex_lock(&service->mutex);
+	state = service->state;
+	pthread_mutex_unlock(&service->mutex);
+	if (state_isTrackingOptional(state)) {
+		executor_enqueue(service->executor, service, serviceComponent_updateInstance, dependency);
+		executor_execute(service->executor);
+	}
+}
+
+void serviceComponent_dependencyUnavailable(SERVICE service, SERVICE_DEPENDENCY dependency)
{
+	STATE old, new;
+	pthread_mutex_lock(&service->mutex);
+	old = service->state;
+	new = state_create(arrayList_clone(service->dependencies), !state_isInactive(old));
+	service->state = new;
+	pthread_mutex_unlock(&service->mutex);
+	serviceComponent_calculateStateChanges(service, old, new);
+	if (state_isTrackingOptional(new)) {
+		executor_enqueue(service->executor, service, serviceComponent_updateInstance, dependency);
+		executor_execute(service->executor);
+	}
+}
+
+void serviceComponent_start(SERVICE service) {
+	service->serviceRegistration = bundleContext_registerService(service->context, SERVICE_COMPONENT_NAME,
service, NULL);
+	STATE old, new;
+	pthread_mutex_lock(&service->mutex);
+	old = service->state;
+	new = state_create(arrayList_clone(service->dependencies), true);
+	service->state = new;
+	pthread_mutex_unlock(&service->mutex);
+	serviceComponent_calculateStateChanges(service, old, new);
+}
+
+void serviceComponent_stop(SERVICE service) {
+	STATE old, new;
+	pthread_mutex_lock(&service->mutex);
+	old = service->state;
+	new = state_create(arrayList_clone(service->dependencies), false);
+	service->state = new;
+	pthread_mutex_unlock(&service->mutex);
+	serviceComponent_calculateStateChanges(service, old, new);
+	serviceRegistration_unregister(service->serviceRegistration);
+}
+
+SERVICE serviceComponent_setInterface(SERVICE service, char * serviceName, PROPERTIES properties)
{
+	service->serviceName = serviceName;
+	service->properties = properties;
+
+	return service;
+}
+
+SERVICE serviceComponent_setImplementation(SERVICE service, void * implementation) {
+	service->impl = implementation;
+	return service;
+}
+
+void serviceComponent_activateService(SERVICE service, void * arg) {
+	STATE state = (STATE) arg;
+	serviceComponent_initService(service);
+	service->init(service->impl);
+	serviceComponent_configureService(service, state);
+	service->start(service->impl);
+	serviceComponent_startTrackingOptional(service, state);
+	serviceComponent_registerService(service);
+}
+
+void serviceComponent_deactivateService(SERVICE service, void * arg) {
+	STATE state = (STATE) arg;
+	serviceComponent_unregisterService(service);
+	serviceComponent_stopTrackingOptional(service, state);
+	service->stop(service->impl);
+	service->destroy(service->impl);
+	serviceComponent_destroyService(service, state);
+}
+
+void serviceComponent_startTrackingOptional(SERVICE service, STATE state) {
+	ARRAY_LIST_ITERATOR i = arrayListIterator_create(state->dependencies);
+	while (arrayListIterator_hasNext(i)) {
+		SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) arrayListIterator_next(i);
+		if (!dependency->required) {
+			serviceDependency_start(dependency, service);
+		}
+	}
+}
+
+void serviceComponent_stopTrackingOptional(SERVICE service, STATE state) {
+	ARRAY_LIST_ITERATOR i = arrayListIterator_create(state->dependencies);
+	while (arrayListIterator_hasNext(i)) {
+		SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) arrayListIterator_next(i);
+		if (!dependency->required) {
+			serviceDependency_stop(dependency, service);
+		}
+	}
+}
+
+void serviceComponent_startTrackingRequired(SERVICE service, void * arg) {
+	STATE state = (STATE) arg;
+	ARRAY_LIST_ITERATOR i = arrayListIterator_create(state->dependencies);
+	while (arrayListIterator_hasNext(i)) {
+		SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) arrayListIterator_next(i);
+		if (dependency->required) {
+			serviceDependency_start(dependency, service);
+		}
+	}
+}
+
+void serviceComponent_stopTrackingRequired(SERVICE service, void * arg) {
+	STATE state = (STATE) arg;
+	ARRAY_LIST_ITERATOR i = arrayListIterator_create(state->dependencies);
+	while (arrayListIterator_hasNext(i)) {
+		SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) arrayListIterator_next(i);
+		if (dependency->required) {
+			serviceDependency_stop(dependency, service);
+		}
+	}
+}
+
+void serviceComponent_initService(SERVICE service) {
+}
+
+void serviceComponent_configureService(SERVICE service, STATE state) {
+	ARRAY_LIST_ITERATOR i = arrayListIterator_create(state->dependencies);
+	while (arrayListIterator_hasNext(i)) {
+		SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) arrayListIterator_next(i);
+		if (dependency->autoConfigureField != NULL) {
+			*dependency->autoConfigureField = serviceDependency_getService(dependency);
+		}
+		if (dependency->required) {
+			serviceDependency_invokeAdded(dependency);
+		}
+	}
+}
+
+void serviceComponent_destroyService(SERVICE service, STATE state) {
+	ARRAY_LIST_ITERATOR i = arrayListIterator_create(state->dependencies);
+	while (arrayListIterator_hasNext(i)) {
+		SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) arrayListIterator_next(i);
+		if (dependency->required) {
+			serviceDependency_invokeRemoved(dependency);
+		}
+	}
+}
+
+void serviceComponent_registerService(SERVICE service) {
+	if (service->serviceName != NULL) {
+		service->registration = bundleContext_registerService(service->context, service->serviceName,
service->impl, service->properties);
+	}
+}
+
+void serviceComponent_unregisterService(SERVICE service) {
+	if (service->serviceName != NULL) {
+		serviceRegistration_unregister(service->registration);
+	}
+}
+
+void serviceComponent_updateInstance(SERVICE service, void * arg) {
+	SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) arg;
+	if (dependency->autoConfigureField != NULL) {
+		*dependency->autoConfigureField = serviceDependency_getService(dependency);
+	}
+}
+
+char * serviceComponent_getName(SERVICE service) {
+	return service->serviceName;
+}
+
+STATE state_create(ARRAY_LIST dependencies, bool active) {
+	STATE state = (STATE) malloc(sizeof(*state));
+	state->dependencies = dependencies;
+	if (active) {
+		bool allReqAvail = true;
+		int i;
+		for (i = 0; i < arrayList_size(dependencies); i++) {
+			SERVICE_DEPENDENCY dependency = arrayList_get(dependencies, i);
+			if (dependency->required) {
+				if (!dependency->available) {
+					allReqAvail = false;
+					break;
+				}
+			}
+		}
+		if (allReqAvail) {
+			state->state = STATE_TRACKING_OPTIONAL;
+		} else {
+			state->state = STATE_WAITING_FOR_REQUIRED;
+		}
+	} else {
+		state->state = STATE_INACTIVE;
+	}
+
+	return state;
+}
+
+bool state_isInactive(STATE state) {
+	return state->state == STATE_INACTIVE;
+}
+
+bool state_isWaitingForRequired(STATE state) {
+	return state->state == STATE_WAITING_FOR_REQUIRED;
+}
+
+bool state_isTrackingOptional(STATE state) {
+	return state->state == STATE_TRACKING_OPTIONAL;
+}
+
+ARRAY_LIST state_getDependencies(STATE state) {
+	return state->dependencies;
+}
+
+EXECUTOR executor_create() {
+	EXECUTOR executor = (EXECUTOR) malloc(sizeof(*executor));
+	executor->workQueue = linkedList_create();
+	executor->active = NULL;
+	pthread_mutex_init(&executor->mutex, NULL);
+	return executor;
+}
+
+void executor_enqueue(EXECUTOR executor, SERVICE service, void (*function), void * argument)
{
+	pthread_mutex_lock(&executor->mutex);
+	struct executorEntry * entry = malloc(sizeof(*entry));
+	entry->service = service;
+	entry->function = function;
+	entry->argument = argument;
+	linkedList_addLast(executor->workQueue, entry);
+	pthread_mutex_unlock(&executor->mutex);
+}
+
+void executor_execute(EXECUTOR executor) {
+	struct executorEntry * active;
+	pthread_mutex_lock(&executor->mutex);
+	active = executor->active;
+	pthread_mutex_unlock(&executor->mutex);
+	if (active == NULL) {
+		executor_scheduleNext(executor);
+	}
+}
+
+void executor_scheduleNext(EXECUTOR executor) {
+	struct executorEntry * entry = NULL;
+	pthread_mutex_lock(&executor->mutex);
+	entry = linkedList_removeFirst(executor->workQueue);
+	pthread_mutex_unlock(&executor->mutex);
+	if (entry != NULL) {
+		entry->function(entry->service, entry->argument);
+	}
+}

Added: incubator/celix/trunk/dependency_manager/service_component.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service_component.h?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_component.h (added)
+++ incubator/celix/trunk/dependency_manager/service_component.h Thu Dec  9 11:54:50 2010
@@ -0,0 +1,20 @@
+/*
+ * service_component.h
+ *
+ *  Created on: Aug 9, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef SERVICE_COMPONENT_H_
+#define SERVICE_COMPONENT_H_
+
+#define SERVICE_COMPONENT_NAME "ServiceComponent"
+
+typedef struct service * SERVICE;
+
+struct serviceComponent {
+	SERVICE handle;
+	char * (*getName)(SERVICE handle);
+};
+
+#endif /* SERVICE_COMPONENT_H_ */

Added: incubator/celix/trunk/dependency_manager/service_component_private.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service_component_private.h?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_component_private.h (added)
+++ incubator/celix/trunk/dependency_manager/service_component_private.h Thu Dec  9 11:54:50
2010
@@ -0,0 +1,81 @@
+/*
+ * service_component_private.h
+ *
+ *  Created on: Aug 9, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef SERVICE_COMPONENT_PRIVATE_H_
+#define SERVICE_COMPONENT_PRIVATE_H_
+#include <stdbool.h>
+
+#include "service_component.h"
+#include "service_dependency.h"
+#include "properties.h"
+#include "dependency_manager.h"
+
+typedef struct state * STATE;
+typedef struct executor * EXECUTOR;
+
+struct service {
+	ARRAY_LIST dependencies;
+	void (*init)(void * userData);
+	void (*start)(void * userData);
+	void (*stop)(void * userData);
+	void (*destroy)(void * userData);
+
+	char * serviceName;
+	void * impl;
+	PROPERTIES properties;
+
+	BUNDLE_CONTEXT context;
+	DEPENDENCY_MANAGER manager;
+
+	SERVICE_REGISTRATION registration;
+	SERVICE_REGISTRATION serviceRegistration;
+
+	bool registered;
+
+	STATE state;
+	EXECUTOR executor;
+
+	pthread_mutex_t mutex;
+};
+
+SERVICE serviceComponent_create(BUNDLE_CONTEXT context, DEPENDENCY_MANAGER manager);
+SERVICE serviceComponent_addServiceDependency(SERVICE service, SERVICE_DEPENDENCY dependency);
+SERVICE serviceComponent_removeServiceDependency(SERVICE service, SERVICE_DEPENDENCY dependency);
+void serviceComponent_dependencyAvailable(SERVICE service, SERVICE_DEPENDENCY dependency);
+void serviceComponent_dependencyChanged(SERVICE service, SERVICE_DEPENDENCY dependency);
+void serviceComponent_dependencyUnavailable(SERVICE service, SERVICE_DEPENDENCY dependency);
+void serviceComponent_start(SERVICE service);
+void serviceComponent_stop(SERVICE service);
+SERVICE serviceComponent_setInterface(SERVICE service, char * serviceName, PROPERTIES properties);
+SERVICE serviceComponent_setImplementation(SERVICE service, void * implementation);
+void serviceComponent_activateService(SERVICE service, void * arg);
+void serviceComponent_deactivateService(SERVICE service, void * arg);
+void serviceComponent_startTrackingOptional(SERVICE service, STATE state);
+void serviceComponent_stopTrackingOptional(SERVICE service, STATE state);
+void serviceComponent_startTrackingRequired(SERVICE service, void * arg);
+void serviceComponent_stopTrackingRequired(SERVICE service, void * arg);
+void serviceComponent_initService(SERVICE service);
+void serviceComponent_configureService(SERVICE service, STATE state);
+void serviceComponent_destroyService(SERVICE service, STATE state);
+void serviceComponent_registerService(SERVICE service);
+void serviceComponent_unregisterService(SERVICE service);
+void serviceComponent_updateInstance(SERVICE service, void * arg);
+char * serviceComponent_getName(SERVICE service);
+
+
+STATE state_create(ARRAY_LIST dependencies, bool active);
+bool state_isInactive(STATE state);
+bool state_isWaitingForRequired(STATE state);
+bool state_isTrackingOptional(STATE state);
+ARRAY_LIST state_getDependencies(STATE state);
+
+EXECUTOR executor_create();
+void executor_enqueue(EXECUTOR executor, SERVICE service, void (*function), void * argument);
+void executor_execute(EXECUTOR executor);
+void executor_scheduleNext(EXECUTOR executor);
+
+#endif /* SERVICE_COMPONENT_PRIVATE_H_ */

Added: incubator/celix/trunk/dependency_manager/service_dependency.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service_dependency.c?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_dependency.c (added)
+++ incubator/celix/trunk/dependency_manager/service_dependency.c Thu Dec  9 11:54:50 2010
@@ -0,0 +1,138 @@
+/*
+ * service_dependency.c
+ *
+ *  Created on: Aug 9, 2010
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+
+#include "service_component_private.h"
+#include "service_dependency.h"
+#include "service_tracker.h"
+#include "bundle_context.h"
+
+void * serviceDependency_addingService(void * handle, SERVICE_REFERENCE reference);
+void serviceDependency_addedService(void * handle, SERVICE_REFERENCE reference, void * service);
+void serviceDependency_modifiedService(void * handle, SERVICE_REFERENCE reference, void *
service);
+void serviceDependency_removedService(void * handle, SERVICE_REFERENCE reference, void *
service);
+
+SERVICE_DEPENDENCY serviceDependency_create(BUNDLE_CONTEXT context) {
+	SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) malloc(sizeof(*dependency));
+	dependency->context = context;
+	dependency->autoConfigureField = NULL;
+	return dependency;
+}
+
+void * serviceDependency_getService(SERVICE_DEPENDENCY dependency) {
+	void * service = NULL;
+	if (dependency->started) {
+		service = tracker_getService(dependency->tracker);
+	}
+	return service;
+}
+
+void serviceDependency_start(SERVICE_DEPENDENCY dependency, SERVICE service) {
+	dependency->service = service;
+
+	if (dependency->trackedServiceName != NULL) {
+		SERVICE_TRACKER_CUSTOMIZER cust = (SERVICE_TRACKER_CUSTOMIZER) malloc(sizeof(*cust));
+		cust->handle = dependency;
+		cust->addingService = serviceDependency_addingService;
+		cust->addedService = serviceDependency_addedService;
+		cust->modifiedService = serviceDependency_modifiedService;
+		cust->removedService = serviceDependency_removedService;
+
+		dependency->tracker = tracker_create(dependency->context, dependency->trackedServiceName,
cust);
+	} else {
+
+	}
+	dependency->started = true;
+	tracker_open(dependency->tracker);
+}
+
+void serviceDependency_stop(SERVICE_DEPENDENCY dependency, SERVICE service) {
+	dependency->started = true;
+	tracker_close(dependency->tracker);
+}
+
+void * serviceDependency_addingService(void * handle, SERVICE_REFERENCE reference) {
+	SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) handle;
+	void * service = bundleContext_getService(dependency->context, reference);
+	dependency->reference = reference;
+	dependency->serviceInstance = service;
+	return service;
+}
+
+void serviceDependency_addedService(void * handle, SERVICE_REFERENCE reference, void * service)
{
+	SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) handle;
+	if (!dependency->available) {
+		dependency->available = true;
+		serviceComponent_dependencyAvailable(dependency->service, dependency);
+	} else {
+		serviceComponent_dependencyChanged(dependency->service, dependency);
+	}
+	if (!dependency->required && dependency->added != NULL) {
+		dependency->added(dependency->service->impl, reference, service);
+	}
+}
+
+void serviceDependency_invokeAdded(SERVICE_DEPENDENCY dependency) {
+	if (dependency->added != NULL) {
+		dependency->added(dependency->service->impl, dependency->reference, dependency->serviceInstance);
+	}
+}
+
+void serviceDependency_modifiedService(void * handle, SERVICE_REFERENCE reference, void *
service) {
+	SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) handle;
+	dependency->reference = reference;
+	dependency->serviceInstance = service;
+	serviceComponent_dependencyChanged(dependency->service, dependency);
+
+	if (dependency->service->registered && dependency->changed != NULL) {
+		dependency->changed(dependency->service->impl, reference, service);
+	}
+}
+
+void serviceDependency_removedService(void * handle, SERVICE_REFERENCE reference, void *
service) {
+	SERVICE_DEPENDENCY dependency = (SERVICE_DEPENDENCY) handle;
+	if (dependency->available && tracker_getService(dependency->tracker) == NULL)
{
+		dependency->available = false;
+		serviceComponent_dependencyUnavailable(dependency->service, dependency);
+	}
+
+	if (!dependency->required && dependency->removed != NULL) {
+		dependency->removed(dependency->service->impl, reference, service);
+	}
+
+	bundleContext_ungetService(dependency->context, reference);
+}
+
+void serviceDependency_invokeRemoved(SERVICE_DEPENDENCY dependency) {
+	if (dependency->removed != NULL) {
+		dependency->removed(dependency->service->impl, dependency->reference, dependency->serviceInstance);
+	}
+}
+
+SERVICE_DEPENDENCY serviceDependency_setService(SERVICE_DEPENDENCY dependency, char * serviceName,
char * filter) {
+	dependency->trackedServiceName = serviceName;
+//	dependency->filter = filter;
+}
+
+SERVICE_DEPENDENCY serviceDependency_setRequired(SERVICE_DEPENDENCY dependency, bool required)
{
+	dependency->required = required;
+}
+
+SERVICE_DEPENDENCY serviceDependency_setAutoConfigure(SERVICE_DEPENDENCY dependency, void
** field) {
+	dependency->autoConfigureField = field;
+
+	return dependency;
+}
+
+SERVICE_DEPENDENCY serviceDependency_setCallbacks(SERVICE_DEPENDENCY dependency, void (*added)(void
* handle, SERVICE_REFERENCE reference, void *),
+		void (*changed)(void * handle, SERVICE_REFERENCE reference, void *),
+		void (*removed)(void * handle, SERVICE_REFERENCE reference, void *)) {
+	dependency->added = added;
+	dependency->changed = changed;
+	dependency->removed = removed;
+	return dependency;
+}

Added: incubator/celix/trunk/dependency_manager/service_dependency.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service_dependency.h?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_dependency.h (added)
+++ incubator/celix/trunk/dependency_manager/service_dependency.h Thu Dec  9 11:54:50 2010
@@ -0,0 +1,52 @@
+/*
+ * service_dependency.h
+ *
+ *  Created on: Aug 9, 2010
+ *      Author: alexanderb
+ */
+
+#ifndef SERVICE_DEPENDENCY_H_
+#define SERVICE_DEPENDENCY_H_
+
+#include <stdbool.h>
+
+#include "headers.h"
+
+struct serviceDependency {
+	char * interface;
+	void (*added)(void * handle, SERVICE_REFERENCE reference, void *);
+	void (*changed)(void * handle, SERVICE_REFERENCE reference, void *);
+	void (*removed)(void * handle, SERVICE_REFERENCE reference, void *);
+	void ** autoConfigureField;
+
+	bool started;
+	bool available;
+	bool required;
+	SERVICE_TRACKER tracker;
+	SERVICE service;
+	SERVICE_REFERENCE reference;
+	BUNDLE_CONTEXT context;
+	void * serviceInstance;
+	char * trackedServiceName;
+};
+
+typedef struct serviceDependency * SERVICE_DEPENDENCY;
+
+SERVICE_DEPENDENCY serviceDependency_create(BUNDLE_CONTEXT context);
+void * serviceDependency_getService(SERVICE_DEPENDENCY dependency);
+
+SERVICE_DEPENDENCY serviceDependency_setRequired(SERVICE_DEPENDENCY dependency, bool required);
+SERVICE_DEPENDENCY serviceDependency_setService(SERVICE_DEPENDENCY dependency, char * serviceName,
char * filter);
+SERVICE_DEPENDENCY serviceDependency_setCallbacks(SERVICE_DEPENDENCY dependency, void (*added)(void
* handle, SERVICE_REFERENCE reference, void *),
+		void (*changed)(void * handle, SERVICE_REFERENCE reference, void *),
+		void (*removed)(void * handle, SERVICE_REFERENCE reference, void *));
+SERVICE_DEPENDENCY serviceDependency_setAutoConfigure(SERVICE_DEPENDENCY dependency, void
** field);
+
+void serviceDependency_start(SERVICE_DEPENDENCY dependency, SERVICE service);
+void serviceDependency_stop(SERVICE_DEPENDENCY dependency, SERVICE service);
+
+void serviceDependency_invokeAdded(SERVICE_DEPENDENCY dependency);
+void serviceDependency_invokeRemoved(SERVICE_DEPENDENCY dependency);
+
+
+#endif /* SERVICE_DEPENDENCY_H_ */

Added: incubator/celix/trunk/hello_world/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hello_world/CMakeLists.txt?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/hello_world/CMakeLists.txt (added)
+++ incubator/celix/trunk/hello_world/CMakeLists.txt Thu Dec  9 11:54:50 2010
@@ -0,0 +1,5 @@
+add_library(hello_world SHARED activator)
+include_directories("${PROJECT_SOURCE_DIR}/celix")
+target_link_libraries(hello_world framework)
+
+bundle(hello_world)

Added: incubator/celix/trunk/hello_world/MANIFEST/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hello_world/MANIFEST/MANIFEST.MF?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/hello_world/MANIFEST/MANIFEST.MF (added)
+++ incubator/celix/trunk/hello_world/MANIFEST/MANIFEST.MF Thu Dec  9 11:54:50 2010
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: hello_world
+Bundle-Version: 1.0.0
+library: hello_world

Added: incubator/celix/trunk/hello_world/activator.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/hello_world/activator.c?rev=1043909&view=auto
==============================================================================
--- incubator/celix/trunk/hello_world/activator.c (added)
+++ incubator/celix/trunk/hello_world/activator.c Thu Dec  9 11:54:50 2010
@@ -0,0 +1,35 @@
+/*
+ * activator.c
+ *
+ *  Created on: Aug 20, 2010
+ *      Author: alexanderb
+ */
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "bundle_activator.h"
+
+struct userData {
+	char * word;
+};
+
+void * bundleActivator_create() {
+	struct userData * data = malloc(sizeof(*data));
+	data->word = "World";
+	return data;
+}
+
+void bundleActivator_start(void * userData, BUNDLE_CONTEXT context) {
+	struct userData * data = (struct userData *) userData;
+	printf("Hello %s\n", data->word);
+
+}
+
+void bundleActivator_stop(void * userData, BUNDLE_CONTEXT context) {
+	struct userData * data = (struct userData *) userData;
+	printf("Goodbye %s\n", data->word);
+}
+
+void bundleActivator_destroy(void * userData) {
+
+}



Mime
View raw message