Task #3349
closedChange the ownership model of Pib and its related entities
Description
Current Pib Implementation simply creates an instance whenever returning an identity (similarly, an identity creates an instance when returning a key). As a result, multiple instances may corresponds the same identity or key. Changing the status of one instance may not affect the other instances.
A desired solution could be to create only one instance for an identity (or key) and give the shared pointer (const) to others, const reference could be another option, but it may have some problem in initialization.
Therefore, we plan to change the ownership as, each identity is maintained in the PIB's IdentityContainer, which provides shared pointer to the identity instance as handle for others. Similar for key and KeyContainer.
Updated by Junxiao Shi almost 9 years ago
each identity is maintained in the PIB's IdentityContainer, which provides shared pointer to the identity instance as handle for others
It's unnecessary to expose shared_ptr
in public API.
Instead:
class Identity // copyable
{
public:
explicit operator bool() const; ///< valid (not deleted)
bool operator!() const; ///< deleted
const Name& getName() const; ///< identity name
// (other getters)
private:
weak_ptr<detail::IdentityImpl> m_impl;
};
namespace detail {
class IdentityImpl;
} // namespace detail
class IdentityContainer : noncopyable
{
public:
Identity getIdentity(..) const;
private:
std::container<shared_ptr<detail::IdentityImpl>> m_container;
};
Updated by Yingdi Yu almost 9 years ago
I think you are right, weak_pointer is a better approach. actually shared_ptr does not address the issue completely. I will use weak_ptr in implementation.
Updated by Yingdi Yu over 8 years ago
- Status changed from Code review to Closed
- % Done changed from 0 to 100