[omniORB] Object Reference Rules

David Riddoch djr@uk.research.att.com
Wed, 24 Mar 1999 19:47:55 +0000 (GMT)



class ObjectHolder_i : public virtual _sk_ObjectHolder {
public:
  virtual ~ObjectHolder_i();

  void put(SimpleObject_ptr obj);
  SimpleObject_ptr get();

private:
  SimpleObject_var m_held;
};


void
ObjectHolder_i::put(SimpleObject_ptr obj)
{
  m_held = SimpleObject::_duplicate(obj);
}


SimpleObject_ptr
ObjectHolder_i::get()
{
  // Method 1
  SimpleObject_ptr tmp = SimpleObject::_duplicate(m_held);
  m_held = SimpleObject::_nil();
  return tmp;

  // Method 2
  return m_held._retn();

  // Or if you want to be able to get() again ...
  return SimpleObject::_duplicate(m_held);
}


Hope this does what you want ...
David



On Wed, 24 Mar 1999, Armen Yampolsky wrote:

> Hi,
> 
> Apologies if this question is not entirely omniORB-specific. I am trying
> to figure out the correct way of passing an object reference from server
> to client and back again. A simple example IDL would look as follows:
> 
> -------------------------------
> interface SimpleObject {
>     attribute long count;
>     void kill();    // counterpart to ObjFactory::createObj(), clears
> server resources.
> };
> 
> interface ObjectHolder {
>     void put(in SimpleObject obj);
>     SimpleObject get();
> };
> 
> interface ObjFactory {
>     SimpleObject createObj();
> };
> -------------------------------
> 
> 
> Now what I want to do is the following:
> (1) receive ref to a newly instantiated SimpleObject via
> ObjFactory::createObj().
> (2) put it into the ObjectHolder on the server.
> (3) get it from the ObjectHolder.
> (4) alter its attribute.
> (5) put it back in the ObjectHolder.
> (6) repeat 3-5 as much as I want.
> 
> Instantiation via ObjFactory::createObj() works fine, we call
> _obj_is_ready and _this as required by the spec. Modifying the object
> reference's attribute on the client works fine. SimpleObject::kill()
> calls _dispose(), and this works correctly as usual. Putting the
> SimpleObject into the ObjectHolder seems to work fine as well. But
> here's where the questions arise. In ObjectHolder::get() we can not call
> _this() on the object prior to returning it, as it is now recognized by
> the ObjectHolder as a SimpleObject_ptr, which does not have a _this()
> method. We tried calling _duplicate in the ObjectHolder::put(), but this
> leaks memory. We then tried adding a CORBA::release() on the new
> duplicate, but then got OBJECT_NOT_EXIST exception on the client. What
> is the correct way to implement these methods (ObjecHolder::put and
> ObjectHolder::get)?
> 
> Note: Client is in Java, server is omniORB2.7.1 on Solaris 2.6.
> 
> TIA,
> -Armen
> 
> 
> 
> --
> Armen Yampolsky
> Axiom Software Labs
> New York