-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to create new instances of loaded libraries #8
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,8 @@ namespace lib_manager { | |
string name = _lib->getLibName(); | ||
|
||
newLib.destroy = 0; | ||
newLib.create = 0; | ||
newLib.configCreate = 0; | ||
newLib.libInterface = _lib; | ||
newLib.useCount = 1; | ||
newLib.wasUnloaded = false; | ||
|
@@ -165,6 +167,8 @@ namespace lib_manager { | |
|
||
libStruct newLib; | ||
newLib.destroy = 0; | ||
newLib.create = 0; | ||
newLib.configCreate = 0; | ||
newLib.libInterface = 0; | ||
newLib.useCount = 0; | ||
newLib.wasUnloaded = false; | ||
|
@@ -177,12 +181,16 @@ namespace lib_manager { | |
if(newLib.destroy) { | ||
if(!config) { | ||
createLib *tmp_con = getFunc<createLib*>(pl, "create_c"); | ||
if(tmp_con) | ||
if(tmp_con) { | ||
newLib.create = tmp_con; | ||
newLib.libInterface = tmp_con(this); | ||
} | ||
} else { | ||
createLib2 *tmp_con2 = getFunc<createLib2*>(pl, "config_create_c"); | ||
if(tmp_con2) | ||
if(tmp_con2){ | ||
newLib.configCreate = tmp_con2; | ||
newLib.libInterface = tmp_con2(this, config); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -303,6 +311,19 @@ namespace lib_manager { | |
return theLib->libInterface; | ||
} | ||
|
||
LibInterface* LibManager::getNewInstance(const string &libName) { | ||
if(libMap.find(libName) == libMap.end()) { | ||
#ifdef DEBUF | ||
fprintf(stderr, "LibManager: could not find \"%s\"\n", libName.c_str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use std::cerr here. We are in C++ not in C. |
||
#endif | ||
return 0; | ||
} | ||
libStruct *theLib = &(libMap[libName]); | ||
// todo: clear how to deal with the use count in this case | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you would use shared pointers, you would not need to reference count yourself. |
||
//theLib->useCount++; | ||
return theLib->create(this); | ||
} | ||
|
||
/** | ||
* Releases a previously acquired library | ||
* @param libName | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ namespace lib_manager { | |
struct libStruct { | ||
LibInterface *libInterface; | ||
destroyLib *destroy; | ||
createLib *create; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend using safer/smart pointers instead of raw ones. |
||
createLib2 *configCreate; | ||
int useCount; | ||
bool wasUnloaded; | ||
std::string path; | ||
|
@@ -92,6 +94,7 @@ namespace lib_manager { | |
bool load = false) | ||
{ return acquireLibraryAs<T>(libName, load); } | ||
|
||
LibInterface* getNewInstance(const std::string &libName); | ||
ErrorNumber releaseLibrary(const std::string &libName); | ||
|
||
ErrorNumber unloadLibrary(const std::string &libPath); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using 0 here, it would be better to use one of the following: