app-Beobot2_GistSalLocalizerWorker.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "Component/ModelManager.H"
00038 #include "Component/ModelComponent.H"
00039 #include "Component/ModelOptionDef.H"
00040 #include "Robots/Beobot2/Localization/Beobot2_GistSalLocalizerWorker.H"
00041 #include <Ice/Ice.h>
00042 #include <Ice/Service.h>
00043 #include "Ice/RobotSimEvents.ice.H"
00044 #include "Ice/RobotBrainObjects.ice.H"
00045 #include "Ice/SimEventsUtils.H"
00046 #include "Ice/IceImageUtils.H"
00047
00048
00049
00050 class RobotBrainServiceService : public Ice::Service {
00051 protected:
00052 virtual bool start(int, char* argv[]);
00053 virtual bool stop() {
00054 if (itsMgr)
00055 delete itsMgr;
00056 return true;
00057 }
00058
00059 private:
00060 Ice::ObjectAdapterPtr itsAdapter;
00061 ModelManager *itsMgr;
00062 };
00063
00064
00065 bool RobotBrainServiceService::start(int argc, char* argv[])
00066 {
00067 char adapterStr[255];
00068
00069 LINFO("Creating Topic!");
00070
00071
00072
00073
00074
00075
00076 int port = RobotBrainObjects::RobotBrainPort;
00077 bool connected = false;
00078 LDEBUG("Opening Connection");
00079
00080 while(!connected)
00081 {
00082 try
00083 {
00084 LINFO("Trying Port:%d", port);
00085 sprintf(adapterStr, "default -p %i", port);
00086 itsAdapter = communicator()->createObjectAdapterWithEndpoints
00087 ("Beobot2_GistSalLocalizerWorker", adapterStr);
00088 connected = true;
00089 }
00090 catch(Ice::SocketException)
00091 {
00092 port++;
00093 }
00094 }
00095
00096
00097 itsMgr = new ModelManager("Beobot2_GistSalLocalizerWorkerService");
00098
00099 LINFO("Starting Beobot2_GistSalLocalizerWorker");
00100 nub::ref<Beobot2_GistSalLocalizerWorkerI> gslw
00101 (new Beobot2_GistSalLocalizerWorkerI
00102 (*itsMgr, "Beobot2_GisSaltLocalizerWorker",
00103 "Beobot2_GistSalLocalizerWorker"));
00104 LINFO("Beobot2_GistSalLocalizerWorker Created");
00105 itsMgr->addSubComponent(gslw);
00106 LINFO("Beobot2_GistSalLocalizerWorker Added As Sub Component");
00107 gslw->init(communicator(), itsAdapter);
00108 LINFO("Beobot2_GistSalLocalizerWorker Initiated");
00109
00110 if (itsMgr->parseCommandLine((const int)argc, (const char**)argv,
00111 "<environment file> "
00112 "<number of workers> "
00113 "<worker index>",
00114 1, 3)
00115 == false) return(1);
00116
00117
00118
00119 std::string envFName = itsMgr->getExtraArg(0);
00120 LINFO("Loading Env file: %s", envFName.c_str());
00121 rutz::shared_ptr<Environment> env(new Environment(envFName));
00122
00123
00124
00125 gslw->setEnvironment(env);
00126 if(itsMgr->numExtraArgs() > 2)
00127 gslw->setWorkerInformation
00128 (itsMgr->getExtraArgAs<uint>(1), itsMgr->getExtraArgAs<uint>(2));
00129
00130 itsAdapter->activate();
00131
00132 itsMgr->start();
00133
00134 return true;
00135 }
00136
00137
00138 int main(int argc, char** argv)
00139 {
00140 LINFO("Creating Service...");
00141 RobotBrainServiceService svc;
00142 LINFO("Service Created...");
00143 return svc.main(argc, argv);
00144 }
00145
00146
00147
00148
00149
00150