main.cpp
Go to the documentation of this file.
1 // -*- mode: c++; indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
2 /*
3  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
4  * All rights reserved. This program is made available under the terms of the
5  * Eclipse Public License v1.0 which accompanies this distribution, and is
6  * available at http://www.eclipse.org/legal/epl-v10.html
7  * Contributors:
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  * General Robotix Inc.
10  */
17 #include <iostream>
18 #include <rtm/Manager.h>
19 
20 #include "BridgeConf.h"
21 #include "Controller_impl.h"
22 #include "VirtualRobotRTC.h"
23 
24 
25 #if ( defined ( WIN32 ) || defined ( _WIN32 ) || defined(__WIN32__) )
26 # if( defined (OPENRTM_VERSION_042) )
27 #include <ace/OS_main.h>
28 # endif
29 #endif
30 
31 
32 using namespace std;
33 
34 namespace {
35 
36 
37  const bool CONTROLLER_BRIDGE_DEBUG = false;
38 
39 
40  CosNaming::NamingContext_ptr getNamingContext(CORBA::ORB_ptr orb, const char* nameServerIdentifier)
41  {
42  CosNaming::NamingContext_ptr namingContext = CosNaming::NamingContext::_nil();
43 
44  CORBA::Object_var nameServer;
45 
46  try {
47  nameServer = orb->string_to_object(nameServerIdentifier);
48  }
49  catch (const CORBA::ORB::InvalidName&) {
50  cerr << "`NameService' cannot be resolved" << endl;
51  }
52 
53  if(CORBA::is_nil(nameServer)){
54  cerr << "`NameService' is a nil object reference" << endl;
55  } else {
56  try {
57  namingContext = CosNaming::NamingContext::_narrow(nameServer);
58  }
59  catch(...){
60  cerr << "`NameService' is not a NamingContext object reference" << endl;
61  }
62  }
63 
64  return namingContext;
65  }
66 
67 
68  bool setup(RTC::Manager* rtcManager, BridgeConf* bridgeConf)
69  {
70  CosNaming::NamingContext_var namingContext =
71  getNamingContext(rtcManager->getORB(), bridgeConf->getOpenHRPNameServerIdentifier());
72 
73  if(CORBA::is_nil(namingContext)){
74  return false;
75  }
76  Controller_impl* controllerServant = new Controller_impl( rtcManager, bridgeConf );
77 
78  CORBA::Object_var controller = controllerServant->_this();
79 
80  CosNaming::Name controllerName;
81  controllerName.length(1);
82  controllerName[0].id = CORBA::string_dup(bridgeConf->getControllerName());
83  controllerName[0].kind = CORBA::string_dup("");
84 
85  namingContext->rebind(controllerName, controller);
86 
87  bridgeConf->setupModules();
88 
89  return true;
90  }
91 }
92 
93 
94 int main(int argc, char* argv[])
95 {
96  int ret = 0;
97  RTC::Manager* rtcManager;
98 
99  try {
100  int i;
101  int rtc_argc = 1;
102  char** rtc_argv = (char **)malloc(sizeof(char *)*argc);
103  rtc_argv[0] = argv[0];
104  for (i=1; i<argc; i++){
105  if (strncmp(argv[i], "--", 2)!=0 ) {
106  rtc_argv[rtc_argc] = argv[i];
107  rtc_argc++;
108  }else {
109  i++;
110  }
111  }
112  rtcManager = RTC::Manager::init(rtc_argc, rtc_argv);
113  rtcManager->activateManager();
114  }
115  catch(...) {
116  cerr << "Cannot initialize OpenRTM" << endl;
117  exit(1);
118  }
119 
120  BridgeConf* bridgeConf;
121 
122  try {
123  bridgeConf = BridgeConf::initialize(argc, argv);
124  } catch (std::exception& ex) {
125  cerr << argv[0] << ": " << ex.what() << endl;
126  exit(1);
127  }
128 
129 
130  if(bridgeConf->isReady()){
131  if(setup(rtcManager, bridgeConf)){
132  cout << "ready" << endl;
133  rtcManager->runManager();
134  } else {
135  ret = 1;
136  }
137  }
138  return ret;
139 }
void runManager(bool no_block=false)
char * malloc()
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
CORBA::ORB_ptr getORB()
png_uint_32 i
Definition: png.h:2735
static BridgeConf * initialize(int argc, char *argv[])
Definition: BridgeConf.cpp:39
const char * getOpenHRPNameServerIdentifier()
Definition: BridgeConf.cpp:366
static Manager * init(int argc, char **argv)
bool activateManager()
void setupModules()
Definition: BridgeConf.cpp:351
const char * getControllerName()
Definition: BridgeConf.cpp:372
int main(int argc, char *argv[])
Definition: main.cpp:94
bool isReady()
Definition: BridgeConf.h:98


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:24