diff options
Diffstat (limited to 'third_party/rust/libdbus-sys')
-rw-r--r-- | third_party/rust/libdbus-sys/.cargo-checksum.json | 1 | ||||
-rw-r--r-- | third_party/rust/libdbus-sys/Cargo.toml | 36 | ||||
-rw-r--r-- | third_party/rust/libdbus-sys/LICENSE-APACHE | 202 | ||||
-rw-r--r-- | third_party/rust/libdbus-sys/LICENSE-MIT | 19 | ||||
-rw-r--r-- | third_party/rust/libdbus-sys/build.rs | 18 | ||||
-rw-r--r-- | third_party/rust/libdbus-sys/cross_compile.md | 138 | ||||
-rw-r--r-- | third_party/rust/libdbus-sys/src/lib.rs | 315 |
7 files changed, 729 insertions, 0 deletions
diff --git a/third_party/rust/libdbus-sys/.cargo-checksum.json b/third_party/rust/libdbus-sys/.cargo-checksum.json new file mode 100644 index 0000000000..ceb508aa70 --- /dev/null +++ b/third_party/rust/libdbus-sys/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.toml":"9714822b5647f5a7692aacdfe78a5648f6fe670837b32fbd4efe9c6bdd5b1ce9","LICENSE-APACHE":"453745410e3be8cf25d56872ea2aec975a78e6c9f217443d0bf908a5bce7c8ff","LICENSE-MIT":"de3911c2d98c8bd2d701ee721347053d9b55995a11f9a8c955e44d3ca1b376bf","build.rs":"ad8091de7621ddfba2df83267a33e6eb5762d9daa100b6fb2b7dce75c4aee56d","cross_compile.md":"f95d4a5b3cd8c0e071b42641e55155ebcbfb1f572b906720ca631203f5f6f455","src/lib.rs":"6b21ff4c23882beed741d7d9a81fde2d7f6f947efeb31caf8ec4162df1cf92cf"},"package":"c185b5b7ad900923ef3a8ff594083d4d9b5aea80bb4f32b8342363138c0d456b"}
\ No newline at end of file diff --git a/third_party/rust/libdbus-sys/Cargo.toml b/third_party/rust/libdbus-sys/Cargo.toml new file mode 100644 index 0000000000..9735c76f76 --- /dev/null +++ b/third_party/rust/libdbus-sys/Cargo.toml @@ -0,0 +1,36 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + +[package] +name = "libdbus-sys" +version = "0.2.2" +authors = ["David Henningsson <diwic@ubuntu.com>"] +build = "build.rs" +links = "dbus" +description = "FFI bindings to libdbus." +documentation = "http://docs.rs/libdbus-sys" +keywords = ["D-Bus", "DBus", "libdbus"] +categories = ["os::unix-apis", "external-ffi-bindings"] +license = "Apache-2.0/MIT" +repository = "https://github.com/diwic/dbus-rs" +[package.metadata.pkg-config] +dbus-1 = "1.6" +[build-dependencies.pkg-config] +version = "0.3" +[badges.is-it-maintained-issue-resolution] +repository = "diwic/dbus-rs" + +[badges.is-it-maintained-open-issues] +repository = "diwic/dbus-rs" + +[badges.travis-ci] +repository = "diwic/dbus-rs" diff --git a/third_party/rust/libdbus-sys/LICENSE-APACHE b/third_party/rust/libdbus-sys/LICENSE-APACHE new file mode 100644 index 0000000000..6003c7dd9a --- /dev/null +++ b/third_party/rust/libdbus-sys/LICENSE-APACHE @@ -0,0 +1,202 @@ +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2014-2018 David Henningsson <diwic@ubuntu.com> and other contributors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/third_party/rust/libdbus-sys/LICENSE-MIT b/third_party/rust/libdbus-sys/LICENSE-MIT new file mode 100644 index 0000000000..aec16d2daa --- /dev/null +++ b/third_party/rust/libdbus-sys/LICENSE-MIT @@ -0,0 +1,19 @@ +Copyright (c) 2014-2018 David Henningsson <diwic@ubuntu.com> and other contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.
\ No newline at end of file diff --git a/third_party/rust/libdbus-sys/build.rs b/third_party/rust/libdbus-sys/build.rs new file mode 100644 index 0000000000..5e2d1cdd73 --- /dev/null +++ b/third_party/rust/libdbus-sys/build.rs @@ -0,0 +1,18 @@ +extern crate pkg_config; + +fn main() { + // See https://github.com/joshtriplett/metadeps/issues/9 for why we don't use + // metadeps here, but instead keep this manually in sync with Cargo.toml. + if let Err(e) = pkg_config::Config::new().atleast_version("1.6").probe("dbus-1") { + eprintln!("pkg_config failed: {}", e); + eprintln!( + "One possible solution is to check whether packages\n\ + 'libdbus-1-dev' and 'pkg-config' are installed:\n\ + On Ubuntu:\n\ + sudo apt install libdbus-1-dev pkg-config\n\ + On Fedora:\n\ + sudo dnf install dbus-devel pkgconf-pkg-config\n" + ); + panic!(); + } +} diff --git a/third_party/rust/libdbus-sys/cross_compile.md b/third_party/rust/libdbus-sys/cross_compile.md new file mode 100644 index 0000000000..439435f126 --- /dev/null +++ b/third_party/rust/libdbus-sys/cross_compile.md @@ -0,0 +1,138 @@ +Cross compiling dbus +==================== + +There are (at least) three different approaches to cross compiling dbus. Choose which one fits you best: + + * Using rust-embedded/cross, see below + * There is an alternative guide at [issue 184](https://github.com/diwic/dbus-rs/issues/184#issuecomment-520228758), which also contains a [powershell script](https://github.com/diwic/dbus-rs/issues/184#issuecomment-520791888) that set things up for you. + * Setting things up manually, see below + +The examples below all assume you're trying to compile for Raspberry Pi 2 or 3 running Raspbian. Adjust target triples accordingly if your target is something else. + + +Cross compiling using rust-embedded/cross +========================================= + +Thanks to [jobale](https://github.com/jobale) for providing these instructions +(taken from [issue 292](https://github.com/diwic/dbus-rs/issues/292)). + +Tested on Ubuntu 20.04 | rustc 1.47.0 + +- Install [rust-embedded/cross](https://github.com/rust-embedded/cross) +- In your project directory, create a **Cross.toml** file: `touch Cross.toml` +Add this code in it: + +``` +[target.armv7-unknown-linux-gnueabihf] +image = "rustcross:dbus-armhf" + +[build.env] +passthrough = [ + "RUSTFLAGS", +] +``` + + +- In your project directory create a **Dockerfile**: `touch Dockerfile` +Put this code in it: + +``` +# Base image for rapsberrypi 3 target +FROM rustembedded/cross:armv7-unknown-linux-gnueabihf + +# Install libdbus libraries and pkg-config +RUN dpkg --add-architecture armhf && \ + apt-get update && \ + apt-get install --assume-yes libdbus-1-dev libdbus-1-dev:armhf pkg-config +``` + +For whatever reason, _in the docker image_, armhf libraries are installed in at least 2 locations. That's the reason of all my troubles: +- /usr/arm-linux-gnueabihf/lib/ +- /usr/lib/arm-linux-gnueabihf/ + +- Cross needs to know those locations. We pass them to the compiler through a command flag. For convenience I put it in a bash script: + +``` +#!/bin/bash +set -o errexit +set -o nounset +set -o pipefail +set -o xtrace + +readonly TARGET_ARCH=armv7-unknown-linux-gnueabihf +readonly LINK_FLAGS='-L /usr/arm-linux-gnueabihf/lib/ -L /usr/lib/arm-linux-gnueabihf/' + +RUSTFLAGS=${LINK_FLAGS} cross build --release --target=${TARGET_ARCH} + +``` + + +Some more explanations for newcomers like me: + +- Cross command act as cargo command (e.g: `cross build` is the same as `cargo build` but for cross-compiling). +- In Cross.toml, `passthrough = [ "RUSTFLAGS",]` is what enable us to pass flags/parameters to the compiler in the docker image. + + + +Setting up cross compiling manually +=================================== + +A cross linker +-------------- + +Apparently, `rustc` in itself can generate code for many archs but not assemble the generated code into the final executable. Hence you need a cross linker. + +**Install it** - here follow whatever guide you have for the target arch. Distributions may also ship with cross toolchains. Example for Ubuntu 18.04: + +`sudo apt install gcc-8-multilib-arm-linux-gnueabihf` + +**Tell rustc where to find it** - in [.cargo/config](https://doc.rust-lang.org/cargo/reference/config.html) add the following: + +``` +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc-8" +``` + +Target rust std +--------------- + +This one's easy, just run rustup: + +`rustup target add armv7-unknown-linux-gnueabihf` + + +Target dbus libraries +--------------------- + +**Installing the libraries** + +Now to the more challenging part. Since we link to a C library `libdbus-1.so`, we also need the target version of that library. However, `libdbus-1.so` in itself links to a systemd library (at least it does so here) which in turn links to other libraries etc, so we need target versions of those libraries too. + +Getting an entire rootfs/image is probably the easiest option. The rootfs needs to have `libdbus-1-dev` installed. I e: + + * Boot your target (i e, a raspberry), install `libdbus-1-dev` on it, turn it off and put the SD card into your computer's SD card reader. Mount the partition. + * If the above is not an option, you could download an image, mount it at the right offset, like this (ugly hack!) `sudo mount -o loop,offset=50331648 2019-04-08-raspbian-stretch-lite.img /tmp/mnt` and then, to manually make the symlink that `libdbus-1-dev` does for you: `cd /tmp/mnt/usr/lib/arm-linux-gnueabihf && ln -s ../../../lib/arm-linux-gnueabihf/libdbus-1.so.3 libdbus-1.so`. + * Or you can use the alternative guide's approach to download, extract and post-process the relevant `.deb` files manually. This might be a preferrable option if an entire image/rootfs would be too large. + +**Finding the libraries** + +When not cross compiling, finding the right library is done by a `build.rs` script which calls `pkg-config`. This will not work when cross compiling because it will point to the `libdbus-1.so` on the host, not the `libdbus-1.so` of the target. +Maybe it is possible to teach `pkg-config` how to return the target library instead, but I have not tried this approach. Instead we can override build script altogether and provide the same info manually. This is possible because `libdbus-sys` has a `links = dbus` line. + +For the example below we assume that we have mounted a Raspbian rootfs on `/tmp/mnt`, and that the cross linker came with some basic libraries (libc, libpthread etc) that are installed on `/usr/arm-linux-gnueabihf/lib`. Unfortunately, we can't use the basic libraries that are present on the image, because they might contain absolute paths. + +And so we add the following to [.cargo/config](https://doc.rust-lang.org/cargo/reference/config.html): + +``` +[target.armv7-unknown-linux-gnueabihf.dbus] +rustc-link-search = ["/usr/arm-linux-gnueabihf/lib", "/tmp/mnt/usr/lib/arm-linux-gnueabihf"] +rustc-link-lib = ["dbus-1"] +``` + + +Finally +------- + +If we are all set up, you should be able to successfully compile with: + +`cargo build --target=armv7-unknown-linux-gnueabihf` diff --git a/third_party/rust/libdbus-sys/src/lib.rs b/third_party/rust/libdbus-sys/src/lib.rs new file mode 100644 index 0000000000..c93388c108 --- /dev/null +++ b/third_party/rust/libdbus-sys/src/lib.rs @@ -0,0 +1,315 @@ +use std::os::raw::{c_void, c_char, c_uint, c_int, c_long}; + +pub type DBusConnection = c_void; +pub type DBusMessage = c_void; +pub type DBusWatch = c_void; +pub type DBusPendingCall = c_void; +pub type DBusTimeout = c_void; + +#[repr(C)] +#[derive(Debug, PartialEq, Copy, Clone)] +/// System or Session bus +pub enum DBusBusType { + Session = 0, + System = 1, + Starter = 2, +} + +pub const DBUS_TYPE_ARRAY: c_int = 'a' as c_int; +pub const DBUS_TYPE_VARIANT: c_int = 'v' as c_int; +pub const DBUS_TYPE_BOOLEAN: c_int = 'b' as c_int; +pub const DBUS_TYPE_INVALID: c_int = 0; +pub const DBUS_TYPE_STRING: c_int = 's' as c_int; +pub const DBUS_TYPE_DICT_ENTRY: c_int = 'e' as c_int; +pub const DBUS_TYPE_BYTE: c_int = 'y' as c_int; +pub const DBUS_TYPE_INT16: c_int = 'n' as c_int; +pub const DBUS_TYPE_UINT16: c_int = 'q' as c_int; +pub const DBUS_TYPE_INT32: c_int = 'i' as c_int; +pub const DBUS_TYPE_UINT32: c_int = 'u' as c_int; +pub const DBUS_TYPE_INT64: c_int = 'x' as c_int; +pub const DBUS_TYPE_UINT64: c_int = 't' as c_int; +pub const DBUS_TYPE_DOUBLE: c_int = 'd' as c_int; +pub const DBUS_TYPE_UNIX_FD: c_int = 'h' as c_int; +pub const DBUS_TYPE_STRUCT: c_int = 'r' as c_int; +pub const DBUS_TYPE_OBJECT_PATH: c_int = 'o' as c_int; +pub const DBUS_TYPE_SIGNATURE: c_int = 'g' as c_int; + +pub const DBUS_TIMEOUT_USE_DEFAULT: c_int = -1; +pub const DBUS_TIMEOUT_INFINITE: c_int = 0x7fffffff; + +pub const DBUS_NAME_FLAG_ALLOW_REPLACEMENT: c_int = 1; +pub const DBUS_NAME_FLAG_REPLACE_EXISTING: c_int = 2; +pub const DBUS_NAME_FLAG_DO_NOT_QUEUE: c_int = 4; + +pub const DBUS_WATCH_READABLE: c_int = 1; +pub const DBUS_WATCH_WRITABLE: c_int = 2; +pub const DBUS_WATCH_ERROR: c_int = 4; +pub const DBUS_WATCH_HANGUP: c_int = 8; + +#[repr(C)] +#[derive(Debug, PartialEq, Copy, Clone)] +pub enum DBusRequestNameReply { + PrimaryOwner = 1, + InQueue = 2, + Exists = 3, + AlreadyOwner = 4, +} + +#[repr(C)] +#[derive(Debug, PartialEq, Copy, Clone)] +pub enum DBusReleaseNameReply { + Released = 1, + NonExistent = 2, + NotOwner = 3, +} + +#[repr(C)] +#[derive(Debug, PartialEq, Copy, Clone)] +pub enum DBusHandlerResult { + Handled = 0, + NotYetHandled = 1, + NeedMemory = 2, +} + +#[repr(C)] +#[derive(Debug, PartialEq, Copy, Clone)] +/// One of the four different D-Bus message types. +pub enum DBusMessageType { + /// This is not a valid message type (rarely used) + Invalid = 0, + /// This is a method call D-Bus message + MethodCall = 1, + /// This is a method return Ok D-Bus message, used when the method call message was successfully processed + MethodReturn = 2, + /// This is a method return with error D-Bus message, used when the method call message could not be handled + Error = 3, + /// This is a signal, usually sent to whoever wants to listen + Signal = 4, +} + +#[repr(C)] +#[derive(Debug, PartialEq, Copy, Clone)] +pub enum DBusDispatchStatus { + DataRemains = 0, + Complete = 1, + NeedMemory = 2, +} + +#[repr(C)] +pub struct DBusError { + pub name: *const c_char, + pub message: *const c_char, + pub dummy: c_uint, + pub padding1: *const c_void +} + +#[repr(C)] +#[derive(Copy, Clone)] +pub struct DBusMessageIter { + pub dummy1: *mut c_void, + pub dummy2: *mut c_void, + pub dummy3: u32, + pub dummy4: c_int, + pub dummy5: c_int, + pub dummy6: c_int, + pub dummy7: c_int, + pub dummy8: c_int, + pub dummy9: c_int, + pub dummy10: c_int, + pub dummy11: c_int, + pub pad1: c_int, + pub pad2: c_int, + // Here would have been padding; because pad3 is a 8 byte aligned pointer (on amd64). + // Rust reserves the right not to copy the padding when cloning a struct, + // but the D-Bus library uses this part of the struct too. + // Hence, add a field as big as the padding to ensure Rust copies all data. + pub pad2_added_by_rust: c_int, + pub pad3: *mut c_void, +} + +pub type DBusHandleMessageFunction = Option<extern fn(conn: *mut DBusConnection, msg: *mut DBusMessage, user_data: *mut c_void) -> DBusHandlerResult>; + +pub type DBusAddWatchFunction = Option<extern fn(watch: *mut DBusWatch, user_data: *mut c_void) -> u32>; +pub type DBusRemoveWatchFunction = Option<extern fn(watch: *mut DBusWatch, user_data: *mut c_void)>; +pub type DBusWatchToggledFunction = Option<extern fn(watch: *mut DBusWatch, user_data: *mut c_void)>; + +pub type DBusAddTimeoutFunction = Option<extern fn(timeout: *mut DBusTimeout, user_data: *mut c_void) -> u32>; +pub type DBusTimeoutToggledFunction = Option<extern fn(timeout: *mut DBusTimeout, user_data: *mut c_void)>; +pub type DBusRemoveTimeoutFunction = Option<extern fn(timeout: *mut DBusTimeout, user_data: *mut c_void)>; + +pub type DBusDispatchStatusFunction = Option<extern fn(conn: *mut DBusConnection, new_status: DBusDispatchStatus, user_data: *mut c_void)>; + +pub type DBusWakeupMainFunction = Option<extern fn(conn: *mut DBusConnection, user_data: *mut c_void)>; + +pub type DBusPendingCallNotifyFunction = Option<extern fn(pending: *mut DBusPendingCall, user_data: *mut c_void)>; + +pub type DBusFreeFunction = Option<extern fn(memory: *mut c_void)>; + +#[repr(C)] +pub struct DBusObjectPathVTable { + pub unregister_function: Option<extern fn(conn: *mut DBusConnection, user_data: *mut c_void)>, + pub message_function: DBusHandleMessageFunction, + pub dbus_internal_pad1: Option<extern fn()>, + pub dbus_internal_pad2: Option<extern fn()>, + pub dbus_internal_pad3: Option<extern fn()>, + pub dbus_internal_pad4: Option<extern fn()>, +} + +extern "C" { + pub fn dbus_bus_get_private(t: DBusBusType, error: *mut DBusError) -> *mut DBusConnection; + pub fn dbus_bus_get_unique_name(conn: *mut DBusConnection) -> *const c_char; + pub fn dbus_bus_request_name(conn: *mut DBusConnection, name: *const c_char, + flags: c_uint, error: *mut DBusError) -> c_int; + pub fn dbus_bus_release_name(conn: *mut DBusConnection, name: *const c_char, + error: *mut DBusError) -> c_int; + pub fn dbus_bus_add_match(conn: *mut DBusConnection, rule: *const c_char, + error: *mut DBusError); + pub fn dbus_bus_remove_match(conn: *mut DBusConnection, rule: *const c_char, + error: *mut DBusError); + pub fn dbus_bus_register(conn: *mut DBusConnection, error: *mut DBusError) -> u32; + + pub fn dbus_connection_close(conn: *mut DBusConnection); + pub fn dbus_connection_dispatch(conn: *mut DBusConnection) -> DBusDispatchStatus; + pub fn dbus_connection_flush(conn: *mut DBusConnection); + pub fn dbus_connection_open_private(address: *const c_char, error: *mut DBusError) -> *mut DBusConnection; + pub fn dbus_connection_unref(conn: *mut DBusConnection); + pub fn dbus_connection_get_is_connected(conn: *mut DBusConnection) -> u32; + pub fn dbus_connection_set_exit_on_disconnect(conn: *mut DBusConnection, enable: u32); + pub fn dbus_connection_send_with_reply_and_block(conn: *mut DBusConnection, + message: *mut DBusMessage, timeout_milliseconds: c_int, error: *mut DBusError) -> *mut DBusMessage; + pub fn dbus_connection_send_with_reply(conn: *mut DBusConnection, + message: *mut DBusMessage, pending_return: *mut *mut DBusPendingCall, timeout_milliseconds: c_int) -> u32; + pub fn dbus_connection_send(conn: *mut DBusConnection, + message: *mut DBusMessage, serial: *mut u32) -> u32; + pub fn dbus_connection_read_write_dispatch(conn: *mut DBusConnection, + timeout_milliseconds: c_int) -> u32; + pub fn dbus_connection_read_write(conn: *mut DBusConnection, timeout_milliseconds: c_int) -> u32; + pub fn dbus_connection_try_register_object_path(conn: *mut DBusConnection, + path: *const c_char, vtable: *const DBusObjectPathVTable, user_data: *mut c_void, + error: *mut DBusError) -> u32; + pub fn dbus_connection_unregister_object_path(conn: *mut DBusConnection, + path: *const c_char) -> u32; + pub fn dbus_connection_list_registered(conn: *mut DBusConnection, + parent_path: *const c_char, child_entries: *mut *mut *mut c_char) -> u32; + pub fn dbus_connection_add_filter(conn: *mut DBusConnection, function: DBusHandleMessageFunction, + user_data: *mut c_void, free_data_function: DBusFreeFunction) -> u32; + pub fn dbus_connection_remove_filter(conn: *mut DBusConnection, function: DBusHandleMessageFunction, + user_data: *mut c_void) -> u32; + pub fn dbus_connection_set_watch_functions(conn: *mut DBusConnection, add_function: DBusAddWatchFunction, + remove_function: DBusRemoveWatchFunction, toggled_function: DBusWatchToggledFunction, + data: *mut c_void, free_data_function: DBusFreeFunction) -> u32; + pub fn dbus_connection_set_timeout_functions(conn: *mut DBusConnection, add_function: DBusAddTimeoutFunction, + remove_function: DBusRemoveTimeoutFunction, toggled_function: DBusTimeoutToggledFunction, + data: *mut c_void, free_data_function: DBusFreeFunction) -> u32; + pub fn dbus_connection_set_dispatch_status_function(conn: *mut DBusConnection, + dispatch_function: DBusDispatchStatusFunction, data: *mut c_void, free_data_function: DBusFreeFunction); + pub fn dbus_connection_set_wakeup_main_function(conn: *mut DBusConnection, + wakeup_function: DBusWakeupMainFunction, data: *mut c_void, free_data_function: DBusFreeFunction); + pub fn dbus_connection_pop_message(conn: *mut DBusConnection) -> *mut DBusMessage; + pub fn dbus_connection_get_dispatch_status(conn: *mut DBusConnection) -> DBusDispatchStatus; + + pub fn dbus_error_init(error: *mut DBusError); + pub fn dbus_error_free(error: *mut DBusError); + pub fn dbus_set_error(error: *mut DBusError, name: *const c_char, message: *const c_char, ...); + pub fn dbus_set_error_from_message(error: *mut DBusError, message: *mut DBusMessage) -> u32; + + pub fn dbus_message_new_method_call(destination: *const c_char, path: *const c_char, + iface: *const c_char, method: *const c_char) -> *mut DBusMessage; + pub fn dbus_message_new_method_return(message: *mut DBusMessage) -> *mut DBusMessage; + pub fn dbus_message_new_error(message: *mut DBusMessage, + error_name: *const c_char, error_message: *const c_char) -> *mut DBusMessage; + pub fn dbus_message_new_signal(path: *const c_char, + iface: *const c_char, name: *const c_char) -> *mut DBusMessage; + pub fn dbus_message_ref(message: *mut DBusMessage) -> *mut DBusMessage; + pub fn dbus_message_unref(message: *mut DBusMessage); + pub fn dbus_message_get_type(message: *mut DBusMessage) -> c_int; + pub fn dbus_message_is_method_call(message: *mut DBusMessage, iface: *const c_char, method: *const c_char) -> u32; + pub fn dbus_message_is_signal(message: *mut DBusMessage, iface: *const c_char, signal_name: *const c_char) -> u32; + pub fn dbus_message_get_reply_serial(message: *mut DBusMessage) -> u32; + pub fn dbus_message_get_serial(message: *mut DBusMessage) -> u32; + pub fn dbus_message_get_path(message: *mut DBusMessage) -> *const c_char; + pub fn dbus_message_get_interface(message: *mut DBusMessage) -> *const c_char; + pub fn dbus_message_get_destination(message: *mut DBusMessage) -> *const c_char; + pub fn dbus_message_get_member(message: *mut DBusMessage) -> *const c_char; + pub fn dbus_message_get_sender(message: *mut DBusMessage) -> *const c_char; + pub fn dbus_message_set_serial(message: *mut DBusMessage, serial: u32); + pub fn dbus_message_set_destination(message: *mut DBusMessage, destination: *const c_char) -> u32; + pub fn dbus_message_get_no_reply(message: *mut DBusMessage) -> u32; + pub fn dbus_message_set_no_reply(message: *mut DBusMessage, no_reply: u32); + pub fn dbus_message_get_auto_start(message: *mut DBusMessage) -> u32; + pub fn dbus_message_set_auto_start(message: *mut DBusMessage, no_reply: u32); + pub fn dbus_message_copy(message: *const DBusMessage) -> *mut DBusMessage; + + pub fn dbus_message_iter_append_basic(iter: *mut DBusMessageIter, t: c_int, value: *const c_void) -> u32; + pub fn dbus_message_iter_append_fixed_array(iter: *mut DBusMessageIter, element_type: c_int, + value: *const c_void, n_elements: c_int) -> u32; + pub fn dbus_message_iter_init(message: *mut DBusMessage, iter: *mut DBusMessageIter) -> u32; + pub fn dbus_message_iter_init_append(message: *mut DBusMessage, iter: *mut DBusMessageIter); + pub fn dbus_message_iter_get_arg_type(iter: *mut DBusMessageIter) -> c_int; + pub fn dbus_message_iter_get_basic(iter: *mut DBusMessageIter, value: *mut c_void); + pub fn dbus_message_iter_get_element_type(iter: *mut DBusMessageIter) -> c_int; + pub fn dbus_message_iter_get_fixed_array(iter: *mut DBusMessageIter, + value: *mut c_void, n_elements: *mut c_int) -> u32; + pub fn dbus_message_iter_get_signature(iter: *mut DBusMessageIter) -> *mut c_char; + pub fn dbus_message_iter_next(iter: *mut DBusMessageIter) -> u32; + pub fn dbus_message_iter_recurse(iter: *mut DBusMessageIter, subiter: *mut DBusMessageIter); + pub fn dbus_message_iter_open_container(iter: *mut DBusMessageIter, _type: c_int, + contained_signature: *const c_char, sub: *mut DBusMessageIter) -> u32; + pub fn dbus_message_iter_close_container(iter: *mut DBusMessageIter, sub: *mut DBusMessageIter) -> u32; + + pub fn dbus_free(memory: *mut c_void); + pub fn dbus_free_string_array(str_array: *mut *mut c_char) -> c_void; + + pub fn dbus_signature_validate_single(signature: *const c_char, error: *mut DBusError) -> u32; + + pub fn dbus_threads_init_default() -> c_int; + + pub fn dbus_validate_bus_name(busname: *const c_char, error: *mut DBusError) -> u32; + pub fn dbus_validate_error_name(errorname: *const c_char, error: *mut DBusError) -> u32; + pub fn dbus_validate_interface(interface: *const c_char, error: *mut DBusError) -> u32; + pub fn dbus_validate_member(member: *const c_char, error: *mut DBusError) -> u32; + pub fn dbus_validate_path(path: *const c_char, error: *mut DBusError) -> u32; + + pub fn dbus_watch_get_enabled(watch: *mut DBusWatch) -> u32; + pub fn dbus_watch_get_flags(watch: *mut DBusWatch) -> c_uint; + pub fn dbus_watch_get_unix_fd(watch: *mut DBusWatch) -> c_int; + pub fn dbus_watch_get_socket(watch: *mut DBusWatch) -> c_int; + pub fn dbus_watch_handle(watch: *mut DBusWatch, flags: c_uint) -> u32; + pub fn dbus_watch_get_data(watch: *mut DBusWatch) -> *mut c_void; + pub fn dbus_watch_set_data(watch: *mut DBusWatch, user_data: *mut c_void, + free_data_function: DBusFreeFunction); + + pub fn dbus_timeout_get_enabled(timeout: *mut DBusTimeout) -> u32; + pub fn dbus_timeout_get_interval(timeout: *mut DBusTimeout) -> c_int; + pub fn dbus_timeout_handle(timeout: *mut DBusTimeout) -> u32; + pub fn dbus_timeout_get_data(timeout: *mut DBusTimeout) -> *mut c_void; + pub fn dbus_timeout_set_data(timeout: *mut DBusTimeout, user_data: *mut c_void, + free_data_function: DBusFreeFunction); + + pub fn dbus_pending_call_ref(pending: *mut DBusPendingCall) -> *mut DBusPendingCall; + pub fn dbus_pending_call_unref(pending: *mut DBusPendingCall); + pub fn dbus_pending_call_set_notify(pending: *mut DBusPendingCall, n: DBusPendingCallNotifyFunction, + user_data: *mut c_void, free_user_data: DBusFreeFunction) -> u32; + pub fn dbus_pending_call_steal_reply(pending: *mut DBusPendingCall) -> *mut DBusMessage; + + pub fn dbus_message_marshal(msg: *mut DBusMessage, marshalled_data_p: *mut *mut c_char, len_p: *mut c_int) -> u32; + pub fn dbus_message_demarshal(s: *const c_char, len: c_int, error: *mut DBusError) -> *mut DBusMessage; + pub fn dbus_message_demarshal_bytes_needed(buf: *const c_char, len: c_int) -> c_int; + + pub fn dbus_connection_set_max_message_size(conn: *mut DBusConnection, size: c_long); + pub fn dbus_connection_get_max_message_size(conn: *mut DBusConnection) -> c_long; + pub fn dbus_connection_set_max_message_unix_fds(conn: *mut DBusConnection, n: c_long); + pub fn dbus_connection_get_max_message_unix_fds(conn: *mut DBusConnection) -> c_long; + + pub fn dbus_connection_set_max_received_size(conn: *mut DBusConnection, size: c_long); + pub fn dbus_connection_get_max_received_size(conn: *mut DBusConnection) -> c_long; + pub fn dbus_connection_set_max_received_unix_fds(conn: *mut DBusConnection, n: c_long); + pub fn dbus_connection_get_max_received_unix_fds(conn: *mut DBusConnection) -> c_long; + + pub fn dbus_connection_get_outgoing_size(conn: *mut DBusConnection) -> c_long; + pub fn dbus_connection_get_outgoing_unix_fds(conn: *mut DBusConnection) -> c_long; + pub fn dbus_connection_has_messages_to_send(conn: *mut DBusConnection) -> u32; + + pub fn dbus_try_get_local_machine_id(error: *mut DBusError) -> *mut c_char; + pub fn dbus_get_local_machine_id() -> *mut c_char; +} |