[omniORB] Using cdrMemoryStream?

amos at amos.mailshell.com amos at amos.mailshell.com
Fri Jul 22 10:26:26 BST 2005


On Thu, 2005-07-21 at 17:46 +0100, Duncan Grisby wrote:
> It would be really helpful if you gave us the IDL definitions of your
> types. Otherwise we have to guess from the code, which isn't very easy.
> Certainly "op" is not an object by the CORBA usage of the word. I guess
> it's a union...

Sorry. Here is the relevant part from the IDL:

module operationslog {
  struct AddDomainOp {
    long id;
    string name;
  };
  struct AddRealmOp {
    long id;
    string name;
  };
  union Operation switch(long) {
    case 0: AddDomainOp     addDomain;
    case 1: AddRealmOp addRealm;
  };
};

> 
> > operationslog::Operation op;
> > op._d(0);
> > operationslog::AddRealmOp addRealmOp;
> > addRealmOp.id = id;
> > addRealmOp.name = name;
> > op.addRealm(addRealmOp);
> > cdrMemoryStream stream;
> > 	
> > op >>= stream;
> > cout << "addRealm: stream: buffer size: " << stream.bufSize() << endl;
> > 
> > But apparently this causes the operation to abort.
> 
> In what way does it abort?

I narrowed it down to the:
op._d(0)
call - the generated code explicitly checks for values
mentioned in the case: statements and throws an exception if these
are passed (also the "0" parameter to this call was wrong).

Here is what my code looks like now (and works):

operationslog::Operation op;
operationslog::AddRealmOp addRealmOp;
addRealmOp.id = id;
addRealmOp.name = name;
op.addRealm(addRealmOp);
cdrMemoryStream stream;
op >>= stream;

And then accessing stream.bufSize() and stream.bufPtr() to retrieve
the serialized object's byte stream.

> 
> Have you initialised the ORB?  Guessing that name is a string or
> wstring, marshalling it requires that the ORB has been initialised, so
> the code set conversion support is initialised.

What do you mean by "initialized the ORB"? This method is called by the
ORB as a "server" of a CORBA request but doesn't use an ORB anywere
in its code.

> 
> On an side note, what are you going to do with the value once you've
> marshalled it?  If you're going to store it somewhere, remember that the
> marshalled form depends on the byte order of the platform. If you want
> to be immune to problems with that, you might want to use a
> cdrEncapsulationStream, which adds a bit of overhead, but handles the
> byte order issues for you.

Thanks for the warning.

Once the objects are serialized, I store and retrieve them to/from a
Berkeley DB 4.3 local database. Once they are retrieved and
de-serialized they are sent to other CORBA clients which for are
expected to be solely Intel x86 machines for the foreseeable future.
I might actually try to avoid the de-serialization until the byte stream
reaches the final destination.

Is there documentation about these classes?  I couldn't find any.

> 
> Cheers,
> 
> Duncan.
> 

Thanks,

--Amos




More information about the omniORB-list mailing list