00001 /*!@file Ice/IceStorm/Subscriber2.C */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Lior Elazary 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Ice/IceStorm/Subscriber2.C $ 00035 // $Id: Subscriber2.C 10794 2009-02-08 06:21:09Z itti $ 00036 // 00037 00038 #include "Ice/IceStorm/Subscriber2.H" 00039 #include "Image/ColorOps.H" 00040 00041 Subscriber2I::Subscriber2I(OptionManager& mgr, 00042 const std::string& descrName, 00043 const std::string& tagName ) : 00044 ModelComponent(mgr, descrName, tagName) 00045 { 00046 } 00047 00048 void Subscriber2I::initSimEvents(Ice::CommunicatorPtr icPtr, Ice::ObjectPrx objectPrx) 00049 { 00050 //Get the IceStorm object 00051 Ice::ObjectPrx obj = icPtr->stringToProxy("SimEvents/TopicManager:tcp -p 10000"); 00052 IceStorm::TopicManagerPrx topicManager = 00053 IceStorm::TopicManagerPrx::checkedCast(obj); 00054 00055 //Create a Subscriber2 Topic 00056 IceStorm::TopicPrx topic; 00057 try { 00058 IceStorm::QoS qos; 00059 topic = topicManager->retrieve("Publisher2Message"); //Get the retina topic 00060 topic->subscribeAndGetPublisher(qos, objectPrx); //Subscribe to the retina topic 00061 } catch (const IceStorm::NoSuchTopic&) { 00062 LFATAL("Error! No retina topic found!"); 00063 } 00064 } 00065 00066 00067 void Subscriber2I::evolve(const EventsNS::EventPtr& e, 00068 const Ice::Current&) 00069 { 00070 LINFO("Got message %i", e->id); 00071 if (e->ice_isA("::EventsNS::Message1")) { 00072 EventsNS::Message1Ptr m1 = EventsNS::Message1Ptr::dynamicCast(e); 00073 LINFO("Message 1: %i '%s'", m1->m, m1->msg.c_str()); 00074 } else if (e->ice_isA("::EventsNS::Message2")) { 00075 EventsNS::Message2Ptr m2 = EventsNS::Message2Ptr::dynamicCast(e); 00076 LINFO("Message 2: %i,%i '%s'", m2->i, m2->j, m2->msg.c_str()); 00077 } 00078 } 00079 00080 /////////////////////////// The Retina Service to init the retina and start as a deamon /////////////// 00081 class Subscriber2Service : public Ice::Service { 00082 protected: 00083 virtual bool start(int, char* argv[]); 00084 virtual bool stop() { 00085 if (itsMgr) 00086 delete itsMgr; 00087 return true; 00088 } 00089 00090 private: 00091 Ice::ObjectAdapterPtr itsAdapter; 00092 ModelManager *itsMgr; 00093 }; 00094 00095 bool Subscriber2Service::start(int argc, char* argv[]) 00096 { 00097 00098 itsMgr = new ModelManager("Subscriber2Service"); 00099 00100 nub::ref<Subscriber2I> s2(new Subscriber2I(*itsMgr)); 00101 itsMgr->addSubComponent(s2); 00102 00103 itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0); 00104 00105 itsAdapter = communicator()->createObjectAdapterWithEndpoints("Subscriber2Adapter", "default -p 20004"); 00106 00107 Ice::ObjectPtr object = s2.get(); 00108 Ice::ObjectPrx objectPrx = itsAdapter->add(object, communicator()->stringToIdentity("Subscriber2")); 00109 s2->initSimEvents(communicator(), objectPrx); 00110 itsAdapter->activate(); 00111 00112 itsMgr->start(); 00113 00114 return true; 00115 } 00116 00117 // ###################################################################### 00118 int main(int argc, char** argv) { 00119 00120 Subscriber2Service svc; 00121 return svc.main(argc, argv); 00122 } 00123 00124