00001 /*!@file Ice/IceStorm/Publisher2.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/Publisher2.C $ 00035 // $Id: Publisher2.C 10794 2009-02-08 06:21:09Z itti $ 00036 // 00037 00038 #include "Ice/IceStorm/Publisher2.H" 00039 #include "Image/ColorOps.H" 00040 00041 Publisher2I::Publisher2I(OptionManager& mgr, 00042 const std::string& descrName, 00043 const std::string& tagName ) : 00044 ModelComponent(mgr, descrName, tagName) 00045 { 00046 } 00047 00048 void Publisher2I::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 Publisher2 Topic 00056 IceStorm::TopicPrx topic; 00057 try { 00058 topic = topicManager->retrieve("Publisher2Message"); //check if the Retina topic exists 00059 } catch (const IceStorm::NoSuchTopic&) { 00060 topic = topicManager->create("Publisher2Message"); //The retina topic does not exists, create 00061 } 00062 //Make a one way Publisher2 message publisher for efficency 00063 Ice::ObjectPrx pub = topic->getPublisher()->ice_oneway(); 00064 itsMessagePub = EventsNS::EventsPrx::uncheckedCast(pub); 00065 00066 try { 00067 IceStorm::QoS qos; 00068 topic = topicManager->retrieve("Publisher1Message"); //Get the retina topic 00069 topic->subscribeAndGetPublisher(qos, objectPrx); //Subscribe to the retina topic 00070 } catch (const IceStorm::NoSuchTopic&) { 00071 LFATAL("Error! No retina topic found!"); 00072 } 00073 00074 } 00075 00076 00077 void Publisher2I::evolve(const EventsNS::EventPtr& e, 00078 const Ice::Current&) 00079 { 00080 LINFO("Got message %i", e->id); 00081 00082 if (e->ice_isA("::EventsNS::Message1")) { 00083 EventsNS::Message1Ptr m1 = EventsNS::Message1Ptr::dynamicCast(e); 00084 LINFO("Message 1: %i '%s'", m1->m, m1->msg.c_str()); 00085 00086 EventsNS::Message2Ptr msg2 = new EventsNS::Message2; 00087 msg2->id = 20; 00088 msg2->i = 19; 00089 msg2->j = 115; 00090 msg2->msg = "This is message 2.2"; 00091 LINFO("Sending message 2"); 00092 itsMessagePub->evolve(msg2); 00093 00094 } else if (e->ice_isA("::EventsNS::Message2")) { 00095 EventsNS::Message2Ptr m2 = EventsNS::Message2Ptr::dynamicCast(e); 00096 LINFO("Message 2: %i,%i '%s'", m2->i, m2->j, m2->msg.c_str()); 00097 } 00098 00099 } 00100 00101 void Publisher2I::run() 00102 { 00103 while(1) 00104 { 00105 EventsNS::Message2Ptr msg2 = new EventsNS::Message2; 00106 msg2->id = 20; 00107 msg2->i = 9; 00108 msg2->j = 15; 00109 msg2->msg = "This is message 2"; 00110 LINFO("Sending message 2"); 00111 itsMessagePub->evolve(msg2); 00112 sleep(1); 00113 } 00114 } 00115 00116 /////////////////////////// The Retina Service to init the retina and start as a deamon /////////////// 00117 class Publisher2Service : public Ice::Service { 00118 protected: 00119 virtual bool start(int, char* argv[]); 00120 virtual bool stop() { 00121 if (itsMgr) 00122 delete itsMgr; 00123 return true; 00124 } 00125 00126 private: 00127 Ice::ObjectAdapterPtr itsAdapter; 00128 ModelManager *itsMgr; 00129 }; 00130 00131 bool Publisher2Service::start(int argc, char* argv[]) 00132 { 00133 00134 itsMgr = new ModelManager("Publisher2Service"); 00135 00136 nub::ref<Publisher2I> p2(new Publisher2I(*itsMgr)); 00137 itsMgr->addSubComponent(p2); 00138 00139 itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0); 00140 00141 itsAdapter = communicator()->createObjectAdapterWithEndpoints("Publisher2Adapter", "default -p 20003"); 00142 00143 Ice::ObjectPtr object = p2.get(); 00144 Ice::ObjectPrx objectPrx = itsAdapter->add(object, communicator()->stringToIdentity("Publisher2")); 00145 p2->initSimEvents(communicator(), objectPrx); 00146 itsAdapter->activate(); 00147 00148 itsMgr->start(); 00149 00150 //Start the evolve thread 00151 IceUtil::ThreadPtr p2Thread = p2.get(); 00152 p2Thread->start(); 00153 00154 return true; 00155 } 00156 00157 // ###################################################################### 00158 int main(int argc, char** argv) { 00159 00160 Publisher2Service svc; 00161 return svc.main(argc, argv); 00162 } 00163 00164