library/src/dynamic_modules/BP-DynamicModules.cc
// Attempt to add a module into the "/dynamic_modules" section of the GHT.  Will return false
// if the module is already loaded or load cannot
Attempt to add a module into the "/dynamic_modules" section of the GHT.  Will return false
if the module is already loaded or load cannot
Attempt to add a module into the " / dynamic_modules " section of the GHT . Will return false if the module is already loaded or load cannot
BP_ERROR_T BP_DynamicModuleLoadIntoGHT(P_BP_DYNAMIC_MODULE module)
{
	if(!global_hash_table_init_ok)
		return ERR_FAILURE;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry);
	P_BP_HTKE modules_table = BP_HashRegLookupTableByPathQuery((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, "/system/dynamic_modules");
	if(!modules_table)
	{
		if(!BP_HashRegAddTableByPathQuery((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, "/system/dynamic_modules"))
		{
			BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, ERR_FAILURE);
		}
	}
	modules_table = BP_HashRegLookupTableByPathQuery((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, "/system/dynamic_modules");
	if(!modules_table)
	{
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, ERR_FAILURE);
	}
	if(BP_DynamicModuleIsAlreadyLoadedInGHT(module))
	{
		module->already_loaded = BP_TRUE;
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, ERR_FAILURE);
	}
	char * new_mod_table_entry[] =
	{
		"system",
		"dynamic_modules",
		module->so_module_name,
		NULL
	};
	if(!BP_HashRegAddTableByPath((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, (char **) &new_mod_table_entry))
	{
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC((P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry, ERR_FAILURE);
	}
	BP_HashRegAddDataToTableByPath
	(
			(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
			(char **) &new_mod_table_entry,
			"so_module_name",
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING,
			module->so_module_name,
			bpstrlen(module->so_module_name)
	);
	BP_HashRegAddDataToTableByPath
	(
			(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
			(char **) &new_mod_table_entry,
			"so_module_handle",
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
			&module->so_handle,
			sizeof(module->so_handle)
	);
	BP_HashRegAddDataToTableByPath
	(
			(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
			(char **) &new_mod_table_entry,
			"so_module_config_json",
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING,
			module->so_module_config_json,
			bpstrlen(module->so_module_config_json)
	);
	BP_HashRegAddDataToTableByPath
	(
			(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
			(char **) &new_mod_table_entry,
			"so_module_load_path",
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING,
			module->so_module_load_path,
			bpstrlen(module->so_module_load_path)
	);
	BP_HashRegAddDataToTableByPath
	(
			(P_BP_HASH_TABLE_REGISTRY) &global_hash_table_registry,
			(char **) &new_mod_table_entry,
			"so_module_filesystem_sha1_hash",
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING,
			module->so_module_filesystem_sha1_hash,
			bpstrlen(module->so_module_filesystem_sha1_hash)
	);
	module->loaded_ok = BP_TRUE;
	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_DynamicModuleLoadIntoGHT ( P_BP_DYNAMIC_MODULE module ) { if ( ! global_hash_table_init_ok ) return ERR_FAILURE ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry ) ; P_BP_HTKE modules_table = BP_HashRegLookupTableByPathQuery ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , " " ) ; if ( ! modules_table ) { if ( ! BP_HashRegAddTableByPathQuery ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , " " ) ) { BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ERR_FAILURE ) ; } } modules_table = BP_HashRegLookupTableByPathQuery ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , " " ) ; if ( ! modules_table ) { BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ERR_FAILURE ) ; } if ( BP_DynamicModuleIsAlreadyLoadedInGHT ( module ) ) { module -> already_loaded = BP_TRUE ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ERR_FAILURE ) ; } char * new_mod_table_entry [ ] = { " " , " " , module -> so_module_name , NULL } ; if ( ! BP_HashRegAddTableByPath ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ( char * * ) & new_mod_table_entry ) ) { BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ERR_FAILURE ) ; } BP_HashRegAddDataToTableByPath ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ( char * * ) & new_mod_table_entry , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING , module -> so_module_name , bpstrlen ( module -> so_module_name ) ) ; BP_HashRegAddDataToTableByPath ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ( char * * ) & new_mod_table_entry , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , & module -> so_handle , sizeof ( module -> so_handle ) ) ; BP_HashRegAddDataToTableByPath ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ( char * * ) & new_mod_table_entry , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING , module -> so_module_config_json , bpstrlen ( module -> so_module_config_json ) ) ; BP_HashRegAddDataToTableByPath ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ( char * * ) & new_mod_table_entry , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING , module -> so_module_load_path , bpstrlen ( module -> so_module_load_path ) ) ; BP_HashRegAddDataToTableByPath ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ( char * * ) & new_mod_table_entry , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING , module -> so_module_filesystem_sha1_hash , bpstrlen ( module -> so_module_filesystem_sha1_hash ) ) ; module -> loaded_ok = BP_TRUE ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ( P_BP_HASH_TABLE_REGISTRY ) & global_hash_table_registry , ERR_SUCCESS ) ; }
Attempt to add a module into the "/dynamic_modules" section of the GHT.
Attempt to add a module into the " / dynamic_modules " section of the GHT .
// global hash init must be ok // enter critical section // attempt to lookup /system/dynamic_modules table within the GHT // if there is no modules table, attempt to create it // attempt to add table // check to see if the modules table was created ok // -- Check to see if module is already loaded ----------------- // attempt to check and see if the module is already loaded // set the inout flag to indicate that the module appears to already be loaded // -- Module is Not Loaded, Attempt Loading // set path for new entry // exit if we can't add our new entry // -- add individual entries --------------- // add module name // add module handle // add module initial configuration JSON // add module load path // add module sha1 hash to registry // --- mark module and exit routine after addition ------------ // mark the module as having loaded ok // return indicating that we've successfully loaded our module