Home Help Center

Pointers and Proxies

MikeGerdesMikeGerdes Member Mike GerdesOrganization: TU hamburg-HarburgProject: Tree Structure
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

  • hiaslhiasl Member Matthias WeberOrganization: University of Erlangen-NurembergProject: This baby is still nameless
    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
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    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.
  • davidcr1983davidcr1983 Member David VallejoOrganization: University of Castilla-La Mancha (Spain)Project: Intelligent Surveillance System ✭✭
    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!
  • MikeGerdesMikeGerdes Member Mike GerdesOrganization: TU hamburg-HarburgProject: Tree Structure
    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.
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    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.)
Sign In or Register to comment.