Archived

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

Pointers and Proxies

Hi,

I want to make a system with a tree structure that constits of nodes. These nodes have a parent and several children. And I use C++.

The slice description looks like this:

module structure {

sequence<Node> NodeSeq;

interface Node {

void setParent(string);
Node getParent();
NodeSeq getChildren();
}
}

The nodes have internally a vector where the child nodes are saved and a variable where the parent is set. SetParent is called from the parent of a node with the indentifier of the parent node. All nodes know only their children from a configuration file.

That is the setup. Now to my problem.

When I generate the C++ files from the Slice file, getParent returns a NodePtr and getChildren a vector of NodePtr.
When setParten gets called, a child resolves the given identifier and creates a proxy to his parten, so that he can call methodes there. The same happens for his children.

But how do I transform now the NodePrx objects into NodePtr objects? And is it possible that pointers point to remote objects and can I call methodes there? I have thried this setup in CORBA before, there there I simply used _var pointers, to call remote functions and for return values.

I have found no solution to my problem in the Ice book and in the examples. Have I overread something or am I doing it totally wrong?

Comments

  • Hi Mike,

    you could try to use asterixes. Then you get "remote references" to your nodes. We use a similar interface to access remote trees.

    module structure {

    sequence<Node *> NodeSeq;

    interface Node {

    void setParent(Node *);
    Node *getParent();
    NodeSeq getChildren();
    }
    }

    Bye
    Matthias
  • As Matthias writes above, you have to use Node* for proxies, not Node . Have a look at "4.11.11 Pass-by-Value Versus Pass-by-Reference" in the Ice manual for more details.
  • Hello!

    You are confusing classes with interfaces. You should study the Simple File System exposed in the Ice documentation because is similar to your problem. In addition, it seems your application must be persistent... Freeze is the solution.

    Regards!
  • Oh I see, so I need to know if the object will be a remote or a local reference, when I design the Slice file.

    I looked at the simple file server example, but there they never used a function that returns a remote reference, so I was a bit confused.

    Many thanks, I will try it and let you know if I encounter any other problems.
  • MikeGerdes wrote: »
    Oh I see, so I need to know if the object will be a remote or a local reference, when I design the Slice file.

    You can use proxies, regardless of whether the Ice object is local or remote. This is completely transparent. The difference between Foo* and Foo has nothing to do with local vs. remote, but simply that in one case, you pass by proxy, while in the other case, you pass by value.

    (We try to avoid the term "reference" because it has so many possible meanings.)