Created
June 13, 2021 22:37
-
-
Save mbenford/0e9a5240246bc2ff7cb5114c94508f45 to your computer and use it in GitHub Desktop.
Monitoring DBus with dbus-next
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dbus_next.aio import MessageBus | |
from dbus_next.message import Message | |
from dbus_next.constants import BusType | |
import asyncio | |
async def main(): | |
match = ( | |
"type='method_call'," | |
"interface='org.freedesktop.PowerManagement.Inhibit'," | |
"path='/org/freedesktop/PowerManagement/Inhibit'" | |
) | |
bus = await MessageBus(bus_type=BusType.SESSION).connect() | |
await bus.call(Message( | |
destination="org.freedesktop.DBus", | |
path="/org/freedesktop/DBus", | |
interface="org.freedesktop.DBus.Monitoring", | |
member="BecomeMonitor", | |
signature="asu", | |
body=[[match], 0], | |
serial=bus.next_serial(), | |
)) | |
bus.add_message_handler(handler) | |
def handler(message): | |
print(message.member) | |
return True | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment