Archived

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

Passing references and objects in nested classes

Hello everybody,

I have a problem with passing Ice references and objects within classes passed in other classes.

The interface will I use to demonstrate the problem is based on "value" demo provided with Ice.

class Printer
{
string message;
void printBackwards();
};

class NotSoSimple
{
string message;
Printer getPrinter1();
Printer* getPrinter2();
};

class Initial
{
Simple getSimple();
NotSoSimple getNotSoSimple();
void getPrinter(out Printer impl, out Printer* proxy);
};

Getting the Printer reference via Initial.getPrinter works, but after calling Initial.getNotSoSimple, the Printer's reference is null - both in case of getPrinter1 and getPrinter2.
Is it allowed to pass references to Ice objects like this? Neither Ice tutorial nor samples show similar examples. By sniffing Ice messages I suspect that the server sends the null remote reference and null (empty) object so it is not the client-side problem.

With best regards,
Lukasz

Comments

  • bernard
    bernard Jupiter, FL
    Hi Lukasz,

    What the call to initialProxy->getNotSoSimple() returns depends on your implementation of this operation.

    In the C++ implementation of the value demo, getPrinter works because it's implemented as follows in ValueI.cpp:
    void
    InitialI::getPrinter(PrinterPtr& impl, PrinterPrx& proxy, const Ice::Current&)
    {
        impl = _printer;
        proxy = _printerProxy;
    }
    

    So your getNotSoSimple should be something like:
    NotSoSimplePtr
    InitialI::getNotSoSimple(const Ice::Current&)
    {
       return _notSoSimpleObject;
      // or return new NotSoSimpleI(...);
    }
    

    Here you're returning an object by value. If you want to return a proxy to an Ice object in your server, the Slice definition for this operation should be:
    NotSoSimple* getNotSoSimple();
    

    Cheers,
    Bernard
  • Hi Bernard,

    Thanks for the replay.

    Passing the NotSoSimple object works OK, its message field is passed correctly; the problem is that Printer's remote reference / object are not sent by the server to the client (are seen as null).

    So calling (in C#)
    PrinterPrx printerPrx = notsosimple.getPrinter2();
    Printer printerObj = notsosimple.getPrinter1();
    
    returns null in both cases (notsosimple is not null).

    Regards,
    Lukasz
  • bernard
    bernard Jupiter, FL
    Hi Lukasz,

    With your Slice definitions, the NotSoSimple object is passed by value, so these:
    PrinterPrx printerPrx = notsosimple.getPrinter2();
    Printer printerObj = notsosimple.getPrinter1();
    

    are just local calls in your client. The result depends entirely on your implementation of NotSoSimple in the client.

    If you want to return the printer proxy or object held by the server, you'll have to modify NotSoSimple to include these data members as well, set them properly in the server, and update the getPrinter1/getPrinter2 implementation in your client.

    Cheers,
    Bernard
  • Bernard,

    Many thanks. It's completely clear now.

    Best regards,
    Lukasz