[omniORB] WG: How to return an object reference?

renej renej.frog at gmail.com
Sat Jul 9 18:22:09 BST 2005


On 7/7/05, Andreas Groch <groch at promessmontage.de> wrote:
>  
> 
> I am trying to use an ObjectFactory in order to get an object reference on
> the client side of an existing object in the server. 
> 
> It should be possible that any number of clients can connect to the
> DefaultApi at any time. 
> 
> This is the idl: 
> 
>   
> 
> interface DefaultApi { 
> 
>             void hello(); 
> 
> }; 
> 
>   
> 
> interface ObjectFactory { 
> 
>             DefaultApi getDefaultApi(); 
> 
>             void hello(); 
> 
> }; 
> 
>   
> 
> I create the object and the object reference like this: 
> 
>   
> 
> DefaultApi_var defaultApi_ref; 
> 
>   
> 
> DefaultApi_impl* defaultApi_servant = new DefaultApi_impl(); 
> 
> defaultApi_ref = defaultApi_servant->_this(); 
> 
>   
> 
> The getDefaultApi function looks like this: 
> 
>   
> 
> DefaultApi_ptr ObjectFactory_impl::getDefaultApi() { 
> 
>             return defaultApi_ref; 

NOTE: you should do:

   return DefaultApi::_duplicate(defaultApi_ref)

> 
> } 
> 
>   
> 
> When I call the getDefaultApi() function on the client I get an object
> reference and I can invoke the hello function on it. But the console output
> of the server says: 
> 
> "omniORB: ObjRef(IDL:DefaultApi:1.0) – deleted." 
> 

returning object references in interface method implementations
requires the returned references to have their reference count
incremented; the "caller" (still on server-side) releases afterwards.
In your example, the object reference will be deleted somewhere after
the call. Hence, when used later on by the client it doesn't exist
anymore.

>   
> 
> When I call the function again or when I start the client again and invoke
> the getDefaultApi function I get a segmentation fault on the server. 
> 
> I am wondering if this is the right way of passing an object reference from
> the server to the client. 

use _duplicate()
> 
> How can I avoid that the ObjRef(IDL:DefaultApi:1.0) gets deleted when I
> return it in the getDefaultApi function? 
> 
>   
> 
> Any help would be greatly appreciated. 

hope this helps

renej
> 
>   
> 
> Best regards/Mit freundlichen Grüßen 
> 
>   
> 
> Andreas Groch 
> 
> ......................... 
>  Promess Gesellschaft für Montage- und Prüfsysteme mbH 
>  Nunsdorfer Ring. 29 
>  D-12277 Berlin 
>    
>  Tel.:          0049 - (0)30 - 62 88 72 - 0
>  Fax:           0049 - (0)30 - 62 88 72 - 59 
>  Mobil:         0049 - (0) 
>  E-Mail:        groch at promessmontage.de 
>  Web:           www.promessmontage.de 
>  ........................ 
> 
>   
> _______________________________________________
> 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