|
| 1 | +# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 | + |
| 3 | +# Copyright (C) 2025 igo95862 |
| 4 | + |
| 5 | +# This file is part of python-sdbus |
| 6 | + |
| 7 | +# This library is free software; you can redistribute it and/or |
| 8 | +# modify it under the terms of the GNU Lesser General Public |
| 9 | +# License as published by the Free Software Foundation; either |
| 10 | +# version 2.1 of the License, or (at your option) any later version. |
| 11 | + |
| 12 | +# This library is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | +# Lesser General Public License for more details. |
| 16 | + |
| 17 | +# You should have received a copy of the GNU Lesser General Public |
| 18 | +# License along with this library; if not, write to the Free Software |
| 19 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | +from __future__ import annotations |
| 21 | + |
| 22 | +from sdbus import DbusInterfaceCommon, dbus_method, dbus_property |
| 23 | + |
| 24 | +# The interface has to be redefined using the blocking base class |
| 25 | +# and decorators. |
| 26 | + |
| 27 | + |
| 28 | +class ExampleInterfaceBlocking( |
| 29 | + DbusInterfaceCommon, interface_name="org.example.interface" |
| 30 | +): |
| 31 | + @dbus_method( |
| 32 | + input_signature="s", |
| 33 | + result_signature="s", |
| 34 | + ) |
| 35 | + def upper(self, string: str) -> str: |
| 36 | + return string.upper() |
| 37 | + |
| 38 | + @dbus_property( |
| 39 | + property_signature="s", |
| 40 | + ) |
| 41 | + def hello_world(self) -> str: |
| 42 | + return "Hello, World!" |
| 43 | + |
| 44 | + |
| 45 | +def main() -> None: |
| 46 | + # Create a new proxied object |
| 47 | + example_object = ExampleInterfaceBlocking( |
| 48 | + service_name="org.example.test", |
| 49 | + object_path="/", |
| 50 | + ) |
| 51 | + |
| 52 | + # Call upper |
| 53 | + s = "test string" |
| 54 | + s_after = example_object.upper(s) |
| 55 | + |
| 56 | + print("Initial string: ", s) |
| 57 | + print("After call: ", s_after) |
| 58 | + |
| 59 | + # Get property |
| 60 | + print("Remote property: ", example_object.hello_world) |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + main() |
0 commit comments