Publisher1.C

00001 /*!@file Ice/IceStorm/publisher1.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/Publisher1.C $
00035 // $Id: Publisher1.C 10794 2009-02-08 06:21:09Z itti $
00036 //
00037 
00038 #include "Ice/IceStorm/Publisher1.H"
00039 #include "Image/ColorOps.H"
00040 
00041 Publisher1I::Publisher1I(OptionManager& mgr,
00042     const std::string& descrName,
00043     const std::string& tagName ) :
00044   ModelComponent(mgr, descrName, tagName)
00045 {
00046 }
00047 
00048 void Publisher1I::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 Publisher1 Topic
00056   IceStorm::TopicPrx topic;
00057   try {
00058     topic = topicManager->retrieve("Publisher1Message"); //check if the Retina topic exists
00059   } catch (const IceStorm::NoSuchTopic&) {
00060     topic = topicManager->create("Publisher1Message"); //The retina topic does not exists, create
00061   }
00062   //Make a one way Publisher1 message publisher for efficency
00063   Ice::ObjectPrx pub = topic->getPublisher()->ice_oneway();
00064   itsMessagePub = EventsNS::EventsPrx::uncheckedCast(pub);
00065 }
00066 
00067 
00068 void Publisher1I::evolve(const EventsNS::EventPtr& e,
00069     const Ice::Current&)
00070 {
00071   LINFO("Got message");
00072   //itsMessage->Publisher1Output(Image2Ice(smap)); //post the saliency map message to the SimEvents
00073 }
00074 
00075 void Publisher1I::run()
00076 {
00077   int i = 0;
00078   while(1)
00079   {
00080     EventsNS::Message1Ptr msg1 = new EventsNS::Message1;
00081     msg1->id = 10;
00082     msg1->m = i;
00083     msg1->msg = "This is message 1";
00084     LINFO("Sending message 1: %i", i);
00085     itsMessagePub->evolve(msg1);
00086     i++;
00087     usleep(10000);
00088   }
00089 }
00090 
00091 /////////////////////////// The Retina Service to init the retina and start as a deamon ///////////////
00092 class Publisher1Service : public Ice::Service {
00093   protected:
00094     virtual bool start(int, char* argv[]);
00095     virtual bool stop() {
00096       if (itsMgr)
00097         delete itsMgr;
00098       return true;
00099     }
00100 
00101   private:
00102     Ice::ObjectAdapterPtr itsAdapter;
00103     ModelManager *itsMgr;
00104 };
00105 
00106 bool Publisher1Service::start(int argc, char* argv[])
00107 {
00108 
00109         itsMgr = new ModelManager("Publisher1Service");
00110 
00111   nub::ref<Publisher1I> p1(new Publisher1I(*itsMgr));
00112         itsMgr->addSubComponent(p1);
00113 
00114         itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0);
00115 
00116         itsAdapter = communicator()->createObjectAdapterWithEndpoints("Publisher1Adapter", "default -p 20000");
00117 
00118         Ice::ObjectPtr object = p1.get();
00119   Ice::ObjectPrx objectPrx = itsAdapter->add(object, communicator()->stringToIdentity("Publisher1"));
00120   p1->initSimEvents(communicator(), objectPrx);
00121         itsAdapter->activate();
00122 
00123   itsMgr->start();
00124 
00125   //Start the evolve thread
00126   IceUtil::ThreadPtr p1Thread = p1.get();
00127   p1Thread->start();
00128 
00129         return true;
00130 }
00131 
00132 // ######################################################################
00133 int main(int argc, char** argv) {
00134 
00135   Publisher1Service svc;
00136   return svc.main(argc, argv);
00137 }
00138 
00139 
Generated on Sun May 8 08:40:44 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3