Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00017 #include <iostream>
00018 #include <rtm/Manager.h>
00019
00020 #include "BridgeConf.h"
00021 #include "Controller_impl.h"
00022 #include "VirtualRobotRTC.h"
00023
00024
00025 #if ( defined ( WIN32 ) || defined ( _WIN32 ) || defined(__WIN32__) )
00026 # if( defined (OPENRTM_VERSION_042) )
00027 #include <ace/OS_main.h>
00028 # endif
00029 #endif
00030
00031
00032 using namespace std;
00033
00034 namespace {
00035
00036
00037 const bool CONTROLLER_BRIDGE_DEBUG = false;
00038
00039
00040 CosNaming::NamingContext_ptr getNamingContext(CORBA::ORB_ptr orb, const char* nameServerIdentifier)
00041 {
00042 CosNaming::NamingContext_ptr namingContext = CosNaming::NamingContext::_nil();
00043
00044 CORBA::Object_var nameServer;
00045
00046 try {
00047 nameServer = orb->string_to_object(nameServerIdentifier);
00048 }
00049 catch (const CORBA::ORB::InvalidName&) {
00050 cerr << "`NameService' cannot be resolved" << endl;
00051 }
00052
00053 if(CORBA::is_nil(nameServer)){
00054 cerr << "`NameService' is a nil object reference" << endl;
00055 } else {
00056 try {
00057 namingContext = CosNaming::NamingContext::_narrow(nameServer);
00058 }
00059 catch(...){
00060 cerr << "`NameService' is not a NamingContext object reference" << endl;
00061 }
00062 }
00063
00064 return namingContext;
00065 }
00066
00067
00068 bool setup(RTC::Manager* rtcManager, BridgeConf* bridgeConf)
00069 {
00070 CosNaming::NamingContext_var namingContext =
00071 getNamingContext(rtcManager->getORB(), bridgeConf->getOpenHRPNameServerIdentifier());
00072
00073 if(CORBA::is_nil(namingContext)){
00074 return false;
00075 }
00076 Controller_impl* controllerServant = new Controller_impl( rtcManager, bridgeConf );
00077
00078 CORBA::Object_var controller = controllerServant->_this();
00079
00080 CosNaming::Name controllerName;
00081 controllerName.length(1);
00082 controllerName[0].id = CORBA::string_dup(bridgeConf->getControllerName());
00083 controllerName[0].kind = CORBA::string_dup("");
00084
00085 namingContext->rebind(controllerName, controller);
00086
00087 bridgeConf->setupModules();
00088
00089 return true;
00090 }
00091 }
00092
00093
00094 int main(int argc, char* argv[])
00095 {
00096 int ret = 0;
00097 RTC::Manager* rtcManager;
00098
00099 try {
00100 int i;
00101 int rtc_argc = 1;
00102 char** rtc_argv = (char **)malloc(sizeof(char *)*argc);
00103 rtc_argv[0] = argv[0];
00104 for (i=1; i<argc; i++){
00105 if (strncmp(argv[i], "--", 2)!=0 ) {
00106 rtc_argv[rtc_argc] = argv[i];
00107 rtc_argc++;
00108 }else {
00109 i++;
00110 }
00111 }
00112 rtcManager = RTC::Manager::init(rtc_argc, rtc_argv);
00113 rtcManager->activateManager();
00114 }
00115 catch(...) {
00116 cerr << "Cannot initialize OpenRTM" << endl;
00117 exit(1);
00118 }
00119
00120 BridgeConf* bridgeConf;
00121
00122 try {
00123 bridgeConf = BridgeConf::initialize(argc, argv);
00124 } catch (std::exception& ex) {
00125 cerr << argv[0] << ": " << ex.what() << endl;
00126 exit(1);
00127 }
00128
00129
00130 if(bridgeConf->isReady()){
00131 if(setup(rtcManager, bridgeConf)){
00132 cout << "ready" << endl;
00133 rtcManager->runManager();
00134 } else {
00135 ret = 1;
00136 }
00137 }
00138 return ret;
00139 }