[omniORB] Boost shared_ptr

Michael omniorb at bindone.de
Fri Nov 14 15:45:47 GMT 2008


Client side:
There is very little reason to do this, don't try to use
boost::shared_ptr<User_ptr>, it won't really work and cause headaches.
You could of course use boost::shared_ptr<User_var>, but this is not
smart either.
If anybody knows a reasonable way of doing this I would like to be
enlightened as well :)

Server side:
Depending of the type of POA you're using it can make sense to have
shared_ptrs here. I use the following template:

template<class T>
class CorbaDeleter
{
  PortableServer::POA_var _poa;

public:
  CorbaDeleter(PortableServer::POA_ptr poa):
           _poa(PortableServer::POA::_duplicate(poa))
  {}

  void operator()(T* p)
  {
    try
    {
      if (!_poa->_non_existent())
      {
        PortableServer::ObjectId_var oid = _poa->servant_to_id(p);
        _poa->deactivate_object(oid);
      }
    }
    catch(...)
    {
      std::cerr << "Exception while deactivating object (maybe not
activated in the first place)" << std::endl;
    }
    p->_remove_ref();
  }
};

I use this for hierarchical objects where I also need to keep a list of
child objects in a parent object. This way all children will get
destroyed correctly if the parent goes away.

Usage looks like:
typedef boost::shared_ptr<User_impl> UserRef;
typedef std::vector<UserRef> UserList;

UserRef user(new User_impl(...), CorbaDeleter<User_impl>(myPoa));
PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(...);
myPoa->activate_object_with_id(oid, user.get());

UserList ul;
ul.push_back(user);





Vázquez Landa wrote:
> Hi, 
> 
> I guess many of you are using shared_ptr's in your codes... So I wanted to ask how does it work with CORBA...
> 
> Say I have an interface:
> 
> Interface User
> {
> 	void setName(in string name);
> 	string getName();
> };
> 
> Normally, I would use CORBA's User_var in my code to perform operations... Now my obvious question is if I can use a shared pointer for that purpose... 
> 
> Thanks :)
> 
> _______________________________________________
> omniORB-list mailing list
> omniORB-list at omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list




More information about the omniORB-list mailing list