[omniORB] Can't compile client that retrieves a struct which contains a sequence

Luke Deller ldeller at iress.com.au
Thu May 1 12:06:17 BST 2008


Hi Tom,

> void foo(SequenceTestIF_var seqTest) {
>
>   SequenceTestIF::Message msg;
>
>   seqTest->setMessage(msg);   // compiles OK
>
>   seqTest->getMessage(msg);   // Does not compile!
> }
...
> Looking at the generated IDL header file, getMessage() is defined as
> follows:
> virtual void getMessage(SequenceTestIF::Message_out msg) = 0;
> So it appears that the compiler is expecting the getMessage() parameter
> to be of type "SequenceTestIF::Message_out".  So I modified the client:
>
>   SequenceTestIF::Message_out msgOut;
>   seqTest->getMessage(msgOut);   // Still does not compile!

Not quite... here's a quote from section 4.11.2 of the C++ language mapping:

| Note that the T_out types are not intended to serve as general-purpose
| data types to be created and destroyed by applications; they are used
| only as types within operation signatures to allow necessary memory
| management side-effects to occur properly.

So you don't actually construct a Message_out instance explicitly.  Basically you want to pass a reference to a pointer, so that the function can point your pointer at the returned message:

    SequenceTestIF::Message *msgptr;
    seqTest->getMessage(msgptr);
    // now you can use msgptr->body
    seqTest->setMessage(*msgptr);
    delete msgptr;

Alternatively you can use the Message_var type to ease memory management:

    SequenceTestIF::Message_var msg;
    seqTest->getMessage(msg);
    // now you can use msg->body
    seqTest->setMessage(msg);
    // no need to delete anything; the Message_var destructor handles it

For more details, check out the IDL C++ language mapping which is available for download from:
http://www.omg.org/technology/documents/idl2x_spec_catalog.htm

Regards,
Luke.
**********************************************************************************************
Important Note
This email (including any attachments) contains information which is confidential and may be subject to legal privilege.  If you are not the intended recipient you must not use, distribute or copy this email.  If you have received this email in error please notify the
sender immediately and delete this email. Any views expressed in this email are not necessarily the views of IRESS Market Technology Limited.

It is the duty of the recipient to virus scan and otherwise test the information provided before loading onto any computer system.
IRESS Market Technology Limited does not warrant that the information is free of a virus or any other defect or error.
**********************************************************************************************



More information about the omniORB-list mailing list