67 return "C++ component code generator" 71 C++ generator specific usage (short version) 74 Options for C++ backend: 76 [--svc-impl-suffix[=suffix]] Suffix of implementation class 77 [--svc-skel-suffix[=suffix]] Suffix of server skeleton files 78 [--svc-stub-suffix[=suffix]] Suffix of client stub files 83 C++ generator specific usage 86 ------------------------------- 87 Help for C++ code geenrator 88 ------------------------------- 89 --svc-impl-suffix=[Suffix]: 90 Specify the suffix for implementation class name. This suffix is also 91 used for implementation class header file and code file. 93 --svc-skel-suffix=[Suffix]: 94 Specify the suffix for server skeleton files. 96 --svc-stub-suffix=[Suffix]: 97 Specify the suffix for client stub files. 99 C++ code generator generates the following files. 100 [Component name].h.............Component class header 101 [Component name].cpp...........Component class soruce code 102 [Component name]Comp.cpp.......Component startup code 103 [IDL basename]Skel.h...........Server skeleton header 104 [IDL basename]Skel.cpp.........Server skeleton source code 105 [IDL basename]Stub.h...........Client stub header 106 [IDL basename]Stub.cpp.........Client stub source code 107 [IDL basename]SVC_impl.h.......Server implementation header 108 [IDL basename]SVC_impl.cpp.....Server implementation source code 109 Makefile.[Component name]......Makefile to compile this codes 110 README.[Component name]........Specification template of the component 112 Suffixes (Skel, Stub, SVC_impl) can be specified --svc-*-suffix option 114 Other CORBA implementation specific skeleton/stub code would be generated. 116 [IDL basename].hh..............Client stub header 117 [IDL basename]SK.cc............Server skeleton source code 118 [IDL basename]DynSK.cc.........Dynamic server skeleton source code 120 [IDL basename]S.h..............Server skeleton header 121 [IDL basename]S.h..............Server skeleton source code 122 [IDL basename]C.h..............Client stub header 123 [IDL basename]C.h..............Client stub source code 125 [IDL basename].h...............Server skeleton header 126 [IDL basename]_skel.cc.........Server skeleton source code 127 [IDL basename].h...............Client stub header 128 [IDL basename].cc..............Client stub source code 133 opt_args_fmt = [
"svc-impl-suffix=",
142 comp_header =
"""// -*- C++ -*- 145 * @brief [module.desc] 154 #include <rtm/Manager.h> 155 #include <rtm/DataFlowComponentBase.h> 156 #include <rtm/CorbaPort.h> 157 #include <rtm/DataInPort.h> 158 #include <rtm/DataOutPort.h> 159 #include <rtm/idl/BasicDataTypeSkel.h> 161 // Service implementation headers 162 // <rtc-template block="service_impl_h"> 165 // Service Consumer stub headers 166 // <rtc-template block="consumer_stub_h"> 172 : public RTC::DataFlowComponentBase 175 [module.name](RTC::Manager* manager); 178 // The initialize action (on CREATED->ALIVE transition) 179 // formaer rtc_init_entry() 180 virtual RTC::ReturnCode_t onInitialize(); 182 // The finalize action (on ALIVE->END transition) 183 // formaer rtc_exiting_entry() 184 // virtual RTC::ReturnCode_t onFinalize(); 186 // The startup action when ExecutionContext startup 187 // former rtc_starting_entry() 188 // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id); 190 // The shutdown action when ExecutionContext stop 191 // former rtc_stopping_entry() 192 // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id); 194 // The activated action (Active state entry action) 195 // former rtc_active_entry() 196 // virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id); 198 // The deactivated action (Active state exit action) 199 // former rtc_active_exit() 200 // virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id); 202 // The execution action that is invoked periodically 203 // former rtc_active_do() 204 // virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id); 206 // The aborting action when main logic error occurred. 207 // former rtc_aborting_entry() 208 // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id); 210 // The error action in ERROR state 211 // former rtc_error_do() 212 // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id); 214 // The reset action that is invoked resetting 215 // This is same but different the former rtc_init_entry() 216 // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id); 218 // The state update action that is invoked after onExecute() action 219 // no corresponding operation exists in OpenRTm-aist-0.2.0 220 // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id); 222 // The action that is invoked when execution context's rate is changed 223 // no corresponding operation exists in OpenRTm-aist-0.2.0 224 // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id); 228 // Configuration variable declaration 229 // <rtc-template block="config_declare"> 232 // DataInPort declaration 233 // <rtc-template block="inport_declare"> 236 // DataOutPort declaration 237 // <rtc-template block="outport_declare"> 240 // CORBA Port declaration 241 // <rtc-template block="corbaport_declare"> 244 // Service declaration 245 // <rtc-template block="service_declare"> 248 // Consumer declaration 249 // <rtc-template block="consumer_declare"> 260 void [module.name]Init(RTC::Manager* manager); 270 comp_soruce =
"""// -*- C++ -*- 273 * @brief [module.desc] 281 // Module specification 282 // <rtc-template block="module_spec"> 285 [module.name]::[module.name](RTC::Manager* manager) 286 : RTC::DataFlowComponentBase(manager), 287 // <rtc-template block="initializer"> 291 // Registration: InPort/OutPort/Service 292 // <rtc-template block="registration"> 297 [module.name]::~[module.name]() 302 RTC::ReturnCode_t [module.name]::onInitialize() 304 // <rtc-template block="bind_config"> 312 RTC::ReturnCode_t [module.name]::[activity.name]([activity.args]) 323 void [module.name]Init(RTC::Manager* manager) 325 RTC::Properties profile([l_name]_spec); 326 manager->registerFactory(profile, 327 RTC::Create<[module.name]>, 328 RTC::Delete<[module.name]>); 340 comp_compsrc =
"""// -*- C++ -*- 342 * @file [module.name]Comp.cpp 343 * @brief Standalone component 349 #include <rtm/Manager.h> 355 void MyModuleInit(RTC::Manager* manager) 357 [module.name]Init(manager); 360 // Create a component 361 comp = manager->createComponent("[module.name]"); 365 // The following procedure is examples how handle RT-Components. 366 // These should not be in this function. 368 // Get the component's object reference 369 // RTC::RTObject_var rtobj; 370 // rtobj = RTC::RTObject::_narrow(manager->getPOA()->servant_to_reference(comp)); 372 // Get the port list of the component 373 // PortList* portlist; 374 // portlist = rtobj->get_ports(); 376 // getting port profiles 377 // std::cout << "Number of Ports: "; 378 // std::cout << portlist->length() << std::endl << std::endl; 379 // for (CORBA::ULong i(0), n(portlist->length()); i < n; ++i) 382 // port = (*portlist)[begin_brace]i[end_brace]; 383 // std::cout << "Port" << i << " (name): "; 384 // std::cout << port->get_port_profile()->name << std::endl; 386 // RTC::PortInterfaceProfileList iflist; 387 // iflist = port->get_port_profile()->interfaces; 388 // std::cout << "---interfaces---" << std::endl; 389 // for (CORBA::ULong i(0), n(iflist.length()); i < n; ++i) 391 // std::cout << "I/F name: "; 392 // std::cout << iflist[begin_brace]i[end_brace].instance_name << std::endl; 393 // std::cout << "I/F type: "; 394 // std::cout << iflist[begin_brace]i[end_brace].type_name << std::endl; 396 // pol = iflist[begin_brace]i[end_brace].polarity == 0 ? "PROVIDED" : "REQUIRED"; 397 // std::cout << "Polarity: " << pol << std::endl; 399 // std::cout << "---properties---" << std::endl; 400 // NVUtil::dump(port->get_port_profile()->properties); 401 // std::cout << "----------------" << std::endl << std::endl; 407 int main (int argc, char** argv) 409 RTC::Manager* manager; 410 manager = RTC::Manager::init(argc, argv); 412 // Initialize manager 413 manager->init(argc, argv); 415 // Set module initialization proceduer 416 // This procedure will be invoked in activateManager() function. 417 manager->setModuleInitProc(MyModuleInit); 419 // Activate manager and register to naming service 420 manager->activateManager(); 422 // run the manager in blocking mode 423 // runManager(false) is the default. 424 manager->runManager(); 426 // If you want to run the manager in non-blocking mode, do like this 427 // manager->runManager(true); 437 makefile =
"""# -*- Makefile -*- 439 # @file Makefile.[module.name] 440 # @brief RTComponent makefile for "[module.name] component" 443 # This file is generated by rtc-template with the following argments. 445 [for fmtd_args]# [fmtd_args] 450 CXXFLAGS = `rtm-config --cflags` 451 LDFLAGS = `rtm-config --libs` 454 IDLC = `rtm-config --idlc` 455 IDLFLAGS = `rtm-config --idlflags` -I`rtm-config --prefix`/include/rtm/idl 456 WRAPPER = rtm-skelwrapper 457 WRAPPER_FLAGS = --include-dir="" --skel-suffix=Skel --stub-suffix=Stub 459 SKEL_OBJ = [for service_idl][service_idl.skel_basename].o [end] \ 460 [for consumer_idl][consumer_idl.stub_basename].o [end] 461 STUB_OBJ = [for service_idl][service_idl.stub_basename].o [end] 462 IMPL_OBJ = [for service_idl][service_idl.impl_basename].o [end] 463 OBJS = [module.name].o $(SKEL_OBJ) $(IMPL_OBJ) 467 all: [module.name].so [module.name]Comp 472 $(CXX) $(CXXFLAGS) -c -o $@ $< 476 $(CXX) $(SHFLAGS) -o $@ $(OBJS) $(LDFLAGS) 478 [module.name]Comp: [module.name]Comp.o $(OBJS) 479 $(CXX) -o $@ $(OBJS) [module.name]Comp.o $(LDFLAGS) 482 clean: clean_objs clean_skelstub 486 rm -f $(OBJS) [module.name]Comp.o [module.name].so [module.name]Comp 489 rm -f *[skel_suffix].h *[skel_suffix].cpp 490 rm -f *[stub_suffix].h *[stub_suffix].cpp 495 [service_idl.skel_basename].cpp : [service_idl.idl_fname] 496 $(IDLC) $(IDLFLAGS) [service_idl.idl_fname] 497 $(WRAPPER) $(WRAPPER_FLAGS) --idl-file=[service_idl.idl_fname] 498 [service_idl.skel_basename].h : [service_idl.idl_fname] 499 $(IDLC) $(IDLFLAGS) [service_idl.idl_fname] 500 $(WRAPPER) $(WRAPPER_FLAGS) --idl-file=[service_idl.idl_fname] 501 [service_idl.stub_basename].cpp : [service_idl.idl_fname] 502 $(IDLC) $(IDLFLAGS) [service_idl.idl_fname] 503 $(WRAPPER) $(WRAPPER_FLAGS) --idl-file=[service_idl.idl_fname] 504 [service_idl.stub_basename].h : [service_idl.idl_fname] 505 $(IDLC) $(IDLFLAGS) [service_idl.idl_fname] 506 $(WRAPPER) $(WRAPPER_FLAGS) --idl-file=[service_idl.idl_fname] 510 [consumer_idl.stub_basename].cpp : [consumer_idl.idl_fname] 511 $(IDLC) $(IDLFLAGS) [consumer_idl.idl_fname] 512 $(WRAPPER) $(WRAPPER_FLAGS) --idl-file=[consumer_idl.idl_fname] 513 [consumer_idl.stub_basename].h : [consumer_idl.idl_fname] 514 $(IDLC) $(IDLFLAGS) [consumer_idl.idl_fname] 515 $(WRAPPER) $(WRAPPER_FLAGS) --idl-file=[consumer_idl.idl_fname] 519 [module.name].so: $(OBJS) 520 [module.name].o: [module.name].h \ 521 [for service_idl][service_idl.skel_basename].h [service_idl.impl_basename].h [end] \ 522 [for consumer_idl][consumer_idl.stub_basename].h [end] 523 [module.name]Comp.o: [module.name]Comp.cpp [module.name].cpp [module.name].h [for service_idl][service_idl.skel_basename].h [service_idl.impl_basename].h [end] 526 [service_idl.impl_basename].o: [service_idl.impl_basename].cpp [service_idl.impl_basename].h [service_idl.skel_basename].h [service_idl.stub_basename].h 527 [service_idl.skel_basename].o: [service_idl.skel_basename].cpp [service_idl.skel_basename].h [service_idl.stub_basename].h 528 [service_idl.stub_basename].o: [service_idl.stub_basename].cpp [service_idl.stub_basename].h 532 [consumer_idl.stub_basename].o: [consumer_idl.stub_basename].cpp [consumer_idl.stub_basename].h 542 service_impl_h =
"""[for service_idl]#include "[service_idl.impl_h]" 544 consumer_stub_h =
"""[for consumer_idl]#include "[consumer_idl.stub_h]" 547 module_spec =
"""static const char* [l_name]_spec[] = 549 "implementation_id", "[module.name]", 550 "type_name", "[module.name]", 551 "description", "[module.desc]", 552 "version", "[module.version]", 553 "vendor", "[module.vendor]", 554 "category", "[module.category]", 555 "activity_type", "[module.comp_type]", 556 "max_instance", "[module.max_inst]", 558 "lang_type", "compile", 559 // Configuration variables 560 [for config] "conf.default.[config.name]", "[config.default]", 566 """ [for config][config.type] m_[config.name]; 571 """ [for inport][inport.type] m_[inport.name]; 572 InPort<[inport.type]> m_[inport.name]In; 576 """ [for outport][outport.type] m_[outport.name]; 577 OutPort<[outport.type]> m_[outport.name]Out; 580 corbaport_declare = \
581 """ [for corbaport]RTC::CorbaPort m_[corbaport.name]Port; 585 """ [for service][service.type]SVC_impl m_[service.name]; 589 """ [for consumer]RTC::CorbaConsumer<[consumer.type]> m_[consumer.name]; 593 """ [for inport]m_[inport.name]In("[inport.name]", m_[inport.name]), 594 [end][for outport]m_[outport.name]Out("[outport.name]", m_[outport.name]), 595 [end][for corbaport]m_[corbaport.name]Port("[corbaport.name]"),[end]""" 599 """ // Set InPort buffers 600 [for inport]registerInPort("[inport.name]", m_[inport.name]In); 602 // Set OutPort buffer 603 [for outport]registerOutPort("[outport.name]", m_[outport.name]Out); 605 // Set service provider to Ports 606 [for service]m_[service.port]Port.registerProvider("[service.name]", "[service.type]", m_[service.name]); 608 // Set service consumers to Ports 609 [for consumer]m_[consumer.port]Port.registerConsumer("[consumer.name]", "[consumer.type]", m_[consumer.name]); 611 // Set CORBA Service Ports 612 [for corbaport]registerPort(m_[corbaport.name]Port); 616 """ // Bind variables and configuration variable 617 [for config]bindParameter("[config.name]", m_[config.name], "[config.default]"); 633 impl_suffix =
"SVC_impl" 636 for opt, arg
in opts:
637 if opt.find(
"--svc-impl-suffix") == 0:
639 if opt.find(
"--svc-skel-suffix") == 0:
641 if opt.find(
"--svc-stub-suffix") == 0:
643 dict[
"impl_suffix"] = impl_suffix
644 dict[
"skel_suffix"] = skel_suffix
645 dict[
"stub_suffix"] = stub_suffix
649 for d
in dict[
"service_idl"]:
650 d.impl_basename = d.idl_basename + dict[
"impl_suffix"]
651 d.impl_h = d.impl_basename +
".h" 652 d.impl_cpp = d.impl_basename +
".cpp" 653 d.skel_basename = d.idl_basename + dict[
"skel_suffix"]
654 d.skel_h = d.skel_basename +
".h" 655 d.skel_cpp = d.skel_basename +
".cpp" 656 d.stub_suffix = dict[
"stub_suffix"]
657 d.stub_basename = d.idl_basename + dict[
"stub_suffix"]
658 d.stub_h = d.stub_basename +
".h" 659 d.stub_cpp = d.stub_basename +
".cpp" 664 for cons
in dict[
"consumer_idl"]:
666 for svc
in dict[
"service_idl"]:
667 if cons.idl_fname == svc.idl_fname:
671 tmp.stub_suffix = dict[
"stub_suffix"]
672 tmp.stub_basename = tmp.idl_basename \
673 + dict[
"stub_suffix"]
674 tmp.stub_h = tmp.stub_basename +
".h" 675 tmp.stub_cpp = tmp.stub_basename +
".cpp" 677 dict[
"consumer_idl"] = conslist
681 acts = ((
"onFinalize",
""), \
682 (
"onStartup",
"RTC::UniqueId ec_id"), \
683 (
"onShutdown",
"RTC::UniqueId ec_id"), \
684 (
"onActivated",
"RTC::UniqueId ec_id"), \
685 (
"onDeactivated",
"RTC::UniqueId ec_id"), \
686 (
"onExecute",
"RTC::UniqueId ec_id"), \
687 (
"onAborting",
"RTC::UniqueId ec_id"), \
688 (
"onError",
"RTC::UniqueId ec_id"), \
689 (
"onReset",
"RTC::UniqueId ec_id"), \
690 (
"onStateUpdate",
"RTC::UniqueId ec_id"), \
691 (
"onRateChanged",
"RTC::UniqueId ec_id"))
693 for name, args
in acts:
699 dict[
"activity"] = actlist
704 C++ component source code generator 714 self.
data[
"begin_brace"] =
"[" 715 self.
data[
"end_brace"] =
"]" 716 self.
data[
"rcs_date"] =
"$" +
"Date" +
"$" 717 self.
data[
"rcs_id"] =
"$" +
"Id" +
"$" 718 self.
data[
"fname_h"] = self.
data[
"fname"] +
".h" 719 self.
data[
"fname_cpp"] = self.
data[
"fname"] +
".cpp" 720 self.
data[
"fname_comp"] = self.
data[
"fname"] +
"Comp.cpp" 721 self.
data[
"makefile"] =
"Makefile." + self.
data[
"fname"]
722 self.
data[
"u_name"] = self.
data[
"module"].name.upper()
723 self.
data[
"l_name"] = self.
data[
"module"].name.lower()
727 self.
tags[
"service_impl_h"] = service_impl_h
728 self.
tags[
"consumer_stub_h"] = consumer_stub_h
729 self.
tags[
"module_spec"] = module_spec
730 self.
tags[
"config_declare"] = config_declare
731 self.
tags[
"inport_declare"] = inport_declare
732 self.
tags[
"outport_declare"] = outport_declare
733 self.
tags[
"corbaport_declare"] = corbaport_declare
734 self.
tags[
"service_declare"] = service_declare
735 self.
tags[
"consumer_declare"] = consumer_declare
736 self.
tags[
"initializer"] = initializer
737 self.
tags[
"registration"] = registration
738 self.
tags[
"bind_config"] = bind_config
746 Generate component class header 755 Generate component class source code 757 self.
gen(self.
data[
"fname_cpp"],
764 Generate component source code 766 self.
gen(self.
data[
"fname_comp"],
775 self.
gen(self.
data[
"makefile"],
780 for svc_idl
in self.
data[
"service_idl"]:
785 if not os.access(svc_idl.idl_fname, os.F_OK):
786 sys.stderr.write(
"Error: IDL file \"" \
787 + svc_idl.idl_fname \
792 fd_cpp, lines_cpp = \
795 sys.stderr.write(
"Cannot open file:" +
796 svc_idl.impl_h +
"\n")
799 sys.stderr.write(
"Cannot open file:" +
800 svc_idl.impl_cpp +
"\n")
802 if lines_h
or lines_cpp:
803 sys.stderr.write(
"Merge of service impl." +
804 "code is not supported.\n")
808 idl_include = self.
data[
"idl_include"]
809 impl_suffix = self.
data[
"impl_suffix"]
810 skel_suffix = self.
data[
"skel_suffix"]
812 ifs = cxx_svc_impl.generate(svc_idl.idl_fname,
819 +
"\" was generated." 822 +
"\" was generated." 824 sys.stderr.write(
"Generate error: " \
827 + svc_idl.impl_cpp +
"\n")
859 m = re.search(
"/\*.*\*/", l)
861 l = l.replace(m.group(),
"")
863 m = re.search(
".*\*/", l)
865 l = l.replace(m.group(),
"")
869 m = re.search(
"/\*.*$", l)
871 l = l.replace(m.group(),
"")
875 m = re.search(
"//.*$", l)
877 l = l.replace(m.group(),
"")
879 m = re.search(
"\s+$", l)
881 l = l.replace(m.group(),
"")
884 m = re.search(
"\S", l)
894 self.
lines = self.lines.replace(
"\n",
"\\n\\\n")
895 self.
lines = self.lines.replace(
"\"",
"\\\"")
896 self.
lines =
"static char* " + var_name \
897 +
" = \"\\\n" + self.
lines 898 self.
lines +=
"\";\n" 902 self.
lines = self.lines.replace(
"\n",
"\\\n")
906 f = open(filename,
"w")
def erase_comments(self, lines)
def MakeConsumerIDL(dict)
def __init__(self, filename=None)
def open_file(self, filename)
def write_file(self, filename)
def MakeActivityFuncs(dict)
def make_chardata(self, var_name)
def gen(self, fname, temp_txt, data, tags)
def MakeSuffix(opts, dict)
def check_overwrite(self, fname)
def __init__(self, data, opts)