Ice::ObjectPrx base = communicator()->stringToProxy("SimpleFoo:default -h localhost -p 10000");
#include <Ice/Ice.h>
#include <foo.h>
using namespace std;
using namespace Demo;
class FooI : virtual public Foo
{
public:
virtual std::string getName(Ice::Int value, const Ice::Current&);
};
std::string
FooI::getName(Ice::Int value, const Ice::Current&)
{
cout << "value: " << value << endl;
return "kasicass";
}
class MyApplication : virtual public Ice::Application {
public:
virtual int run(int, char *[]) {
shutdownOnInterrupt();
Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints(
"SimpleFooAdapter", "default -h localhost -p 10000");
Ice::ObjectPtr obj = new FooI;
adapter->add(obj, communicator()->stringToIdentity("SimpleFoo"));
adapter->activate();
communicator()->waitForShutdown();
if (interrupted()) {
cerr << appName() << ": recv signal, shutting down" << endl;
}
return 0;
}
};
int main(int argc, char *argv[])
{
MyApplication app;
return app.main(argc, argv);
}
-----------------------------------------------------------------------
而且还封装了 Ctrl + C 之类的 signal handle,很方便。
还有个类 Ice::Service,用于将程序启动为 *nix daemon or win32 service。
评论