library/src/dynamic_modules/BP-DynamicModules.cc
// Attempt to unload the dynamic module from the GHT
Attempt to unload the dynamic module from the GHT
Attempt to unload the dynamic module from the GHT
BP_ERROR_T BP_DynamicModuleUnloadFromGHTByName(char *module_name)
{
	if(!module_name)
		return ERR_FAILURE;
	if(!BP_HashRegPathArrayIndexFilterTest(module_name, bpstrlen(module_name)))
		return ERR_FAILURE;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry);
	char *module_lookup_path[] =
	{
			"system",
			"dynamic_modules",
			module_name,
			NULL
	};
	P_BP_HTKE module_table = BP_HashRegLookupTableByPath((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, (char **) &module_lookup_path);
	if(!module_table)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, ERR_FAILURE);
	P_BP_HTKE so_module_name                 = NULL;
	P_BP_HTKE so_module_handle               = NULL;
	P_BP_HTKE so_module_config_json          = NULL;
	P_BP_HTKE so_module_load_path            = NULL;
	P_BP_HTKE so_module_filesystem_sha1_hash = NULL;
	so_module_name                 = BP_HashRegLookupEntryFromHashKeyViaRelativePosition((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, module_table, "so_module_name");
	so_module_handle               = BP_HashRegLookupEntryFromHashKeyViaRelativePosition((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, module_table, "so_module_handle");
	so_module_config_json          = BP_HashRegLookupEntryFromHashKeyViaRelativePosition((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, module_table, "so_module_config_json");
	so_module_load_path            = BP_HashRegLookupEntryFromHashKeyViaRelativePosition((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, module_table, "so_module_load_path");
	so_module_filesystem_sha1_hash = BP_HashRegLookupEntryFromHashKeyViaRelativePosition((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, module_table, "so_module_filesystem_sha1_hash");
	void *so_handle_actual = NULL;
	if(so_module_handle)
	{
		if(so_module_handle->data)
		{
			memcpy(&so_handle_actual, so_module_handle->data, sizeof(so_handle_actual));
		}
	}
	if(so_handle_actual)
	{
		dlclose(so_handle_actual);
	}
	BP_HashRegDestroyEntry
	(
			(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
			so_module_name
	);
	BP_HashRegDestroyEntry
	(
			(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
			so_module_handle
	);
	BP_HashRegDestroyEntry
	(
			(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
			so_module_config_json
	);
	BP_HashRegDestroyEntry
	(
			(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
			so_module_load_path
	);
	BP_HashRegDestroyEntry
	(
			(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
			so_module_filesystem_sha1_hash
	);
	BP_HashRegDestroyTable
	(
		(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
		module_table
	);
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, ERR_SUCCESS);
}
BP_ERROR_T BP_DynamicModuleUnloadFromGHTByName ( char * module_name ) { if ( ! module_name ) return ERR_FAILURE ; if ( ! BP_HashRegPathArrayIndexFilterTest ( module_name , bpstrlen ( module_name ) ) ) return ERR_FAILURE ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry ) ; char * module_lookup_path [ ] = { " " , " " , module_name , NULL } ; P_BP_HTKE module_table = BP_HashRegLookupTableByPath ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ( char * * ) & module_lookup_path ) ; if ( ! module_table ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ERR_FAILURE ) ; P_BP_HTKE so_module_name = NULL ; P_BP_HTKE so_module_handle = NULL ; P_BP_HTKE so_module_config_json = NULL ; P_BP_HTKE so_module_load_path = NULL ; P_BP_HTKE so_module_filesystem_sha1_hash = NULL ; so_module_name = BP_HashRegLookupEntryFromHashKeyViaRelativePosition ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , module_table , " " ) ; so_module_handle = BP_HashRegLookupEntryFromHashKeyViaRelativePosition ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , module_table , " " ) ; so_module_config_json = BP_HashRegLookupEntryFromHashKeyViaRelativePosition ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , module_table , " " ) ; so_module_load_path = BP_HashRegLookupEntryFromHashKeyViaRelativePosition ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , module_table , " " ) ; so_module_filesystem_sha1_hash = BP_HashRegLookupEntryFromHashKeyViaRelativePosition ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , module_table , " " ) ; void * so_handle_actual = NULL ; if ( so_module_handle ) { if ( so_module_handle -> data ) { memcpy ( & so_handle_actual , so_module_handle -> data , sizeof ( so_handle_actual ) ) ; } } if ( so_handle_actual ) { dlclose ( so_handle_actual ) ; } BP_HashRegDestroyEntry ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , so_module_name ) ; BP_HashRegDestroyEntry ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , so_module_handle ) ; BP_HashRegDestroyEntry ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , so_module_config_json ) ; BP_HashRegDestroyEntry ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , so_module_load_path ) ; BP_HashRegDestroyEntry ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , so_module_filesystem_sha1_hash ) ; BP_HashRegDestroyTable ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , module_table ) ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ERR_SUCCESS ) ; }
Attempt to unload the dynamic module from the GHT
Attempt to unload the dynamic module from the GHT
// basic null check // filter test check // -- enter critical section after module passes basic checks ---- // enter critical section // set the module lookup path // look for module table // declare keyed entries // lookup entry data // ---- Attempt to Close Handle to Library ------------- // IMPORTANT NOTE: This does not call the library destructor as the library itself //                 does not unload from the process here.  It's a quirk of development //                 that dlclose() doesn't actually unload anything. // attempt to reference handle // close handle after refrence // -- destroy individual entries ---------------- // --- destroy table itself ----- // return indicating that we've successfully loaded our module