test-XBox360RemoteControl.C
00001
00002 #include "Component/ModelManager.H"
00003 #include "Component/ModelComponent.H"
00004 #include "Component/ModelOptionDef.H"
00005 #include "Robots/SeaBeeIII/XBox360RemoteControlI.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("Starting XBox Controller...");
00033
00034
00035
00036
00037 int port = RobotBrainObjects::RobotBrainPort;
00038 bool connected = false;
00039
00040 while(!connected)
00041 {
00042 try
00043 {
00044 LINFO("Trying Port:%d", port);
00045 sprintf(adapterStr, "default -p %i", port);
00046 itsAdapter = communicator()->createObjectAdapterWithEndpoints("XBox360RemoteControl",
00047 adapterStr);
00048 connected = true;
00049 }
00050 catch(Ice::SocketException)
00051 {
00052 port++;
00053 }
00054 }
00055
00056
00057 itsMgr = new ModelManager("XBox360RemoteControlService");
00058
00059 LINFO("Starting XBox360RemoteControl");
00060 nub::ref<XBox360RemoteControlI> ret(new XBox360RemoteControlI(0, *itsMgr, "XBox360RemoteControl1", "XBox360RemoteControl2"));
00061 LINFO("XBox360RemoteControl Created");
00062 itsMgr->addSubComponent(ret);
00063 LINFO("XBox360RemoteControl Added As Sub Component");
00064 ret->init(communicator(), itsAdapter);
00065 LINFO("XBox360RemoteControl Inited");
00066
00067 itsMgr->parseCommandLine((const int)argc, (const char**)argv, "", 0, 0);
00068
00069 itsAdapter->activate();
00070
00071 itsMgr->start();
00072
00073 return true;
00074 }
00075
00076
00077 int main(int argc, char** argv) {
00078
00079 RobotBrainServiceService svc;
00080 return svc.main(argc, argv);
00081 }
00082
00083