http://git-wip-us.apache.org/repos/asf/celix/blob/8464f3d5/framework/src/framework.c
----------------------------------------------------------------------
diff --cc framework/src/framework.c
index 0566572,2460434..c87eaf4
--- a/framework/src/framework.c
+++ b/framework/src/framework.c
@@@ -53,12 -54,12 +54,12 @@@ typedef celix_status_t (*dm_destroy_fp)
  
  struct activator {
      void * userData;
--
++    
      create_function_fp create;
      start_function_fp start;
      stop_function_fp stop;
      destroy_function_fp destroy;
--
++    
      dm_create_fp dmCreate;
      dm_init_fp dmInit;
      dm_destroy_fp dmDestroy;
@@@ -114,47 -115,47 +115,47 @@@ celix_status_t fw_refreshHelper_restart
  celix_status_t fw_refreshHelper_stop(struct fw_refreshHelper * refreshHelper);
  
  struct fw_serviceListener {
--      bundle_pt bundle;
--      service_listener_pt listener;
--      filter_pt filter;
++    bundle_pt bundle;
++    service_listener_pt listener;
++    filter_pt filter;
      array_list_pt retainedReferences;
  };
  
  typedef struct fw_serviceListener * fw_service_listener_pt;
  
  struct fw_bundleListener {
--      bundle_pt bundle;
--      bundle_listener_pt listener;
++    bundle_pt bundle;
++    bundle_listener_pt listener;
  };
  
  typedef struct fw_bundleListener * fw_bundle_listener_pt;
  
  struct fw_frameworkListener {
--      bundle_pt bundle;
--      framework_listener_pt listener;
++    bundle_pt bundle;
++    framework_listener_pt listener;
  };
  
  typedef struct fw_frameworkListener * fw_framework_listener_pt;
  
  enum event_type {
--      FRAMEWORK_EVENT_TYPE,
--      BUNDLE_EVENT_TYPE,
--      EVENT_TYPE_SERVICE,
++    FRAMEWORK_EVENT_TYPE,
++    BUNDLE_EVENT_TYPE,
++    EVENT_TYPE_SERVICE,
  };
  
  typedef enum event_type event_type_e;
  
  struct request {
--      event_type_e type;
--      array_list_pt listeners;
--
--      int eventType;
--      long bundleId;
--      char* bundleSymbolicName;
--      celix_status_t errorCode;
--      char *error;
--
--      char *filter;
++    event_type_e type;
++    array_list_pt listeners;
++    
++    int eventType;
++    long bundleId;
++    char* bundleSymbolicName;
++    celix_status_t errorCode;
++    char *error;
++    
++    char *filter;
  };
  
  typedef struct request *request_pt;
@@@ -180,45 -181,45 +181,45 @@@ static void framework_loggerInit(void) 
   * Refer to dlopen manpage for additional details about libraries dynamic 
loading.
   */
  #ifdef _WIN32
--    #define handle_t HMODULE
--    #define fw_openLibrary(path) LoadLibrary(path)
--    #define fw_closeLibrary(handle) FreeLibrary(handle)
++#define handle_t HMODULE
++#define fw_openLibrary(path) LoadLibrary(path)
++#define fw_closeLibrary(handle) FreeLibrary(handle)
  
--    #define fw_getSymbol(handle, name) GetProcAddress(handle, name)
++#define fw_getSymbol(handle, name) GetProcAddress(handle, name)
  
--    #define fw_getLastError() GetLastError()
++#define fw_getLastError() GetLastError()
  
--    HMODULE fw_getCurrentModule() {
--        HMODULE hModule = NULL;
--        GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, 
(LPCTSTR)fw_getCurrentModule, &hModule);
--        return hModule;
--    }
++HMODULE fw_getCurrentModule() {
++    HMODULE hModule = NULL;
++    GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, 
(LPCTSTR)fw_getCurrentModule, &hModule);
++    return hModule;
++}
++#else
++#define handle_t void *
++#if defined(DEBUG) && !defined(ANDROID)
++#define fw_openLibrary(path) dlopen(path, RTLD_LAZY|RTLD_LOCAL|RTLD_NODELETE)
  #else
--    #define handle_t void *
--    #if defined(DEBUG) && !defined(ANDROID)
--      #define fw_openLibrary(path) dlopen(path, 
RTLD_LAZY|RTLD_LOCAL|RTLD_NODELETE)
--    #else
--      #define fw_openLibrary(path) dlopen(path, RTLD_LAZY|RTLD_LOCAL)
--    #endif
--    #define fw_closeLibrary(handle) dlclose(handle)
--    #define fw_getSymbol(handle, name) dlsym(handle, name)
--    #define fw_getLastError() dlerror()
++#define fw_openLibrary(path) dlopen(path, RTLD_LAZY|RTLD_LOCAL)
++#endif
++#define fw_closeLibrary(handle) dlclose(handle)
++#define fw_getSymbol(handle, name) dlsym(handle, name)
++#define fw_getLastError() dlerror()
  #endif
  
  celix_status_t framework_create(framework_pt *framework, properties_pt 
config) {
      celix_status_t status = CELIX_SUCCESS;
--
++    
      logger = hashMap_get(config, "logger");
      if (logger == NULL) {
          celixThread_once(&loggerInit, framework_loggerInit);
      }
--
++    
      *framework = (framework_pt) malloc(sizeof(**framework));
      if (*framework != NULL) {
          celix_thread_mutexattr_t attr;
          celixThreadMutexAttr_create(&attr);
          celixThreadMutexAttr_settype(&attr, CELIX_THREAD_MUTEX_RECURSIVE);
--
++        
          status = CELIX_DO_IF(status, 
celixThreadCondition_init(&(*framework)->condition, NULL));
          status = CELIX_DO_IF(status, 
celixThreadMutex_create(&(*framework)->mutex, NULL));
          status = CELIX_DO_IF(status, 
celixThreadMutex_create(&(*framework)->installedBundleMapLock, NULL));
@@@ -247,12 -248,8 +248,8 @@@
              (*framework)->requests = NULL;
              (*framework)->configurationMap = config;
              (*framework)->logger = logger;
--
-             //gen uuid
-             uuid_t uuid;
-             uuid_generate(uuid);
-             uuid_unparse(uuid, (*framework)->uuid);
--
++            
++            
              status = CELIX_DO_IF(status, 
bundle_create(&(*framework)->bundle));
              status = CELIX_DO_IF(status, 
arrayList_create(&(*framework)->globalLockWaitersList));
              status = CELIX_DO_IF(status, 
bundle_setFramework((*framework)->bundle, (*framework)));
@@@ -270,14 -267,14 +267,14 @@@
          status = CELIX_FRAMEWORK_EXCEPTION;
          fw_logCode(logger, OSGI_FRAMEWORK_LOG_ERROR, CELIX_ENOMEM, "Could not 
create framework");
      }
--
++    
      return status;
  }
  
  celix_status_t framework_destroy(framework_pt framework) {
      celix_status_t status = CELIX_SUCCESS;
      celixThreadMutex_lock(&framework->installedBundleMapLock);
--
++    
      if (framework->installedBundleMap != NULL) {
          hash_map_iterator_pt iterator = 
hashMapIterator_create(framework->installedBundleMap);
          while (hashMapIterator_hasNext(iterator)) {
@@@ -285,7 -282,7 +282,7 @@@
              bundle_pt bundle = (bundle_pt) hashMapEntry_getValue(entry);
              char * key = hashMapEntry_getKey(entry);
              bundle_archive_pt archive = NULL;
--
++            
              bool systemBundle = false;
              bundle_isSystemBundle(bundle, &systemBundle);
              if (systemBundle) {
@@@ -293,7 -290,7 +290,7 @@@
                  bundle_getContext(framework->bundle, &context);
                  bundleContext_destroy(context);
              }
--
++            
              if (bundle_getArchive(bundle, &archive) == CELIX_SUCCESS) {
                  if (!systemBundle) {
                      bundle_revision_pt revision = NULL;
@@@ -307,7 -304,7 +304,7 @@@
                          }
                      }
                  }
--
++                
                  bundleArchive_destroy(archive);
              }
              bundle_destroy(bundle);
@@@ -316,15 -313,15 +313,15 @@@
          }
          hashMapIterator_destroy(iterator);
      }
--
++    
      celixThreadMutex_unlock(&framework->installedBundleMapLock);
--
--      hashMap_destroy(framework->installRequestMap, false, false);
--
--      serviceRegistry_destroy(framework->registry);
--
--      arrayList_destroy(framework->globalLockWaitersList);
--
++    
++    hashMap_destroy(framework->installRequestMap, false, false);
++    
++    serviceRegistry_destroy(framework->registry);
++    
++    arrayList_destroy(framework->globalLockWaitersList);
++    
      if (framework->serviceListeners != NULL) {
          arrayList_destroy(framework->serviceListeners);
      }
@@@ -334,81 -331,89 +331,89 @@@
      if (framework->frameworkListeners) {
          arrayList_destroy(framework->frameworkListeners);
      }
--
--      if(framework->requests){
--          int i;
--          for (i = 0; i < arrayList_size(framework->requests); i++) {
--              request_pt request = arrayList_get(framework->requests, i);
--              free(request);
--          }
--          arrayList_destroy(framework->requests);
--      }
--      if(framework->installedBundleMap!=NULL){
--              hashMap_destroy(framework->installedBundleMap, true, false);
--      }
--
--      bundleCache_destroy(&framework->cache);
--
--      celixThreadCondition_destroy(&framework->dispatcher);
++    
++    if(framework->requests){
++        int i;
++        for (i = 0; i < arrayList_size(framework->requests); i++) {
++            request_pt request = arrayList_get(framework->requests, i);
++            free(request);
++        }
++        arrayList_destroy(framework->requests);
++    }
++    if(framework->installedBundleMap!=NULL){
++        hashMap_destroy(framework->installedBundleMap, true, false);
++    }
++    
++    bundleCache_destroy(&framework->cache);
++    
++    celixThreadCondition_destroy(&framework->dispatcher);
      celixThreadMutex_destroy(&framework->serviceListenersLock);
      celixThreadMutex_destroy(&framework->frameworkListenersLock);
--      celixThreadMutex_destroy(&framework->bundleListenerLock);
--      celixThreadMutex_destroy(&framework->dispatcherLock);
--      celixThreadMutex_destroy(&framework->installRequestLock);
--      celixThreadMutex_destroy(&framework->bundleLock);
--      celixThreadMutex_destroy(&framework->installedBundleMapLock);
--      celixThreadMutex_destroy(&framework->mutex);
--      celixThreadCondition_destroy(&framework->condition);
--
++    celixThreadMutex_destroy(&framework->bundleListenerLock);
++    celixThreadMutex_destroy(&framework->dispatcherLock);
++    celixThreadMutex_destroy(&framework->installRequestLock);
++    celixThreadMutex_destroy(&framework->bundleLock);
++    celixThreadMutex_destroy(&framework->installedBundleMapLock);
++    celixThreadMutex_destroy(&framework->mutex);
++    celixThreadCondition_destroy(&framework->condition);
++    
      logger = hashMap_get(framework->configurationMap, "logger");
      if (logger == NULL) {
          free(framework->logger);
      }
--
++    
      properties_destroy(framework->configurationMap);
--
++    
      free(framework);
--
--      return status;
++    
++    return status;
  }
  
  celix_status_t fw_init(framework_pt framework) {
--      bundle_state_e state;
--      const char *location = NULL;
--      module_pt module = NULL;
--      linked_list_pt wires = NULL;
--      array_list_pt archives = NULL;
--      bundle_archive_pt archive = NULL;
--
--      celix_status_t status = CELIX_SUCCESS;
--      status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
framework->bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
--      status = CELIX_DO_IF(status, 
arrayList_create(&framework->serviceListeners));
--      status = CELIX_DO_IF(status, 
arrayList_create(&framework->bundleListeners));
--      status = CELIX_DO_IF(status, 
arrayList_create(&framework->frameworkListeners));
--      status = CELIX_DO_IF(status, arrayList_create(&framework->requests));
--      status = CELIX_DO_IF(status, 
celixThread_create(&framework->dispatcherThread, NULL, fw_eventDispatcher, 
framework));
--      status = CELIX_DO_IF(status, bundle_getState(framework->bundle, 
&state));
--      if (status == CELIX_SUCCESS) {
--          if ((state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) || (state == 
OSGI_FRAMEWORK_BUNDLE_RESOLVED)) {
--              bundle_state_e state;
--              status = CELIX_DO_IF(status, 
bundleCache_create(framework->configurationMap,&framework->cache));
--              status = CELIX_DO_IF(status, bundle_getState(framework->bundle, 
&state));
--              if (status == CELIX_SUCCESS) {
--                  if (state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) {
--                      const char *clean = 
properties_get(framework->configurationMap, 
OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN);
--                      if (clean != NULL && (strcmp(clean, 
OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT) == 0)) {
--                          bundleCache_delete(framework->cache);
--                      }
--                  }
++    bundle_state_e state;
++    const char *location = NULL;
++    module_pt module = NULL;
++    linked_list_pt wires = NULL;
++    array_list_pt archives = NULL;
++    bundle_archive_pt archive = NULL;
++    
++    celix_status_t status = CELIX_SUCCESS;
++    status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
framework->bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
++    status = CELIX_DO_IF(status, 
arrayList_create(&framework->serviceListeners));
++    status = CELIX_DO_IF(status, 
arrayList_create(&framework->bundleListeners));
++    status = CELIX_DO_IF(status, 
arrayList_create(&framework->frameworkListeners));
++    status = CELIX_DO_IF(status, arrayList_create(&framework->requests));
++    status = CELIX_DO_IF(status, 
celixThread_create(&framework->dispatcherThread, NULL, fw_eventDispatcher, 
framework));
++    status = CELIX_DO_IF(status, bundle_getState(framework->bundle, &state));
++    if (status == CELIX_SUCCESS) {
++        if ((state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) || (state == 
OSGI_FRAMEWORK_BUNDLE_RESOLVED)) {
++            bundle_state_e state;
++            status = CELIX_DO_IF(status, 
bundleCache_create(framework->configurationMap,&framework->cache));
++            status = CELIX_DO_IF(status, bundle_getState(framework->bundle, 
&state));
++            if (status == CELIX_SUCCESS) {
++                if (state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) {
++                    const char *clean = 
properties_get(framework->configurationMap, 
OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN);
++                    if (clean != NULL && (strcmp(clean, 
OSGI_FRAMEWORK_FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT) == 0)) {
++                        bundleCache_delete(framework->cache);
++                    }
++                }
              }
          }
--      }
--
--      if (status == CELIX_SUCCESS) {
-         properties_set(framework->configurationMap, (char*) 
OSGI_FRAMEWORK_FRAMEWORK_UUID, framework->uuid);
++    }
++    
++    if (status == CELIX_SUCCESS) {
+         /*create and store framework uuid*/
+         char uuid[37];
 -
 -          uuid_t uid;
++        
++        uuid_t uid;
+         uuid_generate(uid);
+         uuid_unparse(uid, uuid);
 -
++        
+         properties_set(framework->configurationMap, (char*) 
OSGI_FRAMEWORK_FRAMEWORK_UUID, uuid);
 -
++        
          framework->installedBundleMap = hashMap_create(utils_stringHash, 
NULL, utils_stringEquals, NULL);
--      }
--
++    }
++    
      status = CELIX_DO_IF(status, bundle_getArchive(framework->bundle, 
&archive));
      status = CELIX_DO_IF(status, bundleArchive_getLocation(archive, 
&location));
      if (status == CELIX_SUCCESS) {
@@@ -424,7 -429,7 +429,7 @@@
              fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, 
"Unresolved constraints in System Bundle");
          }
      }
--
++    
      status = CELIX_DO_IF(status, bundleCache_getArchives(framework->cache, 
&archives));
      if (status == CELIX_SUCCESS) {
          unsigned int arcIdx;
@@@ -434,7 -439,7 +439,7 @@@
              bundle_state_e bundleState;
              bundleArchive_getId(archive1, &id);
              framework->nextBundleId = framework->nextBundleId > id + 1 ? 
framework->nextBundleId : id + 1;
--
++            
              bundleArchive_getPersistentState(archive1, &bundleState);
              if (bundleState == OSGI_FRAMEWORK_BUNDLE_UNINSTALLED) {
                  bundleArchive_closeAndDelete(archive1);
@@@ -447,11 -452,11 +452,11 @@@
          }
          arrayList_destroy(archives);
      }
--
++    
      status = CELIX_DO_IF(status, serviceRegistry_create(framework, 
fw_serviceChanged, &framework->registry));
      status = CELIX_DO_IF(status, framework_setBundleStateAndNotify(framework, 
framework->bundle, OSGI_FRAMEWORK_BUNDLE_STARTING));
      status = CELIX_DO_IF(status, 
celixThreadCondition_init(&framework->shutdownGate, NULL));
--
++    
      bundle_context_t *context = NULL;
      status = CELIX_DO_IF(status, bundleContext_create(framework, 
framework->logger, framework->bundle, &context));
      status = CELIX_DO_IF(status, bundle_setContext(framework->bundle, 
context));
@@@ -461,92 -466,84 +466,84 @@@
          if (activator != NULL) {
              bundle_context_t *context = NULL;
              void * userData = NULL;
--
--                      //create_function_pt create = NULL;
--                      start_function_fp start = (start_function_fp) 
frameworkActivator_start;
--                      stop_function_fp stop = (stop_function_fp) 
frameworkActivator_stop;
--                      destroy_function_fp destroy = (destroy_function_fp) 
frameworkActivator_destroy;
--
++            
++            //create_function_pt create = NULL;
++            start_function_fp start = (start_function_fp) 
frameworkActivator_start;
++            stop_function_fp stop = (stop_function_fp) 
frameworkActivator_stop;
++            destroy_function_fp destroy = (destroy_function_fp) 
frameworkActivator_destroy;
++            
              activator->start = start;
              activator->stop = stop;
              activator->destroy = destroy;
              status = CELIX_DO_IF(status, 
bundle_setActivator(framework->bundle, activator));
              status = CELIX_DO_IF(status, bundle_getContext(framework->bundle, 
&context));
--
++            
              if (status == CELIX_SUCCESS) {
                  /* This code part is in principle dead, but in future it may 
do something.
                   * That's why it's outcommented and not deleted
--                      if (create != NULL) {
--                    create(context, &userData);
--                }
--                */
++                 if (create != NULL) {
++                 create(context, &userData);
++                 }
++                 */
                  activator->userData = userData;
--
++                
                  if (start != NULL) {
                      start(userData, context);
                  }
              }
              else{
--              free(activator);
++                free(activator);
              }
          } else {
              status = CELIX_ENOMEM;
          }
      }
--
++    
      if (status != CELIX_SUCCESS) {
--       fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, "Could 
not init framework");
++        fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, 
"Could not init framework");
      }
--
++    
      framework_releaseBundleLock(framework, framework->bundle);
--
--      return status;
- }
- 
- FRAMEWORK_EXPORT const char* framework_getUUID(framework_t *framework) {
-     const char *uuid = NULL;
-     if (framework != NULL) {
-         uuid = framework->uuid;
-     }
-     return uuid;
++    
++    return status;
  }
  
  celix_status_t framework_start(framework_pt framework) {
--      celix_status_t status = CELIX_SUCCESS;
--      bundle_state_e state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
--
--      status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
framework->bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
--      status = CELIX_DO_IF(status, bundle_getState(framework->bundle, 
&state));
--      if (status == CELIX_SUCCESS) {
--          if ((state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) || (state == 
OSGI_FRAMEWORK_BUNDLE_RESOLVED)) {
--              status = CELIX_DO_IF(status, fw_init(framework));
++    celix_status_t status = CELIX_SUCCESS;
++    bundle_state_e state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
++    
++    status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
framework->bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
++    status = CELIX_DO_IF(status, bundle_getState(framework->bundle, &state));
++    if (status == CELIX_SUCCESS) {
++        if ((state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) || (state == 
OSGI_FRAMEWORK_BUNDLE_RESOLVED)) {
++            status = CELIX_DO_IF(status, fw_init(framework));
          }
--      }
--
--      status = CELIX_DO_IF(status, bundle_getState(framework->bundle, 
&state));
--      if (status == CELIX_SUCCESS) {
--          if (state == OSGI_FRAMEWORK_BUNDLE_STARTING) {
--              status = CELIX_DO_IF(status, 
framework_setBundleStateAndNotify(framework, framework->bundle, 
OSGI_FRAMEWORK_BUNDLE_ACTIVE));
--          }
--
--          framework_releaseBundleLock(framework, framework->bundle);
--      }
--
--      status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_STARTED, framework->bundle));
--      status = CELIX_DO_IF(status, fw_fireFrameworkEvent(framework, 
OSGI_FRAMEWORK_EVENT_STARTED, framework->bundle, 0));
--
--      if (status != CELIX_SUCCESS) {
--       status = CELIX_BUNDLE_EXCEPTION;
--       fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, "Could 
not start framework");
--       fw_fireFrameworkEvent(framework, OSGI_FRAMEWORK_EVENT_ERROR, 
framework->bundle, status);
      }
--
++    
++    status = CELIX_DO_IF(status, bundle_getState(framework->bundle, &state));
++    if (status == CELIX_SUCCESS) {
++        if (state == OSGI_FRAMEWORK_BUNDLE_STARTING) {
++            status = CELIX_DO_IF(status, 
framework_setBundleStateAndNotify(framework, framework->bundle, 
OSGI_FRAMEWORK_BUNDLE_ACTIVE));
++        }
++        
++        framework_releaseBundleLock(framework, framework->bundle);
++    }
++    
++    status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_STARTED, framework->bundle));
++    status = CELIX_DO_IF(status, fw_fireFrameworkEvent(framework, 
OSGI_FRAMEWORK_EVENT_STARTED, framework->bundle, 0));
++    
++    if (status != CELIX_SUCCESS) {
++        status = CELIX_BUNDLE_EXCEPTION;
++        fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, 
"Could not start framework");
++        fw_fireFrameworkEvent(framework, OSGI_FRAMEWORK_EVENT_ERROR, 
framework->bundle, status);
++    }
++    
      bundle_context_t *fwCtx = framework_getContext(framework);
--      if (fwCtx != NULL) {
++    if (fwCtx != NULL) {
          framework_autoStartConfiguredBundles(fwCtx);
      }
--
--      return status;
++    
++    return status;
  }
  
  static void framework_autoStartConfiguredBundles(bundle_context_t *fwCtx) {
@@@ -572,7 -569,7 +569,7 @@@ static void framework_autoStartConfigur
      array_list_pt installed = NULL;
      char *autoStart = strndup(autoStartIn, 1024*1024*10);
      arrayList_create(&installed);
--
++    
      if (autoStart != NULL) {
          char *location = strtok_r(autoStart, delims, &save_ptr);
          while (location != NULL) {
@@@ -587,7 -584,7 +584,7 @@@
              location = strtok_r(NULL, delims, &save_ptr);
          }
      }
--
++    
      unsigned int i;
      for (i = 0; i < arrayList_size(installed); ++i) {
          long bndId = -1;
@@@ -598,89 -595,89 +595,89 @@@
              printf("Could not start bundle %li\n", bndId);
          }
      }
--
++    
      free(autoStart);
      arrayList_destroy(installed);
  }
  
  
  celix_status_t framework_stop(framework_pt framework) {
--      return fw_stopBundle(framework, framework->bundle, true);
++    return fw_stopBundle(framework, framework->bundle, true);
  }
  
  celix_status_t fw_getProperty(framework_pt framework, const char* name, const 
char* defaultValue, const char** value) {
--      celix_status_t status = CELIX_SUCCESS;
--
--      if (framework == NULL || name == NULL) {
--              status = CELIX_ILLEGAL_ARGUMENT;
--      } else {
--              if (framework->configurationMap != NULL) {
--                      *value = properties_get(framework->configurationMap, 
name);
--              }
--              if (*value == NULL) {
--                      *value = getenv(name);
--              }
++    celix_status_t status = CELIX_SUCCESS;
++    
++    if (framework == NULL || name == NULL) {
++        status = CELIX_ILLEGAL_ARGUMENT;
++    } else {
++        if (framework->configurationMap != NULL) {
++            *value = properties_get(framework->configurationMap, name);
++        }
++        if (*value == NULL) {
++            *value = getenv(name);
++        }
          if (*value == NULL) {
              *value = defaultValue;
          }
--      }
--
--      return status;
++    }
++    
++    return status;
  }
  
  celix_status_t fw_installBundle(framework_pt framework, bundle_pt * bundle, 
const char * location, const char *inputFile) {
--      return fw_installBundle2(framework, bundle, -1, location, inputFile, 
NULL);
++    return fw_installBundle2(framework, bundle, -1, location, inputFile, 
NULL);
  }
  
  celix_status_t fw_installBundle2(framework_pt framework, bundle_pt * bundle, 
long id, const char * location, const char *inputFile, bundle_archive_pt 
archive) {
      celix_status_t status = CELIX_SUCCESS;
--//    bundle_archive_pt bundle_archive = NULL;
++    //    bundle_archive_pt bundle_archive = NULL;
      bundle_state_e state = OSGI_FRAMEWORK_BUNDLE_UNKNOWN;
--      bool locked;
--
--      status = CELIX_DO_IF(status, framework_acquireInstallLock(framework, 
location));
--      status = CELIX_DO_IF(status, bundle_getState(framework->bundle, 
&state));
--      if (status == CELIX_SUCCESS) {
++    bool locked;
++    
++    status = CELIX_DO_IF(status, framework_acquireInstallLock(framework, 
location));
++    status = CELIX_DO_IF(status, bundle_getState(framework->bundle, &state));
++    if (status == CELIX_SUCCESS) {
          if (state == OSGI_FRAMEWORK_BUNDLE_STOPPING || state == 
OSGI_FRAMEWORK_BUNDLE_UNINSTALLED) {
              fw_log(framework->logger, OSGI_FRAMEWORK_LOG_INFO,  "The 
framework is being shutdown");
              status = CELIX_DO_IF(status, 
framework_releaseInstallLock(framework, location));
              status = CELIX_FRAMEWORK_SHUTDOWN;
          }
--      }
--
++    }
++    
      if (status == CELIX_SUCCESS) {
          *bundle = framework_getBundle(framework, location);
          if (*bundle != NULL) {
              framework_releaseInstallLock(framework, location);
              return CELIX_SUCCESS;
          }
--
++        
          if (archive == NULL) {
              id = framework_getNextBundleId(framework);
--
++            
              status = CELIX_DO_IF(status, 
bundleCache_createArchive(framework->cache, id, location, inputFile, &archive));
--
++            
              if (status != CELIX_SUCCESS) {
--              bundleArchive_destroy(archive);
++                bundleArchive_destroy(archive);
              }
          } else {
              // purge revision
              // multiple revisions not yet implemented
          }
--
++        
          if (status == CELIX_SUCCESS) {
              locked = framework_acquireGlobalLock(framework);
              if (!locked) {
                  status = CELIX_BUNDLE_EXCEPTION;
              } else {
                  status = CELIX_DO_IF(status, bundle_createFromArchive(bundle, 
framework, archive));
--
++                
                  framework_releaseGlobalLock(framework);
                  if (status == CELIX_SUCCESS) {
                      celixThreadMutex_lock(&framework->installedBundleMapLock);
                      hashMap_put(framework->installedBundleMap, 
strdup(location), *bundle);
                      
celixThreadMutex_unlock(&framework->installedBundleMapLock);
--
++                    
                  } else {
                      status = CELIX_BUNDLE_EXCEPTION;
                      status = CELIX_DO_IF(status, 
bundleArchive_closeAndDelete(archive));
@@@ -688,26 -685,26 +685,26 @@@
              }
          }
      }
--
++    
      framework_releaseInstallLock(framework, location);
--
++    
      if (status != CELIX_SUCCESS) {
--      fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, "Could 
not install bundle");
++        fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, 
"Could not install bundle");
      } else {
          status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_INSTALLED, *bundle));
      }
--
--      return status;
++    
++    return status;
  }
  
  celix_status_t framework_getBundleEntry(framework_pt framework, bundle_pt 
bundle, const char* name, char** entry) {
--      celix_status_t status = CELIX_SUCCESS;
--
--      bundle_revision_pt revision;
--      bundle_archive_pt archive = NULL;
++    celix_status_t status = CELIX_SUCCESS;
++    
++    bundle_revision_pt revision;
++    bundle_archive_pt archive = NULL;
      const char *root;
--
--      status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive));
++    
++    status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive));
      status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, 
&revision));
      status = CELIX_DO_IF(status, bundleRevision_getRoot(revision, &root));
      if (status == CELIX_SUCCESS) {
@@@ -719,33 -716,33 +716,33 @@@
              strcat(e, "/");
              strcat(e, name);
          }
--
++        
          if (access(e, F_OK) == 0) {
-             (*entry) = strndup(e, 1024*1024*10);
+             (*entry) = strndup(e, 1024*10);
          } else {
              (*entry) = NULL;
          }
      }
--
--      return status;
++    
++    return status;
  }
  
  celix_status_t fw_startBundle(framework_pt framework, bundle_pt bundle, int 
options __attribute__((unused))) {
--      celix_status_t status = CELIX_SUCCESS;
--
--      linked_list_pt wires = NULL;
--      bundle_context_t *context = NULL;
--      bundle_state_e state;
--      module_pt module = NULL;
--      activator_pt activator = NULL;
--      char *error = NULL;
--      const char *name = NULL;
--
--      status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
--      status = CELIX_DO_IF(status, bundle_getState(bundle, &state));
--
--      if (status == CELIX_SUCCESS) {
--          switch (state) {
++    celix_status_t status = CELIX_SUCCESS;
++    
++    linked_list_pt wires = NULL;
++    bundle_context_t *context = NULL;
++    bundle_state_e state;
++    module_pt module = NULL;
++    activator_pt activator = NULL;
++    char *error = NULL;
++    const char *name = NULL;
++    
++    status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
++    status = CELIX_DO_IF(status, bundle_getState(bundle, &state));
++    
++    if (status == CELIX_SUCCESS) {
++        switch (state) {
              case OSGI_FRAMEWORK_BUNDLE_UNKNOWN:
                  error = "state is unknown";
                  status = CELIX_ILLEGAL_STATE;
@@@ -774,7 -771,7 +771,7 @@@
                          return CELIX_BUNDLE_EXCEPTION;
                      }
                      framework_markResolvedModules(framework, wires);
--
++                    
                  }
                  /* no break */
              case OSGI_FRAMEWORK_BUNDLE_RESOLVED:
@@@ -784,7 -781,7 +781,7 @@@
                  module_getSymbolicName(module, &name);
                  status = CELIX_DO_IF(status, bundleContext_create(framework, 
framework->logger, bundle, &context));
                  status = CELIX_DO_IF(status, bundle_setContext(bundle, 
context));
--
++                
                  if (status == CELIX_SUCCESS) {
                      activator = (activator_pt) calloc(1,(sizeof(*activator)));
                      if (activator == NULL) {
@@@ -796,20 -793,20 +793,20 @@@
                          start_function_fp start = (start_function_fp) 
fw_getSymbol((handle_t) bundle_getHandle(bundle), 
OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_START);
                          stop_function_fp stop = (stop_function_fp) 
fw_getSymbol((handle_t) bundle_getHandle(bundle), 
OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_STOP);
                          destroy_function_fp destroy = (destroy_function_fp) 
fw_getSymbol((handle_t) bundle_getHandle(bundle), 
OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_DESTROY);
--
++                        
                          dm_create_fp dmCreate = 
fw_getSymbol((handle_t)bundle_getHandle(bundle), 
OSGI_FRAMEWORK_BUNDLE_DM_ACTIVATOR_CREATE);
                          dm_init_fp dmInit = 
fw_getSymbol((handle_t)bundle_getHandle(bundle), 
OSGI_FRAMEWORK_BUNDLE_DM_ACTIVATOR_INIT);
                          dm_destroy_fp dmDestroy = 
fw_getSymbol((handle_t)bundle_getHandle(bundle), 
OSGI_FRAMEWORK_BUNDLE_DM_ACTIVATOR_DESTROY);
--
++                        
                          activator->create = create;
                          activator->start = start;
                          activator->stop = stop;
                          activator->destroy = destroy;
--
++                        
                          activator->dmCreate = dmCreate;
                          activator->dmInit = dmInit;
                          activator->dmDestroy = dmDestroy;
--
++                        
                          if (activator->dmCreate != NULL) {
                              //only allow one activator, if dm is used -> set 
other to NULL
                              activator->create = NULL;
@@@ -817,14 -814,14 +814,14 @@@
                              activator->stop = NULL;
                              activator->destroy = NULL;
                          }
--
++                        
                          status = CELIX_DO_IF(status, 
bundle_setActivator(bundle, activator));
--
++                        
                          status = CELIX_DO_IF(status, 
framework_setBundleStateAndNotify(framework, bundle, 
OSGI_FRAMEWORK_BUNDLE_STARTING));
                          status = CELIX_DO_IF(status, 
fw_fireBundleEvent(framework, OSGI_FRAMEWORK_BUNDLE_EVENT_STARTING, bundle));
--
++                        
                          status = CELIX_DO_IF(status, 
bundle_getContext(bundle, &context));
--
++                        
                          if (status == CELIX_SUCCESS) {
                              if (create != NULL) {
                                  status = CELIX_DO_IF(status, create(context, 
&userData));
@@@ -846,97 -843,97 +843,97 @@@
                                  status = CELIX_DO_IF(status, dmInit(userData, 
context, mng));
                              }
                          }
--
++                        
                          status = CELIX_DO_IF(status, 
framework_setBundleStateAndNotify(framework, bundle, 
OSGI_FRAMEWORK_BUNDLE_ACTIVE));
                          status = CELIX_DO_IF(status, 
fw_fireBundleEvent(framework, OSGI_FRAMEWORK_BUNDLE_EVENT_STARTED, bundle));
                      }
                  }
--
--            break;
++                
++                break;
          }
--      }
--
--      framework_releaseBundleLock(framework, bundle);
--
--      if (status != CELIX_SUCCESS) {
--          module_pt module = NULL;
--          const char *symbolicName = NULL;
--          long id = 0;
--          bundle_getCurrentModule(bundle, &module);
--          module_getSymbolicName(module, &symbolicName);
--          bundle_getBundleId(bundle, &id);
--          if (error != NULL) {
--              fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, 
"Could not start bundle: %s [%ld]; cause: %s", symbolicName, id, error);
--          } else {
--              fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, 
"Could not start bundle: %s [%ld]", symbolicName, id);
--          }
--          if(activator!=NULL){
--              free(activator);
--          }
--      }
--
--      return status;
++    }
++    
++    framework_releaseBundleLock(framework, bundle);
++    
++    if (status != CELIX_SUCCESS) {
++        module_pt module = NULL;
++        const char *symbolicName = NULL;
++        long id = 0;
++        bundle_getCurrentModule(bundle, &module);
++        module_getSymbolicName(module, &symbolicName);
++        bundle_getBundleId(bundle, &id);
++        if (error != NULL) {
++            fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, 
"Could not start bundle: %s [%ld]; cause: %s", symbolicName, id, error);
++        } else {
++            fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, 
"Could not start bundle: %s [%ld]", symbolicName, id);
++        }
++        if(activator!=NULL){
++            free(activator);
++        }
++    }
++    
++    return status;
  }
  
  celix_status_t framework_updateBundle(framework_pt framework, bundle_pt 
bundle, const char *inputFile) {
--      celix_status_t status = CELIX_SUCCESS;
--      bundle_state_e oldState;
--      const char *location;
--      bundle_archive_pt archive = NULL;
--      char *error = NULL;
--
--      status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
--      status = CELIX_DO_IF(status, bundle_getState(bundle, &oldState));
--      if (status == CELIX_SUCCESS) {
++    celix_status_t status = CELIX_SUCCESS;
++    bundle_state_e oldState;
++    const char *location;
++    bundle_archive_pt archive = NULL;
++    char *error = NULL;
++    
++    status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
++    status = CELIX_DO_IF(status, bundle_getState(bundle, &oldState));
++    if (status == CELIX_SUCCESS) {
          if (oldState == OSGI_FRAMEWORK_BUNDLE_ACTIVE) {
              fw_stopBundle(framework, bundle, false);
          }
--      }
--      status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive));
--      status = CELIX_DO_IF(status, bundleArchive_getLocation(archive, 
&location));
--
--      if (status == CELIX_SUCCESS) {
--          bool locked = framework_acquireGlobalLock(framework);
--          if (!locked) {
--              status = CELIX_BUNDLE_EXCEPTION;
--              error = "Unable to acquire the global lock to update the 
bundle";
--          }
--      }
--
--      status = CELIX_DO_IF(status, bundle_revise(bundle, location, 
inputFile));
--      status = CELIX_DO_IF(status, framework_releaseGlobalLock(framework));
--
--      status = CELIX_DO_IF(status, bundleArchive_setLastModified(archive, 
time(NULL)));
--      status = CELIX_DO_IF(status, 
framework_setBundleStateAndNotify(framework, bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED));
--
--      bundle_revision_pt revision = NULL;
--      array_list_pt handles = NULL;
--      status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, 
&revision));
++    }
++    status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive));
++    status = CELIX_DO_IF(status, bundleArchive_getLocation(archive, 
&location));
++    
++    if (status == CELIX_SUCCESS) {
++        bool locked = framework_acquireGlobalLock(framework);
++        if (!locked) {
++            status = CELIX_BUNDLE_EXCEPTION;
++            error = "Unable to acquire the global lock to update the bundle";
++        }
++    }
++    
++    status = CELIX_DO_IF(status, bundle_revise(bundle, location, inputFile));
++    status = CELIX_DO_IF(status, framework_releaseGlobalLock(framework));
++    
++    status = CELIX_DO_IF(status, bundleArchive_setLastModified(archive, 
time(NULL)));
++    status = CELIX_DO_IF(status, framework_setBundleStateAndNotify(framework, 
bundle, OSGI_FRAMEWORK_BUNDLE_INSTALLED));
++    
++    bundle_revision_pt revision = NULL;
++    array_list_pt handles = NULL;
++    status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, 
&revision));
      status = CELIX_DO_IF(status, bundleRevision_getHandles(revision, 
&handles));
      if (handles != NULL) {
          int i;
--          for (i = arrayList_size(handles) - 1; i >= 0; i--) {
--              void* handle = arrayList_get(handles, i);
--              fw_closeLibrary(handle);
--          }
++        for (i = arrayList_size(handles) - 1; i >= 0; i--) {
++            void* handle = arrayList_get(handles, i);
++            fw_closeLibrary(handle);
++        }
      }
--
--
--      status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_UNRESOLVED, bundle));
--      status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_UPDATED, bundle));
--
++    
++    
++    status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_UNRESOLVED, bundle));
++    status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_UPDATED, bundle));
++    
      // Refresh packages?
--
--      if (status == CELIX_SUCCESS) {
--          if (oldState == OSGI_FRAMEWORK_BUNDLE_ACTIVE) {
--              status = CELIX_DO_IF(status, fw_startBundle(framework, bundle, 
1));
--          }
--      }
--
--      framework_releaseBundleLock(framework, bundle);
--
--      if (status != CELIX_SUCCESS) {
--          module_pt module = NULL;
++    
++    if (status == CELIX_SUCCESS) {
++        if (oldState == OSGI_FRAMEWORK_BUNDLE_ACTIVE) {
++            status = CELIX_DO_IF(status, fw_startBundle(framework, bundle, 
1));
++        }
++    }
++    
++    framework_releaseBundleLock(framework, bundle);
++    
++    if (status != CELIX_SUCCESS) {
++        module_pt module = NULL;
          const char *symbolicName = NULL;
          long id = 0;
          bundle_getCurrentModule(bundle, &module);
@@@ -947,29 -944,29 +944,29 @@@
          } else {
              fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, 
"Cannot update bundle: %s [%ld]", symbolicName, id);
          }
--      }
--
--      return status;
++    }
++    
++    return status;
  }
  
  celix_status_t fw_stopBundle(framework_pt framework, bundle_pt bundle, bool 
record) {
--      celix_status_t status = CELIX_SUCCESS;
--      bundle_state_e state;
++    celix_status_t status = CELIX_SUCCESS;
++    bundle_state_e state;
      activator_pt activator = NULL;
      bundle_context_t *context = NULL;
      bool wasActive = false;
      long id = 0;
      char *error = NULL;
--
--      status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
--
--      if (record) {
--          status = CELIX_DO_IF(status, 
bundle_setPersistentStateInactive(bundle));
++    
++    status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
++    
++    if (record) {
++        status = CELIX_DO_IF(status, 
bundle_setPersistentStateInactive(bundle));
      }
--
--      status = CELIX_DO_IF(status, bundle_getState(bundle, &state));
--      if (status == CELIX_SUCCESS) {
--          switch (state) {
++    
++    status = CELIX_DO_IF(status, bundle_getState(bundle, &state));
++    if (status == CELIX_SUCCESS) {
++        switch (state) {
              case OSGI_FRAMEWORK_BUNDLE_UNKNOWN:
                  status = CELIX_ILLEGAL_STATE;
                  error = "state is unknown";
@@@ -993,18 -990,18 +990,18 @@@
                  wasActive = true;
                  break;
          }
--      }
--
--
--      status = CELIX_DO_IF(status, 
framework_setBundleStateAndNotify(framework, bundle, 
OSGI_FRAMEWORK_BUNDLE_STOPPING));
--      status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_STOPPING, bundle));
++    }
++    
++    
++    status = CELIX_DO_IF(status, framework_setBundleStateAndNotify(framework, 
bundle, OSGI_FRAMEWORK_BUNDLE_STOPPING));
++    status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_STOPPING, bundle));
      status = CELIX_DO_IF(status, bundle_getBundleId(bundle, &id));
--      if (status == CELIX_SUCCESS) {
--          if (wasActive || (id == 0)) {
--              activator = bundle_getActivator(bundle);
--
--              status = CELIX_DO_IF(status, bundle_getContext(bundle, 
&context));
--              if (status == CELIX_SUCCESS) {
++    if (status == CELIX_SUCCESS) {
++        if (wasActive || (id == 0)) {
++            activator = bundle_getActivator(bundle);
++            
++            status = CELIX_DO_IF(status, bundle_getContext(bundle, &context));
++            if (status == CELIX_SUCCESS) {
                  if (activator->stop != NULL) {
                      status = CELIX_DO_IF(status, 
activator->stop(activator->userData, context));
                  } else if (activator->dmInit != NULL) {
@@@ -1012,7 -1009,7 +1009,7 @@@
                      dm_dependency_manager_t *mng = 
celix_bundleContext_getDependencyManager(context);
                      dependencyManager_removeAllComponents(mng);
                  }
--              }
++            }
              if (status == CELIX_SUCCESS) {
                  if (activator->destroy != NULL) {
                      status = CELIX_DO_IF(status, 
activator->destroy(activator->userData, context));
@@@ -1020,8 -1017,8 +1017,8 @@@
                      dm_dependency_manager_t *mng = 
celix_bundleContext_getDependencyManager(context);
                      status = CELIX_DO_IF(status, 
activator->dmDestroy(activator->userData, context, mng));
                  }
--              }
--
++            }
++            
              if (id != 0) {
                  status = CELIX_DO_IF(status, 
serviceRegistry_clearServiceRegistrations(framework->registry, bundle));
                  if (status == CELIX_SUCCESS) {
@@@ -1031,30 -1028,30 +1028,30 @@@
                      bundle_getCurrentModule(bundle, &module);
                      module_getSymbolicName(module, &symbolicName);
                      bundle_getBundleId(bundle, &id);
--
++                    
                      serviceRegistry_clearReferencesFor(framework->registry, 
bundle);
                  }
                  // #TODO remove listeners for bundle
--
++                
                  if (context != NULL) {
                      status = CELIX_DO_IF(status, 
bundleContext_destroy(context));
                      status = CELIX_DO_IF(status, bundle_setContext(bundle, 
NULL));
                  }
--
++                
                  status = CELIX_DO_IF(status, 
framework_setBundleStateAndNotify(framework, bundle, 
OSGI_FRAMEWORK_BUNDLE_RESOLVED));
              }
--          }
--
--          if (activator != NULL) {
--              bundle_setActivator(bundle, NULL);
--              free(activator);
--          }
--      }
--
--      framework_releaseBundleLock(framework, bundle);
--
--      if (status != CELIX_SUCCESS) {
--          module_pt module = NULL;
++        }
++        
++        if (activator != NULL) {
++            bundle_setActivator(bundle, NULL);
++            free(activator);
++        }
++    }
++    
++    framework_releaseBundleLock(framework, bundle);
++    
++    if (status != CELIX_SUCCESS) {
++        module_pt module = NULL;
          const char *symbolicName = NULL;
          long id = 0;
          bundle_getCurrentModule(bundle, &module);
@@@ -1065,11 -1062,11 +1062,11 @@@
          } else {
              fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, 
"Cannot stop bundle: %s [%ld]", symbolicName, id);
          }
--      } else {
++    } else {
          fw_fireBundleEvent(framework, OSGI_FRAMEWORK_BUNDLE_EVENT_STOPPED, 
bundle);
--      }
--
--      return status;
++    }
++    
++    return status;
  }
  
  celix_status_t fw_uninstallBundle(framework_pt framework, bundle_pt bundle) {
@@@ -1079,7 -1076,7 +1076,7 @@@
      const char * location = NULL;
      bundle_pt target = NULL;
      char *error = NULL;
--
++    
      status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED|OSGI_FRAMEWORK_BUNDLE_RESOLVED|OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE|OSGI_FRAMEWORK_BUNDLE_STOPPING));
      status = CELIX_DO_IF(status, fw_stopBundle(framework, bundle, true));
      if (status == CELIX_SUCCESS) {
@@@ -1089,58 -1086,58 +1086,58 @@@
              error = "Unable to acquire the global lock to uninstall the 
bundle";
          }
      }
--
++    
      status = CELIX_DO_IF(status, bundle_getArchive(bundle, &archive));
      status = CELIX_DO_IF(status, bundleArchive_getLocation(archive, 
&location));
      if (status == CELIX_SUCCESS) {
--
++        
          celixThreadMutex_lock(&framework->installedBundleMapLock);
--
++        
          hash_map_entry_pt entry = 
hashMap_getEntry(framework->installedBundleMap, location);
          char* entryLocation = hashMapEntry_getKey(entry);
--
++        
          target = (bundle_pt) hashMap_remove(framework->installedBundleMap, 
location);
--
++        
          free(entryLocation);
          if (target != NULL) {
              status = CELIX_DO_IF(status, 
bundle_setPersistentStateUninstalled(target));
              // fw_rememberUninstalledBundle(framework, target);
          }
          celixThreadMutex_unlock(&framework->installedBundleMapLock);
--
++        
      }
--
++    
      framework_releaseGlobalLock(framework);
--
++    
      if (status == CELIX_SUCCESS) {
          if (target == NULL) {
              fw_log(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, "Could not 
remove bundle from installed map");
          }
      }
--
++    
      status = CELIX_DO_IF(status, framework_setBundleStateAndNotify(framework, 
bundle, OSGI_FRAMEWORK_BUNDLE_INSTALLED));
--
++    
      // TODO Unload all libraries for transition to unresolved
      bundle_revision_pt revision = NULL;
--      array_list_pt handles = NULL;
--      status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, 
&revision));
--      status = CELIX_DO_IF(status, bundleRevision_getHandles(revision, 
&handles));
--      if(handles != NULL){
--              for (int i = arrayList_size(handles) - 1; i >= 0; i--) {
--                      void *handle = arrayList_get(handles, i);
--                      fw_closeLibrary(handle);
--              }
--      }
--
++    array_list_pt handles = NULL;
++    status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, 
&revision));
++    status = CELIX_DO_IF(status, bundleRevision_getHandles(revision, 
&handles));
++    if(handles != NULL){
++        for (int i = arrayList_size(handles) - 1; i >= 0; i--) {
++            void *handle = arrayList_get(handles, i);
++            fw_closeLibrary(handle);
++        }
++    }
++    
      status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_UNRESOLVED, bundle));
--
++    
      status = CELIX_DO_IF(status, framework_setBundleStateAndNotify(framework, 
bundle, OSGI_FRAMEWORK_BUNDLE_UNINSTALLED));
      status = CELIX_DO_IF(status, bundleArchive_setLastModified(archive, 
time(NULL)));
--
++    
      framework_releaseBundleLock(framework, bundle);
--
++    
      status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_UNINSTALLED, bundle));
--
++    
      if (status == CELIX_SUCCESS) {
          locked = framework_acquireGlobalLock(framework);
          if (locked) {
@@@ -1152,38 -1149,38 +1149,38 @@@
                  bundleArchive_destroy(archive);
                  status = CELIX_DO_IF(status, bundle_destroy(bundle));
              }
--
++            
              status = CELIX_DO_IF(status, 
framework_releaseGlobalLock(framework));
          }
      }
--
--
++    
++    
      if (status != CELIX_SUCCESS) {
--//        module_pt module = NULL;
--//        char *symbolicName = NULL;
--//        long id = 0;
--//        bundle_getCurrentModule(bundle, &module);
--//        module_getSymbolicName(module, &symbolicName);
--//        bundle_getBundleId(bundle, &id);
--
++        //        module_pt module = NULL;
++        //        char *symbolicName = NULL;
++        //        long id = 0;
++        //        bundle_getCurrentModule(bundle, &module);
++        //        module_getSymbolicName(module, &symbolicName);
++        //        bundle_getBundleId(bundle, &id);
++        
          framework_logIfError(framework->logger, status, error, "Cannot 
uninstall bundle");
      }
--
++    
      return status;
  }
  
  celix_status_t fw_refreshBundles(framework_pt framework, bundle_pt bundles[], 
int size) {
      celix_status_t status = CELIX_SUCCESS;
--
++    
      bool locked = framework_acquireGlobalLock(framework);
      if (!locked) {
          framework_releaseGlobalLock(framework);
          status = CELIX_ILLEGAL_STATE;
      } else {
--              hash_map_values_pt values;
++        hash_map_values_pt values;
          bundle_pt *newTargets;
          unsigned int nrofvalues;
--              bool restart = false;
++        bool restart = false;
          hash_map_pt map = hashMap_create(NULL, NULL, NULL, NULL);
          int targetIdx = 0;
          for (targetIdx = 0; targetIdx < size; targetIdx++) {
@@@ -1194,19 -1191,19 +1191,19 @@@
          values = hashMapValues_create(map);
          hashMapValues_toArray(values, (void ***) &newTargets, &nrofvalues);
          hashMapValues_destroy(values);
--
++        
          hashMap_destroy(map, false, false);
--
++        
          if (newTargets != NULL) {
              int i = 0;
--                      struct fw_refreshHelper * helpers;
++            struct fw_refreshHelper * helpers;
              for (i = 0; i < nrofvalues && !restart; i++) {
                  bundle_pt bundle = (bundle_pt) newTargets[i];
                  if (framework->bundle == bundle) {
                      restart = true;
                  }
              }
--
++            
              helpers = (struct fw_refreshHelper * )malloc(nrofvalues * 
sizeof(struct fw_refreshHelper));
              for (i = 0; i < nrofvalues && !restart; i++) {
                  bundle_pt bundle = (bundle_pt) newTargets[i];
@@@ -1214,74 -1211,74 +1211,74 @@@
                  helpers[i].bundle = bundle;
                  helpers[i].oldState = OSGI_FRAMEWORK_BUNDLE_INSTALLED;
              }
--
++            
              for (i = 0; i < nrofvalues; i++) {
                  struct fw_refreshHelper helper = helpers[i];
                  fw_refreshHelper_stop(&helper);
                  fw_refreshHelper_refreshOrRemove(&helper);
              }
--
++            
              for (i = 0; i < nrofvalues; i++) {
                  struct fw_refreshHelper helper = helpers[i];
                  fw_refreshHelper_restart(&helper);
              }
--
++            
              if (restart) {
                  bundle_update(framework->bundle, NULL);
              }
--                      free(helpers);
--                      free(newTargets);
++            free(helpers);
++            free(newTargets);
          }
--
++        
          framework_releaseGlobalLock(framework);
      }
--
++    
      framework_logIfError(framework->logger, status, NULL, "Cannot refresh 
bundles");
--
++    
      return status;
  }
  
  celix_status_t fw_refreshBundle(framework_pt framework, bundle_pt bundle) {
      celix_status_t status = CELIX_SUCCESS;
      bundle_state_e state;
--
++    
      status = framework_acquireBundleLock(framework, bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED | OSGI_FRAMEWORK_BUNDLE_RESOLVED);
      if (status != CELIX_SUCCESS) {
          printf("Cannot refresh bundle");
          framework_releaseBundleLock(framework, bundle);
      } else {
--      bool fire;
--              bundle_getState(bundle, &state);
++        bool fire;
++        bundle_getState(bundle, &state);
          fire = (state != OSGI_FRAMEWORK_BUNDLE_INSTALLED);
          bundle_refresh(bundle);
--
++        
          if (fire) {
              framework_setBundleStateAndNotify(framework, bundle, 
OSGI_FRAMEWORK_BUNDLE_INSTALLED);
              fw_fireBundleEvent(framework, 
OSGI_FRAMEWORK_BUNDLE_EVENT_UNRESOLVED, bundle);
          }
--
++        
          framework_releaseBundleLock(framework, bundle);
      }
--
++    
      framework_logIfError(framework->logger, status, NULL, "Cannot refresh 
bundle");
--
++    
      return status;
  }
  
  celix_status_t fw_refreshHelper_stop(struct fw_refreshHelper * refreshHelper) 
{
--      bundle_state_e state;
--      bundle_getState(refreshHelper->bundle, &state);
++    bundle_state_e state;
++    bundle_getState(refreshHelper->bundle, &state);
      if (state == OSGI_FRAMEWORK_BUNDLE_ACTIVE) {
          refreshHelper->oldState = OSGI_FRAMEWORK_BUNDLE_ACTIVE;
          fw_stopBundle(refreshHelper->framework, refreshHelper->bundle, false);
      }
--
++    
      return CELIX_SUCCESS;
  }
  
  celix_status_t fw_refreshHelper_refreshOrRemove(struct fw_refreshHelper * 
refreshHelper) {
--      bundle_state_e state;
--      bundle_getState(refreshHelper->bundle, &state);
++    bundle_state_e state;
++    bundle_getState(refreshHelper->bundle, &state);
      if (state == OSGI_FRAMEWORK_BUNDLE_UNINSTALLED) {
          bundle_closeAndDelete(refreshHelper->bundle);
          refreshHelper->bundle = NULL;
@@@ -1300,96 -1297,96 +1297,96 @@@ celix_status_t fw_refreshHelper_restart
  
  celix_status_t fw_getDependentBundles(framework_pt framework, bundle_pt 
exporter, array_list_pt *list) {
      celix_status_t status = CELIX_SUCCESS;
--
++    
      if (*list != NULL || exporter == NULL || framework == NULL) {
--      return CELIX_ILLEGAL_ARGUMENT;
--    }
--
--       array_list_pt modules;
--       unsigned int modIdx = 0;
--       arrayList_create(list);
--
--       modules = bundle_getModules(exporter);
--       for (modIdx = 0; modIdx < arrayList_size(modules); modIdx++) {
--                              module_pt module = (module_pt) 
arrayList_get(modules, modIdx);
--                              array_list_pt dependents = 
module_getDependents(module);
--                      if(dependents!=NULL){
--                                      unsigned int depIdx = 0;
--                                      for (depIdx = 0; depIdx < 
arrayList_size(dependents); depIdx++) {
--                                                        module_pt dependent = 
(module_pt) arrayList_get(dependents, depIdx);
--                                                        arrayList_add(*list, 
module_getBundle(dependent));
--                                      }
--                                      arrayList_destroy(dependents);
--                              }
--       }
--
++        return CELIX_ILLEGAL_ARGUMENT;
++    }
++    
++    array_list_pt modules;
++    unsigned int modIdx = 0;
++    arrayList_create(list);
++    
++    modules = bundle_getModules(exporter);
++    for (modIdx = 0; modIdx < arrayList_size(modules); modIdx++) {
++        module_pt module = (module_pt) arrayList_get(modules, modIdx);
++        array_list_pt dependents = module_getDependents(module);
++        if(dependents!=NULL){
++            unsigned int depIdx = 0;
++            for (depIdx = 0; depIdx < arrayList_size(dependents); depIdx++) {
++                module_pt dependent = (module_pt) arrayList_get(dependents, 
depIdx);
++                arrayList_add(*list, module_getBundle(dependent));
++            }
++            arrayList_destroy(dependents);
++        }
++    }
++    
      framework_logIfError(framework->logger, status, NULL, "Cannot get 
dependent bundles");
--
++    
      return status;
  }
  
  celix_status_t fw_populateDependentGraph(framework_pt framework, bundle_pt 
exporter, hash_map_pt *map) {
      celix_status_t status = CELIX_SUCCESS;
--
++    
      if(framework == NULL || exporter == NULL){
--      return CELIX_ILLEGAL_ARGUMENT;
++        return CELIX_ILLEGAL_ARGUMENT;
      }
--
++    
      array_list_pt dependents = NULL;
      if ((status = fw_getDependentBundles(framework, exporter, &dependents)) 
== CELIX_SUCCESS) {
--                if(dependents!=NULL){
--         unsigned int depIdx = 0;
--              for (depIdx = 0; depIdx < arrayList_size(dependents); depIdx++) 
{
--                  if (!hashMap_containsKey(*map, arrayList_get(dependents, 
depIdx))) {
--                      hashMap_put(*map, arrayList_get(dependents, depIdx), 
arrayList_get(dependents, depIdx));
--                      fw_populateDependentGraph(framework, (bundle_pt) 
arrayList_get(dependents, depIdx), map);
--                  }
--              }
--              arrayList_destroy(dependents);
--                }
++        if(dependents!=NULL){
++            unsigned int depIdx = 0;
++            for (depIdx = 0; depIdx < arrayList_size(dependents); depIdx++) {
++                if (!hashMap_containsKey(*map, arrayList_get(dependents, 
depIdx))) {
++                    hashMap_put(*map, arrayList_get(dependents, depIdx), 
arrayList_get(dependents, depIdx));
++                    fw_populateDependentGraph(framework, (bundle_pt) 
arrayList_get(dependents, depIdx), map);
++                }
++            }
++            arrayList_destroy(dependents);
++        }
      }
--
++    
      framework_logIfError(framework->logger, status, NULL, "Cannot populate 
dependent graph");
--
++    
      return status;
  }
  
  celix_status_t fw_registerService(framework_pt framework, 
service_registration_pt *registration, bundle_pt bundle, const char* 
serviceName, const void* svcObj, properties_pt properties) {
--      celix_status_t status = CELIX_SUCCESS;
--      char *error = NULL;
--      if (serviceName == NULL || svcObj == NULL) {
--          status = CELIX_ILLEGAL_ARGUMENT;
--          error = "ServiceName and SvcObj cannot be null";
--      }
--
--      status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
--      status = CELIX_DO_IF(status, 
serviceRegistry_registerService(framework->registry, bundle, serviceName, 
svcObj, properties, registration));
--      bool res = framework_releaseBundleLock(framework, bundle);
--      if (!res) {
--          status = CELIX_ILLEGAL_STATE;
--          error = "Could not release bundle lock";
--      }
--
--      if (status == CELIX_SUCCESS) {
--          // If this is a listener hook, invoke the callback with all current 
listeners
++    celix_status_t status = CELIX_SUCCESS;
++    char *error = NULL;
++    if (serviceName == NULL || svcObj == NULL) {
++        status = CELIX_ILLEGAL_ARGUMENT;
++        error = "ServiceName and SvcObj cannot be null";
++    }
++    
++    status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
++    status = CELIX_DO_IF(status, 
serviceRegistry_registerService(framework->registry, bundle, serviceName, 
svcObj, properties, registration));
++    bool res = framework_releaseBundleLock(framework, bundle);
++    if (!res) {
++        status = CELIX_ILLEGAL_STATE;
++        error = "Could not release bundle lock";
++    }
++    
++    if (status == CELIX_SUCCESS) {
++        // If this is a listener hook, invoke the callback with all current 
listeners
          if (strcmp(serviceName, OSGI_FRAMEWORK_LISTENER_HOOK_SERVICE_NAME) == 
0) {
              unsigned int i;
              array_list_pt infos = NULL;
              service_reference_pt ref = NULL;
              listener_hook_service_pt hook = NULL;
--
++            
              status = CELIX_DO_IF(status, arrayList_create(&infos));
--
++            
              if (status == CELIX_SUCCESS) {
                  celix_status_t subs = CELIX_SUCCESS;
--
++                
                  celixThreadMutex_lock(&framework->serviceListenersLock);
                  for (i = 0; i < arrayList_size(framework->serviceListeners); 
i++) {
                      fw_service_listener_pt listener =(fw_service_listener_pt) 
arrayList_get(framework->serviceListeners, i);
                      bundle_context_t *context = NULL;
                      listener_hook_info_pt info = NULL;
                      bundle_context_pt lContext = NULL;
--
++                    
                      subs = CELIX_DO_IF(subs, bundle_getContext(bundle, 
&context));
                      if (subs == CELIX_SUCCESS) {
                          info = (listener_hook_info_pt) malloc(sizeof(*info));
@@@ -1397,14 -1394,14 +1394,14 @@@
                              subs = CELIX_ENOMEM;
                          }
                      }
--
++                    
                      subs = CELIX_DO_IF(subs, 
bundle_getContext(listener->bundle, &lContext));
                      if (subs == CELIX_SUCCESS) {
                          info->context = lContext;
                          info->removed = false;
                      }
                      subs = CELIX_DO_IF(subs, 
filter_getString(listener->filter, &info->filter));
--
++                    
                      if (subs == CELIX_SUCCESS) {
                          arrayList_add(infos, info);
                      }
@@@ -1414,7 -1411,7 +1411,7 @@@
                      }
                  }
                  celixThreadMutex_unlock(&framework->serviceListenersLock);
--
++                
                  status = CELIX_DO_IF(status, 
serviceRegistry_getServiceReference(framework->registry, framework->bundle,
                                                                                
   *registration, &ref));
                  status = CELIX_DO_IF(status, 
fw_getService(framework,framework->bundle, ref, (const void **) &hook));
@@@ -1423,59 -1420,59 +1420,59 @@@
                  }
                  status = CELIX_DO_IF(status, 
serviceRegistry_ungetService(framework->registry, framework->bundle, ref, 
NULL));
                  status = CELIX_DO_IF(status, 
serviceRegistry_ungetServiceReference(framework->registry, framework->bundle, 
ref));
--
++                
                  int i = 0;
                  for (i = 0; i < arrayList_size(infos); i++) {
                      listener_hook_info_pt info = arrayList_get(infos, i);
                      free(info);
                  }
                  arrayList_destroy(infos);
--             }
++            }
          }
--      }
--
++    }
++    
      framework_logIfError(framework->logger, status, error, "Cannot register 
service: %s", serviceName);
--
--      return status;
++    
++    return status;
  }
  
  celix_status_t fw_registerServiceFactory(framework_pt framework, 
service_registration_pt *registration, bundle_pt bundle, const char* 
serviceName, service_factory_pt factory, properties_pt properties) {
      celix_status_t status = CELIX_SUCCESS;
      char *error = NULL;
--      if (serviceName == NULL || factory == NULL) {
++    if (serviceName == NULL || factory == NULL) {
          status = CELIX_ILLEGAL_ARGUMENT;
          error = "Service name and factory cannot be null";
      }
--
--      status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
--      status = CELIX_DO_IF(status, 
serviceRegistry_registerServiceFactory(framework->registry, bundle, 
serviceName, factory, properties, registration));
++    
++    status = CELIX_DO_IF(status, framework_acquireBundleLock(framework, 
bundle, OSGI_FRAMEWORK_BUNDLE_STARTING|OSGI_FRAMEWORK_BUNDLE_ACTIVE));
++    status = CELIX_DO_IF(status, 
serviceRegistry_registerServiceFactory(framework->registry, bundle, 
serviceName, factory, properties, registration));
      if (!framework_releaseBundleLock(framework, bundle)) {
          status = CELIX_ILLEGAL_STATE;
          error = "Could not release bundle lock";
      }
--
++    
      framework_logIfError(framework->logger, status, error, "Cannot register 
service factory: %s", serviceName);
--
++    
      return CELIX_SUCCESS;
  }
  
  celix_status_t fw_getServiceReferences(framework_pt framework, array_list_pt 
*references, bundle_pt bundle, const char * serviceName, const char * sfilter) {
      celix_status_t status = CELIX_SUCCESS;
--
--      filter_pt filter = NULL;
--      unsigned int refIdx = 0;
--
++    
++    filter_pt filter = NULL;
++    unsigned int refIdx = 0;
++    
      if (sfilter != NULL) {
          filter = filter_create(sfilter);
--      }
--
--      status = CELIX_DO_IF(status, 
serviceRegistry_getServiceReferences(framework->registry, bundle, serviceName, 
filter, references));
--
--      if (filter != NULL) {
--              filter_destroy(filter);
--      }
--
--      if (status == CELIX_SUCCESS) {
++    }
++    
++    status = CELIX_DO_IF(status, 
serviceRegistry_getServiceReferences(framework->registry, bundle, serviceName, 
filter, references));
++    
++    if (filter != NULL) {
++        filter_destroy(filter);
++    }
++    
++    if (status == CELIX_SUCCESS) {
          for (refIdx = 0; (*references != NULL) && refIdx < 
arrayList_size(*references); refIdx++) {
              service_reference_pt ref = (service_reference_pt) 
arrayList_get(*references, refIdx);
              service_registration_pt reg = NULL;
@@@ -1491,11 -1488,11 +1488,11 @@@
                  }
              }
          }
--      }
--
--      framework_logIfError(framework->logger, status, NULL, "Failed to get 
service references");
--
--      return status;
++    }
++    
++    framework_logIfError(framework->logger, status, NULL, "Failed to get 
service references");
++    
++    return status;
  }
  
  celix_status_t framework_ungetServiceReference(framework_pt framework, 
bundle_pt bundle, service_reference_pt reference) {
@@@ -1503,78 -1500,78 +1500,78 @@@
  }
  
  celix_status_t fw_getService(framework_pt framework, bundle_pt bundle, 
service_reference_pt reference, const void **service) {
--      return serviceRegistry_getService(framework->registry, bundle, 
reference, service);
++    return serviceRegistry_getService(framework->registry, bundle, reference, 
service);
  }
  
  celix_status_t fw_getBundleRegisteredServices(framework_pt framework, 
bundle_pt bundle, array_list_pt *services) {
--      return serviceRegistry_getRegisteredServices(framework->registry, 
bundle, services);
++    return serviceRegistry_getRegisteredServices(framework->registry, bundle, 
services);
  }
  
  celix_status_t fw_getBundleServicesInUse(framework_pt framework, bundle_pt 
bundle, array_list_pt *services) {
--      celix_status_t status = CELIX_SUCCESS;
--      status = serviceRegistry_getServicesInUse(framework->registry, bundle, 
services);
--      return status;
++    celix_status_t status = CELIX_SUCCESS;
++    status = serviceRegistry_getServicesInUse(framework->registry, bundle, 
services);
++    return status;
  }
  
  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);
++    return serviceRegistry_ungetService(framework->registry, bundle, 
reference, result);
  }
  
  void fw_addServiceListener(framework_pt framework, bundle_pt bundle, 
service_listener_pt listener, const char* sfilter) {
--      array_list_pt listenerHooks = NULL;
--      unsigned int i;
--
--      fw_service_listener_pt fwListener = (fw_service_listener_pt) calloc(1, 
sizeof(*fwListener));
--      bundle_context_t *context = NULL;
--
--      fwListener->bundle = bundle;
++    array_list_pt listenerHooks = NULL;
++    unsigned int i;
++    
++    fw_service_listener_pt fwListener = (fw_service_listener_pt) calloc(1, 
sizeof(*fwListener));
++    bundle_context_t *context = NULL;
++    
++    fwListener->bundle = bundle;
      arrayList_create(&fwListener->retainedReferences);
--      if (sfilter != NULL) {
--              filter_pt filter = filter_create(sfilter);
--              fwListener->filter = filter;
--      } else {
--              fwListener->filter = NULL;
--      }
--      fwListener->listener = listener;
--
++    if (sfilter != NULL) {
++        filter_pt filter = filter_create(sfilter);
++        fwListener->filter = filter;
++    } else {
++        fwListener->filter = NULL;
++    }
++    fwListener->listener = listener;
++    
      celixThreadMutex_lock(&framework->serviceListenersLock);
--      arrayList_add(framework->serviceListeners, fwListener);
++    arrayList_add(framework->serviceListeners, fwListener);
      celixThreadMutex_unlock(&framework->serviceListenersLock);
--
--      serviceRegistry_getListenerHooks(framework->registry, 
framework->bundle, &listenerHooks);
--
++    
++    serviceRegistry_getListenerHooks(framework->registry, framework->bundle, 
&listenerHooks);
++    
      struct listener_hook_info info;
--
--      bundle_getContext(bundle, &context);
--      info.context = context;
--      info.removed = false;
--      info.filter = sfilter;
--
--      for (i = 0; i < arrayList_size(listenerHooks); i++) {
--              service_reference_pt ref = (service_reference_pt) 
arrayList_get(listenerHooks, i);
--              listener_hook_service_pt hook = NULL;
--              array_list_pt infos = NULL;
--              bool ungetResult = false;
--
--              fw_getService(framework, framework->bundle, ref, (const void 
**) &hook);
--
--              arrayList_create(&infos);
--              arrayList_add(infos, &info);
--              hook->added(hook->handle, infos);
--              serviceRegistry_ungetService(framework->registry, 
framework->bundle, ref, &ungetResult);
--              serviceRegistry_ungetServiceReference(framework->registry, 
framework->bundle, ref);
--              arrayList_destroy(infos);
--      }
--
--      arrayList_destroy(listenerHooks);
++    
++    bundle_getContext(bundle, &context);
++    info.context = context;
++    info.removed = false;
++    info.filter = sfilter;
++    
++    for (i = 0; i < arrayList_size(listenerHooks); i++) {
++        service_reference_pt ref = (service_reference_pt) 
arrayList_get(listenerHooks, i);
++        listener_hook_service_pt hook = NULL;
++        array_list_pt infos = NULL;
++        bool ungetResult = false;
++        
++        fw_getService(framework, framework->bundle, ref, (const void **) 
&hook);
++        
++        arrayList_create(&infos);
++        arrayList_add(infos, &info);
++        hook->added(hook->handle, infos);
++        serviceRegistry_ungetService(framework->registry, framework->bundle, 
ref, &ungetResult);
++        serviceRegistry_ungetServiceReference(framework->registry, 
framework->bundle, ref);
++        arrayList_destroy(infos);
++    }
++    
++    arrayList_destroy(listenerHooks);
  }
  
  void fw_removeServiceListener(framework_pt framework, bundle_pt bundle, 
service_listener_pt listener) {
--      fw_service_listener_pt match = NULL;
--
--      bundle_context_t *context;
--      bundle_getContext(bundle, &context);
--
++    fw_service_listener_pt match = NULL;
++    
++    bundle_context_t *context;
++    bundle_getContext(bundle, &context);
++    
      int i;
      celixThreadMutex_lock(&framework->serviceListenersLock);
      for (i = 0; i < arrayList_size(framework->serviceListeners); i++) {
@@@ -1586,19 -1583,19 +1583,19 @@@
          }
      }
      celixThreadMutex_unlock(&framework->serviceListenersLock);
--
--
++    
++    
      if (match != NULL) {
          //invoke listener hooks
--
++        
          bundle_context_pt lContext = NULL;
--
++        
          struct listener_hook_info info;
          bundle_getContext(match->bundle, &lContext);
          info.context = lContext;
          filter_getString(match->filter, &info.filter);
          info.removed = true;
--
++        
          array_list_pt listenerHooks = NULL;
          serviceRegistry_getListenerHooks(framework->registry, 
framework->bundle, &listenerHooks);
          for (i = 0; i < arrayList_size(listenerHooks); i++) {
@@@ -1606,9 -1603,9 +1603,9 @@@
              listener_hook_service_pt hook = NULL;
              array_list_pt infos = NULL;
              bool ungetResult;
--
++            
              fw_getService(framework, framework->bundle, ref, (const void **) 
&hook);
--
++            
              arrayList_create(&infos);
              arrayList_add(infos, &info);
              hook->removed(hook->handle, infos);
@@@ -1618,7 -1615,7 +1615,7 @@@
          }
          arrayList_destroy(listenerHooks);
      }
--
++    
      if (match != NULL) {
          //unregistering retained service references. For these refs a 
unregister event will not be triggered.
          int rSize = arrayList_size(match->retainedReferences);
@@@ -1628,129 -1625,129 +1625,129 @@@
                  serviceRegistry_ungetServiceReference(framework->registry, 
match->bundle, ref); // decrease retain counter
              }
          }
--
++        
          match->bundle = NULL;
          filter_destroy(match->filter);
          arrayList_destroy(match->retainedReferences);
          match->filter = NULL;
          match->listener = NULL;
          free(match);
--      }
++    }
  }
  
  celix_status_t fw_addBundleListener(framework_pt framework, bundle_pt bundle, 
bundle_listener_pt listener) {
--      celix_status_t status = CELIX_SUCCESS;
--      fw_bundle_listener_pt bundleListener = NULL;
--
--      bundleListener = (fw_bundle_listener_pt) 
malloc(sizeof(*bundleListener));
--      if (!bundleListener) {
--              status = CELIX_ENOMEM;
--      } else {
--              bundleListener->listener = listener;
--              bundleListener->bundle = bundle;
--
--              if (celixThreadMutex_lock(&framework->bundleListenerLock) != 
CELIX_SUCCESS) {
--                      status = CELIX_FRAMEWORK_EXCEPTION;
--              } else {
--                      arrayList_add(framework->bundleListeners, 
bundleListener);
--
--                      if 
(celixThreadMutex_unlock(&framework->bundleListenerLock)) {
--                              status = CELIX_FRAMEWORK_EXCEPTION;
--                      }
--              }
--      }
--
--      framework_logIfError(framework->logger, status, NULL, "Failed to add 
bundle listener");
--
--      return status;
++    celix_status_t status = CELIX_SUCCESS;
++    fw_bundle_listener_pt bundleListener = NULL;
++    
++    bundleListener = (fw_bundle_listener_pt) malloc(sizeof(*bundleListener));
++    if (!bundleListener) {
++        status = CELIX_ENOMEM;
++    } else {
++        bundleListener->listener = listener;
++        bundleListener->bundle = bundle;
++        
++        if (celixThreadMutex_lock(&framework->bundleListenerLock) != 
CELIX_SUCCESS) {
++            status = CELIX_FRAMEWORK_EXCEPTION;
++        } else {
++            arrayList_add(framework->bundleListeners, bundleListener);
++            
++            if (celixThreadMutex_unlock(&framework->bundleListenerLock)) {
++                status = CELIX_FRAMEWORK_EXCEPTION;
++            }
++        }
++    }
++    
++    framework_logIfError(framework->logger, status, NULL, "Failed to add 
bundle listener");
++    
++    return status;
  }
  
  celix_status_t fw_removeBundleListener(framework_pt framework, bundle_pt 
bundle, bundle_listener_pt listener) {
--      celix_status_t status = CELIX_SUCCESS;
--
--      unsigned int i;
--      fw_bundle_listener_pt bundleListener;
--
--      if (celixThreadMutex_lock(&framework->bundleListenerLock) != 
CELIX_SUCCESS) {
--              status = CELIX_FRAMEWORK_EXCEPTION;
--      }
--      else {
--              for (i = 0; i < arrayList_size(framework->bundleListeners); 
i++) {
--                      bundleListener = (fw_bundle_listener_pt) 
arrayList_get(framework->bundleListeners, i);
--                      if (bundleListener->listener == listener && 
bundleListener->bundle == bundle) {
--                              arrayList_remove(framework->bundleListeners, i);
--
--                              bundleListener->bundle = NULL;
--                              bundleListener->listener = NULL;
--                              free(bundleListener);
--                      }
--              }
--              if (celixThreadMutex_unlock(&framework->bundleListenerLock)) {
--                      status = CELIX_FRAMEWORK_EXCEPTION;
--              }
--      }
--
--      framework_logIfError(framework->logger, status, NULL, "Failed to remove 
bundle listener");
--
--      return status;
++    celix_status_t status = CELIX_SUCCESS;
++    
++    unsigned int i;
++    fw_bundle_listener_pt bundleListener;
++    
++    if (celixThreadMutex_lock(&framework->bundleListenerLock) != 
CELIX_SUCCESS) {
++        status = CELIX_FRAMEWORK_EXCEPTION;
++    }
++    else {
++        for (i = 0; i < arrayList_size(framework->bundleListeners); i++) {
++            bundleListener = (fw_bundle_listener_pt) 
arrayList_get(framework->bundleListeners, i);
++            if (bundleListener->listener == listener && 
bundleListener->bundle == bundle) {
++                arrayList_remove(framework->bundleListeners, i);
++                
++                bundleListener->bundle = NULL;
++                bundleListener->listener = NULL;
++                free(bundleListener);
++            }
++        }
++        if (celixThreadMutex_unlock(&framework->bundleListenerLock)) {
++            status = CELIX_FRAMEWORK_EXCEPTION;
++        }
++    }
++    
++    framework_logIfError(framework->logger, status, NULL, "Failed to remove 
bundle listener");
++    
++    return status;
  }
  
  celix_status_t fw_addFrameworkListener(framework_pt framework, bundle_pt 
bundle, framework_listener_pt listener) {
--      celix_status_t status = CELIX_SUCCESS;
--      fw_framework_listener_pt frameworkListener = NULL;
--
--      frameworkListener = (fw_framework_listener_pt) 
malloc(sizeof(*frameworkListener));
--      if (!frameworkListener) {
--              status = CELIX_ENOMEM;
--      } else {
--              frameworkListener->listener = listener;
--              frameworkListener->bundle = bundle;
--
++    celix_status_t status = CELIX_SUCCESS;
++    fw_framework_listener_pt frameworkListener = NULL;
++    
++    frameworkListener = (fw_framework_listener_pt) 
malloc(sizeof(*frameworkListener));
++    if (!frameworkListener) {
++        status = CELIX_ENOMEM;
++    } else {
++        frameworkListener->listener = listener;
++        frameworkListener->bundle = bundle;
++        
          celixThreadMutex_lock(&framework->frameworkListenersLock);
--              arrayList_add(framework->frameworkListeners, frameworkListener);
++        arrayList_add(framework->frameworkListeners, frameworkListener);
          celixThreadMutex_unlock(&framework->frameworkListenersLock);
--      }
--
--      framework_logIfError(framework->logger, status, NULL, "Failed to add 
framework listener");
--
--      return status;
++    }
++    
++    framework_logIfError(framework->logger, status, NULL, "Failed to add 
framework listener");
++    
++    return status;
  }
  
  celix_status_t fw_removeFrameworkListener(framework_pt framework, bundle_pt 
bundle, framework_listener_pt listener) {
--      celix_status_t status = CELIX_SUCCESS;
--
--      unsigned int i;
--      fw_framework_listener_pt frameworkListener;
--
++    celix_status_t status = CELIX_SUCCESS;
++    
++    unsigned int i;
++    fw_framework_listener_pt frameworkListener;
++    
      celixThreadMutex_lock(&framework->frameworkListenersLock);
--      for (i = 0; i < arrayList_size(framework->frameworkListeners); i++) {
--              frameworkListener = (fw_framework_listener_pt) 
arrayList_get(framework->frameworkListeners, i);
--              if (frameworkListener->listener == listener && 
frameworkListener->bundle == bundle) {
--                      arrayList_remove(framework->frameworkListeners, i);
--
--                      frameworkListener->bundle = NULL;
++    for (i = 0; i < arrayList_size(framework->frameworkListeners); i++) {
++        frameworkListener = (fw_framework_listener_pt) 
arrayList_get(framework->frameworkListeners, i);
++        if (frameworkListener->listener == listener && 
frameworkListener->bundle == bundle) {
++            arrayList_remove(framework->frameworkListeners, i);
++            
++            frameworkListener->bundle = NULL;
              frameworkListener->listener = NULL;
              free(frameworkListener);
--              }
--      }
++        }
++    }
      celixThreadMutex_unlock(&framework->frameworkListenersLock);
--
--      framework_logIfError(framework->logger, status, NULL, "Failed to remove 
framework listener");
--
--      return status;
++    
++    framework_logIfError(framework->logger, status, NULL, "Failed to remove 
framework listener");
++    
++    return status;
  }
  
  void fw_serviceChanged(framework_pt framework, service_event_type_e 
eventType, service_registration_pt registration, properties_pt oldprops) {
      unsigned int i;
      fw_service_listener_pt element;
--
++    
      celixThreadMutex_lock(&framework->serviceListenersLock);
      if (arrayList_size(framework->serviceListeners) > 0) {
          for (i = 0; i < arrayList_size(framework->serviceListeners); i++) {
              int matched = 0;
              properties_pt props = NULL;
              bool matchResult = false;
--
++            
              element = (fw_service_listener_pt) 
arrayList_get(framework->serviceListeners, i);
              serviceRegistration_getProperties(registration, &props);
              if (element->filter != NULL) {
@@@ -1760,34 -1757,34 +1757,34 @@@
              if (matched) {
                  service_reference_pt reference = NULL;
                  service_event_pt event;
--
++                
                  event = (service_event_pt) malloc(sizeof (*event));
--
++                
                  serviceRegistry_getServiceReference(framework->registry, 
element->bundle, registration, &reference);
--
++                
                  //NOTE: that you are never sure that the UNREGISTERED event 
will by handle by an service_listener. listener could be gone
                  //Every reference retained is therefore stored and called 
when a service listener is removed from the framework.
                  if (eventType == OSGI_FRAMEWORK_SERVICE_EVENT_REGISTERED) {
                      
serviceRegistry_retainServiceReference(framework->registry, element->bundle, 
reference);
                      arrayList_add(element->retainedReferences, reference); 
//TODO improve by using set (or hashmap) instead of list
                  }
--
++                
                  event->type = eventType;
                  event->reference = reference;
--
++                
                  element->listener->serviceChanged(element->listener, event);
--
++                
                  serviceRegistry_ungetServiceReference(framework->registry, 
element->bundle, reference);
--
++                
                  if (eventType == OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING) {
                      //if service listener was active when service was 
registered, release the retained reference
                      if (arrayList_removeElement(element->retainedReferences, 
reference)) {
                          
serviceRegistry_ungetServiceReference(framework->registry, element->bundle, 
reference); // decrease retain counter
                      }
                  }
--
++                
                  free(event);
--
++                
              } else if (eventType == OSGI_FRAMEWORK_SERVICE_EVENT_MODIFIED) {
                  bool matchResult = false;
                  int matched = 0;
@@@ -1798,22 -1795,22 +1795,22 @@@
                  if (matched) {
                      service_reference_pt reference = NULL;
                      service_event_pt endmatch = (service_event_pt) 
malloc(sizeof (*endmatch));
--
++                    
                      serviceRegistry_getServiceReference(framework->registry, 
element->bundle, registration, &reference);
--
++                    
                      endmatch->reference = reference;
                      endmatch->type = 
OSGI_FRAMEWORK_SERVICE_EVENT_MODIFIED_ENDMATCH;
                      element->listener->serviceChanged(element->listener, 
endmatch);
--
++                    
                      
serviceRegistry_ungetServiceReference(framework->registry, element->bundle, 
reference);
                      free(endmatch);
--
++                    
                  }
              }
          }
      }
      celixThreadMutex_unlock(&framework->serviceListenersLock);
--
++    
  }
  
  //celix_status_t fw_isServiceAssignable(framework_pt fw, bundle_pt requester, 
service_reference_pt reference, bool *assignable) {
@@@ -1833,110 -1830,110 +1830,110 @@@
  //}
  
  long framework_getNextBundleId(framework_pt framework) {
--      long id = framework->nextBundleId;
--      framework->nextBundleId++;
--      return id;
++    long id = framework->nextBundleId;
++    framework->nextBundleId++;
++    return id;
  }
  
  celix_status_t framework_markResolvedModules(framework_pt framework, 
linked_list_pt resolvedModuleWireMap) {
--      if (resolvedModuleWireMap != NULL) {
--              // hash_map_iterator_pt iterator = 
hashMapIterator_create(resolvedModuleWireMap);
--              linked_list_iterator_pt iterator = 
linkedListIterator_create(resolvedModuleWireMap, 
linkedList_size(resolvedModuleWireMap));
--              while (linkedListIterator_hasPrevious(iterator)) {
--                  importer_wires_pt iw = 
linkedListIterator_previous(iterator);
--                      // hash_map_entry_pt entry = 
hashMapIterator_nextEntry(iterator);
--                      module_pt module = iw->importer;
--
--//                    bundle_pt bundle = module_getBundle(module);
--//                    bundle_archive_pt archive = NULL;
--//                    bundle_getArchive(bundle, &archive);
--//                    bundle_revision_pt revision = NULL;
--//                    bundleArchive_getCurrentRevision(archive, &revision);
--//                    char *root = NULL;
--//                    bundleRevision_getRoot(revision, &root);
--//                    manifest_pt manifest = NULL;
--//                    bundleRevision_getManifest(revision, &manifest);
--//
--//                    char *private = manifest_getValue(manifest, 
OSGI_FRAMEWORK_PRIVATE_LIBRARY);
--//                    char *export = manifest_getValue(manifest, 
OSGI_FRAMEWORK_EXPORT_LIBRARY);
--//
--//                    printf("Root %s\n", root);
--
--                      // for each library update the reference to the wires, 
if there are any
--
--                      linked_list_pt wires = iw->wires;
--
--//                    linked_list_iterator_pt wit = 
linkedListIterator_create(wires, 0);
--//                    while (linkedListIterator_hasNext(wit)) {
--//                        wire_pt wire = linkedListIterator_next(wit);
--//                        module_pt importer = NULL;
--//                        requirement_pt requirement = NULL;
--//                        module_pt exporter = NULL;
--//                capability_pt capability = NULL;
--//                        wire_getImporter(wire, &importer);
--//                        wire_getRequirement(wire, &requirement);
--//
--//                        wire_getExporter(wire, &exporter);
--//                        wire_getCapability(wire, &capability);
--//
--//                        char *importerName = NULL;
--//                        module_getSymbolicName(importer, &importerName);
--//
--//                        char *exporterName = NULL;
--//                module_getSymbolicName(exporter, &exporterName);
--//
--//                version_pt version = NULL;
--//                char *name = NULL;
--//                capability_getServiceName(capability, &name);
--//                capability_getVersion(capability, &version);
--//                char *versionString = NULL;
--//                version_toString(version, framework->mp, &versionString);
--//
--//                printf("Module %s imports library %s:%s from %s\n", 
importerName, name, versionString, exporterName);
--//                    }
--
--                      module_setWires(module, wires);
--
--                      module_setResolved(module);
--                      resolver_moduleResolved(module);
--
--                      const char *mname = NULL;
--                      module_getSymbolicName(module, &mname);
--                      framework_markBundleResolved(framework, module);
--                      linkedListIterator_remove(iterator);
--                      free(iw);
--              }
--              linkedListIterator_destroy(iterator);
--              linkedList_destroy(resolvedModuleWireMap);
--      }
--      return CELIX_SUCCESS;
++    if (resolvedModuleWireMap != NULL) {
++        // hash_map_iterator_pt iterator = 
hashMapIterator_create(resolvedModuleWireMap);
++        linked_lis

<TRUNCATED>
http://git-wip-us.apache.org/repos/asf/celix/blob/8464f3d5/framework/src/framework_private.h
----------------------------------------------------------------------

Reply via email to