Archived
This forum has been archived. Please start a new discussion on GitHub.
Please give me a simple sample for interface and class.
in Help Center
I want a sample for interface and class
My Ice file:
interface value {
nonmutating int getvalue();
idempotent void setvalue(int Value);
};
class Clock implements value {
int Value;
};
How can I at client get and set the Value on Server?
How do I write code in Server and Client? I can't find similar sample in Ice manual.
thank you very much.
My Ice file:
interface value {
nonmutating int getvalue();
idempotent void setvalue(int Value);
};
class Clock implements value {
int Value;
};
How can I at client get and set the Value on Server?
How do I write code in Server and Client? I can't find similar sample in Ice manual.
thank you very much.
0
Comments
-
Sorry,I am a beginner on Ice.:(0
-
If My class 'clock' inherit from the interface class 'time', I must use 'implements' in ice file. But I don't understand the principle of it.How can I write the code in server.cpp and in client.cpp?
thank you.0 -
I solve this problem.:D
If a class inherits from a interface. in fact, its code is similar to the code of interface.haha
My ice file:
interface Time {
nonmutating int getint();
idempotent void setint(int x);
};
class Clock implements Time {
int x;
};
My code in server.cpp:
class ClockI : public Clock {
::Ice::Int getint(const Ice::Current &) const;
void setint(Ice::Int px, const Ice::Current &);
};
::Ice::Int ClockI::getint(const Ice::Current &) const
{
return x;
}
void ClockI::setint(Ice::Int px, const Ice::Current &)
{
x = px;
cout << "Set value of int successfully!" << endl;
}
int main(int argc, char* argv[])
{
......
//
Test for Set and Get
object = new ClockI;
adapter->add(object, Ice::stringToIdentity("IntDemo"));
//
......
}
My code in client.cpp:
Ice::ObjectPrx base3 = ic->stringToProxy(
properties->getProperty("IntDemoAdapter.Proxy"));
......
ClockPrx IntDemo = ClockPrx::checkedCast(base3);
//
//test the inheritance of class from interface
IntDemo->setint(54);
cout << "int = " << IntDemo->getint() << endl;
//
......
implements means that when a class inherit from a interface,the class can access and edit the value of the interface via interface.It is simple.0 -
You may find it instructive to have a close look at how the value demo (in ice/demo/Ice/value) works. It shows how to implement a class and illustrates the difference between local and remote invocations on a class.
Cheers,
Michi.0