Subscriber1.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Ice/IceStorm/Subscriber1.H"
00039 #include "Image/ColorOps.H"
00040
00041 Subscriber1I::Subscriber1I(OptionManager& mgr,
00042 const std::string& descrName,
00043 const std::string& tagName ) :
00044 ModelComponent(mgr, descrName, tagName)
00045 {
00046 }
00047
00048 void Subscriber1I::initSimEvents(Ice::CommunicatorPtr icPtr, Ice::ObjectPrx objectPrx)
00049 {
00050
00051 Ice::ObjectPrx obj = icPtr->stringToProxy("SimEvents/TopicManager:tcp -p 10000");
00052 IceStorm::TopicManagerPrx topicManager =
00053 IceStorm::TopicManagerPrx::checkedCast(obj);
00054
00055
00056 IceStorm::TopicPrx topic;
00057 try {
00058 IceStorm::QoS qos;
00059
00060 topic = topicManager->retrieve("Publisher1Message");
00061 topic->subscribeAndGetPublisher(qos, objectPrx->ice_oneway());
00062 } catch (const IceStorm::NoSuchTopic&) {
00063 LFATAL("Error! No retina topic found!");
00064 }
00065 }
00066
00067
00068 void Subscriber1I::evolve(const EventsNS::EventPtr& e,
00069 const Ice::Current&)
00070 {
00071 LINFO("Got message %i", e->id);
00072
00073 if (e->ice_isA("::EventsNS::Message1")) {
00074 EventsNS::Message1Ptr m1 = EventsNS::Message1Ptr::dynamicCast(e);
00075 LINFO("Message 1: %i '%s'", m1->m, m1->msg.c_str());
00076 } else if (e->ice_isA("::EventsNS::Message2")) {
00077 EventsNS::Message2Ptr m2 = EventsNS::Message2Ptr::dynamicCast(e);
00078 LINFO("Message 2: %i,%i '%s'", m2->i, m2->j, m2->msg.c_str());
00079 }
00080 sleep(1);
00081 }
00082
00083
00084 class Subscriber1Service : public Ice::Service {
00085 protected:
00086 virtual bool start(int, char* argv[]);
00087 virtual bool stop() {
00088 if (itsMgr)
00089 delete itsMgr;
00090 return true;
00091 }
00092
00093 private:
00094 Ice::ObjectAdapterPtr itsAdapter;
00095 ModelManager *itsMgr;
00096 };
00097
00098 bool Subscriber1Service::start(int argc, char* argv[])
00099 {
00100
00101 itsMgr = new ModelManager("Subscriber1Service");
00102
00103 nub::ref<Subscriber1I> s1(new Subscriber1I(*itsMgr));
00104 itsMgr->addSubComponent(s1);
00105
00106 itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0);
00107
00108 itsAdapter = communicator()->createObjectAdapterWithEndpoints("Subscriber1Adapter", "default -p 20001");
00109
00110 Ice::ObjectPtr object = s1.get();
00111 Ice::ObjectPrx objectPrx = itsAdapter->add(object, communicator()->stringToIdentity("Subscriber1"));
00112 s1->initSimEvents(communicator(), objectPrx);
00113 itsAdapter->activate();
00114
00115 itsMgr->start();
00116
00117 return true;
00118 }
00119
00120
00121 int main(int argc, char** argv) {
00122
00123 Subscriber1Service svc;
00124 return svc.main(argc, argv);
00125 }
00126
00127