00001 /*!@file */ 00002 // //////////////////////////////////////////////////////////////////// // 00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00004 // University of Southern California (USC) and the iLab at USC. // 00005 // See http://iLab.usc.edu for information about this project. // 00006 // //////////////////////////////////////////////////////////////////// // 00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00009 // in Visual Environments, and Applications'' by Christof Koch and // 00010 // Laurent Itti, California Institute of Technology, 2001 (patent // 00011 // pending; application number 09/912,225 filed July 23, 2001; see // 00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00013 // //////////////////////////////////////////////////////////////////// // 00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00015 // // 00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00017 // redistribute it and/or modify it under the terms of the GNU General // 00018 // Public License as published by the Free Software Foundation; either // 00019 // version 2 of the License, or (at your option) any later version. // 00020 // // 00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00024 // PURPOSE. See the GNU General Public License for more details. // 00025 // // 00026 // You should have received a copy of the GNU General Public License // 00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00029 // Boston, MA 02111-1307 USA. // 00030 // //////////////////////////////////////////////////////////////////// // 00031 // 00032 // Primary maintainer for this file: Christian Siagian <siagian@usc.edu> 00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/Beobot2/Localization/app-Beobot2_GistSalLocalizerWorker.C $ 00034 // $Id: app-Beobot2_GistSalLocalizerWorker.C 12962 2010-03-06 02:13:53Z irock $ 00035 // 00036 00037 #include "Component/ModelManager.H" 00038 #include "Component/ModelComponent.H" 00039 #include "Component/ModelOptionDef.H" 00040 #include "Robots/Beobot2/Localization/Beobot2_GistSalLocalizerWorker.H" 00041 #include <Ice/Ice.h> 00042 #include <Ice/Service.h> 00043 #include "Ice/RobotSimEvents.ice.H" 00044 #include "Ice/RobotBrainObjects.ice.H" 00045 #include "Ice/SimEventsUtils.H" 00046 #include "Ice/IceImageUtils.H" 00047 00048 00049 // ###################################################################### 00050 class RobotBrainServiceService : public Ice::Service { 00051 protected: 00052 virtual bool start(int, char* argv[]); 00053 virtual bool stop() { 00054 if (itsMgr) 00055 delete itsMgr; 00056 return true; 00057 } 00058 00059 private: 00060 Ice::ObjectAdapterPtr itsAdapter; 00061 ModelManager *itsMgr; 00062 }; 00063 00064 // ###################################################################### 00065 bool RobotBrainServiceService::start(int argc, char* argv[]) 00066 { 00067 char adapterStr[255]; 00068 00069 LINFO("Creating Topic!"); 00070 00071 // Create the topics 00072 // SimEventsUtils::createTopic(communicator(), 00073 // "Beobot2_GistSalLocalizerWorkerMessageTopic"); 00074 00075 //Create the adapter 00076 int port = RobotBrainObjects::RobotBrainPort; 00077 bool connected = false; 00078 LDEBUG("Opening Connection"); 00079 00080 while(!connected) 00081 { 00082 try 00083 { 00084 LINFO("Trying Port:%d", port); 00085 sprintf(adapterStr, "default -p %i", port); 00086 itsAdapter = communicator()->createObjectAdapterWithEndpoints 00087 ("Beobot2_GistSalLocalizerWorker", adapterStr); 00088 connected = true; 00089 } 00090 catch(Ice::SocketException) 00091 { 00092 port++; 00093 } 00094 } 00095 00096 //Create the manager and its objects 00097 itsMgr = new ModelManager("Beobot2_GistSalLocalizerWorkerService"); 00098 00099 LINFO("Starting Beobot2_GistSalLocalizerWorker"); 00100 nub::ref<Beobot2_GistSalLocalizerWorkerI> gslw 00101 (new Beobot2_GistSalLocalizerWorkerI 00102 (*itsMgr, "Beobot2_GisSaltLocalizerWorker", 00103 "Beobot2_GistSalLocalizerWorker")); 00104 LINFO("Beobot2_GistSalLocalizerWorker Created"); 00105 itsMgr->addSubComponent(gslw); 00106 LINFO("Beobot2_GistSalLocalizerWorker Added As Sub Component"); 00107 gslw->init(communicator(), itsAdapter); 00108 LINFO("Beobot2_GistSalLocalizerWorker Initiated"); 00109 00110 if (itsMgr->parseCommandLine((const int)argc, (const char**)argv, 00111 "<environment file> " 00112 "<number of workers> " 00113 "<worker index>", 00114 1, 3) 00115 == false) return(1); 00116 00117 // initialize an environment - even if the .env file does not exist 00118 // automatically create a blank environment, ready to be built 00119 std::string envFName = itsMgr->getExtraArg(0); 00120 LINFO("Loading Env file: %s", envFName.c_str()); 00121 rutz::shared_ptr<Environment> env(new Environment(envFName)); 00122 //env->setWindow(matchWin); 00123 00124 // link the environment to the localizer 00125 gslw->setEnvironment(env); 00126 if(itsMgr->numExtraArgs() > 2) 00127 gslw->setWorkerInformation 00128 (itsMgr->getExtraArgAs<uint>(1), itsMgr->getExtraArgAs<uint>(2)); 00129 00130 itsAdapter->activate(); 00131 00132 itsMgr->start(); 00133 00134 return true; 00135 } 00136 00137 // ###################################################################### 00138 int main(int argc, char** argv) 00139 { 00140 LINFO("Creating Service..."); 00141 RobotBrainServiceService svc; 00142 LINFO("Service Created..."); 00143 return svc.main(argc, argv); 00144 } 00145 00146 // ###################################################################### 00147 /* So things look consistent in everyone's emacs... */ 00148 /* Local Variables: */ 00149 /* indent-tabs-mode: nil */ 00150 /* End: */