29 id: # RTC:SampleVendor.SampleCategory.SampleComponent:1.0.0
37 activityType: PERIODIC
38 componentKind: DataFlowComponent
42 executionType: PeriodicExecutionContext
64 "rtcExt::versionUpLog":
65 - "2008/04/18 14:00:00:Ver1.0"
66 - "2008/04/18 17:00:00:Ver1.1"
74 description: on_aborting description
75 postCondition: on_aborting Post_condition
76 preCondition: on_aborting Pre_condition
80 description: on_activated description
81 postCondition: on_activated Post_condition
82 preCondition: on_activated Pre_condition
86 description: on_deactivated description
87 postCondition: on_deactivated Post_condition
88 preCondition: on_deactivated Pre_condition
91 description: on_error description
92 postCondition: on_error Post_condition
93 preCondition: on_error Pre_condition
96 description: on_execute description
97 postCondition: on_execute Post_condition
98 preCondition: on_execute Pre_condition
101 description: on_finalize description
102 postCondition: on_finalize Post_condition
103 preCondition: on_finalize Pre_condition
106 description: on_initialize description
107 postCondition: on_initialize Post_condition
108 preCondition: on_initialize Pre_condition
112 description: on_rate_changed description
113 postCondition: on_rate_changed Post_condition
114 preCondition: on_rate_changed Pre_condition
117 description: on_reset description
118 postCondition: on_reset Post_condition
119 preCondition: on_reset Pre_condition
122 description: on_shutdown description
123 postCondition: on_shutdown Post_condition
124 preCondition: on_shutdown Pre_condition
128 description: on_startup description
129 postCondition: on_startup Post_condition
130 preCondition: on_startup Pre_condition
133 description: on_state_update description
134 postCondition: on_state_update Post_condition
135 preCondition: on_state_update Pre_condition
140 type: "RTC::TimedLong"
141 interfaceType: CorbaPort
142 dataflowType: "Push,Pull"
143 subscriprionType: "Periodic,New,Flush"
144 idlFile: DataPort1.idl
147 description: In1Description
149 occerrence: In1Occerrence
150 operation: In1Operation
151 semantics: In1Semantics
153 "rtcExt::position": LEFT
154 "rtcExt::varname": In1Var
159 description: ServicePort1 description
160 ifdescription: ServicePort1 I/F description
161 "rtcExt::position": LEFT
166 description: if1 Description
167 docArgument: if1 Argument
168 docException: if1 Exception
169 docPostCondition: if1 PostCond
170 docPreCondition: if1 PreCond
171 docReturn: if1 Return
172 idlFile: IF1Idlfile.idl
173 instanceName: IF1Instance
186 constraint: config_constraint1
188 defaultValue: default1
189 description: config_Desc1
194 defaultValue: param_def1
197 defaultValue: param_def2
207 libdir_path = os.popen(
"rtm-config --libdir",
"r").read().split(
"\n")
208 if libdir_path[0] !=
'':
209 pyhelper_path = libdir_path[0] +
"/py_helper"
210 sys.path.append(pyhelper_path)
212 pyhelper_path = os.environ[
'RTM_ROOT'] +
"/utils/rtc-template"
213 sys.path.append(pyhelper_path)
216 opt_args_fmt = [
"help",
243 Usage: rtc-template [OPTIONS]
247 [-h] Print short help.
248 [--help] Print details help.
249 [--backend[=backend] or -b] Specify template code generator.
250 [--module-name[=name]] Your module name.
251 [--module-desc[=description]] Module description.
252 [--module-version[=version]] Module version.
253 [--module-vendor[=vendor]] Module vendor.
254 [--module-category[=category]] Module category.
255 [--module-comp-type[=component_type]] Component type.
256 [--module-act-type[=activity_type]] Component's activity type.
257 [--module-max-inst[=max_instance]] Number of maximum instance.
258 [--module-lang[=language]] Language.
259 [--config[=ParamName:Type:Default]] Configuration variable.
260 [--inport[=PortName:Type]] InPort's name and type.
261 [--outport[=PortName:Type]] OutPort's name and type
262 [--service[=PortName:Name:Type]] Service Provider Port
263 [--service-idl[=IDL_file]] IDL file name for service
264 [--consumer[=PortName:Name:Type]] Service Consumer Port
265 [--consumer-idl[=IDL_file]] IDL file name for consumer
266 [--idl-include=[path]] Search path for IDL compile
274 --output[=output_file]:
275 Specify base name of output file. If 'XXX' is specified,
276 C++ source codes XXX.cpp, XXX.h, XXXComp.cpp Makefile.XXX is generated.
278 --module-name[=name]:
279 Your component's base name. This string is used as module's
280 name and component's base name. A generated new component
281 class name is also names as this RTC_MODULE_NAME.
282 Only alphabetical and numerical characters are acceptable.
284 --module-desc[=description]:
285 Short description. If space characters are included, string should be
288 --module-version[=version]:
289 Your module version. ex. 1.0.0
291 --module-vendor[=vendor]:
292 Vendor's name of this component.
294 --module-category[=category]:
295 This component module's category. ex. Manipulator MobileRobot, etc...
297 --module-comp-type[=component_type]:
298 Specify component type.
299 'STATIC', 'UNIQUE', 'COMMUTATIVE' are acceptable.
301 --module-act-type[=activity_type]:
302 Specify component activity's type.
303 'PERIODIC', 'SPORADIC', 'EVENT_DRIVEN' ace acceptable.
305 --module-max-inst[=max_instance]:
306 Specify maximum number of component instance.
308 --config=[ParamName:Type:Default]:
309 Specify configuration value. The 'ParamName' is used as the
310 configuration value identifier. This character string is also used as
311 variable name in the source code. The 'Type' is type of configuration
312 value. The type that can be converted to character string is allowed.
313 In C++ language, the type should have operators '<<' and '>>' that
315 'istream& operator<<(Type)'
317 'ostream& operator>>(Type)'.
319 --inport=[PortName:Type]:
320 Specify InPort's name and type. 'PortName' is used as this InPort's
321 name. This string is also used as variable name in soruce code.
322 'Type' is InPort's variable type. The acceptable types are,
323 Timed[ Short | Long | UShort | ULong | Float | Double | Char | Boolean
324 | Octet | String ] and its sequence types.
326 --outport=[PortName:Type]:
327 Specify OutPort's name and type. 'PortName' is used as this OutPort's
328 name. This string is also used as variable name in soruce code.
329 'Type' is OutPort's variable type. The acceptable types are,
330 Timed[ Short | Long | UShort | ULong | Float | Double | Char | Boolean
331 | Octet | String ] and its sequence types.
333 --service=[PortName:Name:Type]:
334 Specify service name, type and port name.
335 PortName: The name of Port to which the interface belongs.
336 This name is used as CorbaPort's name.
337 Name: The name of the service interface. This name is used as
338 the name of the interface, instance name and variable name.
339 Type: The type of the serivce interface.
340 This name is used as type name of the service.
342 --service-idl=[IDL filename]:
343 Specify IDL file of service interface.
344 For simplicity, please define one interface in one IDL file, although
345 this IDL file can include two or more interface definition,
347 --consumer=[PortName:Name:Type]:
348 Specify consumer name, type and port name.
349 PortName: The name of Port to which the consumer belongs.
350 This name is used as CorbaPort's name.
351 Name: The name of the consumer. This name is used as
352 the name of the consumer, instance name and variable name.
353 Type: The serivce interface type that is required by the consumer.
354 This name is used as type name of the consumer.
356 --consumer-idl=[IDL filename]:
357 Specify IDL file of service consumer.
358 For simplicity, please define one interface in one IDL file, although
359 this IDL file can include two or more interface definition,
363 rtc-template -bcxx \\
364 --module-name=Sample --module-desc='Sample component' \\
365 --module-version=0.1 --module-vendor=AIST --module-category=Generic \\
366 --module-comp-type=DataFlowComponent --module-act-type=SPORADIC \\
367 --module-max-inst=10 \\
368 --config=int_param0:int:0 --config=int_param1:int:1 \\
369 --config=double_param0:double:3.14 --config=double_param1:double:9.99 \\
370 --config="str_param0:std::string:hoge" \\
371 --config="str_param1:std::string:foo" \\
372 --inport=Ref:TimedFloat --inport=Sens:TimedFloat \\
373 --outport=Ctrl:TimedDouble --outport=Monitor:TimedShort \\
374 --service=MySvcPort:myservice0:MyService \\
375 --consumer=YourSvcPort:yourservice0:YourService \\
376 --service-idl=MyService.idl --consumer-idl=YourService.idl
391 Create ModuleProfile list from command options
395 'desc':
'description',
396 'version':
'version',
398 'category':
'category',
399 'comp-type':
'componentType',
400 'act-type':
'activityType',
401 'type':
'componentKind',
402 'max-inst':
'maxInstances'
411 "componentType":
"STATIC",
412 "activityType":
"PERIODIC",
413 "componentKind":
"DataFlowComponent",
416 "executionRate":
"1000.0",
417 "executionType":
"PeriodicExecutionContext",
445 "rtcExt::versionUpLog": []
449 for opt, arg
in opts:
450 if opt.find(
"--module-") == 0:
451 var = opt.replace(
"--module-",
"")
452 if mapping[var]
in prof:
453 prof[mapping[var]] = arg
455 cDate = time.localtime()
457 cDateKey = [
'year',
'month',
'day',
'hour',
'minute',
'second']
459 prof[
"creationDate"][key] = cDate[i]
463 for key
in prof.keys():
489 "description": a +
" description",
490 "postCondition": a +
" Post_condition",
491 "preCondition": a +
" Pre_condition"
499 MakeConfigurationParameters
501 Create Configuration list from command options
512 "constraint":
"constraint",
513 "dataname":
"dataname",
514 "defaultValue":
"default",
515 "description":
"description",
520 for opt, arg
in opts:
521 if opt == (
"--config"):
524 arg = re.sub(
"::",
"@@", arg)
525 name, type, default = arg.split(
":")
526 name = re.sub(
"@@",
"::", name)
527 type = re.sub(
"@@",
"::", type)
528 default = re.sub(
"@@",
"::", default)
530 sys.stderr.write(
"Invalid option: " \
534 tmp = copy.deepcopy(prof)
536 tmp[
"varname"] = name
537 tmp[
"l_name"] = name.lower()
538 tmp[
"u_name"] = name.upper()
540 tmp[
"defaultValue"] = default
541 tmp[
"rtcDoc::doc"][
"defaultValue"] = default
542 prof_list.append(tmp)
543 return {
'configuration': prof_list}
550 Create PortProfile list from command options
557 "interfaceType":
"CorbaPort",
558 "dataflowType":
"Push,Pull",
559 "subscriptionType":
"Periodic,New,Flush",
571 "rtcExt::position":
"",
572 "rtcExt::varname":
""
575 portType = {
"--inport":
"DataInPort",
"--outport":
"DataOutPort"}
576 position = {
"--inport":
"LEFT",
"--outport":
"RIGHT"}
577 for opt, arg
in opts:
578 if opt ==
"--inport" or opt ==
"--outport":
580 arg = re.sub(
"::",
"@@", arg)
581 name, type = arg.split(
":")
582 name = re.sub(
"@@",
"::", name)
583 type = re.sub(
"@@",
"::", type)
585 sys.stderr.write(
"Invalid option: " \
589 tmp = copy.deepcopy(prof)
591 tmp[
"portType"] = portType[opt]
594 tmp[
"rtcDoc::doc"][
"type"] = type
595 tmp[
"rtcDoc::doc"][
"number"] = cnt
596 tmp[
"rtcExt::varname"] = name
597 tmp[
"rtcExt::position"] = position[opt]
598 prof_list.append(tmp)
607 Create Port interface profile list from command options
618 "rtcExt::position":
"LEFT",
619 "serviceInterface": []
634 "docPostCondition":
"",
635 "docPreCondition":
"",
640 def findport(prof_list, port_name):
642 if p[
"name"] == port_name:
646 cnt = {
"Provided": 0,
"Required": 0}
647 for ifprof
in port[
"serviceInterface"]:
648 cnt[ifprof[
"direction"]] += 1
649 if cnt[
"Provided"] < cnt[
"Required"]:
654 ifType = {
"--service":
"Provided",
"--consumer":
"Required"}
655 for opt, arg
in opts:
656 if opt ==
"--service" or opt ==
"--consumer":
658 arg = re.sub(
"::",
"@@", arg)
659 portname, name, type = arg.split(
":")
660 portname = re.sub(
"@@",
"::", portname)
661 name = re.sub(
"@@",
"::", name)
662 type = re.sub(
"@@",
"::", type)
664 sys.stderr.write(
"Invalid option: " \
668 port = findport(prof_list, portname)
670 port = copy.deepcopy(prof)
671 port[
"name"] = portname
672 prof_list.append(port)
674 tmp = copy.deepcopy(ifprof)
677 tmp[
"direction"] = ifType[opt]
678 tmp[
"varname"] = name
679 tmp[
"instanceName"] = name
683 print(
"IDL file not found for a interface: ", type)
685 tmp[
"idlFile"] = idlfname
686 port[
"serviceInterface"].append(tmp)
687 port[
"rtcExt::position"] = lr(port)
693 _re_text =
"interface\s+" + ifname
694 for opt, arg
in opts:
695 if opt ==
"--service-idl" or opt ==
"--consumer-idl":
697 fd = open(fname,
"r")
699 print(
"IDL file not found: ", arg)
702 if None != re.compile(_re_text).search(t):
711 for svc
in dict[
"servicePorts"]:
712 for sif
in svc[
"serviceInterface"]:
713 if sif[
"direction"] ==
"Provided":
714 svcidls[sif[
"idlFile"]] =
""
715 elif sif[
"direction"] ==
"Required":
716 if sif[
"idlFile"]
not in svcidls:
717 cnsidls[sif[
"idlFile"]] =
""
718 dict[
"service_idl"] = []
719 dict[
"consumer_idl"] = []
720 for f
in svcidls.keys():
723 idl[
"idl_basename"] = f.split(
".")[0]
724 dict[
"service_idl"].append(idl)
725 for f
in cnsidls.keys():
728 idl[
"idl_basename"] = f.split(
".")[0]
729 dict[
"consumer_idl"].append(idl)
733 dict[
"id"] =
"RTC:" + \
734 dict[
"basicInfo"][
"vendor"] +
"." + \
735 dict[
"basicInfo"][
"category"] +
"." + \
736 dict[
"basicInfo"][
"name"] +
":" + \
737 dict[
"basicInfo"][
"version"]
740 for opt, arg
in opts:
741 if opt.find(value) == 0:
751 for opt, arg
in opts:
752 if opt == (
"--" + value):
760 self.
obj = getattr(mod, mod_name)
773 path_list = [pyhelper_path,
"."]
774 for path
in path_list:
775 for f
in os.listdir(path):
776 if re.compile(
"_gen.py$").search(f):
777 mod_name = f.replace(
".py",
"")
778 opt_name = f.replace(
"_gen.py",
"")
779 mod = __import__(mod_name, globals(), locals(), [])
792 if opt.find(
'-b') == 0:
793 backend_name = opt.replace(
"-b",
"")
795 self.
opts.append(backend_name)
797 print(
"No such backend: ", backend_name)
799 elif opt.find(
'--backend=') == 0:
800 backend_name = opt.replace(
"--backend=",
"")
802 self.
opts.append(backend_name)
804 print(
"No such backend: ", backend_name)
812 fmts += self.
backends[be].mod.get_opt_fmt()
817 print(
"The following backends are available.")
820 desc = self.
backends[key].mod.description()
821 print(
" -b" + key + (
"." * (space - len(key))) + desc)
823 Backend [xxx] specific help can be available by the following options.
824 -bxxx --help|-h or --backend=xxx --help|-h
831 print(self.
backends[be].mod.usage())
837 print(self.
backends[be].mod.usage_short())
858 arg_fmt[line] += a +
" "
867 backends.check_args(sys.argv[1:])
868 opt_args_fmt += backends.get_opt_fmts()
871 opts, args = getopt.getopt(sys.argv[1:],
"b:ho:v", opt_args_fmt)
872 except getopt.GetoptError:
873 print(
"Error: Invalid option.", getopt.GetoptError)
875 backends.usage_available()
880 backends.usage_available()
886 output_python =
False
893 backends.usage_available()
894 backends.usage_short()
898 backends.usage_available()
901 if o
in (
"-o",
"--output"):
905 prefix = os.popen(
"rtm-config --prefix",
"r").read().split(
"\n")
908 idl_inc.append(prefix[0] +
"/include/rtm/idl")
909 idl_inc.append(prefix[0] +
"/include/rtm")
920 'idl_include': idl_inc
925 if 'fname' not in data:
926 data[
'fname'] = data[
'basicInfo'][
'name']
927 backends.generate_code(data, opts)
930 readme = README_gen.README_gen(data)
933 profile = profile_gen.profile_gen(data)
938 if __name__ ==
"__main__":