calling out from Javascript to C++

12 views
Skip to first unread message

kewarken

unread,
Jan 7, 2010, 12:39:12 PM1/7/10
to google-gadgets-for-linux-user
Hi,

We've got our own host/gadget container which uses GGL to display
gadgets. It's a desktop type application which supports various
plugins, one of which is a GGL gadget container.

Desktop --> another_plugin
| \
V V
plugin gadget_plugin
|
V
some gadgets

There can be multiple gadgets per gadget_plugin and there can be
multiple gadget_plugins.

The problem we have is that we'd like the gadgets to be able to notify
the underlying desktop of changes in state to that it can make the
desktop behave differently under certain circumstances. For instance,
if the gadget is focused in option mode, we might want to make several
soft-keys change their appearance/function.

We've got a couple ideas so we were hoping someone might give some
guidance for the best way to accomplish this.

The first thought was to just use DBUS to let the gadget tell the
parent its status.
Problems:
- Identification. Each gadget needs to be uniquely identifiable so
that the dbus message will know which gadget we're talking about.
- DBus receiver. Who gets the dbus message? The gadget_plugin or the
desktop? Since there are potentially multiple gadget_plugins, it
might make more sense for the desktop to get the message but then we
have to pass it on to each plugin. Alternatively we could do a dbus
signal and then each the gadget_plugins can decide if they're
interested or not. Can the GGL dbus extension do a signal?

The next idea was to write an extension. I had the thought that we
could make something like a 'parent' object that the gadget could use
through javascript. Something like 'parent.tellState("grumpy")'.
This feels like a cleaner solution but I have a few questions about
whether it's practical.
Questions:
- Context. Does the gadget plugin have a way to know which gadget the
call comes from or do we still have the identification issue?
- Implementation. I really don't know quite where to start. Most of
the extensions seem to be self contained. I think this one would have
to expose some API on the C++ side. I imagine that when gadget_plugin
is instantiating gadgets, it would have to do something like pass a
callback handle into the extension for notifications.

Sorry the post is so long. Can anyone give me some ideas?

cheers,

Kris

James Su

unread,
Jan 8, 2010, 12:59:55 AM1/8/10
to google-gadgets...@googlegroups.com
I think the extension approach would be feasible. You may create an extension and add a special object to the framework namespace. Just similar than framework.runtime or framework.audio.
A framework extension will be loaded into each individual gadget, and a pointer to the Gadget object will be passed into the extension upon initialization. You can use that pointer to identify the gadget when your special object gets called.
You may refer to extensions/default_framework/default_framework.cc to see how to implement a framework extension and how to hook special objects or methods to the framework namespace.

Regards
James Su 

2010/1/8 kewarken <kewa...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "google-gadgets-for-linux-user" group.
To post to this group, send email to google-gadgets...@googlegroups.com.
To unsubscribe from this group, send email to google-gadgets-for-l...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-gadgets-for-linux-user?hl=en.




kewarken

unread,
Jan 8, 2010, 7:01:42 AM1/8/10
to google-gadgets-for-linux-user
Thanks James, I'll look at that.

cheers,

Kris

On Jan 8, 12:59 am, James Su <james...@gmail.com> wrote:
> I think the extension approach would be feasible. You may create an
> extension and add a special object to the

> framework<http://code.google.com/apis/desktop/docs/gadget_apiref.html#framework>namespace.


> Just similar than framework.runtime or framework.audio.
> A framework extension will be loaded into each individual gadget, and a
> pointer to the Gadget object will be passed into the extension upon
> initialization. You can use that pointer to identify the gadget when your
> special object gets called.
> You may refer to

> extensions/default_framework/default_framework.cc<http://code.google.com/p/google-gadgets-for-linux/source/browse/trunk...>


> to
> see how to implement a framework extension and how to hook special objects
> or methods to the framework namespace.
>
> Regards
> James Su
>

> 2010/1/8 kewarken <kewar...@gmail.com>

> > google-gadgets-for-l...@googlegroups.com<google-gadgets-for-linux-user%2Bunsu...@googlegroups.com>

kewarken

unread,
Jan 11, 2010, 2:31:45 PM1/11/10
to google-gadgets-for-linux-user
Hi James,

I was successful in creating the new object so from javascript I can
do:

framework.parent.tellState("test");

and the ggl-gtk host prints out:

got state: test

from the C++ code. The next question is how do I cause this to
actually do something in the host? Ideally I'd like to be able to
have the ggl extension call out to some function in our host code.

I looked at the Perfmon class and it seems to support something like
this but I'm not sure how you actually do it. I kind of imagined
something like:

PerfmonInterface *pmi = some_ggl_object.getExtension("Perfmon");
pmi.AddCounter("some_path", NewSlot(some_callback))

But I don't know how to do the first part.

The next question is header related. It doesn't seem like extensions
install their own headers. Does that mean I need to modify one of the
global headers like framework_interface.h or perhaps put my own into
the ggadget directory? I was kind of hoping to have the extension
completely self contained rather than having to modify common code.

cheers,

Kris

On Jan 8, 12:59 am, James Su <james...@gmail.com> wrote:

> I think the extension approach would be feasible. You may create an
> extension and add a special object to the

> framework<http://code.google.com/apis/desktop/docs/gadget_apiref.html#framework>namespace.


> Just similar than framework.runtime or framework.audio.
> A framework extension will be loaded into each individual gadget, and a
> pointer to the Gadget object will be passed into the extension upon
> initialization. You can use that pointer to identify the gadget when your
> special object gets called.
> You may refer to

> extensions/default_framework/default_framework.cc<http://code.google.com/p/google-gadgets-for-linux/source/browse/trunk...>


> to
> see how to implement a framework extension and how to hook special objects
> or methods to the framework namespace.
>
> Regards
> James Su
>

> 2010/1/8 kewarken <kewar...@gmail.com>

> > google-gadgets-for-l...@googlegroups.com<google-gadgets-for-linux-user%2Bunsu...@googlegroups.com>

James Su

unread,
Jan 11, 2010, 9:23:17 PM1/11/10
to google-gadgets...@googlegroups.com
1. You can add a special global function in your extension, such as:
  void RegisterHostCallback(CallbackInterface* callback);

  The CallbackInterface is an interface class provided by your host.
  Then in your host, implement a special extension register (derived from ExtensionRegisterInterface) to find and call this symbol from the extension. Then calling ExtensionManager::RegisterLoadedExtensions() with this special extension register as soon as your extension is loaded. Then your extension can communicate with your host through the callback.

2. An extension should not have public header.

Regards
James Su

2010/1/12 kewarken <kewa...@gmail.com>
To unsubscribe from this group, send email to google-gadgets-for-l...@googlegroups.com.

Kris Warkentin

unread,
Jan 11, 2010, 9:36:39 PM1/11/10
to google-gadgets...@googlegroups.com
On Mon, Jan 11, 2010 at 9:23 PM, James Su <james.su@gmail.com> wrote:
1. You can add a special global function in your extension, such as:
  void RegisterHostCallback(CallbackInterface* callback);

  The CallbackInterface is an interface class provided by your host.
  Then in your host, implement a special extension register (derived from ExtensionRegisterInterface) to find and call this symbol from the extension. Then calling ExtensionManager::RegisterLoadedExtensions() with this special extension register as soon as your extension is loaded. Then your extension can communicate with your host through the callback.


Okay.  That sounds straightforward enough.  Thanks very much.

cheers,

Kris

James Su

unread,
Jan 11, 2010, 9:55:51 PM1/11/10
to google-gadgets...@googlegroups.com
May I ask what kind of desktop application you are working on? Is it an opensource project or a commercial one?

Regards
James Su

2010/1/12 Kris Warkentin <kewa...@gmail.com>

Kris Warkentin

unread,
Jan 12, 2010, 6:16:14 AM1/12/10
to google-gadgets...@googlegroups.com
That's a good question and to be honest, I'm not 100% sure.  I think that it may wind up being a bit of both.  The largest portion is a custom GUI written in QT for a client's embedded system.  Most of the features are just plugins written in QT as well but the client also wanted to be able to display google gadgets so we wrote another plugin that uses your library to display them.

The larger framework is designed to be used on multiple embedded projects so likely will be kept in-house but anything we do with GPL type code or which doesn't represent 'interesting' intellectual property would be released.  I imagine that if the stuff I'm monkeying around with has any generic interest (rather than just task-specific) we would be submitting it back upstream to you.  Actually, even if it isn't useful in of itself, it might be useful as a sort of canonical 'hello world' example of how to hook these things up.

cheers,

Kris

James Su

unread,
Jan 12, 2010, 6:22:05 AM1/12/10
to google-gadgets...@googlegroups.com
I see. Thanks.

Kris Warkentin

unread,
Jan 12, 2010, 6:26:26 AM1/12/10
to google-gadgets...@googlegroups.com
I'm curious.  Does that matter to you?

cheers,

Kris
Reply all
Reply to author
Forward
0 new messages