test-CircleDetectionComponent.C
00001 #include "Component/ModelManager.H"
00002 #include "Component/ModelComponent.H"
00003 #include "Component/ModelOptionDef.H"
00004 #include "Robots/SeaBeeIII/CircleDetectionComponent.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
00012
00013 class RobotBrainServiceService : public Ice::Service {
00014 protected:
00015 virtual bool start(int, char* argv[]);
00016 virtual bool stop() {
00017 if (itsMgr)
00018 delete itsMgr;
00019 return true;
00020 }
00021
00022 private:
00023 Ice::ObjectAdapterPtr itsAdapter;
00024 ModelManager *itsMgr;
00025 };
00026
00027 bool RobotBrainServiceService::start(int argc, char* argv[])
00028 {
00029 char adapterStr[255];
00030
00031 LINFO("Starting the Circle Detection Component");
00032
00033
00034
00035
00036 int port = RobotBrainObjects::RobotBrainPort;
00037 bool connected = false;
00038
00039 while(!connected)
00040 {
00041 try
00042 {
00043 LINFO("Trying Port:%d", port);
00044 sprintf(adapterStr, "default -p %i", port);
00045 itsAdapter = communicator()->createObjectAdapterWithEndpoints("CircleDetectionComponent",
00046 adapterStr);
00047 connected = true;
00048 }
00049 catch(Ice::SocketException)
00050 {
00051 port++;
00052 }
00053 }
00054
00055
00056 itsMgr = new ModelManager("CircleDetectionComponentService");
00057
00058 LINFO("Starting CircleDetectionComponent");
00059 nub::ref<CircleDetectionComponent> ret(new CircleDetectionComponent(0, *itsMgr, "CircleDetectionComponent1", "CircleDetectionComponent2"));
00060 LINFO("CircleDetectionComponent Created");
00061 itsMgr->addSubComponent(ret);
00062 LINFO("CircleDetectionComponent Added As Sub Component");
00063 ret->init(communicator(), itsAdapter);
00064 LINFO("CircleDetectionComponent Inited");
00065
00066 itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0);
00067
00068 itsAdapter->activate();
00069
00070 itsMgr->start();
00071
00072 return true;
00073 }
00074
00075
00076 int main(int argc, char** argv) {
00077
00078 RobotBrainServiceService svc;
00079 return svc.main(argc, argv);
00080 }
00081
00082