test-ObjectFinder.C

00001 /*
00002  * test-ObjectFinder.C
00003  */
00004 
00005 #include "Component/ModelManager.H"
00006 #include "Component/ModelComponent.H"
00007 #include "Component/ModelOptionDef.H"
00008 #include "Robots/BeoHawk/vision/ObjectFinder.H"
00009 #include <Ice/Ice.h>
00010 #include <Ice/Service.h>
00011 #include "Ice/RobotSimEvents.ice.H"
00012 #include "Ice/RobotBrainObjects.ice.H"
00013 #include "Ice/SimEventsUtils.H"
00014 #include "Ice/IceImageUtils.H"
00015 
00016 
00017 class ObjectFinderService : public Ice::Service {
00018 protected:
00019         virtual bool start(int, char * argv[]);
00020         virtual bool stop() {
00021                 if (itsMgr)
00022                         delete itsMgr;
00023                 return true;
00024         }
00025 
00026 private:
00027         Ice::ObjectAdapterPtr itsAdapter;
00028         ModelManager *itsMgr;
00029 };
00030 
00031 bool ObjectFinderService::start (int argc, char * argv[]) {
00032 
00033         char adapterStr[255];
00034 
00035         int port = RobotBrainObjects::RobotBrainPort;
00036         bool connected = false;
00037         LDEBUG("Opening Connection");
00038 
00039         while (!connected) {
00040                 try {
00041                         LINFO("Trying Port: %d", port);
00042                         sprintf(adapterStr, "default -p %i", port);
00043                         itsAdapter = communicator()->createObjectAdapterWithEndpoints(
00044                                         "ObjectFinder", adapterStr);
00045                         connected = true;
00046                 } catch (Ice::SocketException) {
00047                         port++;
00048                 }
00049         }
00050 
00051         itsMgr = new ModelManager("ObjectFinderService");
00052 
00053         LINFO("Creating ObjectFinder");
00054         nub::ref<ObjectFinder> ret (new ObjectFinder(*itsMgr, "ObjectFinder", "ObjectFinder"));
00055         LINFO("ObjectFinder Created");
00056         itsMgr->addSubComponent(ret);
00057         ret->init(communicator(), itsAdapter);
00058         itsMgr->parseCommandLine((const int) argc, (const char **) argv, "", 0, 0);
00059         ret->buildFeatureDB();
00060         LINFO("ObjectFinder Initialized, DB Built");
00061 
00062         itsAdapter->activate();
00063         itsMgr->start();
00064 
00065         return true;
00066 }
00067 
00068 
00069 //#############################################################
00070 int main(int argc, char ** argv) {
00071         LINFO("Creating Object Finder Service...");
00072         ObjectFinderService svc;
00073         LINFO("Service Created...");
00074         return svc.main(argc, argv);
00075 }
Generated on Sun May 8 08:41:21 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3