Re: [ros-users] Draft REP: Automatic unloading of libraries …

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: User discussions
Date:  
To: User discussions
Subject: Re: [ros-users] Draft REP: Automatic unloading of libraries for pluginlib
> While I like boost::shared_ptr, it is not always possible to use it nicely.
>
> In rviz I have plugin classes which are subclasses of QWidget (from Qt GUI library). These objects are automatically deleted by Qt when their parent widgets are deleted. I can be notified of their
> deletion by Qt, and call an "unload" or "decrement-reference-count" function, but it is not easy to use these QWidget pointers inside boost::shared_ptr without getting double-deletion crashes.


That sounds like a very reasonable use case.
Automatically deleting and unloading is a nice feature but might not always be desired.
Having the option to get a raw pointer (as before) and take care of garbaging stuff manually would be great.

> pluginlib::ClassLoader could have two interfaces, one which gives a shared_ptr and manages the reference count for the library itself, and another which gives a raw pointer and increments the ref
> count and also has a decrement-ref-count function.


Since both methods have the same right-hand signature (passing the lookup name) we need two different names.
I propose the following names to make clear what the difference is (of course with a more detailed doc-string):

boost::shared_ptr<T> getManagedInstance(const std::string& lookup_name)

T* getInstance(const std::string& lookup_name)

In the first case the user does not need to take care about anything - just let the shared pointer run out of scope.
In the second case he is responsible for a) deleting the instance and b) calling unloadLibraryForClass() manually.

I have updated the REP and reference implementation accordingly.

Dirk