00001 00002 #include "Component/ModelManager.H" 00003 #include "Component/ModelComponent.H" 00004 #include "Component/ModelOptionDef.H" 00005 #include <Ice/Ice.h> 00006 #include <Ice/Service.h> 00007 #include "Ice/RobotSimEvents.ice.H" 00008 #include "Ice/RobotBrainObjects.ice.H" 00009 #include "Ice/SimEventsUtils.H" 00010 #include "Ice/IceImageUtils.H" 00011 #include "Robots/SeaBeeIII/ColorSegmenterI.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 int port = RobotBrainObjects::RobotBrainPort; 00033 bool connected = false; 00034 00035 while(!connected) 00036 { 00037 try 00038 { 00039 LINFO("Trying Port: %d", port); 00040 sprintf(adapterStr, "default -p %i", port); 00041 itsAdapter = communicator()->createObjectAdapterWithEndpoints("ColorSegmenter", adapterStr); 00042 connected = true; 00043 } catch(Ice::SocketException) 00044 { 00045 port++; 00046 } 00047 } 00048 00049 //Create the manager and its objects 00050 itsMgr = new ModelManager("ColorSegmenterService"); 00051 00052 LINFO("Starting ColorSegmenter"); 00053 nub::ref<ColorSegmenterI> ret(new ColorSegmenterI(*itsMgr)); 00054 itsMgr->addSubComponent(ret); 00055 00056 ret->init(communicator(), itsAdapter); 00057 00058 itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0); 00059 00060 itsAdapter->activate(); 00061 00062 itsMgr->start(); 00063 00064 return true; 00065 } 00066 00067 // ###################################################################### 00068 int main(int argc, char** argv) { 00069 00070 RobotBrainServiceService svc; 00071 return svc.main(argc, argv); 00072 }