comparison src/bridge/bridge_constructor/bridge_contructor.py @ 375:502489e17685

D-Bus constructor: add Constructors specific flags (--flags argument) dbus-xml constructor now as annotation flag to add Qt annotation usefull for the Qt frontend (bellaciao)
author Goffi <goffi@goffi.org>
date Mon, 08 Aug 2011 23:04:19 +0200
parents 193fd5995430
children aa2cd6639e00
comparison
equal deleted inserted replaced
374:193fd5995430 375:502489e17685
480 480
481 def __init__(self, bridge_template, options): 481 def __init__(self, bridge_template, options):
482 Constructor.__init__(self, bridge_template, options) 482 Constructor.__init__(self, bridge_template, options)
483 483
484 self.template="dbus_xml_template.xml" 484 self.template="dbus_xml_template.xml"
485 self.core_dest="org.goffi.sat.xml" 485 self.core_dest="org.goffi.sat.xml"
486 self.default_annotation = { 'a{ss}': 'StringDict',
487 'a(sa{ss}as)': 'QList<ContactT>',
488 'a{i(ss)}': 'HistoryT',
489 'a(sss)': 'QList<MenuT>',
490 'a{sa{s(sia{ss})}}': 'PresenceStatusT',
491 'a{sa{ss}}': 'ActionResultExtDataT',
492 }
486 493
487 def generateCoreSide(self): 494 def generateCoreSide(self):
488 try: 495 try:
489 doc = minidom.parse(self.template) 496 doc = minidom.parse(self.template)
490 interface_elt = doc.getElementsByTagName('interface')[0] 497 interface_elt = doc.getElementsByTagName('interface')[0]
508 args_doc = self.getArgumentsDoc(section) 515 args_doc = self.getArgumentsDoc(section)
509 for arg in self.argumentsParser(function['sig_in'] or ''): 516 for arg in self.argumentsParser(function['sig_in'] or ''):
510 arg_elt = doc.createElement('arg') 517 arg_elt = doc.createElement('arg')
511 arg_elt.setAttribute('name', args_doc[idx][0] if args_doc.has_key(idx) else "arg_%i" % idx) 518 arg_elt.setAttribute('name', args_doc[idx][0] if args_doc.has_key(idx) else "arg_%i" % idx)
512 arg_elt.setAttribute('type', arg) 519 arg_elt.setAttribute('type', arg)
513 arg_elt.setAttribute('direction', 'in' if function["type"]=='method' else 'out') 520 _direction = 'in' if function["type"]=='method' else 'out'
521 arg_elt.setAttribute('direction', _direction)
514 new_elt.appendChild(arg_elt) 522 new_elt.appendChild(arg_elt)
523 if "annotation" in self.options.flags:
524 if arg in self.default_annotation:
525 annot_elt = doc.createElement("annotation")
526 annot_elt.setAttribute('name', "com.trolltech.QtDBus.QtTypeName.In%d" % idx)
527 annot_elt.setAttribute('value', self.default_annotation[arg])
528 new_elt.appendChild(annot_elt)
515 idx+=1 529 idx+=1
516 530
517 if function['sig_out']: 531 if function['sig_out']:
518 arg_elt = doc.createElement('arg') 532 arg_elt = doc.createElement('arg')
519 arg_elt.setAttribute('type', function['sig_out']) 533 arg_elt.setAttribute('type', function['sig_out'])
520 arg_elt.setAttribute('direction', 'out') 534 arg_elt.setAttribute('direction', 'out')
521 new_elt.appendChild(arg_elt) 535 new_elt.appendChild(arg_elt)
536 if "annotation" in self.options.flags:
537 if function['sig_out'] in self.default_annotation:
538 annot_elt = doc.createElement("annotation")
539 annot_elt.setAttribute('name', "com.trolltech.QtDBus.QtTypeName.Out0")
540 annot_elt.setAttribute('value', self.default_annotation[function['sig_out']])
541 new_elt.appendChild(annot_elt)
522 542
523 interface_elt.appendChild(new_elt) 543 interface_elt.appendChild(new_elt)
524 544
525 #now we write to final file 545 #now we write to final file
526 self.finalWrite(self.core_dest, [doc.toprettyxml()]) 546 self.finalWrite(self.core_dest, [doc.toprettyxml()])
562 help=("Force overwritting of existing files")) 582 help=("Force overwritting of existing files"))
563 parser.add_option("-d", "--debug", action="store_true", default=False, 583 parser.add_option("-d", "--debug", action="store_true", default=False,
564 help=("Add debug information printing")) 584 help=("Add debug information printing"))
565 parser.add_option("--no_unicode", action="store_false", dest="unicode", default=True, 585 parser.add_option("--no_unicode", action="store_false", dest="unicode", default=True,
566 help=("Remove unicode type protection from string results")) 586 help=("Remove unicode type protection from string results"))
587 parser.add_option("--flags", action="store", type="string",
588 help=("Constructors' specific flags, comma separated"))
567 589
568 590
569 (self.options, args) = parser.parse_args() 591 (self.options, args) = parser.parse_args()
592 self.options.flags = self.options.flags.split(',') if self.options.flags else []
570 return args 593 return args
571 594
572 def go(self): 595 def go(self):
573 self.check_options() 596 self.check_options()
574 self.template = Parser() 597 self.template = Parser()