mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
Merge pull request #1 from bleackstorm/feat/gpui-redesign
Feat/gpui redesign
This commit is contained in:
34 files changed
+7616
-176
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
[target.x86_64-unknown-linux-gnu]
|
||||||
|
rustflags = ["-L", "/home/bleack/.local/lib"]
|
||||||
Generated
+4878
-128
File diff suppressed because it is too large.
Load diff
@@ -11,9 +11,15 @@ chrono = "0.4"
|
|||||||
clap = { version = "4.5", features = ["derive"] }
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
eframe = { version = "0.29", default-features = true }
|
eframe = { version = "0.29", default-features = true }
|
||||||
glam = "0.29"
|
glam = "0.29"
|
||||||
|
gpui = "0.2.2"
|
||||||
gstreamer = "0.23"
|
gstreamer = "0.23"
|
||||||
gstreamer-app = "0.23"
|
gstreamer-app = "0.23"
|
||||||
gstreamer-video = "0.23"
|
gstreamer-video = "0.23"
|
||||||
|
image = "0.25"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
openxr = { version = "0.19", features = ["loaded"] }
|
openxr = { version = "0.19", features = ["loaded"] }
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
|
smallvec = "1.16"
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
xattr = { path = "patches/xattr" }
|
||||||
@@ -5,6 +5,12 @@ set -e
|
|||||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
||||||
cd "$DIR"
|
cd "$DIR"
|
||||||
|
|
||||||
|
# Vérifier les dépendances locales de linkage (libxkbcommon-x11)
|
||||||
|
mkdir -p "$HOME/.local/lib"
|
||||||
|
if [ ! -f "$HOME/.local/lib/libxkbcommon-x11.so" ] && [ -f "/usr/lib/x86_64-linux-gnu/libxkbcommon-x11.so.0" ]; then
|
||||||
|
ln -sf /usr/lib/x86_64-linux-gnu/libxkbcommon-x11.so.0 "$HOME/.local/lib/libxkbcommon-x11.so"
|
||||||
|
fi
|
||||||
|
|
||||||
# Vérifier si le binaire release existe, sinon le compiler
|
# Vérifier si le binaire release existe, sinon le compiler
|
||||||
if [ ! -f "$DIR/target/release/steamframe-fpv" ]; then
|
if [ ! -f "$DIR/target/release/steamframe-fpv" ]; then
|
||||||
echo "Compilation initiale de SteamFrame FPV en mode Release..."
|
echo "Compilation initiale de SteamFrame FPV en mode Release..."
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{"v":1}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"git": {
|
||||||
|
"sha1": "e42c1da499b72103a9c9ef5693ff31f998ad31e6"
|
||||||
|
},
|
||||||
|
"path_in_vcs": ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
freebsd_instance:
|
||||||
|
image: freebsd-11-2-release-amd64
|
||||||
|
|
||||||
|
task:
|
||||||
|
name: cargo test
|
||||||
|
# Record some info about the test environment
|
||||||
|
sysinfo_script:
|
||||||
|
- mount
|
||||||
|
- df -h
|
||||||
|
- sysctl hw.model hw.ncpu hw.physmem
|
||||||
|
- freebsd-version
|
||||||
|
# Install Rust
|
||||||
|
setup_script:
|
||||||
|
- pkg install -y curl
|
||||||
|
- curl https://sh.rustup.rs -sSf --output rustup.sh
|
||||||
|
- sh rustup.sh -y
|
||||||
|
test_script:
|
||||||
|
- . $HOME/.cargo/env
|
||||||
|
- cargo test
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
target
|
||||||
|
Cargo.lock
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
language: rust
|
||||||
|
sudo: false
|
||||||
|
rust:
|
||||||
|
- nightly
|
||||||
|
- beta
|
||||||
|
- stable
|
||||||
|
os:
|
||||||
|
- linux
|
||||||
|
- osx
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# 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 are reading this file be aware that the original Cargo.toml
|
||||||
|
# will likely look very different (and much more reasonable).
|
||||||
|
# See Cargo.toml.orig for the original contents.
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "xattr"
|
||||||
|
version = "0.2.3"
|
||||||
|
authors = ["Steven Allen <steven@stebalien.com>"]
|
||||||
|
description = "unix extended filesystem attributes"
|
||||||
|
documentation = "https://docs.rs/xattr"
|
||||||
|
keywords = [
|
||||||
|
"xattr",
|
||||||
|
"filesystem",
|
||||||
|
"unix",
|
||||||
|
]
|
||||||
|
license = "MIT/Apache-2.0"
|
||||||
|
repository = "https://github.com/Stebalien/xattr"
|
||||||
|
|
||||||
|
[dependencies.libc]
|
||||||
|
version = "0.2"
|
||||||
|
|
||||||
|
[dev-dependencies.tempfile]
|
||||||
|
version = "3"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["unsupported"]
|
||||||
|
unsupported = []
|
||||||
Generated
+26
@@ -0,0 +1,26 @@
|
|||||||
|
[package]
|
||||||
|
name = "xattr"
|
||||||
|
version = "0.2.3"
|
||||||
|
authors = ["Steven Allen <steven@stebalien.com>"]
|
||||||
|
description = "unix extended filesystem attributes"
|
||||||
|
|
||||||
|
documentation = "https://docs.rs/xattr"
|
||||||
|
repository = "https://github.com/Stebalien/xattr"
|
||||||
|
keywords = ["xattr", "filesystem", "unix"]
|
||||||
|
license = "MIT/Apache-2.0"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["unsupported"]
|
||||||
|
# Adds a dummy implementation for unsupported platforms. This is useful when
|
||||||
|
# developing platform-independent code that doesn't absolutely need xattr
|
||||||
|
# support.
|
||||||
|
#
|
||||||
|
# You can disable this feature if you want compilation to fail on unsupported
|
||||||
|
# platforms. This would make sense if you absolutely need xattr support.
|
||||||
|
unsupported = []
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
libc = "0.2"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempfile = "3"
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
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 [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
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.
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
Copyright (c) 2015 Steven Allen
|
||||||
|
|
||||||
|
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.
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
xattr
|
||||||
|
=====
|
||||||
|
|
||||||
|
[](https://travis-ci.org/Stebalien/xattr)
|
||||||
|
[](https://cirrus-ci.com/github/Stebalien/xattr)
|
||||||
|
|
||||||
|
A small library for setting, getting, and listing extended attributes.
|
||||||
|
|
||||||
|
Supported Platforms: Android, Linux, MacOS, FreeBSD, and NetBSD.
|
||||||
|
|
||||||
|
API Documentation: https://stebalien.github.com/xattr/xattr/
|
||||||
|
|
||||||
|
Unsupported Platforms
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
This library includes no-op support for unsupported platforms. That is, it will
|
||||||
|
build on *all* platforms but always fail on unsupported platforms.
|
||||||
|
|
||||||
|
1. You can turn this off by disabling the default `unsupported` feature. If you
|
||||||
|
do so, this library will fail to compile on unsupported platforms.
|
||||||
|
2. Alternatively, you can detect unsupported platforms at runtime by checking
|
||||||
|
the `xattr::SUPPORTED_PLATFORM` boolean.
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
use std::error::Error;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
/// The error type returned on unsupported platforms.
|
||||||
|
///
|
||||||
|
/// On unsupported platforms, all operations will fail with an `io::Error` with
|
||||||
|
/// a kind `io::ErrorKind::Other` and an `UnsupportedPlatformError` error as the inner error.
|
||||||
|
/// While you *could* check the inner error, it's probably simpler just to check
|
||||||
|
/// `xattr::SUPPORTED_PLATFORM`.
|
||||||
|
///
|
||||||
|
/// This error mostly exists for pretty error messages.
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub struct UnsupportedPlatformError;
|
||||||
|
|
||||||
|
impl Error for UnsupportedPlatformError {
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
"unsupported platform"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for UnsupportedPlatformError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"unsupported platform, please file a bug at `https://github.com/Stebalien/xattr'"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
//! A pure-Rust library to manage extended attributes.
|
||||||
|
//!
|
||||||
|
//! It provides support for manipulating extended attributes
|
||||||
|
//! (`xattrs`) on modern Unix filesystems. See the `attr(5)`
|
||||||
|
//! manpage for more details.
|
||||||
|
//!
|
||||||
|
//! An extension trait [`FileExt`](::FileExt) is provided to directly work with
|
||||||
|
//! standard `File` objects and file descriptors.
|
||||||
|
//!
|
||||||
|
//! NOTE: In case of a symlink as path argument, all methods
|
||||||
|
//! in this library work on the symlink itself **without**
|
||||||
|
//! de-referencing it.
|
||||||
|
//!
|
||||||
|
//! ```rust
|
||||||
|
//! let mut xattrs = xattr::list("/").unwrap().peekable();
|
||||||
|
//!
|
||||||
|
//! if xattrs.peek().is_none() {
|
||||||
|
//! println!("no xattr set on root");
|
||||||
|
//! return;
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! println!("Extended attributes:");
|
||||||
|
//! for attr in xattrs {
|
||||||
|
//! println!(" - {:?}", attr);
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
|
||||||
|
extern crate libc;
|
||||||
|
|
||||||
|
mod error;
|
||||||
|
mod sys;
|
||||||
|
mod util;
|
||||||
|
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io;
|
||||||
|
use std::os::unix::io::AsRawFd;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
pub use error::UnsupportedPlatformError;
|
||||||
|
pub use sys::{XAttrs, SUPPORTED_PLATFORM};
|
||||||
|
|
||||||
|
/// Get an extended attribute for the specified file.
|
||||||
|
pub fn get<N, P>(path: P, name: N) -> io::Result<Option<Vec<u8>>>
|
||||||
|
where
|
||||||
|
P: AsRef<Path>,
|
||||||
|
N: AsRef<OsStr>,
|
||||||
|
{
|
||||||
|
util::extract_noattr(sys::get_path(path.as_ref(), name.as_ref()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set an extended attribute on the specified file.
|
||||||
|
pub fn set<N, P>(path: P, name: N, value: &[u8]) -> io::Result<()>
|
||||||
|
where
|
||||||
|
P: AsRef<Path>,
|
||||||
|
N: AsRef<OsStr>,
|
||||||
|
{
|
||||||
|
sys::set_path(path.as_ref(), name.as_ref(), value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Remove an extended attribute from the specified file.
|
||||||
|
pub fn remove<N, P>(path: P, name: N) -> io::Result<()>
|
||||||
|
where
|
||||||
|
P: AsRef<Path>,
|
||||||
|
N: AsRef<OsStr>,
|
||||||
|
{
|
||||||
|
sys::remove_path(path.as_ref(), name.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// List extended attributes attached to the specified file.
|
||||||
|
///
|
||||||
|
/// Note: this may not list *all* attributes. Speficially, it definitely won't list any trusted
|
||||||
|
/// attributes unless you are root and it may not list system attributes.
|
||||||
|
pub fn list<P>(path: P) -> io::Result<XAttrs>
|
||||||
|
where
|
||||||
|
P: AsRef<Path>,
|
||||||
|
{
|
||||||
|
sys::list_path(path.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extension trait to manipulate extended attributes on `File`-like objects.
|
||||||
|
pub trait FileExt: AsRawFd {
|
||||||
|
/// Get an extended attribute for the specified file.
|
||||||
|
fn get_xattr<N>(&self, name: N) -> io::Result<Option<Vec<u8>>>
|
||||||
|
where
|
||||||
|
N: AsRef<OsStr>,
|
||||||
|
{
|
||||||
|
util::extract_noattr(sys::get_fd(self.as_raw_fd(), name.as_ref()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set an extended attribute on the specified file.
|
||||||
|
fn set_xattr<N>(&self, name: N, value: &[u8]) -> io::Result<()>
|
||||||
|
where
|
||||||
|
N: AsRef<OsStr>,
|
||||||
|
{
|
||||||
|
sys::set_fd(self.as_raw_fd(), name.as_ref(), value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Remove an extended attribute from the specified file.
|
||||||
|
fn remove_xattr<N>(&self, name: N) -> io::Result<()>
|
||||||
|
where
|
||||||
|
N: AsRef<OsStr>,
|
||||||
|
{
|
||||||
|
sys::remove_fd(self.as_raw_fd(), name.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// List extended attributes attached to the specified file.
|
||||||
|
///
|
||||||
|
/// Note: this may not list *all* attributes. Speficially, it definitely won't list any trusted
|
||||||
|
/// attributes unless you are root and it may not list system attributes.
|
||||||
|
fn list_xattr(&self) -> io::Result<XAttrs> {
|
||||||
|
sys::list_fd(self.as_raw_fd())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FileExt for File {}
|
||||||
@@ -0,0 +1,367 @@
|
|||||||
|
//! FreeBSD and NetBSD xattr support.
|
||||||
|
|
||||||
|
use std::ffi::{CString, OsStr, OsString};
|
||||||
|
use std::io;
|
||||||
|
use std::mem;
|
||||||
|
use std::os::unix::ffi::{OsStrExt, OsStringExt};
|
||||||
|
use std::os::unix::io::RawFd;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use libc::{c_char, c_int, c_void, size_t, ssize_t, EPERM};
|
||||||
|
use util::{allocate_loop, path_to_c};
|
||||||
|
|
||||||
|
const EXTATTR_NAMESPACE_USER_STRING: &'static str = "user";
|
||||||
|
const EXTATTR_NAMESPACE_SYSTEM_STRING: &'static str = "system";
|
||||||
|
const EXTATTR_NAMESPACE_NAMES: [&'static str; 3] = [
|
||||||
|
"empty",
|
||||||
|
EXTATTR_NAMESPACE_USER_STRING,
|
||||||
|
EXTATTR_NAMESPACE_SYSTEM_STRING,
|
||||||
|
];
|
||||||
|
const EXTATTR_NAMESPACE_USER: c_int = 1;
|
||||||
|
const EXTATTR_NAMESPACE_SYSTEM: c_int = 2;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
pub fn extattr_list_fd(
|
||||||
|
fd: c_int,
|
||||||
|
attrnamespace: c_int,
|
||||||
|
data: *mut c_void,
|
||||||
|
nbytes: size_t,
|
||||||
|
) -> ssize_t;
|
||||||
|
pub fn extattr_get_fd(
|
||||||
|
fd: c_int,
|
||||||
|
attrnamespace: c_int,
|
||||||
|
attrname: *const c_char,
|
||||||
|
data: *mut c_void,
|
||||||
|
nbytes: size_t,
|
||||||
|
) -> ssize_t;
|
||||||
|
pub fn extattr_delete_fd(fd: c_int, attrname: c_int, attrname: *const c_char) -> c_int;
|
||||||
|
pub fn extattr_set_fd(
|
||||||
|
fd: c_int,
|
||||||
|
attrname: c_int,
|
||||||
|
attrname: *const c_char,
|
||||||
|
data: *const c_void,
|
||||||
|
nbytes: size_t,
|
||||||
|
) -> ssize_t;
|
||||||
|
|
||||||
|
pub fn extattr_list_link(
|
||||||
|
path: *const c_char,
|
||||||
|
attrnamespace: c_int,
|
||||||
|
data: *mut c_void,
|
||||||
|
nbytes: size_t,
|
||||||
|
) -> ssize_t;
|
||||||
|
pub fn extattr_get_link(
|
||||||
|
path: *const c_char,
|
||||||
|
attrnamespace: c_int,
|
||||||
|
attrname: *const c_char,
|
||||||
|
data: *mut c_void,
|
||||||
|
nbytes: size_t,
|
||||||
|
) -> ssize_t;
|
||||||
|
pub fn extattr_delete_link(
|
||||||
|
path: *const c_char,
|
||||||
|
attrname: c_int,
|
||||||
|
attrname: *const c_char,
|
||||||
|
) -> c_int;
|
||||||
|
pub fn extattr_set_link(
|
||||||
|
path: *const c_char,
|
||||||
|
attrname: c_int,
|
||||||
|
attrname: *const c_char,
|
||||||
|
data: *const c_void,
|
||||||
|
nbytes: size_t,
|
||||||
|
) -> ssize_t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An iterator over a set of extended attributes names.
|
||||||
|
pub struct XAttrs {
|
||||||
|
user_attrs: Box<[u8]>,
|
||||||
|
system_attrs: Box<[u8]>,
|
||||||
|
offset: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clone for XAttrs {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
XAttrs {
|
||||||
|
user_attrs: Vec::from(&*self.user_attrs).into_boxed_slice(),
|
||||||
|
system_attrs: Vec::from(&*self.system_attrs).into_boxed_slice(),
|
||||||
|
offset: self.offset,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clone_from(&mut self, other: &XAttrs) {
|
||||||
|
self.offset = other.offset;
|
||||||
|
|
||||||
|
let mut data = mem::replace(&mut self.user_attrs, Box::new([])).into_vec();
|
||||||
|
data.extend(other.user_attrs.iter().cloned());
|
||||||
|
self.user_attrs = data.into_boxed_slice();
|
||||||
|
|
||||||
|
data = mem::replace(&mut self.system_attrs, Box::new([])).into_vec();
|
||||||
|
data.extend(other.system_attrs.iter().cloned());
|
||||||
|
self.system_attrs = data.into_boxed_slice();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for XAttrs {
|
||||||
|
type Item = OsString;
|
||||||
|
fn next(&mut self) -> Option<OsString> {
|
||||||
|
if self.user_attrs.is_empty() && self.system_attrs.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.offset == self.user_attrs.len() + self.system_attrs.len() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = if self.offset < self.system_attrs.len() {
|
||||||
|
&self.system_attrs[self.offset..]
|
||||||
|
} else {
|
||||||
|
&self.user_attrs[self.offset - self.system_attrs.len()..]
|
||||||
|
};
|
||||||
|
|
||||||
|
let siz = data[0] as usize;
|
||||||
|
|
||||||
|
self.offset += siz + 1;
|
||||||
|
if self.offset < self.system_attrs.len() {
|
||||||
|
Some(prefix_namespace(
|
||||||
|
OsStr::from_bytes(&data[1..siz + 1]),
|
||||||
|
EXTATTR_NAMESPACE_SYSTEM,
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Some(prefix_namespace(
|
||||||
|
OsStr::from_bytes(&data[1..siz + 1]),
|
||||||
|
EXTATTR_NAMESPACE_USER,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
if self.user_attrs.len() + self.system_attrs.len() == self.offset {
|
||||||
|
(0, Some(0))
|
||||||
|
} else {
|
||||||
|
(1, None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name_to_ns(name: &OsStr) -> io::Result<(c_int, CString)> {
|
||||||
|
let mut groups = name.as_bytes().splitn(2, |&b| b == b'.').take(2);
|
||||||
|
let nsname = match groups.next() {
|
||||||
|
Some(s) => s,
|
||||||
|
None => {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
"couldn't find namespace",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let propname = match groups.next() {
|
||||||
|
Some(s) => s,
|
||||||
|
None => {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
"couldn't find attribute",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let ns_int = match EXTATTR_NAMESPACE_NAMES
|
||||||
|
.iter()
|
||||||
|
.position(|&s| s.as_bytes() == nsname)
|
||||||
|
{
|
||||||
|
Some(i) => i,
|
||||||
|
None => {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
"no matching namespace",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok((ns_int as c_int, CString::new(propname)?))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prefix_namespace(attr: &OsStr, ns: c_int) -> OsString {
|
||||||
|
let nsname = EXTATTR_NAMESPACE_NAMES[ns as usize];
|
||||||
|
let mut v = Vec::with_capacity(nsname.as_bytes().len() + attr.as_bytes().len() + 1);
|
||||||
|
v.extend(nsname.as_bytes());
|
||||||
|
v.extend(".".as_bytes());
|
||||||
|
v.extend(attr.as_bytes());
|
||||||
|
OsString::from_vec(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_fd(fd: RawFd, name: &OsStr) -> io::Result<Vec<u8>> {
|
||||||
|
let (ns, name) = name_to_ns(name)?;
|
||||||
|
unsafe {
|
||||||
|
allocate_loop(|buf, len| {
|
||||||
|
extattr_get_fd(fd, ns, name.as_ptr(), buf as *mut c_void, len as size_t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_fd(fd: RawFd, name: &OsStr, value: &[u8]) -> io::Result<()> {
|
||||||
|
let (ns, name) = name_to_ns(name)?;
|
||||||
|
let ret = unsafe {
|
||||||
|
extattr_set_fd(
|
||||||
|
fd,
|
||||||
|
ns,
|
||||||
|
name.as_ptr(),
|
||||||
|
value.as_ptr() as *const c_void,
|
||||||
|
value.len() as size_t,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
if ret == -1 {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_fd(fd: RawFd, name: &OsStr) -> io::Result<()> {
|
||||||
|
let (ns, name) = name_to_ns(name)?;
|
||||||
|
let ret = unsafe { extattr_delete_fd(fd, ns, name.as_ptr()) };
|
||||||
|
if ret != 0 {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_fd(fd: RawFd) -> io::Result<XAttrs> {
|
||||||
|
let sysvec = unsafe {
|
||||||
|
let res = allocate_loop(|buf, len| {
|
||||||
|
extattr_list_fd(
|
||||||
|
fd,
|
||||||
|
EXTATTR_NAMESPACE_SYSTEM,
|
||||||
|
buf as *mut c_void,
|
||||||
|
len as size_t,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
// On FreeBSD, system attributes require root privileges to view. However,
|
||||||
|
// to mimic the behavior of listxattr in linux and osx, we need to query
|
||||||
|
// them anyway and return empty results if we get EPERM
|
||||||
|
match res {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(err) => {
|
||||||
|
if err.raw_os_error() == Some(EPERM) {
|
||||||
|
Vec::new()
|
||||||
|
} else {
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let uservec = unsafe {
|
||||||
|
let res = allocate_loop(|buf, len| {
|
||||||
|
extattr_list_fd(
|
||||||
|
fd,
|
||||||
|
EXTATTR_NAMESPACE_USER,
|
||||||
|
buf as *mut c_void,
|
||||||
|
len as size_t,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
match res {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(err) => return Err(err),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(XAttrs {
|
||||||
|
system_attrs: sysvec.into_boxed_slice(),
|
||||||
|
user_attrs: uservec.into_boxed_slice(),
|
||||||
|
offset: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_path(path: &Path, name: &OsStr) -> io::Result<Vec<u8>> {
|
||||||
|
let (ns, name) = name_to_ns(name)?;
|
||||||
|
let path = path_to_c(path)?;
|
||||||
|
unsafe {
|
||||||
|
allocate_loop(|buf, len| {
|
||||||
|
extattr_get_link(
|
||||||
|
path.as_ptr(),
|
||||||
|
ns,
|
||||||
|
name.as_ptr(),
|
||||||
|
buf as *mut c_void,
|
||||||
|
len as size_t,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_path(path: &Path, name: &OsStr, value: &[u8]) -> io::Result<()> {
|
||||||
|
let (ns, name) = name_to_ns(name)?;
|
||||||
|
let path = path_to_c(path)?;
|
||||||
|
let ret = unsafe {
|
||||||
|
extattr_set_link(
|
||||||
|
path.as_ptr(),
|
||||||
|
ns,
|
||||||
|
name.as_ptr(),
|
||||||
|
value.as_ptr() as *const c_void,
|
||||||
|
value.len() as size_t,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
if ret == -1 {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_path(path: &Path, name: &OsStr) -> io::Result<()> {
|
||||||
|
let (ns, name) = name_to_ns(name)?;
|
||||||
|
let path = path_to_c(path)?;
|
||||||
|
let ret = unsafe { extattr_delete_link(path.as_ptr(), ns, name.as_ptr()) };
|
||||||
|
if ret != 0 {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_path(path: &Path) -> io::Result<XAttrs> {
|
||||||
|
let path = path_to_c(path)?;
|
||||||
|
let sysvec = unsafe {
|
||||||
|
let res = allocate_loop(|buf, len| {
|
||||||
|
extattr_list_link(
|
||||||
|
path.as_ptr(),
|
||||||
|
EXTATTR_NAMESPACE_SYSTEM,
|
||||||
|
buf as *mut c_void,
|
||||||
|
len as size_t,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
// On FreeBSD, system attributes require root privileges to view. However,
|
||||||
|
// to mimic the behavior of listxattr in linux and osx, we need to query
|
||||||
|
// them anyway and return empty results if we get EPERM
|
||||||
|
match res {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(err) => {
|
||||||
|
if err.raw_os_error() == Some(EPERM) {
|
||||||
|
Vec::new()
|
||||||
|
} else {
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let uservec = unsafe {
|
||||||
|
let res = allocate_loop(|buf, len| {
|
||||||
|
extattr_list_link(
|
||||||
|
path.as_ptr(),
|
||||||
|
EXTATTR_NAMESPACE_USER,
|
||||||
|
buf as *mut c_void,
|
||||||
|
len as size_t,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
match res {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(err) => return Err(err),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(XAttrs {
|
||||||
|
system_attrs: sysvec.into_boxed_slice(),
|
||||||
|
user_attrs: uservec.into_boxed_slice(),
|
||||||
|
offset: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
use libc::{c_char, c_int, c_void, size_t, ssize_t};
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
pub fn flistxattr(fd: c_int, buf: *mut c_char, size: size_t) -> ssize_t;
|
||||||
|
pub fn fgetxattr(fd: c_int, name: *const c_char, value: *mut c_void, size: size_t) -> ssize_t;
|
||||||
|
pub fn fremovexattr(fd: c_int, name: *const c_char) -> c_int;
|
||||||
|
|
||||||
|
pub fn llistxattr(path: *const c_char, buf: *mut c_char, size: size_t) -> ssize_t;
|
||||||
|
pub fn lgetxattr(
|
||||||
|
path: *const c_char,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *mut c_void,
|
||||||
|
size: size_t,
|
||||||
|
) -> ssize_t;
|
||||||
|
pub fn lremovexattr(path: *const c_char, name: *const c_char) -> c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn fsetxattr(
|
||||||
|
fd: c_int,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *const c_void,
|
||||||
|
size: size_t,
|
||||||
|
) -> ssize_t {
|
||||||
|
extern "C" {
|
||||||
|
fn fsetxattr(
|
||||||
|
fd: c_int,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *const c_void,
|
||||||
|
size: size_t,
|
||||||
|
flags: c_int,
|
||||||
|
) -> ssize_t;
|
||||||
|
}
|
||||||
|
fsetxattr(fd, name, value, size, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn lsetxattr(
|
||||||
|
path: *const c_char,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *const c_void,
|
||||||
|
size: size_t,
|
||||||
|
) -> ssize_t {
|
||||||
|
extern "C" {
|
||||||
|
fn lsetxattr(
|
||||||
|
path: *const c_char,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *const c_void,
|
||||||
|
size: size_t,
|
||||||
|
flags: c_int,
|
||||||
|
) -> ssize_t;
|
||||||
|
}
|
||||||
|
lsetxattr(path, name, value, size, 0)
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
use libc::{c_char, c_int, c_void, size_t, ssize_t, uint32_t};
|
||||||
|
|
||||||
|
const XATTR_NOFOLLOW: c_int = 0x0001;
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn fremovexattr(fd: c_int, name: *const c_char) -> c_int {
|
||||||
|
extern "C" {
|
||||||
|
fn fremovexattr(fd: c_int, name: *const c_char, options: c_int) -> c_int;
|
||||||
|
}
|
||||||
|
fremovexattr(fd, name, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn fsetxattr(
|
||||||
|
fd: c_int,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *const c_void,
|
||||||
|
size: size_t,
|
||||||
|
) -> ssize_t {
|
||||||
|
extern "C" {
|
||||||
|
fn fsetxattr(
|
||||||
|
fd: c_int,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *const c_void,
|
||||||
|
size: size_t,
|
||||||
|
position: uint32_t,
|
||||||
|
options: c_int,
|
||||||
|
) -> ssize_t;
|
||||||
|
}
|
||||||
|
fsetxattr(fd, name, value, size, 0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn fgetxattr(
|
||||||
|
fd: c_int,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *mut c_void,
|
||||||
|
size: size_t,
|
||||||
|
) -> ssize_t {
|
||||||
|
extern "C" {
|
||||||
|
fn fgetxattr(
|
||||||
|
fd: c_int,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *mut c_void,
|
||||||
|
size: size_t,
|
||||||
|
position: uint32_t,
|
||||||
|
options: c_int,
|
||||||
|
) -> ssize_t;
|
||||||
|
}
|
||||||
|
fgetxattr(fd, name, value, size, 0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn flistxattr(fd: c_int, buf: *mut c_char, size: size_t) -> ssize_t {
|
||||||
|
extern "C" {
|
||||||
|
fn flistxattr(fd: c_int, buf: *mut c_char, size: size_t, options: c_int) -> ssize_t;
|
||||||
|
}
|
||||||
|
flistxattr(fd, buf, size, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn lremovexattr(path: *const c_char, name: *const c_char) -> c_int {
|
||||||
|
extern "C" {
|
||||||
|
fn removexattr(path: *const c_char, name: *const c_char, options: c_int) -> c_int;
|
||||||
|
}
|
||||||
|
removexattr(path, name, XATTR_NOFOLLOW)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn lsetxattr(
|
||||||
|
path: *const c_char,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *const c_void,
|
||||||
|
size: size_t,
|
||||||
|
) -> ssize_t {
|
||||||
|
extern "C" {
|
||||||
|
fn setxattr(
|
||||||
|
path: *const c_char,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *const c_void,
|
||||||
|
size: size_t,
|
||||||
|
position: uint32_t,
|
||||||
|
options: c_int,
|
||||||
|
) -> ssize_t;
|
||||||
|
}
|
||||||
|
setxattr(path, name, value, size, 0, XATTR_NOFOLLOW)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn lgetxattr(
|
||||||
|
path: *const c_char,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *mut c_void,
|
||||||
|
size: size_t,
|
||||||
|
) -> ssize_t {
|
||||||
|
extern "C" {
|
||||||
|
fn getxattr(
|
||||||
|
path: *const c_char,
|
||||||
|
name: *const c_char,
|
||||||
|
value: *mut c_void,
|
||||||
|
size: size_t,
|
||||||
|
position: uint32_t,
|
||||||
|
options: c_int,
|
||||||
|
) -> ssize_t;
|
||||||
|
}
|
||||||
|
getxattr(path, name, value, size, 0, XATTR_NOFOLLOW)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn llistxattr(path: *const c_char, buf: *mut c_char, size: size_t) -> ssize_t {
|
||||||
|
extern "C" {
|
||||||
|
fn listxattr(
|
||||||
|
path: *const c_char,
|
||||||
|
buf: *mut c_char,
|
||||||
|
size: size_t,
|
||||||
|
options: c_int,
|
||||||
|
) -> ssize_t;
|
||||||
|
}
|
||||||
|
listxattr(path, buf, size, XATTR_NOFOLLOW)
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
mod linux;
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
use self::linux::*;
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
mod macos;
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
use self::macos::*;
|
||||||
|
|
||||||
|
use std::ffi::{OsStr, OsString};
|
||||||
|
use std::io;
|
||||||
|
use std::mem;
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
use std::os::unix::io::RawFd;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use libc::{c_char, c_void, size_t};
|
||||||
|
|
||||||
|
use util::{allocate_loop, name_to_c, path_to_c};
|
||||||
|
|
||||||
|
/// An iterator over a set of extended attributes names.
|
||||||
|
pub struct XAttrs {
|
||||||
|
data: Box<[u8]>,
|
||||||
|
offset: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clone for XAttrs {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
XAttrs {
|
||||||
|
data: Vec::from(&*self.data).into_boxed_slice(),
|
||||||
|
offset: self.offset,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn clone_from(&mut self, other: &XAttrs) {
|
||||||
|
self.offset = other.offset;
|
||||||
|
|
||||||
|
let mut data = mem::replace(&mut self.data, Box::new([])).into_vec();
|
||||||
|
data.extend(other.data.iter().cloned());
|
||||||
|
self.data = data.into_boxed_slice();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Yes, I could avoid these allocations on linux/macos. However, if we ever want to be freebsd
|
||||||
|
// compatible, we need to be able to prepend the namespace to the extended attribute names.
|
||||||
|
// Furthermore, borrowing makes the API messy.
|
||||||
|
impl Iterator for XAttrs {
|
||||||
|
type Item = OsString;
|
||||||
|
fn next(&mut self) -> Option<OsString> {
|
||||||
|
let data = &self.data[self.offset..];
|
||||||
|
if data.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
// always null terminated (unless empty).
|
||||||
|
let end = data.iter().position(|&b| b == 0u8).unwrap();
|
||||||
|
self.offset += end + 1;
|
||||||
|
Some(OsStr::from_bytes(&data[..end]).to_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
if self.data.len() == self.offset {
|
||||||
|
(0, Some(0))
|
||||||
|
} else {
|
||||||
|
(1, None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_fd(fd: RawFd, name: &OsStr) -> io::Result<Vec<u8>> {
|
||||||
|
let name = name_to_c(name)?;
|
||||||
|
unsafe {
|
||||||
|
allocate_loop(|buf, len| fgetxattr(fd, name.as_ptr(), buf as *mut c_void, len as size_t))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_fd(fd: RawFd, name: &OsStr, value: &[u8]) -> io::Result<()> {
|
||||||
|
let name = name_to_c(name)?;
|
||||||
|
let ret = unsafe {
|
||||||
|
fsetxattr(
|
||||||
|
fd,
|
||||||
|
name.as_ptr(),
|
||||||
|
value.as_ptr() as *const c_void,
|
||||||
|
value.len() as size_t,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
if ret != 0 {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_fd(fd: RawFd, name: &OsStr) -> io::Result<()> {
|
||||||
|
let name = name_to_c(name)?;
|
||||||
|
let ret = unsafe { fremovexattr(fd, name.as_ptr()) };
|
||||||
|
if ret != 0 {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_fd(fd: RawFd) -> io::Result<XAttrs> {
|
||||||
|
let vec =
|
||||||
|
unsafe { allocate_loop(|buf, len| flistxattr(fd, buf as *mut c_char, len as size_t))? };
|
||||||
|
Ok(XAttrs {
|
||||||
|
data: vec.into_boxed_slice(),
|
||||||
|
offset: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_path(path: &Path, name: &OsStr) -> io::Result<Vec<u8>> {
|
||||||
|
let name = name_to_c(name)?;
|
||||||
|
let path = path_to_c(path)?;
|
||||||
|
unsafe {
|
||||||
|
allocate_loop(|buf, len| {
|
||||||
|
lgetxattr(
|
||||||
|
path.as_ptr(),
|
||||||
|
name.as_ptr(),
|
||||||
|
buf as *mut c_void,
|
||||||
|
len as size_t,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_path(path: &Path, name: &OsStr, value: &[u8]) -> io::Result<()> {
|
||||||
|
let name = name_to_c(name)?;
|
||||||
|
let path = path_to_c(path)?;
|
||||||
|
let ret = unsafe {
|
||||||
|
lsetxattr(
|
||||||
|
path.as_ptr(),
|
||||||
|
name.as_ptr(),
|
||||||
|
value.as_ptr() as *const c_void,
|
||||||
|
value.len() as size_t,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
if ret != 0 {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_path(path: &Path, name: &OsStr) -> io::Result<()> {
|
||||||
|
let name = name_to_c(name)?;
|
||||||
|
let path = path_to_c(path)?;
|
||||||
|
let ret = unsafe { lremovexattr(path.as_ptr(), name.as_ptr()) };
|
||||||
|
if ret != 0 {
|
||||||
|
Err(io::Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_path(path: &Path) -> io::Result<XAttrs> {
|
||||||
|
let path = path_to_c(path)?;
|
||||||
|
let vec = unsafe {
|
||||||
|
allocate_loop(|buf, len| llistxattr(path.as_ptr(), buf as *mut c_char, len as size_t))?
|
||||||
|
};
|
||||||
|
Ok(XAttrs {
|
||||||
|
data: vec.into_boxed_slice(),
|
||||||
|
offset: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
macro_rules! platforms {
|
||||||
|
($($($platform:expr);* => $module:ident),*) => {
|
||||||
|
$(
|
||||||
|
#[cfg(any($(target_os = $platform),*))]
|
||||||
|
#[cfg_attr(not(any($(target_os = $platform),*)), allow(dead_code))]
|
||||||
|
mod $module;
|
||||||
|
|
||||||
|
#[cfg(any($(target_os = $platform),*))]
|
||||||
|
pub use self::$module::*;
|
||||||
|
|
||||||
|
#[cfg(any($(target_os = $platform),*))]
|
||||||
|
pub const ENOATTR: ::libc::c_int = ::libc::ENODATA;
|
||||||
|
)*
|
||||||
|
|
||||||
|
#[cfg(all(feature = "unsupported", not(any($($(target_os = $platform),*),*))))]
|
||||||
|
#[cfg_attr(any($($(target_os = $platform),*),*), allow(dead_code))]
|
||||||
|
mod unsupported;
|
||||||
|
|
||||||
|
#[cfg(all(feature = "unsupported", not(any($($(target_os = $platform),*),*))))]
|
||||||
|
pub use self::unsupported::*;
|
||||||
|
#[cfg(all(feature = "unsupported", not(any($($(target_os = $platform),*),*))))]
|
||||||
|
pub const ENOATTR: ::libc::c_int = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/// A constant indicating whether or not the target platform is supported.
|
||||||
|
///
|
||||||
|
/// To make programmer's lives easier, this library builds on all platforms.
|
||||||
|
/// However, all function calls on unsupported platforms will return
|
||||||
|
/// `io::Error`s.
|
||||||
|
///
|
||||||
|
/// Note: If you would like compilation to simply fail on unsupported platforms,
|
||||||
|
/// turn of the `unsupported` feature.
|
||||||
|
pub const SUPPORTED_PLATFORM: bool = cfg!(any($($(target_os = $platform),*),*));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
platforms! {
|
||||||
|
"android"; "linux"; "macos" => linux_macos,
|
||||||
|
"freebsd"; "netbsd" => bsd
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
use std::ffi::{OsStr, OsString};
|
||||||
|
use std::io;
|
||||||
|
use std::os::unix::io::RawFd;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use UnsupportedPlatformError;
|
||||||
|
|
||||||
|
/// An iterator over a set of extended attributes names.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct XAttrs;
|
||||||
|
|
||||||
|
impl Iterator for XAttrs {
|
||||||
|
type Item = OsString;
|
||||||
|
fn next(&mut self) -> Option<OsString> {
|
||||||
|
unreachable!("this should never exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
unreachable!("this should never exist")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_fd(_: RawFd, _: &OsStr) -> io::Result<Vec<u8>> {
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
UnsupportedPlatformError,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_fd(_: RawFd, _: &OsStr, _: &[u8]) -> io::Result<()> {
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
UnsupportedPlatformError,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_fd(_: RawFd, _: &OsStr) -> io::Result<()> {
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
UnsupportedPlatformError,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_fd(_: RawFd) -> io::Result<XAttrs> {
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
UnsupportedPlatformError,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_path(_: &Path, _: &OsStr) -> io::Result<Vec<u8>> {
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
UnsupportedPlatformError,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_path(_: &Path, _: &OsStr, _: &[u8]) -> io::Result<()> {
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
UnsupportedPlatformError,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_path(_: &Path, _: &OsStr) -> io::Result<()> {
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
UnsupportedPlatformError,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_path(_: &Path) -> io::Result<XAttrs> {
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
UnsupportedPlatformError,
|
||||||
|
))
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
use std::ffi::CString;
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
use std::io;
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::ptr;
|
||||||
|
|
||||||
|
use libc::{ssize_t, ERANGE};
|
||||||
|
|
||||||
|
// Need to use this one as libc only defines this on supported platforms. Given
|
||||||
|
// that we want to at least compile on unsupported platforms, we define this in
|
||||||
|
// our platform-specific modules.
|
||||||
|
use sys::ENOATTR;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn name_to_c(name: &OsStr) -> io::Result<CString> {
|
||||||
|
match CString::new(name.as_bytes()) {
|
||||||
|
Ok(name) => Ok(name),
|
||||||
|
Err(_) => Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
"name must not contain null bytes",
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn path_to_c(path: &Path) -> io::Result<CString> {
|
||||||
|
match CString::new(path.as_os_str().as_bytes()) {
|
||||||
|
Ok(name) => Ok(name),
|
||||||
|
Err(_) => Err(io::Error::new(io::ErrorKind::NotFound, "file not found")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn extract_noattr(result: io::Result<Vec<u8>>) -> io::Result<Option<Vec<u8>>> {
|
||||||
|
result.map(Some).or_else(|e| match e.raw_os_error() {
|
||||||
|
Some(ENOATTR) => Ok(None),
|
||||||
|
_ => Err(e),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn allocate_loop<F: FnMut(*mut u8, usize) -> ssize_t>(mut f: F) -> io::Result<Vec<u8>> {
|
||||||
|
let mut vec: Vec<u8> = Vec::new();
|
||||||
|
loop {
|
||||||
|
let ret = (f)(ptr::null_mut(), 0);
|
||||||
|
if ret < 0 {
|
||||||
|
return Err(io::Error::last_os_error());
|
||||||
|
} else if ret == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
vec.reserve_exact(ret as usize);
|
||||||
|
|
||||||
|
let ret = (f)(vec.as_mut_ptr(), vec.capacity());
|
||||||
|
if ret >= 0 {
|
||||||
|
vec.set_len(ret as usize);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
let error = io::Error::last_os_error();
|
||||||
|
if error.raw_os_error() == Some(ERANGE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return Err(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vec.shrink_to_fit();
|
||||||
|
Ok(vec)
|
||||||
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
extern crate tempfile;
|
||||||
|
extern crate xattr;
|
||||||
|
|
||||||
|
use std::collections::BTreeSet;
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
use xattr::FileExt;
|
||||||
|
|
||||||
|
use tempfile::{tempfile_in, NamedTempFile};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||||
|
fn test_fd() {
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
// Only works on "real" filesystems.
|
||||||
|
let tmp = tempfile_in("/var/tmp").unwrap();
|
||||||
|
assert!(tmp.get_xattr("user.test").unwrap().is_none());
|
||||||
|
assert_eq!(
|
||||||
|
tmp.list_xattr()
|
||||||
|
.unwrap()
|
||||||
|
.filter(|x| x.as_bytes().starts_with(b"user."))
|
||||||
|
.count(),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
tmp.set_xattr("user.test", b"my test").unwrap();
|
||||||
|
assert_eq!(tmp.get_xattr("user.test").unwrap().unwrap(), b"my test");
|
||||||
|
assert_eq!(
|
||||||
|
tmp.list_xattr()
|
||||||
|
.unwrap()
|
||||||
|
.filter(|x| x.as_bytes().starts_with(b"user."))
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![OsStr::new("user.test")]
|
||||||
|
);
|
||||||
|
|
||||||
|
tmp.remove_xattr("user.test").unwrap();
|
||||||
|
assert!(tmp.get_xattr("user.test").unwrap().is_none());
|
||||||
|
assert_eq!(
|
||||||
|
tmp.list_xattr()
|
||||||
|
.unwrap()
|
||||||
|
.filter(|x| x.as_bytes().starts_with(b"user."))
|
||||||
|
.count(),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||||
|
fn test_path() {
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
// Only works on "real" filesystems.
|
||||||
|
let tmp = NamedTempFile::new_in("/var/tmp").unwrap();
|
||||||
|
assert!(xattr::get(tmp.path(), "user.test").unwrap().is_none());
|
||||||
|
assert_eq!(
|
||||||
|
xattr::list(tmp.path())
|
||||||
|
.unwrap()
|
||||||
|
.filter(|x| x.as_bytes().starts_with(b"user."))
|
||||||
|
.count(),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
xattr::set(tmp.path(), "user.test", b"my test").unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
xattr::get(tmp.path(), "user.test").unwrap().unwrap(),
|
||||||
|
b"my test"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
xattr::list(tmp.path())
|
||||||
|
.unwrap()
|
||||||
|
.filter(|x| x.as_bytes().starts_with(b"user."))
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![OsStr::new("user.test")]
|
||||||
|
);
|
||||||
|
|
||||||
|
xattr::remove(tmp.path(), "user.test").unwrap();
|
||||||
|
assert!(xattr::get(tmp.path(), "user.test").unwrap().is_none());
|
||||||
|
assert_eq!(
|
||||||
|
xattr::list(tmp.path())
|
||||||
|
.unwrap()
|
||||||
|
.filter(|x| x.as_bytes().starts_with(b"user."))
|
||||||
|
.count(),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||||
|
fn test_missing() {
|
||||||
|
assert!(xattr::get("/var/empty/does-not-exist", "user.test").is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
|
||||||
|
fn test_multi() {
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
// Only works on "real" filesystems.
|
||||||
|
let tmp = tempfile_in("/var/tmp").unwrap();
|
||||||
|
let mut items: BTreeSet<_> = [
|
||||||
|
OsStr::new("user.test1"),
|
||||||
|
OsStr::new("user.test2"),
|
||||||
|
OsStr::new("user.test3"),
|
||||||
|
].iter()
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
for it in &items {
|
||||||
|
tmp.set_xattr(it, b"value").unwrap();
|
||||||
|
}
|
||||||
|
for it in tmp.list_xattr()
|
||||||
|
.unwrap()
|
||||||
|
.filter(|x| x.as_bytes().starts_with(&*b"user."))
|
||||||
|
{
|
||||||
|
assert!(items.remove(&*it));
|
||||||
|
}
|
||||||
|
assert!(items.is_empty());
|
||||||
|
}
|
||||||
@@ -84,6 +84,10 @@ pub struct AppConfig {
|
|||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub head_tracking_enabled: bool,
|
pub head_tracking_enabled: bool,
|
||||||
|
|
||||||
|
/// Moteur d'interface graphique : "gpui" (GPU-accéléré moderne Tailwind) ou "egui" (classique)
|
||||||
|
#[arg(long, default_value = "gpui")]
|
||||||
|
pub gui_engine: String,
|
||||||
|
|
||||||
/// Adresse IP du Backpack Wi-Fi du module RadioMaster Nomad (en mode AP ELRS : 10.0.0.1)
|
/// Adresse IP du Backpack Wi-Fi du module RadioMaster Nomad (en mode AP ELRS : 10.0.0.1)
|
||||||
#[arg(long, default_value = "10.0.0.1")]
|
#[arg(long, default_value = "10.0.0.1")]
|
||||||
pub nomad_ip: String,
|
pub nomad_ip: String,
|
||||||
|
|||||||
@@ -77,15 +77,19 @@ impl DomeWarpLut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply(&self, input_rgba: &[u8], output_rgba: &mut [u8]) {
|
pub fn apply(&self, input_rgba: &[u8], output_rgba: &mut [u8]) {
|
||||||
if !self.enabled || input_rgba.len() < (self.width * self.height * 4) as usize {
|
let expected_len = (self.width * self.height * 4) as usize;
|
||||||
output_rgba.copy_from_slice(input_rgba);
|
if !self.enabled || input_rgba.len() < expected_len || output_rgba.len() < expected_len {
|
||||||
|
let copy_len = output_rgba.len().min(input_rgba.len());
|
||||||
|
output_rgba[..copy_len].copy_from_slice(&input_rgba[..copy_len]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (dst_pixel_idx, &src_byte_idx) in self.src_byte_offsets.iter().enumerate() {
|
for (dst_pixel_idx, &src_byte_idx) in self.src_byte_offsets.iter().enumerate() {
|
||||||
let dst_byte_idx = dst_pixel_idx * 4;
|
let dst_byte_idx = dst_pixel_idx * 4;
|
||||||
|
if src_byte_idx + 4 <= input_rgba.len() && dst_byte_idx + 4 <= output_rgba.len() {
|
||||||
output_rgba[dst_byte_idx..dst_byte_idx + 4]
|
output_rgba[dst_byte_idx..dst_byte_idx + 4]
|
||||||
.copy_from_slice(&input_rgba[src_byte_idx..src_byte_idx + 4]);
|
.copy_from_slice(&input_rgba[src_byte_idx..src_byte_idx + 4]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+40
-28
@@ -36,6 +36,7 @@ pub struct RuntimeMonitor {
|
|||||||
pub preview_width: u32,
|
pub preview_width: u32,
|
||||||
pub preview_height: u32,
|
pub preview_height: u32,
|
||||||
pub preview_frame_seq: u64,
|
pub preview_frame_seq: u64,
|
||||||
|
#[allow(dead_code)]
|
||||||
pub manual_override_enabled: bool,
|
pub manual_override_enabled: bool,
|
||||||
pub manual_pan_deg: f32,
|
pub manual_pan_deg: f32,
|
||||||
pub manual_tilt_deg: f32,
|
pub manual_tilt_deg: f32,
|
||||||
@@ -94,15 +95,15 @@ impl FpvEngineController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_recenter(&self) {
|
pub fn request_recenter(&self) {
|
||||||
self.recenter_flag.store(true, Ordering::Relaxed);
|
self.recenter_flag.store(true, Ordering::Release);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_telemetry_enabled(&self) -> bool {
|
pub fn is_telemetry_enabled(&self) -> bool {
|
||||||
self.telemetry_enabled_flag.load(Ordering::Relaxed)
|
self.telemetry_enabled_flag.load(Ordering::Acquire)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_telemetry_enabled(&self, enabled: bool) {
|
pub fn set_telemetry_enabled(&self, enabled: bool) {
|
||||||
let prev = self.telemetry_enabled_flag.swap(enabled, Ordering::Relaxed);
|
let prev = self.telemetry_enabled_flag.swap(enabled, Ordering::AcqRel);
|
||||||
if prev != enabled {
|
if prev != enabled {
|
||||||
log::info!(
|
log::info!(
|
||||||
"[Action Utilisateur] Télémétrie & OSD basculés sur : {}",
|
"[Action Utilisateur] Télémétrie & OSD basculés sur : {}",
|
||||||
@@ -112,11 +113,11 @@ impl FpvEngineController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_head_tracking_enabled(&self) -> bool {
|
pub fn is_head_tracking_enabled(&self) -> bool {
|
||||||
self.head_tracking_enabled_flag.load(Ordering::Relaxed)
|
self.head_tracking_enabled_flag.load(Ordering::Acquire)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_head_tracking_enabled(&self, enabled: bool) {
|
pub fn set_head_tracking_enabled(&self, enabled: bool) {
|
||||||
let prev = self.head_tracking_enabled_flag.swap(enabled, Ordering::Relaxed);
|
let prev = self.head_tracking_enabled_flag.swap(enabled, Ordering::AcqRel);
|
||||||
if prev != enabled {
|
if prev != enabled {
|
||||||
log::info!(
|
log::info!(
|
||||||
"[Action Utilisateur] Suivi de Tête (RadioMaster Nomad) basculé sur : {}",
|
"[Action Utilisateur] Suivi de Tête (RadioMaster Nomad) basculé sur : {}",
|
||||||
@@ -126,13 +127,11 @@ impl FpvEngineController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(&mut self) {
|
pub fn stop(&mut self) {
|
||||||
if self.is_running() {
|
self.stop_flag.store(true, Ordering::Release);
|
||||||
log::info!("[Moteur FPV] Arrêt des services demandé par l'utilisateur...");
|
|
||||||
self.stop_flag.store(true, Ordering::Relaxed);
|
|
||||||
if let Some(handle) = self.worker_handle.take() {
|
if let Some(handle) = self.worker_handle.take() {
|
||||||
|
log::info!("[Moteur FPV] Arrêt et jonction du thread worker...");
|
||||||
let _ = handle.join();
|
let _ = handle.join();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
let mut mon = self.monitor.lock();
|
let mut mon = self.monitor.lock();
|
||||||
mon.usb_video_status = SubsystemStatus::Stopped;
|
mon.usb_video_status = SubsystemStatus::Stopped;
|
||||||
mon.openxr_status = SubsystemStatus::Stopped;
|
mon.openxr_status = SubsystemStatus::Stopped;
|
||||||
@@ -562,24 +561,32 @@ fn try_run_openxr_session(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut new_raw_frame: Option<Vec<u8>> = None;
|
||||||
|
let mut has_video_stream = false;
|
||||||
|
|
||||||
if let Some(rx) = video_rx {
|
if let Some(rx) = video_rx {
|
||||||
let lock = rx.latest_frame();
|
let lock = rx.latest_frame();
|
||||||
let guard = lock.lock();
|
let guard = lock.lock();
|
||||||
if let Some(ref vf) = *guard {
|
if let Some(ref vf) = *guard {
|
||||||
|
has_video_stream = true;
|
||||||
if vf.frame_id != last_frame_id {
|
if vf.frame_id != last_frame_id {
|
||||||
last_frame_id = vf.frame_id;
|
last_frame_id = vf.frame_id;
|
||||||
fps_counter += 1;
|
fps_counter += 1;
|
||||||
|
new_raw_frame = Some(vf.rgba_data.clone());
|
||||||
}
|
}
|
||||||
dome_lut.apply(&vf.rgba_data, &mut composited_rgba);
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if let Some(raw) = new_raw_frame {
|
||||||
|
dome_lut.apply(&raw, &mut composited_rgba);
|
||||||
|
} else if !has_video_stream {
|
||||||
standby_tick = standby_tick.wrapping_add(1);
|
standby_tick = standby_tick.wrapping_add(1);
|
||||||
let pattern = UsbVideoReceiver::generate_standby_pattern(
|
UsbVideoReceiver::render_standby_pattern(
|
||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
cfg.video_height,
|
cfg.video_height,
|
||||||
standby_tick,
|
standby_tick,
|
||||||
|
&mut composited_rgba,
|
||||||
);
|
);
|
||||||
composited_rgba.copy_from_slice(&pattern);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let telem_snapshot = telem_rx_opt
|
let telem_snapshot = telem_rx_opt
|
||||||
@@ -758,32 +765,32 @@ fn run_desktop_fallback_loop(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut new_raw_frame: Option<Vec<u8>> = None;
|
||||||
|
let mut has_video_stream = false;
|
||||||
|
|
||||||
if let Some(rx) = video_rx {
|
if let Some(rx) = video_rx {
|
||||||
let lock = rx.latest_frame();
|
let lock = rx.latest_frame();
|
||||||
let guard = lock.lock();
|
let guard = lock.lock();
|
||||||
if let Some(ref vf) = *guard {
|
if let Some(ref vf) = *guard {
|
||||||
|
has_video_stream = true;
|
||||||
if vf.frame_id != last_frame_id {
|
if vf.frame_id != last_frame_id {
|
||||||
last_frame_id = vf.frame_id;
|
last_frame_id = vf.frame_id;
|
||||||
fps_counter += 1;
|
fps_counter += 1;
|
||||||
|
new_raw_frame = Some(vf.rgba_data.clone());
|
||||||
}
|
}
|
||||||
dome_lut.apply(&vf.rgba_data, &mut composited_rgba);
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if let Some(raw) = new_raw_frame {
|
||||||
|
dome_lut.apply(&raw, &mut composited_rgba);
|
||||||
|
} else if !has_video_stream {
|
||||||
standby_tick = standby_tick.wrapping_add(1);
|
standby_tick = standby_tick.wrapping_add(1);
|
||||||
let pattern = UsbVideoReceiver::generate_standby_pattern(
|
UsbVideoReceiver::render_standby_pattern(
|
||||||
cfg.video_width,
|
cfg.video_width,
|
||||||
cfg.video_height,
|
cfg.video_height,
|
||||||
standby_tick,
|
standby_tick,
|
||||||
|
&mut composited_rgba,
|
||||||
);
|
);
|
||||||
composited_rgba.copy_from_slice(&pattern);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
standby_tick = standby_tick.wrapping_add(1);
|
|
||||||
let pattern = UsbVideoReceiver::generate_standby_pattern(
|
|
||||||
cfg.video_width,
|
|
||||||
cfg.video_height,
|
|
||||||
standby_tick,
|
|
||||||
);
|
|
||||||
composited_rgba.copy_from_slice(&pattern);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let telem_snapshot = telem_rx_opt
|
let telem_snapshot = telem_rx_opt
|
||||||
@@ -813,7 +820,12 @@ fn run_desktop_fallback_loop(
|
|||||||
fps_counter = 0;
|
fps_counter = 0;
|
||||||
fps_timer = Instant::now();
|
fps_timer = Instant::now();
|
||||||
}
|
}
|
||||||
if current_pose.send_errors > 0 {
|
if current_pose.last_send_ok {
|
||||||
|
mon.nomad_wifi_status = SubsystemStatus::Running(format!(
|
||||||
|
"ON - Cible {}:{} ({} paquets)",
|
||||||
|
cfg.nomad_ip, cfg.nomad_port, current_pose.packets_sent
|
||||||
|
));
|
||||||
|
} else if current_pose.send_errors > 0 {
|
||||||
mon.nomad_wifi_status = SubsystemStatus::Error(format!(
|
mon.nomad_wifi_status = SubsystemStatus::Error(format!(
|
||||||
"Erreur d'envoi UDP vers {}:{} ({} échecs)",
|
"Erreur d'envoi UDP vers {}:{} ({} échecs)",
|
||||||
cfg.nomad_ip, cfg.nomad_port, current_pose.send_errors
|
cfg.nomad_ip, cfg.nomad_port, current_pose.send_errors
|
||||||
|
|||||||
+1
-7
@@ -1,6 +1,6 @@
|
|||||||
use crate::config::AppConfig;
|
use crate::config::AppConfig;
|
||||||
use crate::engine::{FpvEngineController, SubsystemStatus};
|
use crate::engine::{FpvEngineController, SubsystemStatus};
|
||||||
use crate::logger::LogBuffer;
|
use crate::logger::{LogBuffer, LogFilter};
|
||||||
use crate::nomad_elrs::NomadHeadTracker;
|
use crate::nomad_elrs::NomadHeadTracker;
|
||||||
use eframe::egui::{self, Color32, RichText, TextureHandle, TextureOptions};
|
use eframe::egui::{self, Color32, RichText, TextureHandle, TextureOptions};
|
||||||
use log::Level;
|
use log::Level;
|
||||||
@@ -9,12 +9,6 @@ use std::process::Command;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
enum LogFilter {
|
|
||||||
All,
|
|
||||||
WarningsAndErrors,
|
|
||||||
ErrorsOnly,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SteamFrameGuiApp {
|
pub struct SteamFrameGuiApp {
|
||||||
cfg: AppConfig,
|
cfg: AppConfig,
|
||||||
|
|||||||
+1113
File diff suppressed because it is too large.
Load diff
@@ -8,6 +8,13 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
const MAX_LOG_ENTRIES: usize = 1000;
|
const MAX_LOG_ENTRIES: usize = 1000;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum LogFilter {
|
||||||
|
All,
|
||||||
|
WarningsAndErrors,
|
||||||
|
ErrorsOnly,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct LogEntry {
|
pub struct LogEntry {
|
||||||
pub timestamp: String,
|
pub timestamp: String,
|
||||||
@@ -21,6 +28,7 @@ pub struct LogBuffer {
|
|||||||
pub entries: VecDeque<LogEntry>,
|
pub entries: VecDeque<LogEntry>,
|
||||||
pub error_count: usize,
|
pub error_count: usize,
|
||||||
pub warn_count: usize,
|
pub warn_count: usize,
|
||||||
|
pub revision: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Logger centralisé capturant tous les événements et erreurs pour l'interface graphique
|
/// Logger centralisé capturant tous les événements et erreurs pour l'interface graphique
|
||||||
@@ -48,6 +56,16 @@ impl GuiLogger {
|
|||||||
|
|
||||||
impl Log for GuiLogger {
|
impl Log for GuiLogger {
|
||||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||||
|
let t = metadata.target();
|
||||||
|
if t.starts_with("blade_graphics")
|
||||||
|
|| t.starts_with("naga")
|
||||||
|
|| t.starts_with("zbus")
|
||||||
|
|| t.starts_with("tracing")
|
||||||
|
|| t.starts_with("calloop")
|
||||||
|
|| t.starts_with("winit")
|
||||||
|
{
|
||||||
|
return metadata.level() <= Level::Warn;
|
||||||
|
}
|
||||||
metadata.level() <= Level::Info
|
metadata.level() <= Level::Info
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +113,7 @@ impl Log for GuiLogger {
|
|||||||
lock.entries.pop_front();
|
lock.entries.pop_front();
|
||||||
}
|
}
|
||||||
lock.entries.push_back(entry);
|
lock.entries.push_back(entry);
|
||||||
|
lock.revision = lock.revision.wrapping_add(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&self) {}
|
fn flush(&self) {}
|
||||||
|
|||||||
+8
-1
@@ -2,6 +2,7 @@ mod config;
|
|||||||
mod dome_projection;
|
mod dome_projection;
|
||||||
mod engine;
|
mod engine;
|
||||||
mod gui;
|
mod gui;
|
||||||
|
mod gui_gpui;
|
||||||
mod logger;
|
mod logger;
|
||||||
mod nomad_elrs;
|
mod nomad_elrs;
|
||||||
mod telemetry_osd;
|
mod telemetry_osd;
|
||||||
@@ -23,7 +24,8 @@ fn main() -> Result<()> {
|
|||||||
let log_buffer = GuiLogger::init(&cfg.log_file);
|
let log_buffer = GuiLogger::init(&cfg.log_file);
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
"=== Démarrage de SteamFrame FPV v0.2 (Fichier journal : {}) ===",
|
"=== Démarrage de SteamFrame FPV v0.2 (Moteur IHM : {}, Fichier journal : {}) ===",
|
||||||
|
cfg.gui_engine,
|
||||||
cfg.log_file
|
cfg.log_file
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -39,6 +41,11 @@ fn main() -> Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.gui_engine.eq_ignore_ascii_case("gpui") {
|
||||||
|
log::info!("Démarrage de l'interface moderne GPU-accélérée (GPUI)...");
|
||||||
|
return gui_gpui::run_gpui_app(cfg, log_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
let native_options = eframe::NativeOptions {
|
let native_options = eframe::NativeOptions {
|
||||||
viewport: eframe::egui::ViewportBuilder::default()
|
viewport: eframe::egui::ViewportBuilder::default()
|
||||||
.with_title("SteamFrame FPV - Eachine Sphere Link & RadioMaster Nomad")
|
.with_title("SteamFrame FPV - Eachine Sphere Link & RadioMaster Nomad")
|
||||||
|
|||||||
+19
-3
@@ -21,6 +21,7 @@ pub struct HeadPoseSample {
|
|||||||
pub roll_crsf: u16,
|
pub roll_crsf: u16,
|
||||||
pub packets_sent: u64,
|
pub packets_sent: u64,
|
||||||
pub send_errors: u64,
|
pub send_errors: u64,
|
||||||
|
pub last_send_ok: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for HeadPoseSample {
|
impl Default for HeadPoseSample {
|
||||||
@@ -34,6 +35,7 @@ impl Default for HeadPoseSample {
|
|||||||
roll_crsf: CRSF_CHANNEL_MID,
|
roll_crsf: CRSF_CHANNEL_MID,
|
||||||
packets_sent: 0,
|
packets_sent: 0,
|
||||||
send_errors: 0,
|
send_errors: 0,
|
||||||
|
last_send_ok: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,9 +133,10 @@ impl NomadHeadTracker {
|
|||||||
self.socket.send_to(&packet, self.target)
|
self.socket.send_to(&packet, self.target)
|
||||||
};
|
};
|
||||||
|
|
||||||
match send_res {
|
let last_send_ok = match send_res {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.packets_sent = self.packets_sent.wrapping_add(1);
|
self.packets_sent = self.packets_sent.wrapping_add(1);
|
||||||
|
true
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.send_errors = self.send_errors.wrapping_add(1);
|
self.send_errors = self.send_errors.wrapping_add(1);
|
||||||
@@ -149,8 +152,9 @@ impl NomadHeadTracker {
|
|||||||
);
|
);
|
||||||
self.last_error_log = Some(Instant::now());
|
self.last_error_log = Some(Instant::now());
|
||||||
}
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
Ok(HeadPoseSample {
|
Ok(HeadPoseSample {
|
||||||
pan_deg,
|
pan_deg,
|
||||||
@@ -161,12 +165,13 @@ impl NomadHeadTracker {
|
|||||||
roll_crsf,
|
roll_crsf,
|
||||||
packets_sent: self.packets_sent,
|
packets_sent: self.packets_sent,
|
||||||
send_errors: self.send_errors,
|
send_errors: self.send_errors,
|
||||||
|
last_send_ok,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn deg_to_crsf(angle_deg: f32, max_deg: f32) -> u16 {
|
pub fn deg_to_crsf(angle_deg: f32, max_deg: f32) -> u16 {
|
||||||
if max_deg <= 0.0 {
|
if angle_deg.is_nan() || max_deg <= 0.0 {
|
||||||
return CRSF_CHANNEL_MID;
|
return CRSF_CHANNEL_MID;
|
||||||
}
|
}
|
||||||
let norm = (angle_deg / max_deg).clamp(-1.0, 1.0);
|
let norm = (angle_deg / max_deg).clamp(-1.0, 1.0);
|
||||||
@@ -248,6 +253,7 @@ mod tests {
|
|||||||
assert_eq!(NomadHeadTracker::deg_to_crsf(0.0, 90.0), CRSF_CHANNEL_MID);
|
assert_eq!(NomadHeadTracker::deg_to_crsf(0.0, 90.0), CRSF_CHANNEL_MID);
|
||||||
assert_eq!(NomadHeadTracker::deg_to_crsf(90.0, 90.0), CRSF_CHANNEL_MAX);
|
assert_eq!(NomadHeadTracker::deg_to_crsf(90.0, 90.0), CRSF_CHANNEL_MAX);
|
||||||
assert_eq!(NomadHeadTracker::deg_to_crsf(-90.0, 90.0), CRSF_CHANNEL_MIN);
|
assert_eq!(NomadHeadTracker::deg_to_crsf(-90.0, 90.0), CRSF_CHANNEL_MIN);
|
||||||
|
assert_eq!(NomadHeadTracker::deg_to_crsf(f32::NAN, 90.0), CRSF_CHANNEL_MID);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -256,5 +262,15 @@ mod tests {
|
|||||||
assert_eq!(&pkt[0..3], b"$X<");
|
assert_eq!(&pkt[0..3], b"$X<");
|
||||||
assert_eq!(u16::from_le_bytes([pkt[4], pkt[5]]), MSP_ELRS_BACKPACK_SET_PTR);
|
assert_eq!(u16::from_le_bytes([pkt[4], pkt[5]]), MSP_ELRS_BACKPACK_SET_PTR);
|
||||||
assert_eq!(u16::from_le_bytes([pkt[6], pkt[7]]), 6);
|
assert_eq!(u16::from_le_bytes([pkt[6], pkt[7]]), 6);
|
||||||
|
assert_eq!(pkt[14], NomadHeadTracker::crc8_dvb_s2(&pkt[3..14]));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_crsf_rc_channels_packet() {
|
||||||
|
let pkt = NomadHeadTracker::encode_crsf_rc_channels(992, 992, 992);
|
||||||
|
assert_eq!(pkt[0], 0xEE); // Sync CRSF
|
||||||
|
assert_eq!(pkt[1], 24); // Payload len
|
||||||
|
assert_eq!(pkt[2], 0x16); // Type RC_CHANNELS_PACKED
|
||||||
|
assert_eq!(pkt[25], NomadHeadTracker::crc8_dvb_s2(&pkt[2..25]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+20
-7
@@ -10,6 +10,7 @@ use std::thread;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct VideoFrame {
|
pub struct VideoFrame {
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
@@ -52,7 +53,7 @@ impl UsbVideoReceiver {
|
|||||||
decodebin ! \
|
decodebin ! \
|
||||||
videoconvert ! videoscale ! \
|
videoconvert ! videoscale ! \
|
||||||
video/x-raw,format=RGBA,width={target_width},height={target_height} ! \
|
video/x-raw,format=RGBA,width={target_width},height={target_height} ! \
|
||||||
appsink name=fpv_sink sync=false max-buffers=1 drop=true emit-signals=true"
|
appsink name=fpv_sink sync=false max-buffers=1 drop=true emit-signals=false"
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let codec_lower = codec.to_lowercase();
|
let codec_lower = codec.to_lowercase();
|
||||||
@@ -69,6 +70,7 @@ impl UsbVideoReceiver {
|
|||||||
let depay_and_parse = if stream_transport.eq_ignore_ascii_case("rtp") {
|
let depay_and_parse = if stream_transport.eq_ignore_ascii_case("rtp") {
|
||||||
format!(
|
format!(
|
||||||
"application/x-rtp,media=video,clock-rate=90000,encoding-name={codec_name},payload=96 ! \
|
"application/x-rtp,media=video,clock-rate=90000,encoding-name={codec_name},payload=96 ! \
|
||||||
|
rtpjitterbuffer latency=0 drop-on-latency=true ! \
|
||||||
{depay} ! {parser} config-interval=-1"
|
{depay} ! {parser} config-interval=-1"
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@@ -81,12 +83,12 @@ impl UsbVideoReceiver {
|
|||||||
);
|
);
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"udpsrc address={bind_ip} port={port} buffer-size=524288 retrieve-sender-address=false ! \
|
"udpsrc address={bind_ip} port={port} buffer-size=4194304 retrieve-sender-address=false ! \
|
||||||
{depay_and_parse} ! \
|
{depay_and_parse} ! \
|
||||||
{decoder} ! \
|
{decoder} ! \
|
||||||
videoconvert n-threads=2 ! videoscale method=1 ! \
|
videoscale ! videoconvert ! \
|
||||||
video/x-raw,format=RGBA,width={target_width},height={target_height} ! \
|
video/x-raw,format=RGBA,width={target_width},height={target_height} ! \
|
||||||
appsink name=fpv_sink sync=false max-buffers=1 drop=true emit-signals=true"
|
appsink name=fpv_sink sync=false max-buffers=1 drop=true emit-signals=false"
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -134,6 +136,14 @@ impl UsbVideoReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut lock = frame_store.lock();
|
let mut lock = frame_store.lock();
|
||||||
|
if let Some(ref mut vf) = *lock {
|
||||||
|
vf.width = video_info.width();
|
||||||
|
vf.height = video_info.height();
|
||||||
|
vf.frame_id = sequence;
|
||||||
|
vf.received_at = Instant::now();
|
||||||
|
vf.rgba_data.clear();
|
||||||
|
vf.rgba_data.extend_from_slice(map.as_slice());
|
||||||
|
} else {
|
||||||
*lock = Some(VideoFrame {
|
*lock = Some(VideoFrame {
|
||||||
width: video_info.width(),
|
width: video_info.width(),
|
||||||
height: video_info.height(),
|
height: video_info.height(),
|
||||||
@@ -141,6 +151,7 @@ impl UsbVideoReceiver {
|
|||||||
frame_id: sequence,
|
frame_id: sequence,
|
||||||
received_at: Instant::now(),
|
received_at: Instant::now(),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Ok(gst::FlowSuccess::Ok)
|
Ok(gst::FlowSuccess::Ok)
|
||||||
})
|
})
|
||||||
@@ -203,8 +214,11 @@ impl UsbVideoReceiver {
|
|||||||
Arc::clone(&self.latest_frame)
|
Arc::clone(&self.latest_frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_standby_pattern(width: u32, height: u32, tick: u32) -> Vec<u8> {
|
pub fn render_standby_pattern(width: u32, height: u32, tick: u32, data: &mut [u8]) {
|
||||||
let mut data = vec![0u8; (width * height * 4) as usize];
|
let expected_len = (width * height * 4) as usize;
|
||||||
|
if data.len() < expected_len {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let cx = (width / 2) as i32;
|
let cx = (width / 2) as i32;
|
||||||
let cy = (height / 2) as i32;
|
let cy = (height / 2) as i32;
|
||||||
let pulse = ((tick % 120) as f32 / 120.0 * std::f32::consts::TAU).sin() * 0.5 + 0.5;
|
let pulse = ((tick % 120) as f32 / 120.0 * std::f32::consts::TAU).sin() * 0.5 + 0.5;
|
||||||
@@ -233,7 +247,6 @@ impl UsbVideoReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use std::ffi::CString;
|
|||||||
|
|
||||||
/// Moteur de rendu OpenXR + Vulkan pour afficher le flux vidéo USB Sphere Link
|
/// Moteur de rendu OpenXR + Vulkan pour afficher le flux vidéo USB Sphere Link
|
||||||
/// dans les couches de composition OpenXR (`Equirect2`, `Cylinder`, ou `Quad`).
|
/// dans les couches de composition OpenXR (`Equirect2`, `Cylinder`, ou `Quad`).
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct VulkanXrContext {
|
pub struct VulkanXrContext {
|
||||||
pub vk_entry: ash::Entry,
|
pub vk_entry: ash::Entry,
|
||||||
pub vk_instance: ash::Instance,
|
pub vk_instance: ash::Instance,
|
||||||
|
|||||||
Reference in new issue
Block a user