ICE 3.4.2
[php5-ice-freebsdport.git] / cpp / demo / Ice / multicast / Server.cpp
blobd5d10f5111a7aa568a804199979c4a4e96bc641e
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 #include <Ice/Ice.h>
12 #include <Discovery.h>
13 #include <Hello.h>
15 using namespace std;
16 using namespace Demo;
18 class HelloI : public Hello
20 public:
22 virtual void
23 sayHello(const Ice::Current&)
25 cout << "Hello World!" << endl;
29 class DiscoverI : public Discover
31 public:
33 DiscoverI(const Ice::ObjectPrx& obj) :
34 _obj(obj)
38 virtual void
39 lookup(const DiscoverReplyPrx& reply, const Ice::Current&)
41 try
43 reply->reply(_obj);
45 catch(const Ice::LocalException&)
47 // Ignore
51 private:
53 const Ice::ObjectPrx _obj;
56 class HelloServer : public Ice::Application
58 public:
60 virtual int run(int, char*[]);
63 int
64 main(int argc, char* argv[])
66 HelloServer app;
67 return app.main(argc, argv, "config.server");
70 int
71 HelloServer::run(int argc, char* argv[])
73 Ice::StringSeq args = Ice::argsToStringSeq(argc, argv);
74 args = communicator()->getProperties()->parseCommandLineOptions("Discover", args);
76 Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Hello");
77 Ice::ObjectAdapterPtr discoverAdapter = communicator()->createObjectAdapter("Discover");
79 Ice::ObjectPrx hello = adapter->addWithUUID(new HelloI);
80 DiscoverPtr d = new DiscoverI(hello);
81 discoverAdapter->add(d, communicator()->stringToIdentity("discover"));
83 discoverAdapter->activate();
84 adapter->activate();
86 communicator()->waitForShutdown();
87 return EXIT_SUCCESS;