celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1658959 - in /celix/trunk: examples/CMakeLists.txt framework/private/src/bundle.c framework/private/src/framework.c framework/private/src/resolver.c utils/private/src/hash_map.c
Date Wed, 11 Feb 2015 13:48:10 GMT
Author: abroekhuis
Date: Wed Feb 11 13:48:09 2015
New Revision: 1658959

URL: http://svn.apache.org/r1658959
Log:
CELIX-219: Update framework shutdown to clean up bundles that are still installed.

During shutdown of the framework, the shutdown thread has to close stopped bundles as well,
this triggers the resolved to remove the module from the active list.
During destruction of the framework all bundles in the bundle list have to be cleaned up.
This now includes closing the libraries opened during installation.
When modules are removed from the resolver, and the list is empty, the lists are now destroyed.

Fixed a missing dependency when building the examples
Added NULL initialiser to the hash_map.

Modified:
    celix/trunk/examples/CMakeLists.txt
    celix/trunk/framework/private/src/bundle.c
    celix/trunk/framework/private/src/framework.c
    celix/trunk/framework/private/src/resolver.c
    celix/trunk/utils/private/src/hash_map.c

Modified: celix/trunk/examples/CMakeLists.txt
URL: http://svn.apache.org/viewvc/celix/trunk/examples/CMakeLists.txt?rev=1658959&r1=1658958&r2=1658959&view=diff
==============================================================================
--- celix/trunk/examples/CMakeLists.txt (original)
+++ celix/trunk/examples/CMakeLists.txt Wed Feb 11 13:48:09 2015
@@ -14,7 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-celix_subproject(EXAMPLES "Option to enable building the Examples" "OFF" DEPS FRAMEWORK LAUNCHER
SHELL_TUI)
+celix_subproject(EXAMPLES "Option to enable building the Examples" "OFF" DEPS FRAMEWORK LAUNCHER
SHELL_TUI LOG_WRITER)
 if (EXAMPLES)
     add_subdirectory(hello_world)
     add_subdirectory(hello_world_test)

Modified: celix/trunk/framework/private/src/bundle.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/bundle.c?rev=1658959&r1=1658958&r2=1658959&view=diff
==============================================================================
--- celix/trunk/framework/private/src/bundle.c (original)
+++ celix/trunk/framework/private/src/bundle.c Wed Feb 11 13:48:09 2015
@@ -65,7 +65,6 @@ celix_status_t bundle_create(bundle_pt *
 
         module = module_createFrameworkModule((*bundle));
         bundle_addModule(*bundle, module);
-        // (*bundle)->module = module;
 
         status = celixThreadMutex_create(&(*bundle)->lock, NULL);
         if (status != CELIX_SUCCESS) {
@@ -73,8 +72,6 @@ celix_status_t bundle_create(bundle_pt *
         } else {
 			(*bundle)->lockCount = 0;
 			(*bundle)->lockThread = celix_thread_default;
-
-			resolver_addModule(module);
         }
 	}
 
@@ -109,8 +106,6 @@ celix_status_t bundle_createFromArchive(
 		} else {
 			(*bundle)->lockCount = 0;
 			(*bundle)->lockThread = celix_thread_default;
-
-			resolver_addModule(module);
 		}
 	} else {
 	    status = CELIX_FILE_IO_EXCEPTION;

Modified: celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/framework.c?rev=1658959&r1=1658958&r2=1658959&view=diff
==============================================================================
--- celix/trunk/framework/private/src/framework.c (original)
+++ celix/trunk/framework/private/src/framework.c Wed Feb 11 13:48:09 2015
@@ -160,6 +160,30 @@ typedef struct request *request_pt;
 
 framework_logger_pt logger;
 
+#ifdef _WIN32
+    #define handle_t HMODULE
+    #define fw_getSystemLibrary() fw_getCurrentModule()
+    #define fw_openLibrary(path) LoadLibrary(path)
+    #define fw_closeLibrary(handle) FreeLibrary(handle)
+
+    #define fw_getSymbol(handle, name) GetProcAddress(handle, name)
+
+    #define fw_getLastError() GetLastError()
+
+    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 *
+    #define fw_getSystemLibrary() dlopen(NULL, RTLD_LAZY|RTLD_LOCAL)
+    #define fw_openLibrary(path) dlopen(path, RTLD_LAZY|RTLD_LOCAL)
+    #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, apr_pool_t *pool, properties_pt
config) {
     celix_status_t status = CELIX_SUCCESS;
 
@@ -227,6 +251,7 @@ celix_status_t framework_destroy(framewo
 	while (hashMapIterator_hasNext(iterator)) {
 	    hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
 		bundle_pt bundle = (bundle_pt) hashMapEntry_getValue(entry);
+		char * key = hashMapEntry_getKey(entry);
 		bundle_archive_pt archive = NULL;
 
 		bool systemBundle = false;
@@ -238,9 +263,22 @@ celix_status_t framework_destroy(framewo
 		}
 
 		if (bundle_getArchive(bundle, &archive) == CELIX_SUCCESS) {
+			if (!systemBundle) {
+				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));
+				for (int i = arrayList_size(handles) - 1; i >= 0; i--) {
+					void *handle = arrayList_get(handles, i);
+					fw_closeLibrary(handle);
+				}
+			}
+
 			bundleArchive_destroy(archive);
 		}
 		bundle_destroy(bundle);
+		hashMapIterator_remove(iterator);
+		free(key);
 	}
 	hashMapIterator_destroy(iterator);
 	}
@@ -294,30 +332,6 @@ celix_status_t framework_destroy(framewo
 	return status;
 }
 
-#ifdef _WIN32
-    #define handle_t HMODULE
-    #define fw_getSystemLibrary() fw_getCurrentModule()
-    #define fw_openLibrary(path) LoadLibrary(path)
-    #define fw_closeLibrary(handle) FreeLibrary(handle)
-
-    #define fw_getSymbol(handle, name) GetProcAddress(handle, name)
-
-    #define fw_getLastError() GetLastError()
-
-    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 *
-    #define fw_getSystemLibrary() dlopen(NULL, RTLD_LAZY|RTLD_LOCAL)
-    #define fw_openLibrary(path) dlopen(path, RTLD_LAZY|RTLD_LOCAL)
-    #define fw_closeLibrary(handle) dlclose(handle)
-    #define fw_getSymbol(handle, name) dlsym(handle, name)
-    #define fw_getLastError() dlerror()
-#endif
-
 celix_status_t fw_init(framework_pt framework) {
 	bundle_state_e state;
 	char *location;
@@ -2019,9 +2033,15 @@ static void *framework_shutdown(void *fr
             iter = hashMapIterator_create(fw->installedBundleMap);
         }
 	}
-
     hashMapIterator_destroy(iter);
 
+    iter = hashMapIterator_create(fw->installedBundleMap);
+	bundle = NULL;
+	while ((bundle = hashMapIterator_nextValue(iter)) != NULL) {
+		bundle_close(bundle);
+	}
+	hashMapIterator_destroy(iter);
+
     pthread_cancel(fw->dispatcherThread.thread);
     celixThread_join(fw->dispatcherThread, NULL);
 

Modified: celix/trunk/framework/private/src/resolver.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/resolver.c?rev=1658959&r1=1658958&r2=1658959&view=diff
==============================================================================
--- celix/trunk/framework/private/src/resolver.c (original)
+++ celix/trunk/framework/private/src/resolver.c Wed Feb 11 13:48:09 2015
@@ -296,6 +296,14 @@ void resolver_removeModule(module_pt mod
             }
         }
     }
+    if (linkedList_isEmpty(m_modules)) {
+    	linkedList_destroy(m_modules);
+    	m_modules = NULL;
+    	linkedList_destroy(m_unresolvedServices);
+    	m_unresolvedServices = NULL;
+    	linkedList_destroy(m_resolvedServices);
+    	m_resolvedServices = NULL;
+    }
 }
 
 void resolver_moduleResolved(module_pt module) {

Modified: celix/trunk/utils/private/src/hash_map.c
URL: http://svn.apache.org/viewvc/celix/trunk/utils/private/src/hash_map.c?rev=1658959&r1=1658958&r2=1658959&view=diff
==============================================================================
--- celix/trunk/utils/private/src/hash_map.c (original)
+++ celix/trunk/utils/private/src/hash_map.c Wed Feb 11 13:48:09 2015
@@ -153,7 +153,7 @@ hash_map_entry_pt hashMap_getEntry(hash_
 void * hashMap_put(hash_map_pt map, void * key, void * value) {
 	unsigned int hash;
 	int i;
-	hash_map_entry_pt entry;
+	hash_map_entry_pt entry = NULL;
 	if (key == NULL) {
 		hash_map_entry_pt entry;
 		for (entry = map->table[0]; entry != NULL; entry = entry->next) {



Mime
View raw message