test-BasicBrainComponent.C

00001 
00002 #include "Component/ModelManager.H"
00003 #include "Component/ModelComponent.H"
00004 #include "Component/ModelOptionDef.H"
00005 #include "Robots/SeaBeeIII/BasicBrainComponentI.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   //Create the adapter
00033   int port = RobotBrainObjects::RobotBrainPort;
00034   bool connected = false;
00035 
00036   while(!connected)
00037     {
00038       try
00039         {
00040           LINFO("Trying Port:%d", port);
00041           sprintf(adapterStr, "default -p %i", port);
00042           itsAdapter = communicator()->createObjectAdapterWithEndpoints("MovementController",
00043                                                                         adapterStr);
00044           connected = true;
00045         }
00046       catch(Ice::SocketException)
00047         {
00048           port++;
00049         }
00050     }
00051 
00052   //Create the manager and its objects
00053   itsMgr = new ModelManager("BasicBrainComponentService");
00054 
00055   LINFO("Starting BasicBrainComponent");
00056   nub::ref<BasicBrainComponentI> bbc(new BasicBrainComponentI(0, *itsMgr, "BasicBrainComponent1", "BasicBrainComponent2"));
00057   LINFO("BasicBrainComponent Created");
00058   itsMgr->addSubComponent(bbc);
00059   LINFO("BasicBrainComponent Added As Sub Component");
00060   bbc->init(communicator(), itsAdapter);
00061   LINFO("BasicBrainComponent Inited");
00062 
00063   itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0);
00064 
00065   itsAdapter->activate();
00066 
00067   itsMgr->start();
00068 
00069   return true;
00070 }
00071 
00072 // ######################################################################
00073 int main(int argc, char** argv) {
00074 
00075   RobotBrainServiceService svc;
00076   return svc.main(argc, argv);
00077 }
00078 
00079 
Generated on Sun May 8 08:42:07 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3