Christophe Nowicki

June 28, 2006

D-BUS for Mozilla project progress

My current progress on the project is disappointing, I am blocked on the value returned by an method call.
I can make a basic D-BUS method call from Javascript, but I’am unable to get his return value.
Here is the sample of code :

var comp = Components.classes[nsDBUSContactID];
var dbus = comp.createInstance();
var session = dbus.SessionBus();
var iface = session.FindInterface('org.mozilla.TestService', '/',  'org.mozilla.TestInterface')
var ret = iface.Call('Hello')
dump('return value = ' . ret ) 

The ‘ret’ value can be of any kind of type (string, int, array, object, etc…).
I’ve found the javascript code for managing any type of return value from an XPCOM method, in the mozilla xml-rpc extension :

/* Create an instance of the given ContractID, with given interface */
function createInstance(contractId, intf) {
    return Components.classes[contractId].createInstance(Components.interfaces[intf])
}

/* return type */
function testReturn(type) {
    const SUPPORTSID = '@mozilla.org/supports-';
    var ret
    switch(type) {
        case 'INT32':
            ret = createInstance(SUPPORTSID + 'PRInt32;1', 
                'nsISupportsPRInt32')
            ret.data = 65
            break
        case 'STRING':
            ret = createInstance(SUPPORTSID + 'cstring;1', 
                'nsISupportsCString')
            ret.data = 'arf'
            break
        case 'DOUBLE':
            ret = createInstance(SUPPORTSID + 'double;1', 
                'nsISupportsDouble')
            ret.data = 2.4
            break
       ....
    }
    return ret;
}

I’ve wrote the C++ version of this code, but It does not work :
XPIDL prototype of my method :

nsISupports Test();

The C++ implementation :

NS_IMETHODIMP
nsDBusImpl::TestSupports(nsISupports **_retval) {
    nsresult rv;
    nsCOMPtr ret = 
        do_CreateInstance("@mozilla.org/supports-PRInt32;1", &rv);
    if (NS_FAILED(rv)) {
        return rv;
    }
    ret->SetData(42);
    // _retval = (nsISupports **) &ret; // Does not work
    // *_retval = ret;  // Segfault

    return NS_OK;
}

I’am stopped by this problem …

Filed under: Google Summer of Code — Tags:, — cscm @ 09:23

Comments are closed.

Powered by WordPress