מעכשיו פוסטים חדשים מ-Usenet לא יופיעו ואי אפשר להירשם לתוכן מ-Usenet בקבוצות Google. התוכן שכבר פורסם עדיין יופיע.

passing/getting data from/to custom xpcom service

15 צפיות
מעבר להודעה הראשונה שלא נקראה

jonathan

לא נקראה,
13 במרץ 2007, 10:50:3613.3.2007
עד
I currently wish to have a global xpcom service that can get and set a
complex javascript data type.
this data type is defined and used as the following:
var a=new Array();
a['param']='val';
here's my xpcom interface idl file:
#include "nsISupports.idl"

interface nsIMutableArray;
interface nsIPropertyBag;
interface nsIArray;

[scriptable, uuid(45be03e1-7fe3-4467-9ea5-c80d0e2b1234)]
interface nsISD : nsISupports
{
nsIArray getData();
void setData(in nsIArray a);
};

1.what's the right data structure that I can use to pass my custom data(var
a)? can nsIArray do the job?
2. if it's not possible to pass my custom data(var a) around to xpcoms as
it is defined now, what's the suitable data structure that I can use to
redefine and populate my custom data?
3.also I read somewhere that nsIArray should be passed by pointer, so what's
the standard way of defining function signatures? can nsIArray be a return
value?

thanks for the help!

jonathan

לא נקראה,
13 במרץ 2007, 19:04:5113.3.2007
עד
actually the custom object that I need global access to is mroe complicated
than I mentioned, it is something like this:
var a=new Array();
a['param']=new Array();
a['param'].push('val1');
a['param'].push('val2');

"jonathan" <topc...@gmail.com> wrote in message
news:foydnWk8z4qgJ2vY...@mozilla.org...

jonathan

לא נקראה,
13 במרץ 2007, 19:18:3513.3.2007
עד
To make my question more clear I think what I want to know is how do I wrapp
the complex data I described into a xpcom?
thanks

"jonathan" <topc...@gmail.com> wrote in message

news:o72dnawmUrGFs2rY...@mozilla.org...

eric...@yahoo.com

לא נקראה,
13 במרץ 2007, 20:26:3713.3.2007
עד dev-extensions
If the XPCOM service is built with JS, you can use wrappedJSObject on your XPCOM service to pass any kind of data you like; e.g.,

var myService = Components.classes["@jonathan.com/myExtension/myService;1"]
.getService(Components.interfaces.nsISupports).wrappedJSObject;

myService.setData([param1:"foo", param2:"bar"]);

You don't need an IDL for the service in this case. However, if you're writing the XPCOM service with C++, I don't know if you can use wrappedJSObject. Given that it has "JS" in the name, I doubt it :) If that's the case, ignore this email.


_______________________________________________
dev-extensions mailing list
dev-ext...@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-extensions

jonathan

לא נקראה,
13 במרץ 2007, 21:11:4313.3.2007
עד
eric,
can wrappedJSObjet.setData take none arbitrary javascript objects? or just
strings. I still need to define the the getData and setData function along
with rest of the class right?

thanks

-jonathan

<eric...@yahoo.com> wrote in message
news:mailman.1.1173832008...@lists.mozilla.org...

jonathan

לא נקראה,
13 במרץ 2007, 21:40:2913.3.2007
עד
And also how do I register the component so that it can be found if I don't
compile a IDL?
I got a TypeError: Component.class['@mycom.com/myService;1"] has no
properties...
thanks

<eric...@yahoo.com> wrote in message
news:mailman.1.1173832008...@lists.mozilla.org...

eric...@yahoo.com

לא נקראה,
13 במרץ 2007, 23:38:2713.3.2007
עד jonathan,dev-ext...@lists.mozilla.org
>>can wrappedJSObjet.setData take none arbitrary javascript objects? or just strings.<<
It can take anything.

>>I still need to define the the getData and setData function along with rest of the class right?<<

Yes, but in the myService object itself... there's no interface anymore

>>And also how do I register the component so that it can be found if I don't compile a IDL?<<

There are tutorials on this at developer.mozilla.org. Also, Ted has a webpage which auto-generates the XPCOM component service code for you automatically after you fill in a few things (like service name, etc). The URL for the webpage was posted in the last few days on this mailing list.

jonathan

לא נקראה,
14 במרץ 2007, 0:23:3614.3.2007
עד

what do you mean by in the myService object itself?right now this is how I
retrieve the service, right?
var myService = Components.classes["@my.com/myService;1"]
.getService(Components.interfaces.nsISupports).wrappedJSObject;
myService.setData(data);
so do you mean I can just define a javascript class called myService like
this? how does that become a service?

function myService() {
this.wrappedJSObject = this;
}
myService.prototype = {
data:null,
getData:function(){
return this.data;
},
setData: function(d){
this.data=d;
},
}

>>I still need to define the the getData and setData function along with
>>rest of the class right?<<
>Yes, but in the myService object itself... there's no interface anymore

all the tutorial I went through said I need to compile an IDL in order to
create the xpcom component. is this correct?


>>And also how do I register the component so that it can be found if I
>>don't compile a IDL?<<
>There are tutorials on this at developer.mozilla.org. Also, Ted has a

>webpage which auto->generates the XPCOM component service code for you

>automatically after you fill in a few things >(like service name, etc). The
>URL for the webpage was posted in the last few days on this mailing >list.

thanks!

Nickolay Ponomarev

לא נקראה,
15 במרץ 2007, 4:23:4315.3.2007
עד jonathan,dev-ext...@lists.mozilla.org
On 3/14/07, jonathan <topc...@gmail.com> wrote:
>
> what do you mean by in the myService object itself?right now this is how I
> retrieve the service, right?
> var myService = Components.classes["@my.com/myService;1"]
> .getService(Components.interfaces.nsISupports).wrappedJSObject;

No need to pass Components.interfaces.nsISupports explicitly to
getService. Just use .getService().

> myService.setData(data);
> so do you mean I can just define a javascript class called myService like
> this?

Yes.

> how does that become a service?
>

Just like a component implementing interfaces does. You put this code
in a JS file along with XPCOM registration code, which the above
mentioned Ted's tool can generate for you. Then you put the JS file in
components/

http://ted.mielczarek.org/code/mozilla/jscomponentwiz/

> function myService() {
> this.wrappedJSObject = this;
> }
> myService.prototype = {
> data:null,
> getData:function(){
> return this.data;
> },
> setData: function(d){
> this.data=d;
> },
> }
>

BTW, no-one forces you to use the setData/getData functions. You can
as well set the property directly.

> >>I still need to define the the getData and setData function along with
> >>rest of the class right?<<
> >Yes, but in the myService object itself... there's no interface anymore
> all the tutorial I went through said I need to compile an IDL in order to
> create the xpcom component. is this correct?

It is incorrect. The simplest counter-example is that your component
may only implement existing interfaces, like nsISupports and
nsIObserver. Or just nsISupports, which is what Eric suggested you do.

Which tutorial is that? Please always post the URLs, so that we can
fix the confusing docs (if they are under our control).

Nickolay

0 הודעות חדשות