AW: [omniORB] Boost shared_ptr

Michael omniorb at bindone.de
Fri Nov 14 16:24:53 GMT 2008


That's possible, even so I'm not certain if shared_ptr is the best
wrapper for this. In this case you should create a shared_ptr. If you
not certain how to do it exactly I might check on this later (tell me if
you're lost).

Another question of course is if you really need a destroy method. Are
you dealing with persistent objects (e.g. database backed) or are those
objects volatile? If they're persistent you might consider either using
a default servant or a servant locator (+eviction cache) on the server
side. This is much easier from a client perspective and ensures your
server is not leaking resources.

Vázquez Landa wrote:
> Thanks for the answer... Pity that it won't work on the client side, I was hoping for a way of automatically calling "destroy()" when an interface isn't used anymore...
> 
> See, On the server side I use Java, but I still have a destroy() method for my interfaces, such that I can deactivate them (remove them from the AOM.)
> 
> Thus, user would see like:
> 
> Interface user 
> {
> 	void setName(in string name);
> 	string getName();
> 	void destroy();
> };
> 
> And by using shared_ptr on the client side, I was hoping to be able to call my own implementation of the interface's destructor, hence, calling user->destroy(); automatically...
> 
> So now I'm at a loss... :S  If I wrote a wrapper for the interface user, I suppose I could use a shared_ptr to that wrapper and call the wrapper's destructor and, well, you get it, I suppose.
> 
> It's perhaps very onion-like, but I still HAVE TO use wrappers (not my decission really), so I may as well try it like that... 
> 
> What do you think? Would it be viable?
> 
> -----Ursprüngliche Nachricht-----
> Von: Michael [mailto:omniorb at bindone.de] 
> Gesendet: Freitag, 14. November 2008 15:46
> An: Vázquez Landa, David
> Cc: omniorb-list at omniorb-support.com
> Betreff: Re: [omniORB] Boost shared_ptr
> 
> 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