test-BinFinder.C

00001 
00002 #include "Component/ModelManager.H"
00003 #include "Component/ModelComponent.H"
00004 #include "Component/ModelOptionDef.H"
00005 #include "Robots/SeaBeeIII/BinFinder.H"
00006 #include <Ice/Ice.h>
00007 #include <Ice/Service.h>
00008 #include "Ice/RobotSimEvents.ice.H"
00009 #include "Ice/RobotBrainObjects.ice.H"
00010 #include "Ice/SimEventsUtils.H"
00011 #include "Ice/IceImageUtils.H"
00012 
00013 
00014 class RobotBrainServiceService : public Ice::Service {
00015   protected:
00016     virtual bool start(int, char* argv[]);
00017     virtual bool stop() {
00018       if (itsMgr)
00019         delete itsMgr;
00020       return true;
00021     }
00022 
00023   private:
00024     Ice::ObjectAdapterPtr itsAdapter;
00025     ModelManager *itsMgr;
00026 };
00027 
00028 bool RobotBrainServiceService::start(int argc, char* argv[])
00029 {
00030   char adapterStr[255];
00031 
00032   LINFO("Creating Topic!");
00033   //Create the topics
00034 //  SimEventsUtils::createTopic(communicator(), "BinFinderMessageTopic");
00035 
00036   //Create the adapter
00037   int port = RobotBrainObjects::RobotBrainPort;
00038   bool connected = false;
00039   LDEBUG("Opening Connection");
00040 
00041   while(!connected)
00042   {
00043     try
00044     {
00045       LINFO("Trying Port:%d", port);
00046       sprintf(adapterStr, "default -p %i", port);
00047       itsAdapter = communicator()->createObjectAdapterWithEndpoints
00048         ("BinFinder",
00049           adapterStr);
00050       connected = true;
00051     }
00052     catch(Ice::SocketException)
00053     {
00054       port++;
00055     }
00056   }
00057 
00058   //Create the manager and its objects
00059         itsMgr = new ModelManager("BinFinderService");
00060 
00061   LINFO("Starting BinFinder");
00062   nub::ref<BinFinder> ret
00063     (new BinFinder(*itsMgr, "BinFinder1", "BinFinder2"));
00064   LINFO("BinFinder Created");
00065   itsMgr->addSubComponent(ret);
00066   LINFO("BinFinder Added As Sub Component");
00067   ret->init(communicator(), itsAdapter);
00068   LINFO("BinFinder Inited");
00069 
00070   itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0);
00071 
00072   itsAdapter->activate();
00073 
00074   itsMgr->start();
00075 
00076   return true;
00077 }
00078 
00079 // ######################################################################
00080 int main(int argc, char** argv) {
00081 
00082   LINFO("Creating Service...");
00083   RobotBrainServiceService svc;
00084   LINFO("Service Created...");
00085   return svc.main(argc, argv);
00086 }
00087 
00088 
Generated on Sun May 8 08:42:07 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3