Re: Cannot call RegisterDataSource on a own datasource

mcben <[email protected]> Mon, 04 Feb 2008 19:10:02 +0100
Newsgroups gmane.comp.mozilla.devel.rdf
Message-ID <[email protected]>
> 
> Good point.
> 
> I just tried that :
> 
> function myDataSourceImplementation(struct)
> {
>     this.__proto__ = Components.classes["@mozilla.org/rdf/datasource;1?
> name=in-memory-datasource"]
>                          .createInstance(Components.interfaces.nsIRDFDataSource);
> 
>     this.init = function() {
>        // load data with XMLHttpRequest
>     };
> 
>    this.QueryInterface = function(iid) {
>         ConsoleService.logStringMessage("QI called:" + iid);
>         if (!iid.equals(Components.interfaces.nsIDOMEventListener) &&
>             !iid.equals(Components.interfaces.nsIRDFDataSource) &&
>             !iid.equals(Components.interfaces.nsIRDFRemoteDataSource)
> &&
>             !iid.equals(Components.interfaces.nsISupports))
>             throw Components.results.NS_ERROR_NO_INTERFACE;
>         return this;
>     };
> 
>     this.init();
> 
> }
> 
> As you can see, i'm compelled to binds new methods in the constructor
> since, the prototype is overriden by "this.__proto__". Not a real
> problem.
> Code works (i see the data in the chrome).
> 
> But my new QI is never called, like before, and prevents me from
> implementing other interfaces :-(
> 
>> But I guess for real questions on this, you should try .js-engine.
> 
> Maybe.
> This evening, I'll try XPCOM aggregation (like in "Aggregating In
> Memory Datasource"), 

I'm back :)

In fact, I already try to aggregate an in-memory datasource, that was 
not with xml datasource.
See here my post (without replies :[) to .xpcom:
http://groups.google.com/group/mozilla.dev.tech.xpcom/browse_frm/thread/38aeabcf8bfef28c/6d12b03fa5010e7b?lnk=st&q=Javascript%2C+RDF+in-mem+datasource+and+XPCOM+Aggregation#6d12b03fa5010e7b

My new tries is same as previous ones of today :
  in the chrome, i cant QI to another interface the datasource that i 
get from RDFService.GetDataSource(), nor if i directly call my component 
with Components.classes.

The asked interface is not forwarded to the outter object, eg: my own 
component.

Here is the code:

function MyDataSourceImplementation(struct)
{
   this.mInner = Components
     .classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"]
     .createInstance(Components.interfaces.nsIRDFDataSource,
                     this,
                     Components.interfaces.nsISupports);
}
MyDataSourceImplementation.prototype = {
     mInner:null,

     QueryInterface : function MDSI_QueryInterface(iid) {
         if(iid.equals(Components.interfaces.nsIRDFDataSource))
             return this.mInner;

         if (iid.equals(Components.interfaces.nsIDOMEventListener) ||
             iid.equals(Components.interfaces.nsIRDFRemoteDataSource) ||
             iid.equals(Components.interfaces.nsISupports))
             return this;

         throw Components.results.NS_ERROR_NO_INTERFACE;
     }
}

It'worse, if I replace the mInner initialization with :

this.mInner = Components
                 .manager
                 .createInstance(inMemDsCID,
                            this, Components.interfaces.nsISupports);

The datasource if filled, that's fine, but with some QI errors, but 
crashses with a Segmentation fault 15 seconde later.
The QI also does not work.

I can't find any XPCOM aggregation with javascript example :(

Are my parameters right for createInstance ?