How to keep IORs identical?

Sai-Lai Lo S.Lo@orl.co.uk
30 Oct 1997 11:01:01 +0000


Bastiaan Bakker <Bastiaan.Bakker@harbinger.nl> writes:

> From looking at the sources I was under the impression that this could
> be accomplished by:

> 1) using a fixed IIOP port, set by -BOAiiop_port port on the command
> line, and

Correct.

> 2) constuct the server object with the constructor that takes an
> objectKey. The objectKey comes from a previous run of the server by
> calling _key() method.

Correct. The following sample code is modified from eg2_impl, its output
confirms that the key parameter passed to the constructor is used by the
orb as the object's key.

------------ eg2_impl.cc -----------------
#include <iostream.h>
#include <stream.h>
#include "omnithread.h"
#include "echo.hh"

#include "echo_i.cc"

int
main(int argc, char **argv)
{
  CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB2");
  CORBA::BOA_ptr boa = orb->BOA_init(argc,argv,"omniORB2_BOA");

  omniORB::seqOctets* val = omniORB::keyToOctetSequence(omniORB::nullkey());
  {
    for (CORBA::ULong i = 0; i < val->length(); i++) {
      (*val)[i] = i;
    }
  }
  
  omniORB::objectKey key = omniORB::octetSequenceToKey(*val);

  {
    cerr << "Key parameter is : ";
    cerr << hex;
    for (CORBA::ULong i = 0; i < val->length(); i++) {
      cerr << setfill('0') << setw(2) << (int)(*val)[i];
    }
    cerr << dec;
    cerr << endl;
  }

  Echo_i *myobj = new Echo_i(key);
  myobj->_obj_is_ready(boa);

  {
    Echo_var myobjRef = myobj->_this();
    CORBA::String_var p = orb->object_to_string(myobjRef);
    cerr << "'" << (char*)p << "'" << endl;
  }

  val = omniORB::keyToOctetSequence(myobj->_key());
  {
    cerr << "Key is set to : ";
    cerr << hex;
    for (CORBA::ULong i = 0; i < val->length(); i++) {
      cerr << setfill('0') << setw(2) << (int)(*val)[i];
    }
    cerr << dec;
    cerr << endl;
  }
  


  boa->impl_is_ready();
  // Tell the BOA we are ready. The BOA's default behaviour is to block
  // on this call indefinitely.

  return 0;
}

----------------------------------------------------

-------- echo_i.cc ---------------------------------

#include <string.h>
#include "echo.hh"

class Echo_i : public virtual _sk_Echo {
public:
  Echo_i() {}
  Echo_i(omniORB::objectKey& k) : _sk_Echo(k) {}
  virtual ~Echo_i() {}
  virtual char * echoString(const char *mesg);
};

char *
Echo_i::echoString(const char *mesg) {
  char *p = CORBA::string_dup(mesg);
  return p;
}

-----------------------------------------------------

-- 
E-mail:         S.Lo@orl.co.uk          |       Olivetti & Oracle Research Lab
                                        |       24a Trumpington Street
Tel:            +44 223 343000          |       Cambridge CB2 1QA
Fax:            +44 223 313542          |       ENGLAND