Archived

This forum has been archived. Please start a new discussion on GitHub.

out parameter with non basic type

Hello,

I'm new to ice. I have problem (run time error on the server) with the use of out parameter with non basic data type. This one is work fine :

interface Hello
{
void sayHello(out string); // out parameter with basic data type
};

but this is not :

interface Hello
{
void sayHello(out SequenceOfSomething); // out parameter with non basic data type
};

Is there any special treatment for out parameter with non basic type ?. I've tried to search this on the demo sample but can't find it.

Thanks in advance for your help,
regards,
solikhin

Comments

  • It's impossible to help you without known what language you are using. Can you post the code that causes the problem? Also, if you look at language mapping chapter in the manual for your language, you should find the information you need there.

    Cheers,

    Michi.
  • Thanks for your quick reply,

    I'm using C++.
    Unintentionally, I seem to have solved the problem. Calling the servant with uninitialized variables seem to solve the problem (actually I'm not 100% sure because I'm a newbie, but in my case the problem disappear and I get the expected result / value).

    Here is the original client code :

    SequenceOfSomething tmpSomething(someSize); // I determined the size here
    ObjProxy->sayHello(tmpSomething);

    Here is the modified client code :

    SequenceOfSomething tmpSomething; // I remove the size here
    ObjProxy->sayHello(tmpSomething);

    Is this the correct way on doing this thing ?.
  • matthew
    matthew NL, Canada
    I tried to duplicate this problem with the hello world demo (demo/Ice/hello) and could not reproduce it. I don't think this can be the reason for the initial failure, you must have had some other issue.
  • Actually I just use Hello to ilustrate my problem. My actual code has return value of type sequence, several in parameter of type sequence, and 1 out parameter of type sequence.

    Basically, what I have done in trying to solve this problem is just remove the size as ilustrated above (in the client side). In the server side, I made litle change in the way out parameter is processed :

    Original server side code :

    void Demo::sayHello(Demo::SequenceOfSomeThing xyz)
    {
    xyz[0].member1 = ....; // I originally have determined the size of this variable
    xyz[0].member2 = ....; // from client side, and here I just assign the value
    xyz[0].member3 = ....;
    };

    Modified server side code :

    void Demo::sayHello(Demo::SequenceOfSomeThing xyz)
    {
    SequenceOfSomeThing tmpData(SomeSize);
    tmpData[0].member1 = ....;
    tmpData[0].member2 = ....;
    tmpData[0].member3 = ....;
    xyz = tmpData;
    };

    That's all I've done in the client side and the server side. Or, Maybe I just been unlucky by hitting / exceeding maximum message size in first run of my program ?. Any idea ?.
  • matthew
    matthew NL, Canada
    It looks to me like you expect the client to send the expected size of the out field to the server. This is not the case -- out parameters send nothing to the server (that is value that is passed to the servant is uninitialized). if you want to send an expected size then you must pass this as an additional parameter.
    interface Hello
    {
      void sayHello(int sz, out Ice::StringSeq seq);
    };
    
    then you could do something like:
    void HelloI::sayHello(int sz, Ice::StringSeq& seq, const Ice::Current&)
    {
        seq.size(sz);
        for(int i = 0; i < sz; ++i) seq[i] = "hello world";
    }
    

    and
    HelloPrx hello = ....;
    Ice::StringSeq seq;
    hello->sayHello(10, seq);
    assert(seq.size() == 10);
    
  • Thanks a lot for your reply.
    It clarifies something that I never realized before "out parameter send nothing to the server".