(cros) advice on sending a D-Bus signal from arbitrary code

13 views
Skip to first unread message

Luigi Semenzato

unread,
May 16, 2018, 1:58:37 PM5/16/18
to Chromium-dev
I would like to send a D-Bus signal from arbitrary locations. This CL
should be relatively self-explanatory:

https://chromium-review.googlesource.com/#/c/chromium/src/+/1062078

The D-Bus signal is then consumed by a "memory daemon" which collects
and correlates a number of memory manager stats and events. This is
functionally similar to a histogram sample generation, which can also
be inserted in arbitrary code and uses global objects. This
functionality relies on services/objects that aren't always present
(i.e. the dbus service at startup/shutdown) but in these cases it's
fine to do nothing.

I build a D-Bus service provider (which is the proper context for
sending D-Bus signals) and add it to the DBusServices object in the
ChromeBrowserMainPartsChromeos object, which is added to the
ChromeBrowserMainParts object, which is inserted in the
BrowserMainLoop object which I think is globally available as
g_current_browser_main_loop.

The problem is that there are four layers of private members to go
through---although some may have accessor functions.

There is one other place that sends D-Bus signals in the context of
the ComponentUpdater, but that one has a CrosComponentManager object
which helps expose this functionality.

In cros_component_installer.cc:

g_browser_process->platform_part()
->cros_component_manager()
->EmitInstalledSignal(GetName());

https://cs.chromium.org/chromium/src/chrome/browser/component_updater/cros_component_installer_chromeos.cc?q=EmitInstalledSignal&sq=package:chromium&dr=CSs&l=132

I could try to do something similar, but I am wondering if it would be
acceptable to use a static function instead, or a global pointer.
(The static function would also contain a static pointer, same idea.)

Thanks!

P.S. incidentally, I am aware that the D-Bus signal may need to be
posted in a different thread, but haven't looked into that part yet.

Ryo Hashimoto

unread,
May 16, 2018, 10:58:47 PM5/16/18
to seme...@chromium.org, Chromium-dev
D-Bus service objects are owned by the platform part object, so I think adding an accessor method to it is the most natural way.
If you want to avoid typing "g_browser_process->platform_part()->..." multiple times, you can add a helper function for it.
 

Thanks!

P.S. incidentally, I am aware that the D-Bus signal may need to be
posted in a different thread, but haven't looked into that part yet.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
    http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAA25o9QW%3D3SpcFqM3EANd8uN%2Bc%3DVmNgY-fSZ8%2B33hJ-cZ9h10A%40mail.gmail.com.


Luigi Semenzato

unread,
May 17, 2018, 3:20:34 PM5/17/18
to Ryo Hashimoto, Chromium-dev
Thanks a lot!
>> email to chromium-dev...@chromium.org.
Reply all
Reply to author
Forward
0 new messages