Subscriber1.C

Go to the documentation of this file.
00001 /*!@file Ice/IceStorm/Subscriber1.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/Subscriber1.C $
00035 // $Id: Subscriber1.C 10794 2009-02-08 06:21:09Z itti $
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   //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 Subscriber1 Topic
00056   IceStorm::TopicPrx topic;
00057   try {
00058     IceStorm::QoS qos;
00059     //qos["reliability"] = "ordered";
00060     topic = topicManager->retrieve("Publisher1Message"); //Get the retina topic
00061     topic->subscribeAndGetPublisher(qos, objectPrx->ice_oneway()); //Subscribe to the retina topic
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 /////////////////////////// The Retina Service to init the retina and start as a deamon ///////////////
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 
Generated on Sun May 8 08:04:59 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3