Author: abroekhuis
Date: Mon Jun 24 13:02:01 2013
New Revision: 1496015

URL: http://svn.apache.org/r1496015
Log:
CELIX-56: Code/API format changes

Modified:
    incubator/celix/trunk/framework/private/include/framework_private.h
    incubator/celix/trunk/framework/private/src/bundle_context.c
    incubator/celix/trunk/framework/private/src/framework.c
    incubator/celix/trunk/framework/private/src/service_registry.c
    incubator/celix/trunk/framework/public/include/service_registry.h

Modified: incubator/celix/trunk/framework/private/include/framework_private.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/framework_private.h?rev=1496015&r1=1496014&r2=1496015&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/framework_private.h 
(original)
+++ incubator/celix/trunk/framework/private/include/framework_private.h Mon Jun 
24 13:02:01 2013
@@ -61,8 +61,8 @@ FRAMEWORK_EXPORT celix_status_t fw_regis
 FRAMEWORK_EXPORT void fw_unregisterService(service_registration_t 
registration);
 
 FRAMEWORK_EXPORT celix_status_t fw_getServiceReferences(framework_t framework, 
array_list_t *references, bundle_t bundle, const char * serviceName, char * 
filter);
-FRAMEWORK_EXPORT void * fw_getService(framework_t framework, bundle_t bundle, 
service_reference_t reference);
-FRAMEWORK_EXPORT bool framework_ungetService(framework_t framework, bundle_t 
bundle, service_reference_t reference);
+FRAMEWORK_EXPORT celix_status_t fw_getService(framework_t framework, bundle_t 
bundle, service_reference_t reference, void **service);
+FRAMEWORK_EXPORT celix_status_t framework_ungetService(framework_t framework, 
bundle_t bundle, service_reference_t reference, bool *result);
 FRAMEWORK_EXPORT celix_status_t fw_getBundleRegisteredServices(framework_t 
framework, apr_pool_t *pool, bundle_t bundle, array_list_t *services);
 FRAMEWORK_EXPORT celix_status_t fw_getBundleServicesInUse(framework_t 
framework, bundle_t bundle, array_list_t *services);
 

Modified: incubator/celix/trunk/framework/private/src/bundle_context.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_context.c?rev=1496015&r1=1496014&r2=1496015&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_context.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_context.c Mon Jun 24 
13:02:01 2013
@@ -207,7 +207,7 @@ celix_status_t bundleContext_getService(
     celix_status_t status = CELIX_SUCCESS;
 
     if (context != NULL && reference != NULL && *service_instance == NULL) {
-           *service_instance = fw_getService(context->framework, 
context->bundle, reference);
+           status = fw_getService(context->framework, context->bundle, 
reference, service_instance);
     } else {
         status = CELIX_ILLEGAL_ARGUMENT;
     }
@@ -219,7 +219,7 @@ celix_status_t bundleContext_ungetServic
     celix_status_t status = CELIX_SUCCESS;
 
     if (context != NULL && reference != NULL) {
-        *result = framework_ungetService(context->framework, context->bundle, 
reference);
+        status = framework_ungetService(context->framework, context->bundle, 
reference, result);
     } else {
         status = CELIX_ILLEGAL_ARGUMENT;
     }

Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1496015&r1=1496014&r2=1496015&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Mon Jun 24 13:02:01 
2013
@@ -292,7 +292,7 @@ celix_status_t framework_destroy(framewo
 
        hashMap_destroy(framework->installRequestMap, false, false);
 
-       serviceRegistry_destroy(framework->registry);
+//     serviceRegistry_destroy(framework->registry);
 
        arrayList_destroy(framework->globalLockWaitersList);
        arrayList_destroy(framework->serviceListeners);
@@ -408,7 +408,8 @@ celix_status_t fw_init(framework_pt fram
             }
         }
         arrayList_destroy(archives);
-        framework->registry = serviceRegistry_create(framework, 
fw_serviceChanged);
+        framework->registry = NULL;
+               serviceRegistry_create(framework->mp, framework, 
fw_serviceChanged, &framework->registry);
 
         framework_setBundleStateAndNotify(framework, framework->bundle, 
BUNDLE_STARTING);
 
@@ -1186,7 +1187,7 @@ celix_status_t fw_registerService(framew
                framework_releaseBundleLock(framework, bundle);
                return CELIX_ILLEGAL_STATE;
        }
-       *registration = serviceRegistry_registerService(framework->registry, 
bundle, serviceName, svcObj, properties);
+       serviceRegistry_registerService(framework->registry, bundle, 
serviceName, svcObj, properties, registration);
        framework_releaseBundleLock(framework, bundle);
 
        // If this is a listener hook, invoke the callback with all current 
listeners
@@ -1220,13 +1221,14 @@ celix_status_t fw_registerService(framew
 
                        arrayList_add(infos, info);
                }
+               bool ungetResult = false;
 
                apr_pool_create(&subpool, pool);
 
                serviceRegistry_createServiceReference(framework->registry, 
subpool, *registration, &ref);
-               hook = (listener_hook_service_pt) 
fw_getService(framework,framework->bundle, ref);
+               celix_status_t status = 
fw_getService(framework,framework->bundle, ref, (void **) &hook);
                hook->added(hook->handle, infos);
-               serviceRegistry_ungetService(framework->registry, 
framework->bundle, ref);
+               serviceRegistry_ungetService(framework->registry, 
framework->bundle, ref, &ungetResult);
 
                apr_pool_destroy(subpool);
        }
@@ -1250,7 +1252,7 @@ celix_status_t fw_registerServiceFactory
         framework_releaseBundleLock(framework, bundle);
         return CELIX_ILLEGAL_STATE;
     }
-    *registration = 
serviceRegistry_registerServiceFactory(framework->registry, bundle, 
serviceName, factory, properties);
+    serviceRegistry_registerServiceFactory(framework->registry, bundle, 
serviceName, factory, properties, registration);
     framework_releaseBundleLock(framework, bundle);
 
     return CELIX_SUCCESS;
@@ -1290,8 +1292,8 @@ celix_status_t fw_getServiceReferences(f
        return CELIX_SUCCESS;
 }
 
-void * fw_getService(framework_pt framework, bundle_pt bundle, 
service_reference_pt reference) {
-       return serviceRegistry_getService(framework->registry, bundle, 
reference);
+celix_status_t fw_getService(framework_pt framework, bundle_pt bundle, 
service_reference_pt reference, void **service) {
+       return serviceRegistry_getService(framework->registry, bundle, 
reference, service);
 }
 
 celix_status_t fw_getBundleRegisteredServices(framework_pt framework, 
apr_pool_t *pool, bundle_pt bundle, array_list_pt *services) {
@@ -1300,12 +1302,12 @@ celix_status_t fw_getBundleRegisteredSer
 
 celix_status_t fw_getBundleServicesInUse(framework_pt framework, bundle_pt 
bundle, array_list_pt *services) {
        celix_status_t status = CELIX_SUCCESS;
-       *services = serviceRegistry_getServicesInUse(framework->registry, 
bundle);
+       status = serviceRegistry_getServicesInUse(framework->registry, bundle, 
services);
        return status;
 }
 
-bool framework_ungetService(framework_pt framework, bundle_pt bundle, 
service_reference_pt reference) {
-       return serviceRegistry_ungetService(framework->registry, bundle, 
reference);
+celix_status_t framework_ungetService(framework_pt framework, bundle_pt 
bundle, service_reference_pt reference, bool *result) {
+       return serviceRegistry_ungetService(framework->registry, bundle, 
reference, result);
 }
 
 void fw_addServiceListener(framework_pt framework, bundle_pt bundle, 
service_listener_pt listener, char * sfilter) {
@@ -1350,12 +1352,16 @@ void fw_addServiceListener(framework_pt 
 
        for (i = 0; i < arrayList_size(listenerHooks); i++) {
                service_reference_pt ref = (service_reference_pt) 
arrayList_get(listenerHooks, i);
-               listener_hook_service_pt hook = (listener_hook_service_pt) 
fw_getService(framework, framework->bundle, ref);
+               listener_hook_service_pt hook = NULL;
                array_list_pt infos = NULL;
+               bool ungetResult = false;
+
+               celix_status_t status = fw_getService(framework, 
framework->bundle, ref, (void **) &hook);
+
                arrayList_create(subpool, &infos);
                arrayList_add(infos, info);
                hook->added(hook->handle, infos);
-               serviceRegistry_ungetService(framework->registry, 
framework->bundle, ref);
+               serviceRegistry_ungetService(framework->registry, 
framework->bundle, ref, &ungetResult);
        }
 
        arrayList_destroy(listenerHooks);
@@ -1405,15 +1411,18 @@ void fw_removeServiceListener(framework_
                
                for (i = 0; i < arrayList_size(listenerHooks); i++) {
                        service_reference_pt ref = (service_reference_pt) 
arrayList_get(listenerHooks, i);
-                       listener_hook_service_pt hook = 
(listener_hook_service_pt) fw_getService(framework, framework->bundle, ref);
+                       listener_hook_service_pt hook = NULL;
                        array_list_pt infos = NULL;
                        apr_pool_t *pool = NULL;
+                       bool ungetResult;
+
+                       celix_status_t status = fw_getService(framework, 
framework->bundle, ref, (void **) &hook);
 
                        bundle_getMemoryPool(bundle, &pool);
                        arrayList_create(pool, &infos);
                        arrayList_add(infos, info);
                        hook->removed(hook->handle, infos);
-                       serviceRegistry_ungetService(framework->registry, 
framework->bundle, ref);
+                       serviceRegistry_ungetService(framework->registry, 
framework->bundle, ref, &ungetResult);
                }
 
                arrayList_destroy(listenerHooks);

Modified: incubator/celix/trunk/framework/private/src/service_registry.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/service_registry.c?rev=1496015&r1=1496014&r2=1496015&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/service_registry.c (original)
+++ incubator/celix/trunk/framework/private/src/service_registry.c Mon Jun 24 
13:02:01 2013
@@ -36,11 +36,12 @@
 #include "framework_private.h"
 
 struct serviceRegistry {
+       apr_pool_t *pool;
     framework_pt framework;
        hash_map_pt serviceRegistrations;
        hash_map_pt serviceReferences;
        hash_map_pt inUseMap;
-       void (*serviceChanged)(framework_pt, service_event_type_e, 
service_registration_pt, properties_pt);
+       serviceChanged_function_pt serviceChanged;
        long currentServiceId;
 
        array_list_pt listenerHooks;
@@ -52,34 +53,44 @@ struct usageCount {
        unsigned int count;
        service_reference_pt reference;
        void * service;
+       apr_pool_t *pool;
 };
 
 typedef struct usageCount * usage_count_pt;
 
+apr_status_t serviceRegistry_destroy(void *handle);
+
 celix_status_t serviceRegistry_registerServiceInternal(service_registry_pt 
registry, bundle_pt bundle, char * serviceName, void * serviceObject, 
properties_pt dictionary, bool isFactory, service_registration_pt 
*registration);
 celix_status_t serviceRegistry_addHooks(service_registry_pt registry, char 
*serviceName, void *serviceObject, service_registration_pt registration);
 celix_status_t serviceRegistry_removeHook(service_registry_pt registry, 
service_registration_pt registration);
 
 apr_status_t serviceRegistry_removeReference(void *referenceP);
 
-usage_count_pt serviceRegistry_getUsageCount(service_registry_pt registry, 
bundle_pt bundle, service_reference_pt reference) {
+celix_status_t serviceRegistry_getUsageCount(service_registry_pt registry, 
bundle_pt bundle, service_reference_pt reference, usage_count_pt *usageCount) {
        array_list_pt usages = (array_list_pt) hashMap_get(registry->inUseMap, 
bundle);
+       *usageCount = NULL;
        unsigned int i;
        for (i = 0; (usages != NULL) && (i < arrayList_size(usages)); i++) {
                usage_count_pt usage = (usage_count_pt) arrayList_get(usages, 
i);
                if (usage->reference == reference) {
-                       return usage;
+                       *usageCount = usage;
+                       break;
                }
        }
-       return NULL;
+       return CELIX_SUCCESS;
 }
 
-usage_count_pt serviceRegistry_addUsageCount(service_registry_pt registry, 
bundle_pt bundle, service_reference_pt reference) {
+celix_status_t serviceRegistry_addUsageCount(service_registry_pt registry, 
bundle_pt bundle, service_reference_pt reference, usage_count_pt *usageCount) {
+       apr_pool_t *pool = NULL;
+
+       apr_pool_create(&pool, registry->pool);
+
        array_list_pt usages = hashMap_get(registry->inUseMap, bundle);
-       usage_count_pt usage = (usage_count_pt) malloc(sizeof(*usage));
+       usage_count_pt usage = (usage_count_pt) apr_palloc(pool, 
sizeof(*usage));
        usage->reference = reference;
        usage->count = 0;
        usage->service = NULL;
+       usage->pool = pool;
 
        if (usages == NULL) {
                module_pt mod = NULL;
@@ -90,10 +101,11 @@ usage_count_pt serviceRegistry_addUsageC
        }
        arrayList_add(usages, usage);
        hashMap_put(registry->inUseMap, bundle, usages);
-       return usage;
+       *usageCount = usage;
+       return CELIX_SUCCESS;
 }
 
-void serviceRegistry_flushUsageCount(service_registry_pt registry, bundle_pt 
bundle, service_reference_pt reference) {
+celix_status_t serviceRegistry_flushUsageCount(service_registry_pt registry, 
bundle_pt bundle, service_reference_pt reference) {
        array_list_pt usages = hashMap_get(registry->inUseMap, bundle);
        if (usages != NULL) {
                array_list_iterator_pt iter = arrayListIterator_create(usages);
@@ -101,7 +113,7 @@ void serviceRegistry_flushUsageCount(ser
                        usage_count_pt usage = arrayListIterator_next(iter);
                        if (usage->reference == reference) {
                                arrayListIterator_remove(iter);
-                               free(usage);
+                               apr_pool_destroy(usage->pool);
                        }
                }
                arrayListIterator_destroy(iter);
@@ -112,40 +124,50 @@ void serviceRegistry_flushUsageCount(ser
                        arrayList_destroy(removed);
                }
        }
+       return CELIX_SUCCESS;
 }
 
-// #TODO: Add pool as argument
-service_registry_pt serviceRegistry_create(framework_pt framework, void 
(*serviceChanged)(framework_t, service_event_type_e, service_registration_t, 
properties_t)) {
-       service_registry_pt registry;
-       bundle_pt fwBundle = NULL;
-       apr_pool_t *pool = NULL;
+celix_status_t serviceRegistry_create(apr_pool_t *pool, framework_pt 
framework, serviceChanged_function_pt serviceChanged, service_registry_pt 
*registry) {
+       celix_status_t status = CELIX_SUCCESS;
 
-       framework_getFrameworkBundle(framework, &fwBundle);
-       bundle_getMemoryPool(fwBundle, &pool);
-       registry = (service_registry_pt) apr_palloc(pool, (sizeof(*registry)));
-       if (registry == NULL) {
-           // no memory
+       *registry = (service_registry_pt) apr_palloc(pool, 
(sizeof(**registry)));
+       if (!*registry) {
+               status = CELIX_ENOMEM;
        } else {
-               apr_status_t mutexattr;
-
-        registry->serviceChanged = serviceChanged;
-        registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
-        registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, 
NULL);
-        registry->framework = framework;
+               apr_status_t aprStatus;
 
-        arrayList_create(pool, &registry->listenerHooks);
-        mutexattr = apr_thread_mutex_create(&registry->mutex, 
APR_THREAD_MUTEX_NESTED, pool);
+               apr_pool_pre_cleanup_register(pool, *registry, 
serviceRegistry_destroy);
 
-        registry->currentServiceId = 1l;
+               (*registry)->serviceChanged = serviceChanged;
+               (*registry)->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+               (*registry)->serviceRegistrations = hashMap_create(NULL, NULL, 
NULL, NULL);
+               (*registry)->framework = framework;
+               (*registry)->currentServiceId = 1l;
+
+               arrayList_create(pool, &(*registry)->listenerHooks);
+               aprStatus = apr_thread_mutex_create(&(*registry)->mutex, 
APR_THREAD_MUTEX_NESTED, pool);
+               if (aprStatus != APR_SUCCESS) {
+                       status = CELIX_FRAMEWORK_EXCEPTION;
+               }
        }
-       return registry;
+
+       return status;
 }
 
-celix_status_t serviceRegistry_destroy(service_registry_pt registry) {
+apr_status_t serviceRegistry_destroy(void *handle) {
+       service_registry_pt registry = (service_registry_pt) handle;
     hashMap_destroy(registry->inUseMap, false, false);
     hashMap_destroy(registry->serviceRegistrations, false, false);
     arrayList_destroy(registry->listenerHooks);
     apr_thread_mutex_destroy(registry->mutex);
+    registry->framework = NULL;
+    registry->inUseMap = NULL;
+    registry->listenerHooks = NULL;
+    registry->mutex = NULL;
+    registry->pool = NULL;
+    registry->serviceChanged = NULL;
+    registry->serviceReferences = NULL;
+    registry->serviceRegistrations = NULL;
 
     return CELIX_SUCCESS;
 }
@@ -161,10 +183,11 @@ celix_status_t serviceRegistry_getRegist
                for (i = 0; i < arrayList_size(regs); i++) {
                        service_registration_pt reg = arrayList_get(regs, i);
                        if (serviceRegistration_isValid(reg)) {
-                               // #todo Create SERVICE_REFERECEN for each 
registration
                                service_reference_pt reference = NULL;
-                               
serviceRegistry_createServiceReference(registry, pool, reg, &reference);
-                               arrayList_add(*services, reference);
+                               status = 
serviceRegistry_createServiceReference(registry, pool, reg, &reference);
+                               if (status == CELIX_SUCCESS) {
+                                       arrayList_add(*services, reference);
+                               }
                        }
                }
                return status;
@@ -172,16 +195,12 @@ celix_status_t serviceRegistry_getRegist
        return status;
 }
 
-service_registration_pt serviceRegistry_registerService(service_registry_pt 
registry, bundle_pt bundle, char * serviceName, void * serviceObject, 
properties_pt dictionary) {
-    service_registration_pt registration = NULL;
-    serviceRegistry_registerServiceInternal(registry, bundle, serviceName, 
serviceObject, dictionary, false, &registration);
-    return registration;
+celix_status_t serviceRegistry_registerService(service_registry_pt registry, 
bundle_pt bundle, char * serviceName, void * serviceObject, properties_pt 
dictionary, service_registration_pt *registration) {
+    return serviceRegistry_registerServiceInternal(registry, bundle, 
serviceName, serviceObject, dictionary, false, registration);
 }
 
-service_registration_pt 
serviceRegistry_registerServiceFactory(service_registry_pt registry, bundle_pt 
bundle, char * serviceName, service_factory_pt factory, properties_pt 
dictionary) {
-    service_registration_pt registration = NULL;
-    serviceRegistry_registerServiceInternal(registry, bundle, serviceName, 
(void *) factory, dictionary, true, &registration);
-    return registration;
+celix_status_t serviceRegistry_registerServiceFactory(service_registry_pt 
registry, bundle_pt bundle, char * serviceName, service_factory_pt factory, 
properties_pt dictionary, service_registration_pt *registration) {
+    return serviceRegistry_registerServiceInternal(registry, bundle, 
serviceName, (void *) factory, dictionary, true, registration);
 }
 
 celix_status_t serviceRegistry_registerServiceInternal(service_registry_pt 
registry, bundle_pt bundle, char * serviceName, void * serviceObject, 
properties_pt dictionary, bool isFactory, service_registration_pt 
*registration) {
@@ -221,8 +240,8 @@ celix_status_t serviceRegistry_registerS
        return CELIX_SUCCESS;
 }
 
-void serviceRegistry_unregisterService(service_registry_pt registry, bundle_pt 
bundle, service_registration_pt registration) {
-       // array_list_pt clients;
+celix_status_t serviceRegistry_unregisterService(service_registry_pt registry, 
bundle_pt bundle, service_registration_pt registration) {
+       // array_list_t clients;
        unsigned int i;
        array_list_pt regs;
        array_list_pt references = NULL;
@@ -249,23 +268,21 @@ void serviceRegistry_unregisterService(s
        serviceRegistration_getServiceReferences(registration, &references);
        for (i = 0; i < arrayList_size(references); i++) {
                service_reference_pt reference = (service_reference_pt) 
arrayList_get(references, i);
-               bundle_pt fwBundle = NULL;
                apr_pool_t *pool = NULL;
                array_list_pt clients = NULL;
                unsigned int j;
 
-               framework_getFrameworkBundle(registry->framework, &fwBundle);
-               // #TODO: Replace with subpool, destroy pool after usage
-               bundle_getMemoryPool(fwBundle, &pool);
-
+               apr_pool_create(&pool, registry->pool);
                clients = serviceRegistry_getUsingBundles(registry, pool, 
reference);
                for (j = 0; (clients != NULL) && (j < arrayList_size(clients)); 
j++) {
                        bundle_pt client = (bundle_pt) arrayList_get(clients, 
j);
-                       while (serviceRegistry_ungetService(registry, client, 
reference)) {
-                               ;
+                       bool ungetResult = true;
+                       while (ungetResult) {
+                               serviceRegistry_ungetService(registry, client, 
reference, &ungetResult);
                        }
                }
                arrayList_destroy(clients);
+               apr_pool_destroy(pool);
 
                serviceReference_invalidate(reference);
        }
@@ -275,9 +292,10 @@ void serviceRegistry_unregisterService(s
 
        apr_thread_mutex_unlock(registry->mutex);
 
+       return CELIX_SUCCESS;
 }
 
-void serviceRegistry_unregisterServices(service_registry_pt registry, 
bundle_pt bundle) {
+celix_status_t serviceRegistry_unregisterServices(service_registry_pt 
registry, bundle_pt bundle) {
        array_list_pt regs = NULL;
        unsigned int i;
        apr_thread_mutex_lock(registry->mutex);
@@ -300,6 +318,8 @@ void serviceRegistry_unregisterServices(
        apr_thread_mutex_lock(registry->mutex);
        hashMap_remove(registry->serviceRegistrations, bundle);
        apr_thread_mutex_unlock(registry->mutex);
+
+       return CELIX_SUCCESS;
 }
 
 celix_status_t serviceRegistry_createServiceReference(service_registry_pt 
registry, apr_pool_t *pool, service_registration_pt registration, 
service_reference_pt *reference) {
@@ -387,67 +407,69 @@ apr_status_t serviceRegistry_removeRefer
        return APR_SUCCESS;
 }
 
-array_list_pt serviceRegistry_getServicesInUse(service_registry_pt registry, 
bundle_pt bundle) {
+celix_status_t serviceRegistry_getServicesInUse(service_registry_pt registry, 
bundle_pt bundle, array_list_pt *services) {
        array_list_pt usages = hashMap_get(registry->inUseMap, bundle);
        if (usages != NULL) {
                unsigned int i;
                array_list_pt references = NULL;
                apr_pool_t *pool = NULL;
                bundle_getMemoryPool(bundle, &pool);
-               arrayList_create(pool, &references);
+               arrayList_create(pool, services);
                
                for (i = 0; i < arrayList_size(usages); i++) {
                        usage_count_pt usage = arrayList_get(usages, i);
                        arrayList_add(references, usage->reference);
                }
-               return references;
        }
-       return NULL;
+       return CELIX_SUCCESS;
 }
 
-void * serviceRegistry_getService(service_registry_pt registry, bundle_pt 
bundle, service_reference_pt reference) {
+celix_status_t serviceRegistry_getService(service_registry_pt registry, 
bundle_pt bundle, service_reference_pt reference, void **service) {
+       celix_status_t status = CELIX_SUCCESS;
        service_registration_pt registration = NULL;
-       void * service = NULL;
+       *service = NULL;
        usage_count_pt usage = NULL;
        serviceReference_getServiceRegistration(reference, &registration);
        
        apr_thread_mutex_lock(registry->mutex);
 
        if (serviceRegistration_isValid(registration)) {
-               usage = serviceRegistry_getUsageCount(registry, bundle, 
reference);
+               status = serviceRegistry_getUsageCount(registry, bundle, 
reference, &usage);
                if (usage == NULL) {
-                       usage = serviceRegistry_addUsageCount(registry, bundle, 
reference);
+                       status = serviceRegistry_addUsageCount(registry, 
bundle, reference, &usage);
                }
                usage->count++;
-               service = usage->service;
+               *service = usage->service;
        }
        apr_thread_mutex_unlock(registry->mutex);
 
-       if ((usage != NULL) && (service == NULL)) {
-               serviceRegistration_getService(registration, bundle, &service);
+       if ((usage != NULL) && (*service == NULL)) {
+               serviceRegistration_getService(registration, bundle, service);
        }
        apr_thread_mutex_lock(registry->mutex);
-       if ((!serviceRegistration_isValid(registration)) || (service == NULL)) {
+       if ((!serviceRegistration_isValid(registration)) || (*service == NULL)) 
{
                serviceRegistry_flushUsageCount(registry, bundle, reference);
        } else {
-               usage->service = service;
+               usage->service = *service;
        }
        apr_thread_mutex_unlock(registry->mutex);
 
-       return service;
+       return CELIX_SUCCESS;
 }
 
-bool serviceRegistry_ungetService(service_registry_pt registry, bundle_pt 
bundle, service_reference_pt reference) {
+celix_status_t serviceRegistry_ungetService(service_registry_pt registry, 
bundle_pt bundle, service_reference_pt reference, bool *result) {
+       celix_status_t status = CELIX_SUCCESS;
        service_registration_pt registration = NULL;
        usage_count_pt usage = NULL;
        serviceReference_getServiceRegistration(reference, &registration);
        
        apr_thread_mutex_lock(registry->mutex);
 
-       usage = serviceRegistry_getUsageCount(registry, bundle, reference);
+       status = serviceRegistry_getUsageCount(registry, bundle, reference, 
&usage);
        if (usage == NULL) {
                apr_thread_mutex_unlock(registry->mutex);
-               return false;
+               *result = false;
+               return CELIX_SUCCESS;
        }
 
        usage->count--;
@@ -460,7 +482,9 @@ bool serviceRegistry_ungetService(servic
 
        apr_thread_mutex_unlock(registry->mutex);
 
-       return true;
+       *result = true;
+
+       return CELIX_SUCCESS;
 }
 
 void serviceRegistry_ungetServices(service_registry_pt registry, bundle_pt 
bundle) {
@@ -485,8 +509,9 @@ void serviceRegistry_ungetServices(servi
        for (i = 0; i < arrayList_size(fusages); i++) {
                usage_count_pt usage = arrayList_get(fusages, i);
                service_reference_pt reference = usage->reference;
-               while (serviceRegistry_ungetService(registry, bundle, 
reference)) {
-                       //
+               bool ungetResult = true;
+               while (ungetResult) {
+                       serviceRegistry_ungetService(registry, bundle, 
reference, &ungetResult);
                }
        }
 

Modified: incubator/celix/trunk/framework/public/include/service_registry.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/public/include/service_registry.h?rev=1496015&r1=1496014&r2=1496015&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/service_registry.h (original)
+++ incubator/celix/trunk/framework/public/include/service_registry.h Mon Jun 
24 13:02:01 2013
@@ -38,17 +38,18 @@ typedef struct serviceRegistry * service
 #include "array_list.h"
 #include "service_registration.h"
 
-service_registry_pt serviceRegistry_create(framework_pt framework, void 
(*serviceChanged)(framework_pt, service_event_type_e, service_registration_pt, 
properties_pt));
-celix_status_t serviceRegistry_destroy(service_registry_pt registry);
+typedef void (*serviceChanged_function_pt)(framework_pt, service_event_type_e, 
service_registration_pt, properties_pt);
+
+celix_status_t serviceRegistry_create(apr_pool_t *pool, framework_pt 
framework, serviceChanged_function_pt serviceChanged, service_registry_pt 
*registry);
 celix_status_t serviceRegistry_getRegisteredServices(service_registry_pt 
registry, apr_pool_t *pool, bundle_pt bundle, array_list_pt *services);
-array_list_pt serviceRegistry_getServicesInUse(service_registry_pt registry, 
bundle_pt bundle);
-service_registration_pt serviceRegistry_registerService(service_registry_pt 
registry, bundle_pt bundle, char * serviceName, void * serviceObject, 
properties_pt dictionary);
-service_registration_pt 
serviceRegistry_registerServiceFactory(service_registry_pt registry, bundle_pt 
bundle, char * serviceName, service_factory_pt factory, properties_pt 
dictionary);
-void serviceRegistry_unregisterService(service_registry_pt registry, bundle_pt 
bundle, service_registration_pt registration);
-void serviceRegistry_unregisterServices(service_registry_pt registry, 
bundle_pt bundle);
+celix_status_t serviceRegistry_getServicesInUse(service_registry_pt registry, 
bundle_pt bundle, array_list_pt *services);
+celix_status_t serviceRegistry_registerService(service_registry_pt registry, 
bundle_pt bundle, char * serviceName, void * serviceObject, properties_pt 
dictionary, service_registration_pt *registration);
+celix_status_t serviceRegistry_registerServiceFactory(service_registry_pt 
registry, bundle_pt bundle, char * serviceName, service_factory_pt factory, 
properties_pt dictionary, service_registration_pt *registration);
+celix_status_t serviceRegistry_unregisterService(service_registry_pt registry, 
bundle_pt bundle, service_registration_pt registration);
+celix_status_t serviceRegistry_unregisterServices(service_registry_pt 
registry, bundle_pt bundle);
 celix_status_t serviceRegistry_getServiceReferences(service_registry_pt 
registry, apr_pool_t *pool, const char *serviceName, filter_pt filter, 
array_list_pt *references);
-void * serviceRegistry_getService(service_registry_pt registry, bundle_pt 
bundle, service_reference_pt reference);
-bool serviceRegistry_ungetService(service_registry_pt registry, bundle_pt 
bundle, service_reference_pt reference);
+celix_status_t serviceRegistry_getService(service_registry_pt registry, 
bundle_pt bundle, service_reference_pt reference, void **service);
+celix_status_t serviceRegistry_ungetService(service_registry_pt registry, 
bundle_pt bundle, service_reference_pt reference, bool *result);
 void serviceRegistry_ungetServices(service_registry_pt registry, bundle_pt 
bundle);
 array_list_pt serviceRegistry_getUsingBundles(service_registry_pt registry, 
apr_pool_t *pool, service_reference_pt reference);
 service_registration_pt serviceRegistry_findRegistration(service_registry_pt 
registry, service_reference_pt reference);


Reply via email to