'unsigned long': 'double',
'unsigned long long': 'double',
'float':'double',
- 'double':'double'}
+ 'double':'double'
+ }
class IndentPrintable(object):
def __init__(self, isIndent=True, tabstep=2, ignoreLF=False):
self.ctx['activeObjects'] = set()
self.ctx['implementOperations'] = dict()
self.ctx['exportedInterface'] = []
- self.ctx['Tizen'] = []
- self.ctx['Window'] = []
+ #self.ctx['Tizen'] = []
+ #self.ctx['Window'] = []
self.ctx['cmdtable'] = dict()
self.ctx['exportModule'] = module
while self.q.qsize()>0:
self.prepareX(self.q.get())
- for m in self.tree:
+ for m in [m for m in self.tree if m.name.lower() == module.lower()]:
for iface in m.getTypes('Interface'):
- #if iface.inherit in [x.name for x in self.ctx['exportedInterface']]:
- # iface.exported = True
+ xctor = iface.constructor if hasattr(iface, 'constructor') else None
+ if xctor:
+ xctor.primitiveArgs = [x for x in xctor.arguments if x.xtype.name in cppPrimitiveMap]
+ attributes = iface.getTypes('Attribute')
+ ctorArgs = [arg.name for arg in xctor.arguments] if xctor else []
+ for attr in attributes:
+ if attr.name in ctorArgs:
+ attr.existIn = 'ctor'
+ if xctor:
+ for x in xctor.arguments:
+ if x.xtype.name in self.ctx['interfaces'] or x.xtype.name in self.ctx['dictionary']:
+ argtypes = dict(self.ctx['interfaces'].items() + self.ctx['dictionary'].items())
+ argtype = argtypes[x.xtype.name]
+ for child in argtype.childs:
+ if child.name == attr.name:
+ attr.existIn = x.name + "." + child.name
+ break
+ if len([x for x in attributes if not hasattr(x, "existIn")]) > 0:
+ native_function = iface.name + "Constructor"
+ native_cmd = iface.name + "_constructor"
+ self.ctx['cmdtable'][native_function] = native_cmd
+ if iface.inherit in [x.name for x in self.ctx['exportedInterface']]:
+ iface.private = True
#if iface.name in self.ctx['callback']:
#iface.isListener = True
+
for operation in iface.getTypes('Operation'):
if hasattr(iface, 'exported') and iface.exported:
- operation.native_cmd = iface.name+'_'+operation.name
- operation.native_function = iface.name+(operation.name.title())
- self.ctx['cmdtable'][operation.native_function] = operation.native_cmd
+ #operation.native_cmd = iface.name+'_'+operation.name
+ #operation.native_function = iface.name+(operation.name.title())
+ #self.ctx['cmdtable'][operation.native_function] = operation.native_cmd
+ native_cmd = iface.name+'_'+operation.name
+ native_function = iface.name+(operation.name.title())
+ self.ctx['cmdtable'][native_function] = native_cmd
operation.argnames = [a.name for a in operation.arguments]
operation.primitiveArgs = [x for x in operation.arguments if x.xtype.name in cppPrimitiveMap]
for arg in operation.arguments:
+ if arg.xtype.name in self.ctx['interfaces'] and \
+ hasattr(self.ctx['interfaces'][arg.xtype.name], 'constructor'):
+ arg.isPlatformObject = True
+
if arg.xtype.name in self.ctx['enum']:
arg.isEnum = True
arg.enums = self.ctx['enum'][arg.xtype.name]
def prepareX(self, x):
if isinstance(x, WebIDL.XImplements) and (x.name in ['Tizen', 'Window']) and x.parent.name.lower() == self.ctx['exportModule'].lower():
self.ctx['implementedClass'].append(x.impl)
- self.ctx[x.name].append(x.impl)
+ #self.ctx[x.name].append(x.impl)
impl = x.parent.get('Interface', x.impl)
impl.implements = x.name
#inheritIface = x.parent.parent.get('Interface', x.xtype.name)
inheritIface = self.ctx['interfaces'][x.xtype.name]
if inheritIface :
- self.ctx[x.parent.implements] = inheritIface.name
- inheritIface.exported = True
+ #self.ctx[x.parent.implements] = inheritIface.name
+ inheritIface.exported = x.parent.implements
self.ctx['exportedInterface'].append(inheritIface)
if isinstance(x, WebIDL.XInterface):
xctor = next((c for c in x.getTypes('ExtendedAttribute') if c.name == 'Constructor'), None)
if xctor:
x.constructor = xctor
+ x.exported = x.name
if isinstance(x, WebIDL.XOperation):
module = x.parent.parent
#inheritIface = module.get('Interface', x.returnType.name)
inheritIface = self.ctx['interfaces'][x.returnType.name]
if inheritIface :
- inheritIface.exported = True
+ inheritIface.exported = inheritIface.name
self.ctx['exportedInterface'].append(inheritIface)
if isinstance(x, WebIDL.XDictionary):
if isinstance(x, WebIDL.XEnum):
self.ctx['enum'][x.name] = x.childs
+ cppPrimitiveMap[x.name] = 'std::string'
if isinstance(x, WebIDL.XObject):
for child in x.childs:
modules = self.tree if module == None else [m for m in self.tree if m.name.lower() == module.lower()]
return tpl.render({'modules':modules,
'callbacks':self.ctx['callback'],
- 'tizen': self.ctx['Tizen'],
- 'window': self.ctx['Window'],
+ #'tizen': self.ctx['Tizen'],
+ #'window': self.ctx['Window'],
'cmdtable' : self.ctx['cmdtable'],
'year' : date.today().year})
#m = [m for m in self.tree if m.name.lower() == module.lower()]
m = [m for m in self.tree]
vals['moduleObj'] = m[0] if len(m)>0 else None
- vals['tizen'] = self.ctx['Tizen']
- vals['window'] = self.ctx['Window']
+ #vals['tizen'] = self.ctx['Tizen']
+ #vals['window'] = self.ctx['Window']
vals['cmdtable'] = self.ctx['cmdtable']
vals['year'] = date.today().year
{% endfor %}
{% for iface in module.getTypes('Interface') %}
-{% if iface.exported %}
+{% if iface.exported or iface.private %}
+
+{% if iface.private %}
+// private constructor
+{% endif %}
function {{iface.name}}(
{%-if iface.constructor -%}
{%- for arg in iface.constructor.arguments -%}
{%- endfor -%}
{%- endif -%}) {
// constructor of {{iface.name}}
+ {% if iface.constructor %}
+ var nativeParam = {
+ {% for arg in iface.constructor.primitiveArgs %}
+ '{{arg.name}}': args.{{arg.name}}{% if not loop.last %},{% endif %}
+
+ {% endfor %}
+ };
+ var syncResult = callNative('{{iface.name}}_constructor', nativeParam);
+
+ {% for attribute in iface.getTypes('Attribute') %}
+ {% if attribute.existIn == 'ctor' %}
+ {% set attrValue = attribute.name %}
+ {% elif attribute.existIn %}
+ {% set attrValue = attribute.existIn %}
+ {% else %}
+ {% set attrValue = "null" %}
+ {% endif %}
+ {% if attribute.readonly %}
+ SetReadOnlyProperty(this, '{{attribute.name}}', {{attrValue}}); // read only property
+ {% else %}
+ this.{{attribute.name}} = {{attrValue}};
+ {% endif %}
+ {% endfor %}
+ {% endif %}
}
{% if iface.inherit %}
]
{%- elif arg.xtype.name in type_map -%}
{{type_map[arg.xtype.name]}}
+ {%- elif arg.isPlatformObject -%}
+ PLATFORM_OBJECT, 'values': tizen.{{arg.xtype.name}}
{%- else -%}
DICTIONARY
{%- endif -%}
};
{% for arg in operation.primitiveArgs if arg.optional %}
- if (args['{{arg.name}}']){
+ if (args['{{arg.name}}']) {
nativeParam['{{arg.name}}'] = args.{{arg.name}};
}
{% endfor %}
{% if operation.returnInternal %}
var returnObject = new {{operation.returnInternal.name}}();
- {% for attribute in operation.returnInternal.getTypes('Attribute') %}
- {% if attribute.readonly %}
- SetReadOnlyProperty(returnObject, '{{attribute.name}}', {% if attribute.name in operation.argnames -%}
- {{attribute.name}}); // read only property
- {%- else -%}
- null); // read only property
- {%- endif %}
-
- {% else %}
- returnObject.{{attribute.name}} = {% if attribute.name in operation.argnames -%}
- {{attribute.name}};
- {%- else -%}
- null;
- {%- endif %}
-
- {% endif %}
- {% endfor %}
-
return returnObject;
{% endif %}
};
{% endif %}
{% endfor %}
-exports = new {{tizen}}();
-{% if window %}
-window.{{window}} = new {{window}}();
-{% endif %}
+{% for iface in module.getTypes('Interface') %}
+ {% if iface.exported == 'Tizen' %}
+exports = new {{iface.name}}();
+ {% elif iface.exported == 'Window' %}
+window.{{iface.name}} = new {{iface.name}}();
+ {% elif iface.exported %}
+tizen.{{iface.name}} = {{iface.name}};
+ {% endif %}
+{% endfor %}
{% endfor %}