28 return "C++ component code generator" 32 C++ generator specific usage (short version) 35 Options for C++ backend: 37 [--svc-impl-suffix[=suffix]] Suffix of implementation class 38 [--svc-skel-suffix[=suffix]] Suffix of server skeleton files 39 [--svc-stub-suffix[=suffix]] Suffix of client stub files 44 C++ generator specific usage 47 ------------------------------- 48 Help for C++ code geenrator 49 ------------------------------- 50 --svc-impl-suffix=[Suffix]: 51 Specify the suffix for implementation class name. This suffix is also 52 used for implementation class header file and code file. 53 --svc-skel-suffix=[Suffix]: 54 Specify the suffix for server skeleton files. 56 --svc-stub-suffix=[Suffix]: 57 Specify the suffix for client stub files. 59 C++ code generator generates the following files. 60 [Component name].h.............Component class header 61 [Component name].cpp...........Component class soruce code 62 [Component name]Comp.cpp.......Component startup code 63 [IDL basename]Skel.h...........Server skeleton header 64 [IDL basename]Skel.cpp.........Server skeleton source code 65 [IDL basename]Stub.h...........Client stub header 66 [IDL basename]Stub.cpp.........Client stub source code 67 [IDL basename]SVC_impl.h.......Server implementation header 68 [IDL basename]SVC_impl.cpp.....Server implementation source code 69 Makefile.[Component name]......Makefile to compile this codes 70 README.[Component name]........Specification template of the component 72 Suffixes (Skel, Stub, SVC_impl) can be specified --svc-*-suffix option 74 Other CORBA implementation specific skeleton/stub code would be generated. 76 [IDL basename].hh..............Client stub header 77 [IDL basename]SK.cc............Server skeleton source code 78 [IDL basename]DynSK.cc.........Dynamic server skeleton source code 80 [IDL basename]S.h..............Server skeleton header 81 [IDL basename]S.h..............Server skeleton source code 82 [IDL basename]C.h..............Client stub header 83 [IDL basename]C.h..............Client stub source code 85 [IDL basename].h...............Server skeleton header 86 [IDL basename]_skel.cc.........Server skeleton source code 87 [IDL basename].h...............Client stub header 88 [IDL basename].cc..............Client stub source code 93 opt_args_fmt = [
"svc-impl-suffix=",
102 comp_header =
"""// -*- C++ -*- 105 * @brief [basicInfo.description] 115 #include <rtm/idl/BasicDataTypeSkel.h> 116 #include <rtm/Manager.h> 117 #include <rtm/DataFlowComponentBase.h> 118 #include <rtm/CorbaPort.h> 119 #include <rtm/DataInPort.h> 120 #include <rtm/DataOutPort.h> 122 // Service implementation headers 123 // <rtc-template block="service_impl_h"> 126 // Service Consumer stub headers 127 // <rtc-template block="consumer_stub_h"> 132 class [basicInfo.name] 133 : public RTC::DataFlowComponentBase 136 [basicInfo.name](RTC::Manager* manager); 139 // The initialize action (on CREATED->ALIVE transition) 140 // formaer rtc_init_entry() 141 virtual RTC::ReturnCode_t onInitialize(); 143 // The finalize action (on ALIVE->END transition) 144 // formaer rtc_exiting_entry() 145 // virtual RTC::ReturnCode_t onFinalize(); 147 // The startup action when ExecutionContext startup 148 // former rtc_starting_entry() 149 // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id); 151 // The shutdown action when ExecutionContext stop 152 // former rtc_stopping_entry() 153 // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id); 155 // The activated action (Active state entry action) 156 // former rtc_active_entry() 157 // virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id); 159 // The deactivated action (Active state exit action) 160 // former rtc_active_exit() 161 // virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id); 163 // The execution action that is invoked periodically 164 // former rtc_active_do() 165 // virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id); 167 // The aborting action when main logic error occurred. 168 // former rtc_aborting_entry() 169 // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id); 171 // The error action in ERROR state 172 // former rtc_error_do() 173 // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id); 175 // The reset action that is invoked resetting 176 // This is same but different the former rtc_init_entry() 177 // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id); 179 // The state update action that is invoked after onExecute() action 180 // no corresponding operation exists in OpenRTm-aist-0.2.0 181 // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id); 183 // The action that is invoked when execution context's rate is changed 184 // no corresponding operation exists in OpenRTm-aist-0.2.0 185 // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id); 189 // Configuration variable declaration 190 // <rtc-template block="config_declare"> 193 // DataInPort declaration 194 // <rtc-template block="inport_declare"> 197 // DataOutPort declaration 198 // <rtc-template block="outport_declare"> 201 // CORBA Port declaration 202 // <rtc-template block="corbaport_declare"> 205 // Service declaration 206 // <rtc-template block="service_declare"> 209 // Consumer declaration 210 // <rtc-template block="consumer_declare"> 220 DLL_EXPORT void [basicInfo.name]Init(RTC::Manager* manager); 230 comp_soruce =
"""// -*- C++ -*- 233 * @brief [basicInfo.description] 242 // Module specification 243 // <rtc-template block="module_spec"> 246 [basicInfo.name]::[basicInfo.name](RTC::Manager* manager) 247 // <rtc-template block="initializer"> 252 [basicInfo.name]::~[basicInfo.name]() 257 RTC::ReturnCode_t [basicInfo.name]::onInitialize() 259 // Registration: InPort/OutPort/Service 260 // <rtc-template block="registration"> 263 // <rtc-template block="bind_config"> 269 [for act in activity] 271 RTC::ReturnCode_t [basicInfo.name]::[act.name]([act.args]) 282 void [basicInfo.name]Init(RTC::Manager* manager) 284 coil::Properties profile([l_name]_spec); 285 manager->registerFactory(profile, 286 RTC::Create<[basicInfo.name]>, 287 RTC::Delete<[basicInfo.name]>); 299 comp_compsrc =
"""// -*- C++ -*- 301 * @file [basicInfo.name]Comp.cpp 302 * @brief Standalone component 309 #include <rtm/Manager.h> 315 void MyModuleInit(RTC::Manager* manager) 317 [basicInfo.name]Init(manager); 320 // Create a component 321 comp = manager->createComponent("[basicInfo.name]"); 325 // The following procedure is examples how handle RT-Components. 326 // These should not be in this function. 328 // Get the component's object reference 329 // RTC::RTObject_var rtobj; 330 // rtobj = RTC::RTObject::_narrow(manager->getPOA()->servant_to_reference(comp)); 332 // Get the port list of the component 333 // PortServiceList* portlist; 334 // portlist = rtobj->get_ports(); 336 // getting port profiles 337 // std::cout << "Number of Ports: "; 338 // std::cout << portlist->length() << std::endl << std::endl; 339 // for (CORBA::ULong i(0), n(portlist->length()); i < n; ++i) 342 // port = (*portlist)[[]i]; 343 // std::cout << "Port" << i << " (name): "; 344 // std::cout << port->get_port_profile()->name << std::endl; 346 // RTC::PortInterfaceProfileList iflist; 347 // iflist = port->get_port_profile()->interfaces; 348 // std::cout << "---interfaces---" << std::endl; 349 // for (CORBA::ULong i(0), n(iflist.length()); i < n; ++i) 351 // std::cout << "I/F name: "; 352 // std::cout << iflist[[]i].instance_name << std::endl; 353 // std::cout << "I/F type: "; 354 // std::cout << iflist[[]i].type_name << std::endl; 356 // pol = iflist[[]i].polarity == 0 ? "PROVIDED" : "REQUIRED"; 357 // std::cout << "Polarity: " << pol << std::endl; 359 // std::cout << "---properties---" << std::endl; 360 // NVUtil::dump(port->get_port_profile()->properties); 361 // std::cout << "----------------" << std::endl << std::endl; 367 int main (int argc, char** argv) 369 RTC::Manager* manager; 370 manager = RTC::Manager::init(argc, argv); 372 // Initialize manager 373 manager->init(argc, argv); 375 // Set module initialization proceduer 376 // This procedure will be invoked in activateManager() function. 377 manager->setModuleInitProc(MyModuleInit); 379 // Activate manager and register to naming service 380 manager->activateManager(); 382 // run the manager in blocking mode 383 // runManager(false) is the default. 384 manager->runManager(); 386 // If you want to run the manager in non-blocking mode, do like this 387 // manager->runManager(true); 397 makefile =
"""# -*- Makefile -*- 399 # @file Makefile.[basicInfo.name] 400 # @brief RTComponent makefile for "[basicInfo.name] component" 404 # This file is generated by rtc-template with the following argments. 406 [for args in fmtd_args] 407 # [args] [if-index args is last][else]\\[endif] 415 CXX = `rtm-config --cxx` 416 CXXFLAGS = `rtm-config --cflags` -I. 417 LDFLAGS = `rtm-config --libs` 420 IDLC = `rtm-config --idlc` 421 IDLFLAGS = `rtm-config --idlflags` -I`rtm-config --prefix`/include/rtm/idl 422 WRAPPER = rtm-skelwrapper 423 WRAPPER_FLAGS = --include-dir="" --skel-suffix=Skel --stub-suffix=Stub 425 SKEL_OBJ = [for sidl in service_idl][sidl.skel_basename].o [endfor] 426 STUB_OBJ = [for cidl in consumer_idl][if-any cidl.stub_basename][cidl.stub_basename].o [endif][endfor] 427 IMPL_OBJ = [for sidl in service_idl][sidl.impl_basename].o [endfor] 428 OBJS = [basicInfo.name].o $(SKEL_OBJ) $(STUB_OBJ) $(IMPL_OBJ) 432 all: [basicInfo.name].so [basicInfo.name]Comp 437 $(CXX) $(CXXFLAGS) -c -o $@ $< 441 $(CXX) $(SHFLAGS) -o $@ $(OBJS) $(LDFLAGS) 443 [basicInfo.name]Comp: [basicInfo.name]Comp.o $(OBJS) 444 $(CXX) -o $@ $(OBJS) [basicInfo.name]Comp.o $(LDFLAGS) 447 clean: clean_objs clean_skelstub 451 rm -f $(OBJS) [basicInfo.name]Comp.o [basicInfo.name].so [basicInfo.name]Comp 454 rm -f *[skel_suffix].h *[skel_suffix].cpp 455 rm -f *[stub_suffix].h *[stub_suffix].cpp 457 [for sidl in service_idl][if-any sidl.skel_basename] 458 [sidl.skel_basename].cpp : [sidl.idl_fname] 459 $(IDLC) $(IDLFLAGS) [sidl.idl_fname] 460 $(WRAPPER) $(WRAPPER_FLAGS) --idl-file=[sidl.idl_fname] 461 [sidl.skel_basename].h : [sidl.idl_fname] 462 $(IDLC) $(IDLFLAGS) [sidl.idl_fname] 463 $(WRAPPER) $(WRAPPER_FLAGS) --idl-file=[sidl.idl_fname] 466 [for cidl in consumer_idl][if-any cidl.stub_basename] 467 [cidl.stub_basename].cpp : [cidl.idl_fname] 468 $(IDLC) $(IDLFLAGS) [cidl.idl_fname] 469 $(WRAPPER) $(WRAPPER_FLAGS) --idl-file=[cidl.idl_fname] 470 [cidl.stub_basename].h : [cidl.idl_fname] 471 $(IDLC) $(IDLFLAGS) [cidl.idl_fname] 472 $(WRAPPER) $(WRAPPER_FLAGS) --idl-file=[cidl.idl_fname] 475 [basicInfo.name].so: $(OBJS) 476 [basicInfo.name].o: [basicInfo.name].h [for sidl in service_idl][sidl.skel_basename].h [sidl.impl_basename].h [endfor] 477 [for cidl in consumer_idl][if-any cidl.stub_basename][cidl.stub_basename].h [endif][endfor] 478 [basicInfo.name]Comp.o: [basicInfo.name]Comp.cpp [basicInfo.name].cpp [basicInfo.name].h [for sidl in service_idl][sidl.skel_basename].h [sidl.impl_basename].h [endfor] 480 [for sidl in service_idl] 481 [sidl.impl_basename].o: [sidl.impl_basename].cpp [sidl.impl_basename].h [sidl.skel_basename].h [sidl.stub_basename].h 482 [sidl.skel_basename].o: [sidl.skel_basename].cpp [sidl.skel_basename].h [sidl.stub_basename].h 483 [sidl.stub_basename].o: [sidl.stub_basename].cpp [sidl.stub_basename].h 486 [for cidl in consumer_idl][if-any cidl.skel_basename] 487 [cidl.skel_basename].o: [cidl.skel_basename].cpp [cidl.skel_basename].h [cidl.stub_basename].h 488 [cidl.stub_basename].o: [cidl.stub_basename].cpp [cidl.stub_basename].h 498 service_impl_h =
"""[for sidl in service_idl]#include "[sidl.impl_h]" 500 consumer_stub_h =
"""[for cidl in consumer_idl][if-any cidl.stub_h] 501 #include "[cidl.stub_h]" 504 module_spec =
"""static const char* [l_name]_spec[] = 506 "implementation_id", "[basicInfo.name]", 507 "type_name", "[basicInfo.name]", 508 "description", "[basicInfo.description]", 509 "version", "[basicInfo.version]", 510 "vendor", "[basicInfo.vendor]", 511 "category", "[basicInfo.category]", 512 "activity_type", "[basicInfo.activityType]", 513 "kind", "[basicInfo.componentKind]", 514 "max_instance", "[basicInfo.maxInstances]", 516 "lang_type", "compile", 517 // Configuration variables 518 [for config in configurationSet.configuration] "conf.default.[config.name]", "[config.defaultValue]", 524 """ [for config in configurationSet.configuration][config.type] m_[config.name]; 529 """[for inport in dataPorts][if inport.portType is DataInPort] 530 [inport.type] m_[inport.name]; 531 InPort<[inport.type]> m_[inport.name]In; 535 """[for outport in dataPorts][if outport.portType is DataOutPort] 536 [outport.type] m_[outport.name]; 537 OutPort<[outport.type]> m_[outport.name]Out; 540 corbaport_declare = \
541 """[for corbaport in servicePorts] 542 RTC::CorbaPort m_[corbaport.name]Port; 546 """[for service in servicePorts][for interface in service.serviceInterface] 547 [if interface.direction is Provided] 548 [interface.type]SVC_impl m_[interface.name]; 553 """[for service in servicePorts][for interface in service.serviceInterface] 554 [if interface.direction is Required] 555 RTC::CorbaConsumer<[interface.type]> m_[interface.name]; 559 initializer =
""" : RTC::DataFlowComponentBase(manager)[if-any port_init], 560 [for port in port_init] 561 [if-any port.portType] 562 [if port.portType is DataInPort] 563 m_[port.name]In("[port.name]", m_[port.name])[if-index port is last][else],[endif] 566 [if port.portType is DataOutPort] 567 m_[port.name]Out("[port.name]", m_[port.name])[if-index port is last][else],[endif] 571 m_[port.name]Port("[port.name]")[if-index port is last][else],[endif] 579 """ // Set InPort buffers 580 [for inport in dataPorts][if inport.portType is DataInPort] 581 addInPort("[inport.name]", m_[inport.name]In); 584 // Set OutPort buffer 585 [for outport in dataPorts][if outport.portType is DataOutPort] 586 addOutPort("[outport.name]", m_[outport.name]Out); 589 // Set service provider to Ports 590 [for service in servicePorts][for interface in service.serviceInterface] 591 [if interface.direction is Provided] 592 m_[service.name]Port.registerProvider("[interface.name]", "[interface.type]", m_[interface.name]); 596 // Set service consumers to Ports 597 [for consumer in servicePorts][for interface in consumer.serviceInterface] 598 [if interface.direction is Required] 599 m_[consumer.name]Port.registerConsumer("[interface.name]", "[interface.type]", m_[interface.name]); 603 // Set CORBA Service Ports 604 [for corbaport in servicePorts] 605 addPort(m_[corbaport.name]Port); 609 """ // Bind variables and configuration variable 610 [for config in configurationSet.configuration] 611 bindParameter("[config.name]", m_[config.name], "[config.defaultValue]"); 623 impl_suffix =
"SVC_impl" 626 for opt, arg
in opts:
627 if opt.find(
"--svc-impl-suffix") == 0:
629 if opt.find(
"--svc-skel-suffix") == 0:
631 if opt.find(
"--svc-stub-suffix") == 0:
633 dict[
"impl_suffix"] = impl_suffix
634 dict[
"skel_suffix"] = skel_suffix
635 dict[
"stub_suffix"] = stub_suffix
638 for d
in dict[
"service_idl"]:
639 d[
"impl_basename"] = d[
"idl_basename"] + dict[
"impl_suffix"]
640 d[
"impl_h"] = d[
"impl_basename"] +
".h" 641 d[
"impl_cpp"] = d[
"impl_basename"] +
".cpp" 642 d[
"skel_basename"] = d[
"idl_basename"] + dict[
"skel_suffix"]
643 d[
"skel_h"] = d[
"skel_basename"] +
".h" 644 d[
"skel_cpp"] = d[
"skel_basename"] +
".cpp" 645 d[
"stub_suffix"] = dict[
"stub_suffix"]
646 d[
"stub_basename"] = d[
"idl_basename"] + dict[
"stub_suffix"]
647 d[
"stub_h"] = d[
"stub_basename"] +
".h" 648 d[
"stub_cpp"] = d[
"stub_basename"] +
".cpp" 652 for cons
in dict[
"consumer_idl"]:
654 for svc
in dict[
"service_idl"]:
655 if cons[
"idl_fname"] == svc[
"idl_fname"]:
659 tmp[
"skel_basename"] = tmp[
"idl_basename"] + \
661 tmp[
"skel_h"] = tmp[
"skel_basename"] +
".h" 662 tmp[
"skel_cpp"] = tmp[
"skel_basename"] +
".cpp" 663 tmp[
"stub_suffix"] = dict[
"stub_suffix"]
664 tmp[
"stub_basename"] = tmp[
"idl_basename"] + \
666 tmp[
"stub_h"] = tmp[
"stub_basename"] +
".h" 667 tmp[
"stub_cpp"] = tmp[
"stub_basename"] +
".cpp" 673 acts = ((
"onFinalize",
""), \
674 (
"onStartup",
"RTC::UniqueId ec_id"), \
675 (
"onShutdown",
"RTC::UniqueId ec_id"), \
676 (
"onActivated",
"RTC::UniqueId ec_id"), \
677 (
"onDeactivated",
"RTC::UniqueId ec_id"), \
678 (
"onExecute",
"RTC::UniqueId ec_id"), \
679 (
"onAborting",
"RTC::UniqueId ec_id"), \
680 (
"onError",
"RTC::UniqueId ec_id"), \
681 (
"onReset",
"RTC::UniqueId ec_id"), \
682 (
"onStateUpdate",
"RTC::UniqueId ec_id"), \
683 (
"onRateChanged",
"RTC::UniqueId ec_id"))
685 for name, args
in acts:
691 dict[
"activity"] = actlist
695 dict[
"port_init"] = []
696 for d
in dict[
"dataPorts"]:
697 dict[
"port_init"].
append(d)
698 for d
in dict[
"servicePorts"]:
699 dict[
"port_init"].
append(d)
700 if len(dict[
"port_init"]) == 0:
701 dict.pop(
"port_init")
706 C++ component source code generator 717 self.
data[
"rcs_date"] =
"$" +
"Date" +
"$" 718 self.
data[
"rcs_id"] =
"$" +
"Id" +
"$" 719 self.
data[
"fname"] = self.
data[
"basicInfo"][
"name"]
720 self.
data[
"fname_h"] = self.
data[
"fname"] +
".h" 721 self.
data[
"fname_cpp"] = self.
data[
"fname"] +
".cpp" 722 self.
data[
"fname_comp"] = self.
data[
"fname"] +
"Comp.cpp" 723 self.
data[
"makefile"] =
"Makefile." + self.
data[
"fname"]
724 self.
data[
"u_name"] = self.
data[
"fname"].upper()
725 self.
data[
"l_name"] = self.
data[
"fname"].lower()
728 self.
tags[
"service_impl_h"] = service_impl_h
729 self.
tags[
"consumer_stub_h"] = consumer_stub_h
730 self.
tags[
"module_spec"] = module_spec
731 self.
tags[
"config_declare"] = config_declare
732 self.
tags[
"inport_declare"] = inport_declare
733 self.
tags[
"outport_declare"] = outport_declare
734 self.
tags[
"corbaport_declare"] = corbaport_declare
735 self.
tags[
"service_declare"] = service_declare
736 self.
tags[
"consumer_declare"] = consumer_declare
737 self.
tags[
"initializer"] = initializer
738 self.
tags[
"registration"] = registration
739 self.
tags[
"bind_config"] = bind_config
747 Generate component class header 756 Generate component class source code 758 self.
gen(self.
data[
"fname_cpp"],
765 Generate component source code 767 self.
gen(self.
data[
"fname_comp"],
776 self.
gen(self.
data[
"makefile"],
781 Generate vcproj and sln 789 for svc_idl
in self.
data[
"service_idl"]:
794 if not os.access(svc_idl[
"idl_fname"], os.F_OK):
795 sys.stderr.write(
"Error: IDL file \"" \
796 + svc_idl[
"idl_fname"] \
801 fd_cpp, lines_cpp = \
804 sys.stderr.write(
"Cannot open file:" +
805 svc_idl[
"impl_h"] +
"\n")
808 sys.stderr.write(
"Cannot open file:" +
809 svc_idl[
"impl_cpp"] +
"\n")
811 if lines_h
or lines_cpp:
812 sys.stderr.write(
"Merge of service impl." +
813 "code is not supported.\n")
817 idl_include = self.
data[
"idl_include"]
818 impl_suffix = self.
data[
"impl_suffix"]
819 skel_suffix = self.
data[
"skel_suffix"]
827 + svc_idl[
"impl_h"] \
828 +
"\" was generated." 830 + svc_idl[
"impl_cpp"] \
831 +
"\" was generated." 833 sys.stderr.write(
"Generate error: " \
836 + svc_idl[
"impl_cpp"] +
"\n")
869 m = re.search(
"/\*.*\*/", l)
871 l = l.replace(m.group(),
"")
873 m = re.search(
".*\*/", l)
875 l = l.replace(m.group(),
"")
879 m = re.search(
"/\*.*$", l)
881 l = l.replace(m.group(),
"")
885 m = re.search(
"//.*$", l)
887 l = l.replace(m.group(),
"")
889 m = re.search(
"\s+$", l)
891 l = l.replace(m.group(),
"")
894 m = re.search(
"\S", l)
904 self.
lines = self.
lines.replace(
"\n",
"\\n\\\n")
906 self.
lines =
"static char* " + var_name \
907 +
" = \"\\\n" + self.
lines 908 self.
lines +=
"\";\n" 916 f = open(filename,
"w")
def CreateConsumerIDL(dict)
def erase_comments(self, lines)
def gen(self, fname, temp_txt, data, tags)
def make_chardata(self, var_name)
def check_overwrite(self, fname, wmode="w")
def CreateServiceIDL(dict)
def PortInitializer(dict)
def __init__(self, filename=None)
def __init__(self, data, opts)
void append(SDOPackage::NVList &dest, const SDOPackage::NVList &src)
Append an element to NVList.
def write_file(self, filename)
def CreateActivityFuncs(dict)
def open_file(self, filename)
def CreateSuffix(opts, dict)
def generate(idl_file, preproc_args, impl_suffix, skel_suffix="Skel", fd_h=None, fd_cpp=None)