xpcom callbacks

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

xpcom callbacks

Dupes-3
I'm writing an xpcom object that requires callback functinality similar
to the xmlhttprequest object.  This is what I have so far:

[scriptable, uuid(43524)]
interface Callback : nsISupports
{
   void CallbackFunc();
};

[scriptable, uuid(1234)]
interface Device : nsISupports
{
  attribute Callback objCallback;
};

In javascript, I create an object that has a function called
callBackFunc() and I use the setCallBack function of the Device object
to set the callback object.  After setting the callback object, I'm
able to call the javascript function until the javascript code exits.
Then, when the device object tries to call the callback, the program
hangs.  I took a look at the xmlhttprequest code to get some pointers
and found that that object uses a few javascript objects to save the
current javascript context.  After adding similar code, I get a 'too
much recursion' error when I call the callback object.  Does anyone
have any suggestins?

_______________________________________________
Mozilla-xpcom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: xpcom callbacks

Kok Hoor
Hi,

    Actually I am facing a problem quite similar like yours. What I did is I
called the AddRef of the object passed in, to prevent it from being removed
from memory when its reference counter is 0. I noticed that the
XMLHttpRequest sample doesn't seem to do this, but what I did works!!!

    In addition, I do not understand why XMLHttpRequest save and restore
context, as I am able to call the callback without saving and restoring the
context.

Regards,
   Kok Hoor

<[hidden email]> wrote in message
news:[hidden email]...

> I'm writing an xpcom object that requires callback functinality similar
> to the xmlhttprequest object.  This is what I have so far:
>
> [scriptable, uuid(43524)]
> interface Callback : nsISupports
> {
>    void CallbackFunc();
> };
>
> [scriptable, uuid(1234)]
> interface Device : nsISupports
> {
>   attribute Callback objCallback;
> };
>
> In javascript, I create an object that has a function called
> callBackFunc() and I use the setCallBack function of the Device object
> to set the callback object.  After setting the callback object, I'm
> able to call the javascript function until the javascript code exits.
> Then, when the device object tries to call the callback, the program
> hangs.  I took a look at the xmlhttprequest code to get some pointers
> and found that that object uses a few javascript objects to save the
> current javascript context.  After adding similar code, I get a 'too
> much recursion' error when I call the callback object.  Does anyone
> have any suggestins?
>


_______________________________________________
Mozilla-xpcom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: xpcom callbacks

Dupes-3
I'm pretty sure XMLHttpRequest doesn't have to addref becuase it uses
an nsCOMPtr for it's callback object, and using nsCOMPtr automatically
addrefs the object.  I had one implementatin where I used a regular
pointer to point to the javascript callback and that implementation
crashed when I tried to call the callback after the SetCallback
function exited.  Adding and addref call fixed the problem.  Next, I
tried using an nsCOMPtr object and this implementation worked without
doing an addref.

I have a feeling you object is a little different than mine.  My object
creates a thread (using the NSPR thread library included with mozilla
source) that continues to run after the javascript code exits.  The
callback works fine until the javascript code exits.  Does your
callback work after your javascript code exits?

_______________________________________________
Mozilla-xpcom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: xpcom callbacks

Kok Hoor
When you say that your javascript code exits, what javascript code are you
referring to? The javascript that creates the XPCOM?

In my case, I am creating a taskbar icon, so I pass a callback, say
onDoubleClick which will be called when the TrayIcon is double-clicked.
However, when I close the XUL window that creates the TrayIcon, the callback
doesn't work anymore. But fortunately, even when I call the onDoubleClick
callback from XPCOM, it doesn't crash.

This, I believe, is because the context of the callback doesn't exist
anymore, and it doesn't make sense for the code to run, which is fine with
me.

Regards,
    Kok Hoor

"dupes" <[hidden email]> wrote in message
news:[hidden email]...

> I'm pretty sure XMLHttpRequest doesn't have to addref becuase it uses
> an nsCOMPtr for it's callback object, and using nsCOMPtr automatically
> addrefs the object.  I had one implementatin where I used a regular
> pointer to point to the javascript callback and that implementation
> crashed when I tried to call the callback after the SetCallback
> function exited.  Adding and addref call fixed the problem.  Next, I
> tried using an nsCOMPtr object and this implementation worked without
> doing an addref.
>
> I have a feeling you object is a little different than mine.  My object
> creates a thread (using the NSPR thread library included with mozilla
> source) that continues to run after the javascript code exits.  The
> callback works fine until the javascript code exits.  Does your
> callback work after your javascript code exits?
>


_______________________________________________
Mozilla-xpcom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: xpcom callbacks

Dupes-3
Yes, I'm referring to the javascript code that creates the object.  The
object is new'd and a function is made on the xpcom object which starts
a thread.  So the thread in the xpcom object executes and the main
thread returns back to the java script code.  As long as the java
script code does not exit, the callback can be executed.  If the
javascript code exits, I get the 'too much recursion' error.  It sounds
like you have your callback working to the same point that mine works.

dupes

_______________________________________________
Mozilla-xpcom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: xpcom callbacks

Christian Biesinger
In reply to this post by Kok Hoor
Kok Hoor (SolutionX) wrote:
> However, when I close the XUL window that creates the TrayIcon, the callback
> doesn't work anymore. But fortunately, even when I call the onDoubleClick
> callback from XPCOM, it doesn't crash.

Yeah, the global object went away, so stuff like Components doesn't
exist anymore. I believe that stuff like "new Array" "new Object"
doesn't work anymore either. So doing useful stuff when the window is
gone is hard :)


smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: xpcom callbacks

Dupes-3
In reply to this post by Dupes-3
I was able to fix my problem by creating a proxy object from the
callback that's passed to the SetCallback function.  I'll post the code
if anyone's interested....

dupes

_______________________________________________
Mozilla-xpcom mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-xpcom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: xpcom callbacks proxy

Ravi Singh
Hi Dupes,
Can you provide me wih some sample code on how to use proxy objects. I am using C++ and Mozilla 1.7.12
~Ravi

dupes wrote
I was able to fix my problem by creating a proxy object from the
callback that's passed to the SetCallback function.  I'll post the code
if anyone's interested....

dupes

_______________________________________________
Mozilla-xpcom mailing list
Mozilla-xpcom@mozilla.org
http://mail.mozilla.org/listinfo/mozilla-xpcom
Loading...