mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-04-02 02:05:55 +02:00
Collection loading and deletion support (in a thread).
This commit is contained in:
@@ -146,22 +146,25 @@ bool CollectionInfoBuilder::createCollectionDirectory(std::string name)
|
||||
|
||||
struct CIBCallbackInfo {
|
||||
std::string collectionName;
|
||||
void (*callback)(void *);
|
||||
void (*callback)(void *, CollectionInfo *);
|
||||
void *context;
|
||||
CollectionInfoBuilder *cib;
|
||||
};
|
||||
|
||||
int CollectionInfoBuilder::buildCollectionThread(void *context)
|
||||
{
|
||||
CIBCallbackInfo *info = (CIBCallbackInfo *)context;
|
||||
info->cib->buildCollection(info->collectionName);
|
||||
info->callback(info->context);
|
||||
delete info;
|
||||
CIBCallbackInfo *cbinfo = (CIBCallbackInfo *)context;
|
||||
|
||||
CollectionInfo *ci = cbinfo->cib->buildCollection(cbinfo->collectionName);
|
||||
|
||||
cbinfo->callback(cbinfo->context, ci);
|
||||
|
||||
delete cbinfo;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void CollectionInfoBuilder::buildCollection(std::string collectionName, void (*callback)(void *), void *context)
|
||||
void CollectionInfoBuilder::buildCollection(std::string collectionName, void (*callback)(void *, CollectionInfo *), void *context)
|
||||
{
|
||||
CIBCallbackInfo *data = new CIBCallbackInfo();
|
||||
data->collectionName = collectionName;
|
||||
@@ -219,9 +222,21 @@ CollectionInfo *CollectionInfoBuilder::buildCollection(std::string name, std::st
|
||||
|
||||
ImportDirectory(collection, mergedCollectionName);
|
||||
|
||||
//todo: add a critical section
|
||||
allocationMap_[collection] = collection;
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
void CollectionInfoBuilder::destroyCollection(CollectionInfo *collection) {
|
||||
std::map<CollectionInfo *, CollectionInfo *>::iterator it = allocationMap_.find(collection);
|
||||
|
||||
if(it != allocationMap_.end()) {
|
||||
delete it->second;
|
||||
allocationMap_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CollectionInfoBuilder::ImportBasicList(CollectionInfo *info, std::string file, std::map<std::string, Item *> &list)
|
||||
{
|
||||
|
||||
@@ -29,10 +29,11 @@ class CollectionInfoBuilder
|
||||
public:
|
||||
CollectionInfoBuilder(Configuration &c, MetadataDatabase &mdb);
|
||||
virtual ~CollectionInfoBuilder();
|
||||
void buildCollection(std::string collectionName, void (*callback)(void *), void *context);
|
||||
void buildCollection(std::string collectionName, void (*callback)(void *, CollectionInfo *), void *context);
|
||||
CollectionInfo *buildCollection(std::string collectionName);
|
||||
CollectionInfo *buildCollection(std::string collectionName, std::string mergedCollectionName);
|
||||
static bool createCollectionDirectory(std::string collectionName);
|
||||
void destroyCollection(CollectionInfo *info);
|
||||
|
||||
private:
|
||||
static int buildCollectionThread(void *context);
|
||||
@@ -40,4 +41,5 @@ private:
|
||||
MetadataDatabase &metaDB_;
|
||||
bool ImportBasicList(CollectionInfo *info, std::string file, std::map<std::string, Item *> &list);
|
||||
bool ImportDirectory(CollectionInfo *info, std::string mergedCollectionName);
|
||||
std::map<CollectionInfo *, CollectionInfo *> allocationMap_;
|
||||
};
|
||||
|
||||
@@ -16,14 +16,24 @@ void LuaCollection::initialize(Configuration *c, CollectionInfoBuilder *b, LuaE
|
||||
int LuaCollection::load(lua_State *l)
|
||||
{
|
||||
std::string collection = luaL_checkstring(l, 1);
|
||||
|
||||
cib->buildCollection(collection, loadCallback, (void *)l);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LuaCollection::loadCallback(void *context)
|
||||
int LuaCollection::destroy(lua_State *l)
|
||||
{
|
||||
CollectionInfo *i = (CollectionInfo *)luaL_checkinteger(l, 1);
|
||||
cib->destroyCollection(i);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void LuaCollection::loadCallback(void *context, CollectionInfo *info)
|
||||
{
|
||||
lua_State *l = (lua_State *)context;
|
||||
events->trigger(l, "onCollectionLoaded");
|
||||
events->trigger(l, "onCollectionLoaded", (void *)info);
|
||||
|
||||
}
|
||||
|
||||
@@ -9,5 +9,7 @@ namespace LuaCollection
|
||||
{
|
||||
void initialize(Configuration *c, CollectionInfoBuilder *b, LuaEvent *e);
|
||||
int load(lua_State *l);
|
||||
void loadCallback(void *context);
|
||||
int destroy(lua_State *l);
|
||||
|
||||
void loadCallback(void *context, CollectionInfo *info);
|
||||
};
|
||||
@@ -7,6 +7,16 @@ void LuaEvent::trigger(lua_State *l, std::string type)
|
||||
lua_pcall(l, 0, 0, 0);
|
||||
}
|
||||
|
||||
void LuaEvent::trigger(lua_State *l, std::string type, void *value)
|
||||
{
|
||||
lua_getglobal(l, type.c_str());
|
||||
lua_pushinteger(l, (int)value);
|
||||
|
||||
lua_pcall(l, 1, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool LuaEvent::isBusy(lua_State *l, std::string type)
|
||||
{
|
||||
bool retval = true;
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
class LuaEvent {
|
||||
public:
|
||||
void trigger(lua_State *l, std::string type);
|
||||
void trigger(lua_State *l, std::string type, void *value);
|
||||
bool isBusy(lua_State *l, std::string type);
|
||||
};
|
||||
@@ -82,6 +82,7 @@ const luaL_Reg RetroFE::luaImageFuncs[] = {
|
||||
|
||||
const luaL_Reg RetroFE::luaCollectionFuncs[] = {
|
||||
{"load", LuaCollection::load},
|
||||
{"destroy", LuaCollection::destroy},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user