Example #1
0
    def _MakeInterfaceParam_(self, interface, iid, method_index, mi,
                             param_index):
        # Wrap a "raw" interface object in a nice object.  The result of this
        # function will be passed to one of the gateway methods.
        if iid is None:
            # look up the interface info - this will be true for all xpcom called interfaces.
            if self._interface_info_ is None:
                import xpcom.xpt
                self._interface_info_ = xpcom.xpt.Interface(self._iid_)
            iid = self._interface_iid_map_.get((method_index, param_index))
            if iid is None:
                iid = self._interface_info_.GetIIDForParam(
                    method_index, param_index)
                self._interface_iid_map_[(method_index, param_index)] = iid
        # handle nsIVariant
        if iid == IID_nsIVariant:
            interface = interface.QueryInterface(iid)
            dt = interface.dataType
            if dt in VARIANT_INT_TYPES:
                return interface.getAsInt32()
            if dt in VARIANT_LONG_TYPES:
                return interface.getAsInt64()
            if dt in VARIANT_FLOAT_TYPES:
                return interface.getAsFloat()
            if dt in VARIANT_STRING_TYPES:
                return interface.getAsStringWithSize()
            if dt in VARIANT_UNICODE_TYPES:
                return interface.getAsWStringWithSize()
            if dt == xpcom_consts.VTYPE_BOOL:
                return interface.getAsBool()
            if dt == xpcom_consts.VTYPE_INTERFACE:
                return interface.getAsISupports()
            if dt == xpcom_consts.VTYPE_INTERFACE_IS:
                return interface.getAsInterface()
            if dt == xpcom_consts.VTYPE_EMPTY or dt == xpcom_consts.VTYPE_VOID:
                return None
            if dt == xpcom_consts.VTYPE_ARRAY:
                return interface.getAsArray()
            if dt == xpcom_consts.VTYPE_EMPTY_ARRAY:
                return []
            if dt == xpcom_consts.VTYPE_ID:
                return interface.getAsID()
            # all else fails...
            logger.warning(
                "Warning: nsIVariant type %d not supported - returning a string",
                dt)
            try:
                return interface.getAsString()
            except COMException:
                logger.exception(
                    "Error: failed to get Variant as a string - returning variant object"
                )
                return interface

        return client.Component(interface, iid)
# The contents of this file are subject to the Mozilla Public License Version