Christian Biesinger wrote:
C�dric wrote:

Where can I find an XPCOM Service sample in Javascript ?


Services are implemented exactly like components. Callers can use getService if they want it as a service, or createInstance for an instance.

Sorry but I'm not sure to understand so in the following example what are modifications to have an XPCOM service ?
thank in advance.





function mySample() { /* big comment for no code, eh? */ }



mySample.prototype = { test: function () { dump(test); }

        QueryInterface: function (iid) {
         if (!iid.equals(Components.interfaces.nsISample) &&
             !iid.equals(Components.interfaces.nsISupports)) {
             throw Components.results.NS_ERROR_NO_INTERFACE;
         }
         return this;
    },

}

var myModule = {
   firstTime: true,

registerSelf: function (compMgr, fileSpec, location, type) {
if (this.firstTime) {
debug("*** Deferring registration of sample JS components\n");
this.firstTime = false;
throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
}
debug("*** Registering sample JS components\n");
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
compMgr.registerFactoryLocation(this.myCID,
"Sample JS Component",
this.myProgID,
fileSpec,
location,
type);
},


   getClassObject: function (compMgr, cid, iid) {
        if (!cid.equals(this.myCID))
             throw Components.results.NS_ERROR_NO_INTERFACE;

         if (!iid.equals(Components.interfaces.nsIFactory))
             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
         return this.myFactory;
   },

        /* CID for this class */
      myCID: Components.ID("{dea98e50-1dd1-11b2-9344-8902b4805a2e}"),

      /* ProgID for this class */
      myProgID: "@mozilla.org/jssample;1",

     /* factory object */
     myFactory: {
        createInstance: function (outer, iid) {
           debug("CI: " + iid + "\n");
            if (outer != null)
                throw Components.results.NS_ERROR_NO_AGGREGATION;

             return (new mySample()).QueryInterface(iid);
         }
     },

    canUnload: function(compMgr) {
        debug("*** Unloading sample JS components\n");
        return true;
    }
};

function NSGetModule(compMgr, fileSpec) {
     return myModule;
}
_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to