Archived
This forum has been archived. Please start a new discussion on GitHub.
About the well-known object name definition's position.
Hi, I come again for a little question:
In IceGrid environment, I wrote a interface in slice, the interface will compile to the client and server code, and i config the object as a well-known object in the deploy xml.
So next:
Client developer will call stringtoproxy(objName) to get obj proxy.
And server developer should call adapter's method: addObject(objName, objPtr).
I think objName is must same one in client and server.
So I define the objname in the slice like this:
module Test
{
const string ObjectTestName = "Test";
interface ITest
{
void doTest();
}
}
client code:
ic->stringToProxy(Test::ObjectTestName);
server code:
adapter->addObject(Test::ObjectTestName, new CObjectTest());
Code above can resolve part of my question, But if there is multple interface in the module Test, const string var can't match interface define accurately.
I think there is another more good solution?
In IceGrid environment, I wrote a interface in slice, the interface will compile to the client and server code, and i config the object as a well-known object in the deploy xml.
So next:
Client developer will call stringtoproxy(objName) to get obj proxy.
And server developer should call adapter's method: addObject(objName, objPtr).
I think objName is must same one in client and server.
So I define the objname in the slice like this:
module Test
{
const string ObjectTestName = "Test";
interface ITest
{
void doTest();
}
}
client code:
ic->stringToProxy(Test::ObjectTestName);
server code:
adapter->addObject(Test::ObjectTestName, new CObjectTest());
Code above can resolve part of my question, But if there is multple interface in the module Test, const string var can't match interface define accurately.
I think there is another more good solution?
0
Comments
-
Any advise?
0 -
Hi MingYi,
It makes sense to define or of a few root objects in your applications, give these objects simple memorable names. And with IceGrid, you can register these objects as well-known objects.
I would not define Slice constants for these object names or identities: Slice is about defining contracts between clients and servers, and not about sharing this type of information.
Since there are just one or a few of these objects, my recommendation is to copy these names in your server and client configurations. In the client, it would be something like:# Client config Root.Proxy=Test
Your client code would then use communicator->propertyToProxy("Root.Proxy") to create this proxy.
On the server side, you can generate a property in your configuration through the property attribute of the well-known object descriptor. This property's value is the stringified identity of your well-known object.
You could then write:Ice::Identity rootId; rootId.name = communicator->getProperties()->getProperty("Root.Identity"); // Root.Identity is the property attribute of the well-known object adapter->addObject(rootId, new CObjectTest());
Hope this is clearer now!
Best regards,
Bernard
0