Projects
openEuler:Mainline
libgusb
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 10
View file
_service:tar_scm:libgusb.spec
Changed
@@ -1,12 +1,12 @@ Name: libgusb -Version: 0.3.10 +Version: 0.4.6 Release: 1 Summary: GObject-based library for libusb1 License: LGPLv2+ URL: https://github.com/hughsie/libgusb -Source0: http://people.freedesktop.org/~hughsient/releases/%{name}-%{version}.tar.xz +Source0: https://github.com/hughsie/libgusb/releases/download/%{version}/%{name}-%{version}.tar.xz -BuildRequires: vala meson libusb1-devel gtk-doc gobject-introspection-devel glib2-devel +BuildRequires: vala meson libusb1-devel gtk-doc gobject-introspection-devel glib2-devel umockdev-devel gi-docgen %description GUsb is a GObject wrapper for libusb1 that makes it easy to do @@ -57,9 +57,12 @@ %files help %defattr(-,root,root) %doc NEWS README.md -%{_datadir}/gtk-doc/html/gusb/* +%{_datadir}/doc/libgusb/* %changelog +* Sat Jul 22 2023 zhouwenpei <zhouwenpei1@h-partners.com> - 0.4.6-1 +- update to 0.4.6 + * Fri Jul 01 2022 jiangxinyu <jiangxinyu@kylinos.cn> - 0.3.10-1 - Upgrade to 0.3.10
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/docs/api
Deleted
-(directory)
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/docs/api/gusb-docs.sgml
Deleted
@@ -1,78 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" - "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" -<!ENTITY version SYSTEM "version.xml"> -> -<book id="index" xmlns:xi="http://www.w3.org/2003/XInclude"> - <bookinfo> - <title>GUsb Reference Manual</title> - <releaseinfo> - for GUsb &version; - </releaseinfo> - <authorgroup> - <author> - <firstname>Richard</firstname> - <surname>Hughes</surname> - <affiliation> - <address> - <email>richard@hughsie.com</email> - </address> - </affiliation> - </author> - </authorgroup> - <copyright> - <year>2011</year> - <holder>Richard Hughes</holder> - </copyright> - </bookinfo> - - <reference id="specification"> - <title>GUSB Specification</title> - <partintro> - <para> - GUsb is a GLib wrapper for libusb1. - </para> - <para> - This manual documents features of GUsb. - </para> - </partintro> - <xi:include href="gusb-introduction.xml"/> - </reference> - - <reference id="libgusb"> - <title>libgusb GObject library</title> - <partintro> - <para> - This part documents GObjects used in libgusb. - </para> - </partintro> - <xi:include href="xml/gusb-context.xml"/> - <xi:include href="xml/gusb-source.xml"/> - <xi:include href="xml/gusb-device.xml"/> - <xi:include href="xml/gusb-device-list.xml"/> - <xi:include href="xml/gusb-interface.xml"/> - <xi:include href="xml/gusb-endpoint.xml"/> - </reference> - - <reference id="libgusb-helpers"> - <title>libgusb glib helpers</title> - <partintro> - <para> - This part documents helper functions in libgusb. - </para> - </partintro> - <xi:include href="xml/gusb-version.xml"/> - </reference> - - <reference id="faq"> - <title>Frequently asked questions</title> - <partintro> - <para> - This part has answers to developer frequently asked questions. - </para> - </partintro> - <xi:include href="gusb-faq.xml"/> - </reference> - -</book> -
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/docs/api/gusb-faq.xml
Deleted
@@ -1,19 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> -<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"> - -<chapter id="faq"> - <title>FAQ</title> - <para> - The following sections explain frequently asked questions from people. - </para> - - <sect1 id="faq-why"> - <title>Why wrap libusb1?</title> - <para> - libusb1 is a pain in the arse to use in GLib. - </para> - - </sect1> - -</chapter> -
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/docs/api/gusb-introduction.xml
Deleted
@@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> -<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"> - -<chapter id="introduction"> - <title>GUSB Introduction</title> - - <sect1 id="introduction-description"> - <title>Overall Description</title> - <para> - GUsb is a GLib wrapper for libusb1. - </para> - </sect1> - -</chapter> -
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/docs/api/meson.build
Deleted
@@ -1,15 +0,0 @@ -gusb_version_xml = configure_file( - input : 'version.xml.in', - output : 'version.xml', - configuration : conf, -) - -gnome.gtkdoc( - 'gusb', - src_dir : - gusb_source_dir, - gusb_build_dir, - , - main_sgml : 'gusb-docs.sgml', - install : true -)
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/docs/api/version.xml.in
Deleted
@@ -1,1 +0,0 @@ -@VERSION@
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-autocleanups.h
Deleted
@@ -1,20 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2015 Kalev Lember <klember@redhat.com> - * - * SPDX-License-Identifier: LGPL-2.1+ - */ - -#pragma once - -#include <gusb/gusb-context.h> -#include <gusb/gusb-device.h> -#include <gusb/gusb-device-list.h> - -#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC - -G_DEFINE_AUTOPTR_CLEANUP_FUNC(GUsbContext, g_object_unref) -G_DEFINE_AUTOPTR_CLEANUP_FUNC(GUsbDevice, g_object_unref) -G_DEFINE_AUTOPTR_CLEANUP_FUNC(GUsbDeviceList, g_object_unref) - -#endif
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/.clang-format
Added
@@ -0,0 +1,47 @@ +--- +AlignAfterOpenBracket: 'Align' +AlignConsecutiveAssignments: 'false' +AlignConsecutiveDeclarations: 'false' +AlignConsecutiveMacros: 'true' +AlignOperands: 'true' +AlignTrailingComments: 'true' +AllowAllArgumentsOnNextLine: 'false' +AllowAllParametersOfDeclarationOnNextLine: 'false' +AllowShortBlocksOnASingleLine: 'false' +AllowShortCaseLabelsOnASingleLine: 'false' +AllowShortFunctionsOnASingleLine: 'Inline' +AllowShortIfStatementsOnASingleLine: 'false' +AlwaysBreakAfterReturnType: 'All' +BinPackParameters: 'false' +BinPackArguments: 'false' +BreakBeforeBraces: 'Linux' +ColumnLimit: '100' +DerivePointerAlignment: 'false' +IndentCaseLabels: 'false' +IndentWidth: '8' +IncludeBlocks: 'Regroup' +KeepEmptyLinesAtTheStartOfBlocks: 'false' +MaxEmptyLinesToKeep: '1' +PointerAlignment: 'Right' +SortIncludes: 'true' +SpaceAfterCStyleCast: 'false' +SpaceBeforeAssignmentOperators : 'true' +SpaceBeforeParens: 'ControlStatements' +SpaceInEmptyParentheses: 'false' +SpacesInSquareBrackets: 'false' +TabWidth: '8' +UseTab: 'Always' +PenaltyBreakAssignment: '3' +PenaltyBreakBeforeFirstCallParameter: '15' +--- +Language: 'Proto' +--- +Language: 'Cpp' +IncludeCategories: + - Regex: '^"config.h"$' + Priority: '0' + - Regex: '^<' + Priority: '2' + - Regex: '.*' + Priority: '4' +...
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/.github/workflows/main.yml -> _service:tar_scm:libgusb-0.4.6.tar.xz/.github/workflows/main.yml
Changed
@@ -23,18 +23,18 @@ - run: docker run -t -v `pwd`:/build libgusb-${{ matrix.distro }} ./contrib/ci/build_and_test.sh -Dtests=false build-freebsd: - runs-on: macos-10.15 + runs-on: macos-12 steps: - name: Checkout uses: actions/checkout@v2 - name: Build id: test - uses: vmactions/freebsd-vm@v0.1.5 + uses: vmactions/freebsd-vm@v0.2.6 with: usesh: true mem: 8192 prepare: | - pkg install -y git python3 glib meson pkgconf gobject-introspection usbids + pkg install -y git python3 glib json-glib meson pkgconf gobject-introspection usbids sync: rsync run: ./contrib/ci/build_and_test.sh -Dvapi=false -Ddocs=false -Dusb_ids=/usr/local/share/usbids/usb.ids
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/NEWS -> _service:tar_scm:libgusb-0.4.6.tar.xz/NEWS
Changed
@@ -1,385 +1,130 @@ -Version 0.3.10 -~~~~~~~~~~~~~~ -Released: 2021-01-10 - -New Features: - - Add API to change the hotplug poll interval (Richard Hughes) - -Version 0.3.9 -~~~~~~~~~~~~~ -Released: 2021-12-07 - -Bugfixes: - - Don't hard-code the list of OS supporting --version-script (Ting-Wei Lan) - - Fix hotplug after threaded device removal (Richard Hughes) - - Fix version script check for GNU BFD linker on FreeBSD (Ting-Wei Lan) - -Version 0.3.8 -~~~~~~~~~~~~~ -Released: 2021-10-06 - -New Features: - - Add g_usb_device_get_string_descriptor_bytes_full (Ricardo Cañuelo) - -Bugfixes: - - Add the GUsbEndpoint methods to the docs (Richard Hughes) - - Fix hotplug handling and signal emission during enumerate (Benjamin Berg) - -Version 0.3.7 -~~~~~~~~~~~~~ -Released: 2021-05-24 - -New Features: - - Add a FreeBSD CI target (Richard Hughes) - -Bugfixes: - - Do not depend on libusb_get_parent() to fix FreeBSD compile (Richard Hughes) - - Do not depend on libusb_get_port_number() to fix DragonFlyBSD compile (Richard Hughes) - - Do not double-reference USB devices (Marco Trevisan) - - Do not run the tests on FreeBSD (Richard Hughes) - - Require *any* python3 to fix FreeBSD build (Richard Hughes) - -Version 0.3.6 -~~~~~~~~~~~~~ -Released: 2021-03-12 - -New Features: - - Add g_usb_device_get_string_descriptor_bytes() (Richard Hughes) - -Bugfixes: - - Properly set dylib versions on darwin (Caleb Xu) - - Fix cancellation if cancellable is already cancelled (Benjamin Berg) - -Version 0.3.5 -~~~~~~~~~~~~~ -Released: 2020-07-30 - -Notes: - -New Features: - - Add a way to get iConfiguration (Benson Leung) - -Bugfixes: - - Allow building GtkDoc when building as a subproject (Richard Hughes) - - Fix version script to be more portable (Laurent Bigonville, Ting-Wei Lan) - - Include methods on plain structs in the version script (Simon McVittie) - -Version 0.3.4 -~~~~~~~~~~~~~ -Released: 2020-02-20 - -Notes: - - This fixes the symbol version for g_usb_version_string() to be in the right - place, so update this library alongside with external programs if you've - already started using this symbol for example in fwupd. We've put a mechanism - in place so this kind of thing can't happen again. Sorry! - -New Features: - - Validate the exported symbol list during check (Richard Hughes) - -Bugfixes: - - Include the USB bus in the generated platform_id (Richard Hughes) - -Version 0.3.3 -~~~~~~~~~~~~~ -Released: 2020-01-30 - -New Features: - - Add a thin glib wrapper around libusb_endpoint_descriptor (Emmanuel Pacaud) - -Bugfixes: - - Fix high number of wakeups when checking the GUsbContext (Richard Hughes) - - Use '#pragma once' to reduce boilerplate (Richard Hughes) - - Wrap the upstream libusb_strerror() (Richard Hughes) - -Version 0.3.2 -~~~~~~~~~~~~~ -Released: 2020-01-06 - -Bugfixes: - - Do not use deprecated libusb API (Richard Hughes) - - Fix compilation on macOS (Richard Hughes) - - Use a 1ms timeout in the Windows event thread (Richard Hughes) - - Use has_link_argument() to detect linker flags (Richard Hughes) - -Version 0.3.1 -~~~~~~~~~~~~~ -Released: 2019-11-16 +Version 0.4.6 +============= +Released: 2023-06-08 -New Features: - - Add g_usb_device_get_spec() (Richard Hughes) - - Add g_usb_version_string() for fwupd (Richard Hughes) +This release fixes the following bugs: + * Add JSON compatibility helpers for old json-glib versions + * Fix emulation of devices using out-of-order BulkTransfer replies + * Use project_source_root to fix building as a subproject -Bugfixes: - - Add -Wswitch-enum (Benjamin Berg) - - Fix GI length introspection annotations (grindhold) - - Make gir generation optional (maxice8) +Version 0.4.5 +============= +Released: 2023-02-08 -Version 0.3.0 -~~~~~~~~~~~~~ -Released: 2018-02-14 +This release adds the following features: + * Add new API to better detect emulated replug -New Features: - - Add Travis integration (Richard Hughes) - - Allow changing the path to usb.ids file (Ting-Wei Lan) - - Port to the Meson build system (Richard Hughes) +This release fixes the following bugs: + * Do not emit spurious ::device-removed events when emulating + * Record zero-sized device events + * Reset the in-order event index when clearing the event array + * Save the libusb error if libusb_submit_transfer() fails -Bugfixes: - - Replace libusb-1.0/libusb.h with libusb.h (Ting-Wei Lan) +Version 0.4.4 +============= +Released: 2023-01-30 -Version 0.2.11 -~~~~~~~~~~~~~~ -Released: 2017-07-24 +This release adds the following features: + * Add new API to make emulation easier to use -New Features: - - Add g_usb_context_set_flags() (Richard Hughes) +This release fixes the following bugs: + * Emit remove devices with matching tags when loading contexts + * Fix a critical warning when finalizing devices without endpoints + * Reduce the debugging level when emulating firmware -Bugfixes: - - Fix the actual required GLib version (Richard Hughes) +Version 0.4.3 +============= +Released: 2022-12-20 -Version 0.2.10 -~~~~~~~~~~~~~~ -Released: 2017-04-10 +This release fixes the following bugs: + * Export g_usb_device_has_tag() + * Work around a libusb issue which causes devices to appear twice -Bugfixes: - - Correctly detect removed devices when rescanning (Richard Hughes) - - Fix a memory leak when using control transfers (Richard Hughes) - - Fix gtk-doc build when builddir != srcdir (Ting-Wei Lan) - - Fix symbol version table up to version 0.2.9 (Dominique Leuenberger) +Version 0.4.2 +============= +Released: 2022-10-18 -Version 0.2.9 -~~~~~~~~~~~~~ -Released: 2016-03-21 +This release fixes the following bugs: + * Close the GUsbDevice objects in gusbcmd + * Do not call the hotplug callback with the mutex held -New Features: - - Add g_usb_context_wait_for_replug() (Richard Hughes) - - Install gusbcmd as a debugging aid (Richard Hughes) +Version 0.4.1 +============= +Released: 2022-10-01 -Version 0.2.8
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/RELEASE.md -> _service:tar_scm:libgusb-0.4.6.tar.xz/RELEASE.md
Changed
@@ -1,37 +1,23 @@ GUsb Release Notes ================== -Write `NEWS` entries for GUsb in the same format as usual. - - git shortlog 0.3.9.. | grep -i -v trivial | grep -v Merge > NEWS.new - ================================================= - Version 0.3.10 - ~~~~~~~~~~~~~~ - Released: 2021-xx-xx - - Notes: - - New Features: - - Bugfixes: - ================================================= +git log --format="%s" --cherry-pick --right-only 0.4.5... | grep -i -v trivial | grep -v Merge | sort | uniq +Add any user visible changes into ../contrib/org.freedesktop.GUsb.metainfo.xml +appstream-util appdata-to-news ../contrib/org.freedesktop.GUsb.metainfo.xml > ../NEWS Update library version if new ABI or API in `meson.build`, commit, and build tarball: # MAKE SURE THIS IS CORRECT - export release_ver="0.3.10" + export release_ver="0.4.6" git commit -a -m "Release version ${release_ver}" git tag -s -f -m "Release ${release_ver}" "${release_ver}" - <gpg password> ninja dist git push --tags git push gpg -b -a meson-dist/libgusb-${release_ver}.tar.xz -Upload tarball: - - scp meson-dist/libgusb-${release_ver}.tar.* hughsient@people.freedesktop.org:public_html/releases/ +Upload tarball and GPG signatures to https://github.com/hughsie/libgusb Do post release version bump in `meson.build` and commit changes: @@ -41,11 +27,11 @@ Send an email to devkit-devel@lists.freedesktop.org ================================================= - GUsb 0.3.10 released! + GUsb 0.4.6 released GUsb is a GObject wrapper for libusb1 that makes it easy to do asynchronous control, bulk and interrupt transfers with proper cancellation and integration into a mainloop. - Tarballs available here: http://people.freedesktop.org/~hughsient/releases/ + Tarballs available here: https://github.com/hughsie/libgusb/releases =================================================
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/contrib/ci/Dockerfile-debian -> _service:tar_scm:libgusb-0.4.6.tar.xz/contrib/ci/Dockerfile-debian
Changed
@@ -1,8 +1,8 @@ -FROM debian:buster +FROM debian:testing -RUN echo "deb-src http://deb.debian.org/debian/ buster main" >> /etc/apt/sources.list +RUN echo "deb-src http://deb.debian.org/debian/ testing main" >> /etc/apt/sources.list RUN apt-get update -qq -RUN apt-get install -yq --no-install-recommends meson +RUN apt-get install -yq --no-install-recommends meson libjson-glib-dev gi-docgen RUN apt-get build-dep --allow-unauthenticated -yq libgusb RUN mkdir /build
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/contrib/ci/Dockerfile-fedora -> _service:tar_scm:libgusb-0.4.6.tar.xz/contrib/ci/Dockerfile-fedora
Changed
@@ -1,16 +1,17 @@ -FROM fedora:34 +FROM fedora:37 RUN dnf -y update RUN dnf -y install \ diffutils \ glib2-devel \ + json-glib-devel \ gobject-introspection-devel \ - gtk-doc \ + gi-docgen \ libusb1-devel \ meson \ redhat-rpm-config \ rpm-devel \ vala-devel \ - vala-tools + vala RUN mkdir /build WORKDIR /build
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/contrib/libgusb.spec.in -> _service:tar_scm:libgusb-0.4.6.tar.xz/contrib/libgusb.spec.in
Changed
@@ -6,12 +6,14 @@ Release: 0.#BUILD#%{?alphatag}%{?dist} License: LGPLv2+ URL: https://github.com/hughsie/libgusb -Source0: http://people.freedesktop.org/~hughsient/releases/%{name}-%{version}.tar.xz +Source0: https://github.com/hughsie/libgusb/releases/download/%{version}/%{name}-%{version}.tar.xz BuildRequires: glib2-devel >= 2.38.0 +BuildRequires: json-glib-devel BuildRequires: gobject-introspection-devel -BuildRequires: gtk-doc +BuildRequires: gi-docgen BuildRequires: libusb1-devel >= 1.0.19 +BuildRequires: umockdev-devel BuildRequires: meson BuildRequires: vala @@ -51,11 +53,10 @@ %{_bindir}/gusbcmd %{_libdir}/libgusb.so %{_libdir}/pkgconfig/gusb.pc -%{_datadir}/gtk-doc/html/gusb +%{_datadir}/doc/libgusb %{_datadir}/gir-1.0/GUsb-1.0.gir %{_datadir}/vala/vapi/gusb.deps %{_datadir}/vala/vapi/gusb.vapi %changelog -* #LONGDATE# Richard Hughes <richard@hughsie.com> #VERSION#-0.#BUILD##ALPHATAG# -- Update from git +%autochangelog
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/contrib/org.freedesktop.GUsb.metainfo.xml
Added
@@ -0,0 +1,176 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Copyright 2022 Richard Hughes <richard@hughsie.com> --> +<component type="console-application"> + <id>org.freedesktop.GUsb</id> + <metadata_license>CC0-1.0</metadata_license> + <project_license>LGPL-2.0+</project_license> + <name>GUsb</name> + <summary>A GObject wrapper for libusb1</summary> + <description> + <p> + GUsb is a GObject wrapper for libusb1 that makes it easy to do asynchronous control, + bulk and interrupt transfers with proper cancellation and integration into a mainloop. + This makes it easy to integrate low level USB transfers with your high-level application or + system daemon. + </p> + </description> + <url type="bugtracker">https://github.com/hughsie/libgusb/issues</url> + <url type="homepage">https://github.com/hughsie/libgusb</url> + <content_rating type="oars-1.0"/> + <provides> + <binary>gusbcmd</binary> + </provides> + <releases> + <release version="0.4.6" date="2023-06-08"> + <description> + <p>This release fixes the following bugs:</p> + <ul> + <li>Add JSON compatibility helpers for old json-glib versions</li> + <li>Fix emulation of devices using out-of-order BulkTransfer replies</li> + <li>Use project_source_root to fix building as a subproject</li> + </ul> + </description> + </release> + <release version="0.4.5" date="2023-02-08"> + <description> + <p>This release adds the following features:</p> + <ul> + <li>Add new API to better detect emulated replug</li> + </ul> + <p>This release fixes the following bugs:</p> + <ul> + <li>Do not emit spurious ::device-removed events when emulating</li> + <li>Record zero-sized device events</li> + <li>Reset the in-order event index when clearing the event array</li> + <li>Save the libusb error if libusb_submit_transfer() fails</li> + </ul> + </description> + </release> + <release version="0.4.4" date="2023-01-30"> + <description> + <p>This release adds the following features:</p> + <ul> + <li>Add new API to make emulation easier to use</li> + </ul> + <p>This release fixes the following bugs:</p> + <ul> + <li>Emit remove devices with matching tags when loading contexts</li> + <li>Fix a critical warning when finalizing devices without endpoints</li> + <li>Reduce the debugging level when emulating firmware</li> + </ul> + </description> + </release> + <release version="0.4.3" date="2022-12-20"> + <description> + <p>This release fixes the following bugs:</p> + <ul> + <li>Export g_usb_device_has_tag()</li> + <li>Work around a libusb issue which causes devices to appear twice</li> + </ul> + </description> + </release> + <release version="0.4.2" date="2022-10-18"> + <description> + <p>This release fixes the following bugs:</p> + <ul> + <li>Close the GUsbDevice objects in gusbcmd</li> + <li>Do not call the hotplug callback with the mutex held</li> + </ul> + </description> + </release> + <release version="0.4.1" date="2022-10-01"> + <description> + <p>This release adds the following features:</p> + <ul> + <li>Allow loading and saving only devices with specific tags</li> + <li>Include removed devices in the JSON dump</li> + </ul> + <p>This release fixes the following bug:</p> + <ul> + <li>Port from gtkdoc to gi-docgen</li> + </ul> + </description> + </release> + <release version="0.4.0" date="2022-09-12"> + <description> + <p> + The JSON format used to serialising devices is not yet stable, and + might change. + </p> + <p>This release adds the following features:</p> + <ul> + <li>Add support for getting BOS descriptors</li> + <li>Allow emulating devices by saving and replaying device events</li> + <li>Cache the list of interfaces and descriptors</li> + <li>Serialize the GUsbDevice to and from JSON format</li> + </ul> + <p>This release fixes the following bugs:</p> + <ul> + <li>Ignore usb.ids classes, subclasses and protocols</li> + <li>Never dispatch idle events after the context has been destroyed</li> + <li>Skip some functionality when emulating</li> + </ul> + </description> + </release> + <release version="0.3.10" date="2021-01-10"> + <description> + <p>This release adds the following feature:</p> + <ul> + <li>Add API to change the hotplug poll interval</li> + </ul> + </description> + </release> + <release version="0.3.9" date="2021-12-07"> + <description> + <p>This release fixes the following bugs:</p> + <ul> + <li>Don't hard-code the list of OS supporting --version-script</li> + <li>Fix hotplug after threaded device removal</li> + <li>Fix version script check for GNU BFD linker on FreeBSD</li> + </ul> + </description> + </release> + <release version="0.3.8" date="2021-10-06"> + <description> + <p>This release adds the following feature:</p> + <ul> + <li>Add g_usb_device_get_string_descriptor_bytes_full</li> + </ul> + <p>This release fixes the following bugs:</p> + <ul> + <li>Add the GUsbEndpoint methods to the docs</li> + <li>Fix hotplug handling and signal emission during enumerate</li> + </ul> + </description> + </release> + <release version="0.3.7" date="2021-05-24"> + <description> + <p>This release adds the following feature:</p> + <ul> + <li>Add a FreeBSD CI target</li> + </ul> + <p>This release fixes the following bugs:</p> + <ul> + <li>Do not depend on libusb_get_parent() to fix FreeBSD compile</li> + <li>Do not depend on libusb_get_port_number() to fix DragonFlyBSD compile</li> + <li>Do not double-reference USB devices</li> + <li>Do not run the tests on FreeBSD</li> + <li>Require *any* python3 to fix FreeBSD build</li> + </ul> + </description> + </release> + <release version="0.3.6" date="2021-03-12"> + <description> + <p>This release adds the following feature:</p> + <ul> + <li>Add g_usb_device_get_string_descriptor_bytes()</li> + </ul> + <p>This release fixes the following bugs:</p> + <ul> + <li>Properly set dylib versions on darwin</li> + <li>Fix cancellation if cancellable is already cancelled</li> + </ul> + </description> + </release> + </releases> +</component>
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/docs/libgusb.toml.in
Added
@@ -0,0 +1,38 @@ +library +version = "@version@" +browse_url = "https://github.com/hughsie/libgusb" +repository_url = "https://github.com/hughsie/libgusb.git" +website_url = "https://github.com/hughsie/libgusb" +authors = "GUsb Development Team" +license = "LGPL-2.1-or-later" +description = "GUsb is a GLib wrapper for libusb1" +dependencies = + "GObject-2.0", + "Gio-2.0", + "Json-1.0" + +devhelp = true +search_index = true + + dependencies."GObject-2.0" + name = "GObject" + description = "The base type system library" + docs_url = "https://docs.gtk.org/gobject/" + + dependencies."Gio-2.0" + name = "Gio" + description = "A modern, easy-to-use VFS API" + docs_url = "https://docs.gtk.org/gio/" + + dependencies."Json-1.0" + name = "Json" + description = "API for efficient parsing and writing of JSON (JavaScript Object Notation) streams" + docs_url = "https://gnome.pages.gitlab.gnome.org/json-glib/" + +theme +name = "basic" +show_index_summary = true +show_class_hierarchy = true + +extra +urlmap_file = "urlmap_libgusb.js"
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/docs/meson.build -> _service:tar_scm:libgusb-0.4.6.tar.xz/docs/meson.build
Changed
@@ -1,3 +1,45 @@ -if get_option('docs') -subdir('api') +gidocgen_dep = dependency('gi-docgen', + version: '>= 2021.1', + native: true, + required: false, +) +gidocgen_app = find_program('gi-docgen') + +if gidocgen_dep.found() and gidocgen_app.found() and get_option('introspection') + toml_conf = configuration_data() + toml_conf.set('version', meson.project_version()) + + libgusb_toml = configure_file( + input: 'libgusb.toml.in', + output: 'libgusb.toml', + configuration: toml_conf + ) + + custom_target('doc-libgusb', + input: + libgusb_toml, + libgusb_girtarget0, + , + output: 'libgusb', + command: + gidocgen_app, + 'generate', + '--quiet', + '--add-include-path=@0@'.format(meson.current_build_dir() / '../libgusb'), + '--config=@INPUT0@', + '--output-dir=@OUTPUT@', + '--no-namespace-dir', + '--content-dir=@0@'.format(meson.current_source_dir()), + '@INPUT1@', + , + depends: + libgusb_girtarget0, + , + build_by_default: true, + install: true, + install_dir: join_paths(datadir, 'doc'), + ) + install_data('urlmap_libgusb.js', + install_dir: join_paths(datadir, 'doc', 'libgusb') + ) endif
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/docs/urlmap_libgusb.js
Added
@@ -0,0 +1,4 @@ +baseURLs = + 'Gio', 'https://people.gnome.org/~ebassi/docs/_build/Gio/' , + 'GObject', 'https://people.gnome.org/~ebassi/docs/_build/GObject/' , +
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-bos-descriptor-private.h
Added
@@ -0,0 +1,24 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2022 Richard Hughes <richard@hughsie.com> + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#pragma once + +#include <gusb/gusb-bos-descriptor.h> +#include <json-glib/json-glib.h> +#include <libusb.h> + +G_BEGIN_DECLS + +GUsbBosDescriptor * +_g_usb_bos_descriptor_new(const struct libusb_bos_dev_capability_descriptor *bos_cap); + +gboolean +_g_usb_bos_descriptor_load(GUsbBosDescriptor *self, JsonObject *json_object, GError **error); +gboolean +_g_usb_bos_descriptor_save(GUsbBosDescriptor *self, JsonBuilder *json_builder, GError **error); + +G_END_DECLS
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-bos-descriptor.c
Added
@@ -0,0 +1,165 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2022 Richard Hughes <richard@hughsie.com> + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +/** + * SECTION:gusb-bos-descriptor + * @short_description: GLib wrapper around a USB BOS descriptor. + * + * This object is a thin glib wrapper around a `libusb_bos_dev_capability_descriptor`. + * + * All the data is copied when the object is created and the original descriptor can be destroyed + * at any point. + */ + +#include "config.h" + +#include <string.h> + +#include "gusb-bos-descriptor-private.h" +#include "gusb-json-common.h" + +struct _GUsbBosDescriptor { + GObject parent_instance; + + struct libusb_bos_dev_capability_descriptor bos_cap; + GBytes *extra; +}; + +G_DEFINE_TYPE(GUsbBosDescriptor, g_usb_bos_descriptor, G_TYPE_OBJECT) + +static void +g_usb_bos_descriptor_finalize(GObject *object) +{ + GUsbBosDescriptor *self = G_USB_BOS_DESCRIPTOR(object); + + g_bytes_unref(self->extra); + + G_OBJECT_CLASS(g_usb_bos_descriptor_parent_class)->finalize(object); +} + +static void +g_usb_bos_descriptor_class_init(GUsbBosDescriptorClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + object_class->finalize = g_usb_bos_descriptor_finalize; +} + +static void +g_usb_bos_descriptor_init(GUsbBosDescriptor *self) +{ +} + +gboolean +_g_usb_bos_descriptor_load(GUsbBosDescriptor *self, JsonObject *json_object, GError **error) +{ + const gchar *str; + + g_return_val_if_fail(G_USB_IS_BOS_DESCRIPTOR(self), FALSE); + g_return_val_if_fail(json_object != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, -1); + + /* optional properties */ + self->bos_cap.bDevCapabilityType = + json_object_get_int_member_with_default(json_object, "DevCapabilityType", 0x0); + + /* extra data */ + str = json_object_get_string_member_with_default(json_object, "ExtraData", NULL); + if (str != NULL) { + gsize bufsz = 0; + g_autofree guchar *buf = g_base64_decode(str, &bufsz); + if (self->extra != NULL) + g_bytes_unref(self->extra); + self->extra = g_bytes_new_take(g_steal_pointer(&buf), bufsz); + } + + /* success */ + return TRUE; +} + +gboolean +_g_usb_bos_descriptor_save(GUsbBosDescriptor *self, JsonBuilder *json_builder, GError **error) +{ + g_return_val_if_fail(G_USB_IS_BOS_DESCRIPTOR(self), FALSE); + g_return_val_if_fail(json_builder != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + /* start */ + json_builder_begin_object(json_builder); + + /* optional properties */ + if (self->bos_cap.bDevCapabilityType != 0) { + json_builder_set_member_name(json_builder, "DevCapabilityType"); + json_builder_add_int_value(json_builder, self->bos_cap.bDevCapabilityType); + } + + /* extra data */ + if (self->extra != NULL && g_bytes_get_size(self->extra) > 0) { + g_autofree gchar *str = g_base64_encode(g_bytes_get_data(self->extra, NULL), + g_bytes_get_size(self->extra)); + json_builder_set_member_name(json_builder, "ExtraData"); + json_builder_add_string_value(json_builder, str); + } + + /* success */ + json_builder_end_object(json_builder); + return TRUE; +} + +/** + * _g_usb_bos_descriptor_new: + * + * Return value: a new #GUsbBosDescriptor object. + * + * Since: 0.4.0 + **/ +GUsbBosDescriptor * +_g_usb_bos_descriptor_new(const struct libusb_bos_dev_capability_descriptor *bos_cap) +{ + GUsbBosDescriptor *self; + self = g_object_new(G_USB_TYPE_BOS_DESCRIPTOR, NULL); + + /* copy the data */ + memcpy(&self->bos_cap, bos_cap, sizeof(*bos_cap)); + self->extra = g_bytes_new(bos_cap->dev_capability_data, bos_cap->bLength - 0x03); + + return G_USB_BOS_DESCRIPTOR(self); +} + +/** + * g_usb_bos_descriptor_get_capability: + * @self: a #GUsbBosDescriptor + * + * Gets the BOS descriptor capability. + * + * Return value: capability + * + * Since: 0.4.0 + **/ +guint8 +g_usb_bos_descriptor_get_capability(GUsbBosDescriptor *self) +{ + g_return_val_if_fail(G_USB_IS_BOS_DESCRIPTOR(self), 0); + return self->bos_cap.bDevCapabilityType; +} + +/** + * g_usb_bos_descriptor_get_extra: + * @self: a #GUsbBosDescriptor + * + * Gets any extra data from the BOS descriptor. + * + * Return value: (transfer none): a #GBytes, or %NULL for failure + * + * Since: 0.4.0 + **/ +GBytes * +g_usb_bos_descriptor_get_extra(GUsbBosDescriptor *self) +{ + g_return_val_if_fail(G_USB_IS_BOS_DESCRIPTOR(self), NULL); + return self->extra; +}
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-bos-descriptor.h
Added
@@ -0,0 +1,22 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2022 Richard Hughes <richard@hughsie.com> + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#pragma once + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define G_USB_TYPE_BOS_DESCRIPTOR (g_usb_bos_descriptor_get_type()) +G_DECLARE_FINAL_TYPE(GUsbBosDescriptor, g_usb_bos_descriptor, G_USB, BOS_DESCRIPTOR, GObject) + +guint8 +g_usb_bos_descriptor_get_capability(GUsbBosDescriptor *self); +GBytes * +g_usb_bos_descriptor_get_extra(GUsbBosDescriptor *self); + +G_END_DECLS
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-context-private.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-context-private.h
Changed
@@ -7,20 +7,19 @@ #pragma once -#include <libusb.h> - #include <gusb/gusb-context.h> +#include <libusb.h> G_BEGIN_DECLS -libusb_context *_g_usb_context_get_context (GUsbContext *context); +libusb_context * +_g_usb_context_get_context(GUsbContext *self); -const gchar *_g_usb_context_lookup_vendor (GUsbContext *context, - guint16 vid, - GError **error); -const gchar *_g_usb_context_lookup_product (GUsbContext *context, - guint16 vid, - guint16 pid, - GError **error); +const gchar * +_g_usb_context_lookup_vendor(GUsbContext *self, guint16 vid, GError **error); +const gchar * +_g_usb_context_lookup_product(GUsbContext *self, guint16 vid, guint16 pid, GError **error); +gboolean +_g_usb_context_has_flag(GUsbContext *self, GUsbContextFlags flags); G_END_DECLS
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-context.c -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-context.c
Changed
@@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2011-2016 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2011 Richard Hughes <richard@hughsie.com> * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com> * * SPDX-License-Identifier: LGPL-2.1+ @@ -17,47 +17,42 @@ #include <libusb.h> -#include "gusb-context.h" #include "gusb-context-private.h" #include "gusb-device-private.h" #include "gusb-util.h" -enum { - PROP_0, - PROP_LIBUSB_CONTEXT, - PROP_DEBUG_LEVEL, - N_PROPERTIES -}; +enum { PROP_0, PROP_LIBUSB_CONTEXT, PROP_DEBUG_LEVEL, N_PROPERTIES }; -enum { - DEVICE_ADDED_SIGNAL, - DEVICE_REMOVED_SIGNAL, - LAST_SIGNAL -}; +enum { DEVICE_ADDED_SIGNAL, DEVICE_REMOVED_SIGNAL, DEVICE_CHANGED_SIGNAL, LAST_SIGNAL }; #define G_USB_CONTEXT_HOTPLUG_POLL_INTERVAL_DEFAULT 1000 /* ms */ +#define GET_PRIVATE(o) (g_usb_context_get_instance_private(o)) + /** * GUsbContextPrivate: * * Private #GUsbContext data **/ -struct _GUsbContextPrivate -{ - GMainContext *main_ctx; - GPtrArray *devices; - GHashTable *dict_usb_ids; - GHashTable *dict_replug; - GThread *thread_event; - gboolean done_enumerate; - volatile gint thread_event_run; - guint hotplug_poll_id; - guint hotplug_poll_interval; - int debug_level; - GUsbContextFlags flags; - libusb_context *ctx; - libusb_hotplug_callback_handle hotplug_id; -}; +typedef struct { + GMainContext *main_ctx; + GPtrArray *devices; + GPtrArray *devices_removed; + GHashTable *dict_usb_ids; + GHashTable *dict_replug; + GThread *thread_event; + gboolean done_enumerate; + volatile gint thread_event_run; + guint hotplug_poll_id; + guint hotplug_poll_interval; + int debug_level; + GUsbContextFlags flags; + libusb_context *ctx; + libusb_hotplug_callback_handle hotplug_id; + GPtrArray *idle_events; + GMutex idle_events_mutex; + guint idle_events_id; +} GUsbContextPrivate; /* not defined in FreeBSD */ #ifndef HAVE_LIBUSB_CAP_HAS_HOTPLUG @@ -65,25 +60,30 @@ #endif typedef struct { - GMainLoop *loop; - GUsbDevice *device; - guint timeout_id; + GMainLoop *loop; + GUsbDevice *device; + guint timeout_id; } GUsbContextReplugHelper; -static guint signalsLAST_SIGNAL = { 0 }; -static GParamSpec *pspecsN_PROPERTIES = { NULL, }; +static guint signalsLAST_SIGNAL = {0}; +static GParamSpec *pspecsN_PROPERTIES = { + NULL, +}; -static void g_usb_context_initable_iface_init (GInitableIface *iface); +static void +g_usb_context_initable_iface_init(GInitableIface *iface); -G_DEFINE_TYPE_WITH_CODE (GUsbContext, g_usb_context, G_TYPE_OBJECT, - G_ADD_PRIVATE (GUsbContext) - G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE, - g_usb_context_initable_iface_init)) +G_DEFINE_TYPE_WITH_CODE(GUsbContext, + g_usb_context, + G_TYPE_OBJECT, + G_ADD_PRIVATE(GUsbContext) + G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE, + g_usb_context_initable_iface_init)) /* not defined in FreeBSD */ #ifndef HAVE_LIBUSB_HAS_CAPABILITY static gboolean -libusb_has_capability (int cap) +libusb_has_capability(int cap) { if (cap == LIBUSB_CAP_HAS_HOTPLUG) return TRUE; @@ -92,15 +92,16 @@ #endif static void -g_usb_context_replug_helper_free (GUsbContextReplugHelper *replug_helper) +g_usb_context_replug_helper_free(GUsbContextReplugHelper *replug_helper) { if (replug_helper->timeout_id != 0) - g_source_remove (replug_helper->timeout_id); - g_main_loop_unref (replug_helper->loop); - g_object_unref (replug_helper->device); - g_free (replug_helper); + g_source_remove(replug_helper->timeout_id); + g_main_loop_unref(replug_helper->loop); + g_object_unref(replug_helper->device); + g_free(replug_helper); } +/* clang-format off */ /** * g_usb_context_error_quark: * @@ -109,83 +110,85 @@ * Since: 0.1.0 **/ G_DEFINE_QUARK (g-usb-context-error-quark, g_usb_context_error) +/* clang-format on */ static void -g_usb_context_dispose (GObject *object) +g_usb_context_dispose(GObject *object) { - GUsbContext *context = G_USB_CONTEXT (object); - GUsbContextPrivate *priv = context->priv; + GUsbContext *self = G_USB_CONTEXT(object); + GUsbContextPrivate *priv = GET_PRIVATE(self); /* this is safe to call even when priv->hotplug_id is unset */ - if (g_atomic_int_dec_and_test (&priv->thread_event_run)) { - libusb_hotplug_deregister_callback (priv->ctx, priv->hotplug_id); - g_thread_join (priv->thread_event); + if (g_atomic_int_dec_and_test(&priv->thread_event_run)) { + libusb_hotplug_deregister_callback(priv->ctx, priv->hotplug_id); + g_thread_join(priv->thread_event); } if (priv->hotplug_poll_id > 0) { - g_source_remove (priv->hotplug_poll_id); + g_source_remove(priv->hotplug_poll_id); priv->hotplug_poll_id = 0; } + if (priv->idle_events_id > 0) { + g_source_remove(priv->idle_events_id); + priv->idle_events_id = 0; + } - g_clear_pointer (&priv->main_ctx, g_main_context_unref); - g_clear_pointer (&priv->devices, g_ptr_array_unref); - g_clear_pointer (&priv->dict_usb_ids, g_hash_table_unref); - g_clear_pointer (&priv->dict_replug, g_hash_table_unref); - g_clear_pointer (&priv->ctx, libusb_exit); + g_clear_pointer(&priv->main_ctx, g_main_context_unref); + g_clear_pointer(&priv->devices, g_ptr_array_unref); + g_clear_pointer(&priv->devices_removed, g_ptr_array_unref); + g_clear_pointer(&priv->dict_usb_ids, g_hash_table_unref); + g_clear_pointer(&priv->dict_replug, g_hash_table_unref); + g_clear_pointer(&priv->ctx, libusb_exit); + g_clear_pointer(&priv->idle_events, g_ptr_array_unref); + g_mutex_clear(&priv->idle_events_mutex); - G_OBJECT_CLASS (g_usb_context_parent_class)->dispose (object); + G_OBJECT_CLASS(g_usb_context_parent_class)->dispose(object); } static void -g_usb_context_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec)
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-context.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-context.h
Changed
@@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2011-2016 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2011 Richard Hughes <richard@hughsie.com> * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com> * * SPDX-License-Identifier: LGPL-2.1+ @@ -8,46 +8,30 @@ #pragma once -#include <glib-object.h> - #include <gusb/gusb-device.h> #include <gusb/gusb-source.h> G_BEGIN_DECLS -#define G_USB_TYPE_CONTEXT (g_usb_context_get_type ()) -#define G_USB_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_USB_TYPE_CONTEXT, GUsbContext)) -#define G_USB_IS_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_USB_TYPE_CONTEXT)) -#define G_USB_CONTEXT_ERROR (g_usb_context_error_quark ()) - -typedef struct _GUsbContextPrivate GUsbContextPrivate; -typedef struct _GUsbContext GUsbContext; -typedef struct _GUsbContextClass GUsbContextClass; +#define G_USB_TYPE_CONTEXT (g_usb_context_get_type()) +#define G_USB_CONTEXT_ERROR (g_usb_context_error_quark()) -struct _GUsbContext -{ - GObject parent; - GUsbContextPrivate *priv; -}; +G_DECLARE_DERIVABLE_TYPE(GUsbContext, g_usb_context, G_USB, CONTEXT, GObject) -struct _GUsbContextClass -{ - GObjectClass parent_class; - void (*device_added) (GUsbContext *context, - GUsbDevice *device); - void (*device_removed) (GUsbContext *context, - GUsbDevice *device); +struct _GUsbContextClass { + GObjectClass parent_class; + void (*device_added)(GUsbContext *self, GUsbDevice *device); + void (*device_removed)(GUsbContext *self, GUsbDevice *device); + void (*device_changed)(GUsbContext *self, GUsbDevice *device); /*< private >*/ /* * If adding fields to this struct, remove corresponding * amount of padding to avoid changing overall struct size */ - gchar _gusb_reserved62; + gchar _gusb_reserved61; }; -typedef enum { - G_USB_CONTEXT_ERROR_INTERNAL -} GUsbContextError; +typedef enum { G_USB_CONTEXT_ERROR_INTERNAL } GUsbContextError; /** * GUsbContextFlags: @@ -55,53 +39,73 @@ * The flags to use for the context. **/ typedef enum { - G_USB_CONTEXT_FLAGS_NONE = 0, - G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES = 1 << 0, + G_USB_CONTEXT_FLAGS_NONE = 0, + G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES = 1 << 0, + G_USB_CONTEXT_FLAGS_SAVE_EVENTS = 1 << 1, + G_USB_CONTEXT_FLAGS_SAVE_REMOVED_DEVICES = 1 << 2, + G_USB_CONTEXT_FLAGS_DEBUG = 1 << 3, /*< private >*/ G_USB_CONTEXT_FLAGS_LAST } GUsbContextFlags; -GType g_usb_context_get_type (void); -GQuark g_usb_context_error_quark (void); +GQuark +g_usb_context_error_quark(void); -GUsbContext *g_usb_context_new (GError **error); +GUsbContext * +g_usb_context_new(GError **error); -void g_usb_context_set_flags (GUsbContext *context, - GUsbContextFlags flags); -GUsbContextFlags g_usb_context_get_flags (GUsbContext *context); +void +g_usb_context_set_flags(GUsbContext *self, GUsbContextFlags flags); +GUsbContextFlags +g_usb_context_get_flags(GUsbContext *self); G_DEPRECATED -GUsbSource *g_usb_context_get_source (GUsbContext *context, - GMainContext *main_ctx); -GMainContext *g_usb_context_get_main_context (GUsbContext *context); -void g_usb_context_set_main_context (GUsbContext *context, - GMainContext *main_ctx); -guint g_usb_context_get_hotplug_poll_interval(GUsbContext *context); -void g_usb_context_set_hotplug_poll_interval(GUsbContext *context, - guint hotplug_poll_interval); - -void g_usb_context_enumerate (GUsbContext *context); - -void g_usb_context_set_debug (GUsbContext *context, - GLogLevelFlags flags); -GPtrArray *g_usb_context_get_devices (GUsbContext *context); - -GUsbDevice *g_usb_context_find_by_bus_address (GUsbContext *context, - guint8 bus, - guint8 address, - GError **error); - -GUsbDevice *g_usb_context_find_by_vid_pid (GUsbContext *context, - guint16 vid, - guint16 pid, - GError **error); -GUsbDevice *g_usb_context_find_by_platform_id (GUsbContext *context, - const gchar *platform_id, - GError **error); - -GUsbDevice *g_usb_context_wait_for_replug (GUsbContext *context, - GUsbDevice *device, - guint timeout_ms, - GError **error); +GUsbSource * +g_usb_context_get_source(GUsbContext *self, GMainContext *main_ctx); +GMainContext * +g_usb_context_get_main_context(GUsbContext *self); +void +g_usb_context_set_main_context(GUsbContext *self, GMainContext *main_ctx); +guint +g_usb_context_get_hotplug_poll_interval(GUsbContext *self); +void +g_usb_context_set_hotplug_poll_interval(GUsbContext *self, guint hotplug_poll_interval); + +void +g_usb_context_enumerate(GUsbContext *self); + +gboolean +g_usb_context_load(GUsbContext *self, JsonObject *json_object, GError **error); +gboolean +g_usb_context_load_with_tag(GUsbContext *self, + JsonObject *json_object, + const gchar *tag, + GError **error); +gboolean +g_usb_context_save(GUsbContext *self, JsonBuilder *json_builder, GError **error); +gboolean +g_usb_context_save_with_tag(GUsbContext *self, + JsonBuilder *json_builder, + const gchar *tag, + GError **error); + +void +g_usb_context_set_debug(GUsbContext *self, GLogLevelFlags flags); +GPtrArray * +g_usb_context_get_devices(GUsbContext *self); + +GUsbDevice * +g_usb_context_find_by_bus_address(GUsbContext *self, guint8 bus, guint8 address, GError **error); + +GUsbDevice * +g_usb_context_find_by_vid_pid(GUsbContext *self, guint16 vid, guint16 pid, GError **error); +GUsbDevice * +g_usb_context_find_by_platform_id(GUsbContext *self, const gchar *platform_id, GError **error); + +GUsbDevice * +g_usb_context_wait_for_replug(GUsbContext *self, + GUsbDevice *device, + guint timeout_ms, + GError **error); G_END_DECLS
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-device-event-private.h
Added
@@ -0,0 +1,30 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2022 Richard Hughes <richard@hughsie.com> + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#pragma once + +#include <gusb/gusb-device-event.h> +#include <json-glib/json-glib.h> +#include <libusb.h> + +G_BEGIN_DECLS + +GUsbDeviceEvent * +_g_usb_device_event_new(const gchar *id); +void +_g_usb_device_event_set_bytes_raw(GUsbDeviceEvent *self, gconstpointer buf, gsize bufsz); +void +_g_usb_device_event_set_status(GUsbDeviceEvent *self, gint status); +void +_g_usb_device_event_set_rc(GUsbDeviceEvent *self, gint rc); + +gboolean +_g_usb_device_event_load(GUsbDeviceEvent *self, JsonObject *json_object, GError **error); +gboolean +_g_usb_device_event_save(GUsbDeviceEvent *self, JsonBuilder *json_builder, GError **error); + +G_END_DECLS
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-device-event.c
Added
@@ -0,0 +1,259 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2022 Richard Hughes <richard@hughsie.com> + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +/** + * SECTION:gusb-device-event + * @short_description: An event that happened to a GUsbDevice. + */ + +#include "config.h" + +#include "gusb-device-event-private.h" +#include "gusb-json-common.h" + +struct _GUsbDeviceEvent { + GObject parent_instance; + gchar *id; + gint status; + gint rc; + GBytes *bytes; +}; + +G_DEFINE_TYPE(GUsbDeviceEvent, g_usb_device_event, G_TYPE_OBJECT) + +static void +g_usb_device_event_finalize(GObject *object) +{ + GUsbDeviceEvent *self = G_USB_DEVICE_EVENT(object); + + g_free(self->id); + if (self->bytes != NULL) + g_bytes_unref(self->bytes); + + G_OBJECT_CLASS(g_usb_device_event_parent_class)->finalize(object); +} + +static void +g_usb_device_event_class_init(GUsbDeviceEventClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + object_class->finalize = g_usb_device_event_finalize; +} + +static void +g_usb_device_event_init(GUsbDeviceEvent *self) +{ +} + +gboolean +_g_usb_device_event_load(GUsbDeviceEvent *self, JsonObject *json_object, GError **error) +{ + const gchar *str; + + g_return_val_if_fail(G_USB_IS_DEVICE_EVENT(self), FALSE); + g_return_val_if_fail(json_object != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, -1); + + /* optional properties */ + self->id = g_strdup(json_object_get_string_member_with_default(json_object, "Id", NULL)); + self->status = json_object_get_int_member_with_default(json_object, + "Status", + LIBUSB_TRANSFER_COMPLETED); + self->rc = json_object_get_int_member_with_default(json_object, "Error", LIBUSB_SUCCESS); + + /* extra data */ + str = json_object_get_string_member_with_default(json_object, "Data", NULL); + if (str != NULL) { + gsize bufsz = 0; + g_autofree guchar *buf = g_base64_decode(str, &bufsz); + self->bytes = g_bytes_new_take(g_steal_pointer(&buf), bufsz); + } + + /* success */ + return TRUE; +} + +gboolean +_g_usb_device_event_save(GUsbDeviceEvent *self, JsonBuilder *json_builder, GError **error) +{ + g_return_val_if_fail(G_USB_IS_DEVICE_EVENT(self), FALSE); + g_return_val_if_fail(json_builder != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + /* start */ + json_builder_begin_object(json_builder); + + if (self->id != NULL) { + json_builder_set_member_name(json_builder, "Id"); + json_builder_add_string_value(json_builder, self->id); + } + if (self->status != LIBUSB_TRANSFER_COMPLETED) { + json_builder_set_member_name(json_builder, "Status"); + json_builder_add_int_value(json_builder, self->status); + } + if (self->rc != LIBUSB_SUCCESS) { + json_builder_set_member_name(json_builder, "Error"); + json_builder_add_int_value(json_builder, self->rc); + } + if (self->bytes != NULL) { + g_autofree gchar *str = g_base64_encode(g_bytes_get_data(self->bytes, NULL), + g_bytes_get_size(self->bytes)); + json_builder_set_member_name(json_builder, "Data"); + json_builder_add_string_value(json_builder, str); + } + + /* success */ + json_builder_end_object(json_builder); + return TRUE; +} + +/** + * _g_usb_device_event_new: + * @id: a cache key + * + * Return value: a new #GUsbDeviceEvent object. + * + * Since: 0.4.0 + **/ +GUsbDeviceEvent * +_g_usb_device_event_new(const gchar *id) +{ + GUsbDeviceEvent *self; + self = g_object_new(G_USB_TYPE_DEVICE_EVENT, NULL); + self->id = g_strdup(id); + return G_USB_DEVICE_EVENT(self); +} + +/** + * g_usb_device_event_get_id: + * @self: a #GUsbDeviceEvent + * + * Gets the event ID. + * + * Return value: string, or %NULL + * + * Since: 0.4.0 + **/ +const gchar * +g_usb_device_event_get_id(GUsbDeviceEvent *self) +{ + g_return_val_if_fail(G_USB_IS_DEVICE_EVENT(self), NULL); + return self->id; +} + +/** + * g_usb_device_event_get_status: + * @self: a #GUsbDeviceEvent + * + * Gets any status data from the event. + * + * Return value: a `enum libusb_transfer_status`, or -1 for failure + * + * Since: 0.4.0 + **/ +gint +g_usb_device_event_get_status(GUsbDeviceEvent *self) +{ + g_return_val_if_fail(G_USB_IS_DEVICE_EVENT(self), -1); + return self->status; +} + +/** + * _g_usb_device_event_set_status: + * @self: a #GUsbDeviceEvent + * @status: `enum libusb_transfer_status` + * + * Set the status of the event, e.g. `LIBUSB_TRANSFER_COMPLETED`. + * + * Since: 0.4.0 + **/ +void +_g_usb_device_event_set_status(GUsbDeviceEvent *self, gint status) +{ + g_return_if_fail(G_USB_IS_DEVICE_EVENT(self)); + self->status = status; +} + +/** + * g_usb_device_event_get_rc: + * @self: a #GUsbDeviceEvent + * + * Gets any return code from the event. + * + * Return value: a `enum libusb_error` + * + * Since: 0.4.5 + **/ +gint +g_usb_device_event_get_rc(GUsbDeviceEvent *self) +{ + g_return_val_if_fail(G_USB_IS_DEVICE_EVENT(self), LIBUSB_ERROR_OTHER); + return self->rc; +} + +/** + * _g_usb_device_event_set_rc:
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-device-event.h
Added
@@ -0,0 +1,28 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2022 Richard Hughes <richard@hughsie.com> + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#pragma once + +#include <gio/gio.h> + +G_BEGIN_DECLS + +#define G_USB_TYPE_DEVICE_EVENT (g_usb_device_event_get_type()) +G_DECLARE_FINAL_TYPE(GUsbDeviceEvent, g_usb_device_event, G_USB, DEVICE_EVENT, GObject) + +const gchar * +g_usb_device_event_get_id(GUsbDeviceEvent *self); +GBytes * +g_usb_device_event_get_bytes(GUsbDeviceEvent *self); +gint +g_usb_device_event_get_status(GUsbDeviceEvent *self); +gint +g_usb_device_event_get_rc(GUsbDeviceEvent *self); +void +g_usb_device_event_set_bytes(GUsbDeviceEvent *self, GBytes *bytes); + +G_END_DECLS
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-device-list.c -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-device-list.c
Changed
@@ -1,7 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com> - * Copyright (C) 2011-2014 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2011 Richard Hughes <richard@hughsie.com> * * SPDX-License-Identifier: LGPL-2.1+ */ @@ -15,188 +15,179 @@ #include "config.h" -#include <string.h> -#include <stdlib.h> #include <libusb.h> +#include <stdlib.h> +#include <string.h> -#include "gusb-context.h" #include "gusb-context-private.h" -#include "gusb-device.h" #include "gusb-device-list.h" #include "gusb-device-private.h" -enum { - PROP_0, - PROP_CONTEXT -}; +enum { PROP_0, PROP_CONTEXT }; -enum -{ - DEVICE_ADDED_SIGNAL, - DEVICE_REMOVED_SIGNAL, - LAST_SIGNAL -}; +enum { DEVICE_ADDED_SIGNAL, DEVICE_REMOVED_SIGNAL, LAST_SIGNAL }; -struct _GUsbDeviceListPrivate { +typedef struct { GUsbContext *context; -}; +} GUsbDeviceListPrivate; -static guint signalsLAST_SIGNAL = { 0 }; +static guint signalsLAST_SIGNAL = {0}; -G_DEFINE_TYPE_WITH_PRIVATE (GUsbDeviceList, g_usb_device_list, G_TYPE_OBJECT); +G_DEFINE_TYPE_WITH_PRIVATE(GUsbDeviceList, g_usb_device_list, G_TYPE_OBJECT); + +#define GET_PRIVATE(o) (g_usb_device_list_get_instance_private(o)) static void -g_usb_device_list_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +g_usb_device_list_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GUsbDeviceList *list = G_USB_DEVICE_LIST (object); - GUsbDeviceListPrivate *priv = list->priv; + GUsbDeviceList *self = G_USB_DEVICE_LIST(object); + GUsbDeviceListPrivate *priv = GET_PRIVATE(self); switch (prop_id) { case PROP_CONTEXT: - g_value_set_object (value, priv->context); + g_value_set_object(value, priv->context); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } } static void -g_usb_device_added_cb (GUsbContext *context, - GUsbDevice *device, - GUsbDeviceList *list) +g_usb_device_added_cb(GUsbContext *context, GUsbDevice *device, GUsbDeviceList *self) { - g_signal_emit (list, signalsDEVICE_ADDED_SIGNAL, 0, device); + g_signal_emit(self, signalsDEVICE_ADDED_SIGNAL, 0, device); } static void -g_usb_device_removed_cb (GUsbContext *context, - GUsbDevice *device, - GUsbDeviceList *list) +g_usb_device_removed_cb(GUsbContext *context, GUsbDevice *device, GUsbDeviceList *self) { - g_signal_emit (list, signalsDEVICE_REMOVED_SIGNAL, 0, device); + g_signal_emit(self, signalsDEVICE_REMOVED_SIGNAL, 0, device); } static void -g_usb_device_list_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +g_usb_device_list_set_property(GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - GUsbDeviceList *list = G_USB_DEVICE_LIST (object); - GUsbDeviceListPrivate *priv = list->priv; + GUsbDeviceList *self = G_USB_DEVICE_LIST(object); + GUsbDeviceListPrivate *priv = GET_PRIVATE(self); switch (prop_id) { case PROP_CONTEXT: - priv->context = g_value_get_object (value); - g_signal_connect (priv->context, "device-added", - G_CALLBACK (g_usb_device_added_cb), list); - g_signal_connect (priv->context, "device-removed", - G_CALLBACK (g_usb_device_removed_cb), list); + priv->context = g_value_get_object(value); + g_signal_connect(priv->context, + "device-added", + G_CALLBACK(g_usb_device_added_cb), + self); + g_signal_connect(priv->context, + "device-removed", + G_CALLBACK(g_usb_device_removed_cb), + self); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } } static void -g_usb_device_list_class_init (GUsbDeviceListClass *klass) +g_usb_device_list_class_init(GUsbDeviceListClass *klass) { GParamSpec *pspec; - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); - object_class->get_property = g_usb_device_list_get_property; - object_class->set_property = g_usb_device_list_set_property; + object_class->get_property = g_usb_device_list_get_property; + object_class->set_property = g_usb_device_list_set_property; /** * GUsbDeviceList:context: */ - pspec = g_param_spec_object ("context", NULL, NULL, - G_USB_TYPE_CONTEXT, - G_PARAM_CONSTRUCT_ONLY| - G_PARAM_READWRITE); - g_object_class_install_property (object_class, PROP_CONTEXT, pspec); + pspec = g_param_spec_object("context", + NULL, + NULL, + G_USB_TYPE_CONTEXT, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + g_object_class_install_property(object_class, PROP_CONTEXT, pspec); /** * GUsbDeviceList::device-added: - * @list: the #GUsbDeviceList instance that emitted the signal + * @self: the #GUsbDeviceList instance that emitted the signal * @device: A #GUsbDevice * * This signal is emitted when a USB device is added. **/ - signalsDEVICE_ADDED_SIGNAL = g_signal_new ("device-added", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GUsbDeviceListClass, device_added), - NULL, - NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - G_USB_TYPE_DEVICE); + signalsDEVICE_ADDED_SIGNAL = + g_signal_new("device-added", + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GUsbDeviceListClass, device_added), + NULL, + NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, + 1, + G_USB_TYPE_DEVICE); /** * GUsbDeviceList::device-removed: - * @list: the #GUsbDeviceList instance that emitted the signal + * @self: the #GUsbDeviceList instance that emitted the signal * @device: A #GUsbDevice *
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-device-list.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-device-list.h
Changed
@@ -1,42 +1,26 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com> - * Copyright (C) 2011-2014 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2011 Richard Hughes <richard@hughsie.com> * * SPDX-License-Identifier: LGPL-2.1+ */ #pragma once -#include <glib-object.h> - #include <gusb/gusb-context.h> -#include <gusb/gusb-device.h> G_BEGIN_DECLS -#define G_USB_TYPE_DEVICE_LIST (g_usb_device_list_get_type ()) -#define G_USB_DEVICE_LIST(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_USB_TYPE_DEVICE_LIST, GUsbDeviceList)) -#define G_USB_IS_DEVICE_LIST(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_USB_TYPE_DEVICE_LIST)) - -typedef struct _GUsbDeviceListPrivate GUsbDeviceListPrivate; -typedef struct _GUsbDeviceList GUsbDeviceList; -typedef struct _GUsbDeviceListClass GUsbDeviceListClass; +#define G_USB_TYPE_DEVICE_LIST (g_usb_device_list_get_type()) -struct _GUsbDeviceList -{ - GObject parent; - GUsbDeviceListPrivate *priv; -}; +G_DECLARE_DERIVABLE_TYPE(GUsbDeviceList, g_usb_device_list, G_USB, DEVICE_LIST, GObject) -struct _GUsbDeviceListClass -{ - GObjectClass parent_class; +struct _GUsbDeviceListClass { + GObjectClass parent_class; /* Signals */ - void (*device_added) (GUsbDeviceList *list, - GUsbDevice *device); - void (*device_removed) (GUsbDeviceList *list, - GUsbDevice *device); + void (*device_added)(GUsbDeviceList *self, GUsbDevice *device); + void (*device_removed)(GUsbDeviceList *self, GUsbDevice *device); /*< private >*/ /* * If adding fields to this struct, remove corresponding @@ -45,27 +29,27 @@ gchar _gusb_reserved64; }; -GType g_usb_device_list_get_type (void); - G_DEPRECATED_FOR(g_usb_context_new) -GUsbDeviceList *g_usb_device_list_new (GUsbContext *context); +GUsbDeviceList * +g_usb_device_list_new(GUsbContext *context); G_DEPRECATED -void g_usb_device_list_coldplug (GUsbDeviceList *list); +void +g_usb_device_list_coldplug(GUsbDeviceList *self); G_DEPRECATED_FOR(g_usb_context_get_devices) -GPtrArray *g_usb_device_list_get_devices (GUsbDeviceList *list); +GPtrArray * +g_usb_device_list_get_devices(GUsbDeviceList *self); G_DEPRECATED_FOR(g_usb_context_find_by_bus_address) -GUsbDevice *g_usb_device_list_find_by_bus_address (GUsbDeviceList *list, - guint8 bus, - guint8 address, - GError **error); +GUsbDevice * +g_usb_device_list_find_by_bus_address(GUsbDeviceList *self, + guint8 bus, + guint8 address, + GError **error); G_DEPRECATED_FOR(g_usb_context_find_by_vid_pid) -GUsbDevice *g_usb_device_list_find_by_vid_pid (GUsbDeviceList *list, - guint16 vid, - guint16 pid, - GError **error); +GUsbDevice * +g_usb_device_list_find_by_vid_pid(GUsbDeviceList *self, guint16 vid, guint16 pid, GError **error); G_END_DECLS
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-device-private.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-device-private.h
Changed
@@ -7,16 +7,23 @@ #pragma once +#include <gusb/gusb-device-event.h> #include <gusb/gusb-device.h> G_BEGIN_DECLS -GUsbDevice *_g_usb_device_new (GUsbContext *context, - libusb_device *device, - GError **error); +GUsbDevice * +_g_usb_device_new(GUsbContext *context, libusb_device *device, GError **error); +gboolean +_g_usb_device_load(GUsbDevice *self, JsonObject *json_object, GError **error); +gboolean +_g_usb_device_save(GUsbDevice *self, JsonBuilder *json_builder, GError **error); +void +_g_usb_device_add_event(GUsbDevice *self, GUsbDeviceEvent *event); -libusb_device *_g_usb_device_get_device (GUsbDevice *device); -gboolean _g_usb_device_open_internal (GUsbDevice *device, - GError **error); +libusb_device * +_g_usb_device_get_device(GUsbDevice *self); +gboolean +_g_usb_device_open_internal(GUsbDevice *self, GError **error); G_END_DECLS
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-device.c -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-device.c
Changed
@@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2010-2015 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2010 Richard Hughes <richard@hughsie.com> * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com> * Copyright (C) 2011 Debarshi Ray <debarshir@src.gnome.org> * @@ -16,48 +16,58 @@ #include "config.h" -#include <string.h> - #include <libusb.h> +#include <string.h> -#include "gusb-context.h" +#include "gusb-bos-descriptor-private.h" #include "gusb-context-private.h" -#include "gusb-util.h" -#include "gusb-device.h" +#include "gusb-device-event-private.h" #include "gusb-device-private.h" #include "gusb-interface-private.h" +#include "gusb-json-common.h" +#include "gusb-util.h" /** * GUsbDevicePrivate: * * Private #GUsbDevice data **/ -struct _GUsbDevicePrivate -{ - gchar *platform_id; - GUsbContext *context; - libusb_device *device; - libusb_device_handle *handle; +typedef struct { + gchar *platform_id; + GUsbContext *context; + libusb_device *device; + libusb_device_handle *handle; struct libusb_device_descriptor desc; + gboolean interfaces_valid; + gboolean bos_descriptors_valid; + GPtrArray *interfaces; /* of GUsbInterface */ + GPtrArray *bos_descriptors; /* of GUsbBosDescriptor */ + GPtrArray *events; /* of GUsbDeviceEvent */ + GPtrArray *tags; /* of utf-8 */ + guint event_idx; + GDateTime *created; +} GUsbDevicePrivate; + +enum { PROP_0, PROP_LIBUSB_DEVICE, PROP_CONTEXT, PROP_PLATFORM_ID, N_PROPERTIES }; + +static GParamSpec *pspecsN_PROPERTIES = { + NULL, }; -enum { - PROP_0, - PROP_LIBUSB_DEVICE, - PROP_CONTEXT, - PROP_PLATFORM_ID, - N_PROPERTIES -}; - -static GParamSpec *pspecsN_PROPERTIES = { NULL, }; +static void +g_usb_device_initable_iface_init(GInitableIface *iface); -static void g_usb_device_initable_iface_init (GInitableIface *iface); +G_DEFINE_TYPE_EXTENDED(GUsbDevice, + g_usb_device, + G_TYPE_OBJECT, + 0, + G_ADD_PRIVATE(GUsbDevice) + G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE, + g_usb_device_initable_iface_init)); -G_DEFINE_TYPE_WITH_CODE (GUsbDevice, g_usb_device, G_TYPE_OBJECT, - G_ADD_PRIVATE (GUsbDevice) - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, - g_usb_device_initable_iface_init)) +#define GET_PRIVATE(o) (g_usb_device_get_instance_private(o)) +/* clang-format off */ /** * g_usb_device_error_quark: * @@ -66,110 +76,105 @@ * Since: 0.1.0 **/ G_DEFINE_QUARK (g-usb-device-error-quark, g_usb_device_error) +/* clang-format on */ static void -g_usb_device_finalize (GObject *object) +g_usb_device_finalize(GObject *object) { - GUsbDevice *device = G_USB_DEVICE (object); - GUsbDevicePrivate *priv = device->priv; + GUsbDevice *self = G_USB_DEVICE(object); + GUsbDevicePrivate *priv = GET_PRIVATE(self); - g_free (priv->platform_id); + g_free(priv->platform_id); + g_date_time_unref(priv->created); + g_ptr_array_unref(priv->interfaces); + g_ptr_array_unref(priv->bos_descriptors); + g_ptr_array_unref(priv->events); + g_ptr_array_unref(priv->tags); - G_OBJECT_CLASS (g_usb_device_parent_class)->finalize (object); + G_OBJECT_CLASS(g_usb_device_parent_class)->finalize(object); } static void -g_usb_device_dispose (GObject *object) +g_usb_device_dispose(GObject *object) { - GUsbDevice *device = G_USB_DEVICE (object); - GUsbDevicePrivate *priv = device->priv; + GUsbDevice *self = G_USB_DEVICE(object); + GUsbDevicePrivate *priv = GET_PRIVATE(self); - g_clear_pointer (&priv->device, libusb_unref_device); - g_clear_object (&priv->context); + g_clear_pointer(&priv->device, libusb_unref_device); + g_clear_object(&priv->context); - G_OBJECT_CLASS (g_usb_device_parent_class)->dispose (object); + G_OBJECT_CLASS(g_usb_device_parent_class)->dispose(object); } static void -g_usb_device_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +g_usb_device_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - GUsbDevice *device = G_USB_DEVICE (object); - GUsbDevicePrivate *priv = device->priv; + GUsbDevice *self = G_USB_DEVICE(object); + GUsbDevicePrivate *priv = GET_PRIVATE(self); switch (prop_id) { case PROP_LIBUSB_DEVICE: - g_value_set_pointer (value, priv->device); + g_value_set_pointer(value, priv->device); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } } static void -set_libusb_device (GUsbDevice *device, - struct libusb_device *dev) +set_libusb_device(GUsbDevice *self, struct libusb_device *dev) { - GUsbDevicePrivate *priv = device->priv; + GUsbDevicePrivate *priv = GET_PRIVATE(self); - g_clear_pointer (&priv->device, libusb_unref_device); + g_clear_pointer(&priv->device, libusb_unref_device); if (dev != NULL) - priv->device = libusb_ref_device (dev); + priv->device = libusb_ref_device(dev); } static void -g_usb_device_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +g_usb_device_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - GUsbDevice *device = G_USB_DEVICE (object); - GUsbDevicePrivate *priv = device->priv; + GUsbDevice *self = G_USB_DEVICE(object); + GUsbDevicePrivate *priv = GET_PRIVATE(self); switch (prop_id) { case PROP_LIBUSB_DEVICE: - set_libusb_device (device, g_value_get_pointer (value)); + set_libusb_device(self, g_value_get_pointer(value)); break; case PROP_CONTEXT: - priv->context = g_value_dup_object (value); + priv->context = g_value_dup_object(value); break; case PROP_PLATFORM_ID: - priv->platform_id = g_value_dup_string (value);
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-device.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-device.h
Changed
@@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2010-2015 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2010 Richard Hughes <richard@hughsie.com> * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com> * * SPDX-License-Identifier: LGPL-2.1+ @@ -8,22 +8,18 @@ #pragma once -#include <glib-object.h> #include <gio/gio.h> - -#include <gusb/gusb-util.h> +#include <gusb/gusb-bos-descriptor.h> #include <gusb/gusb-interface.h> +#include <gusb/gusb-util.h> +#include <json-glib/json-glib.h> G_BEGIN_DECLS -#define G_USB_TYPE_DEVICE (g_usb_device_get_type ()) -#define G_USB_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_USB_TYPE_DEVICE, GUsbDevice)) -#define G_USB_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_USB_TYPE_DEVICE)) -#define G_USB_DEVICE_ERROR (g_usb_device_error_quark ()) +#define G_USB_TYPE_DEVICE (g_usb_device_get_type()) +#define G_USB_DEVICE_ERROR (g_usb_device_error_quark()) -typedef struct _GUsbDevicePrivate GUsbDevicePrivate; -typedef struct _GUsbDevice GUsbDevice; -typedef struct _GUsbDeviceClass GUsbDeviceClass; +G_DECLARE_DERIVABLE_TYPE(GUsbDevice, g_usb_device, G_USB, DEVICE, GObject) /** * GUsbDeviceDirection: @@ -85,8 +81,8 @@ * g_usb_device_release_interface methods flags parameters. **/ typedef enum { - G_USB_DEVICE_CLAIM_INTERFACE_NONE = 0, - G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER = 1 << 0, + G_USB_DEVICE_CLAIM_INTERFACE_NONE = 0, + G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER = 1 << 0, } GUsbDeviceClaimInterfaceFlags; /** @@ -95,49 +91,41 @@ * The USB device class. **/ typedef enum { - G_USB_DEVICE_CLASS_INTERFACE_DESC = 0x00, - G_USB_DEVICE_CLASS_AUDIO = 0x01, - G_USB_DEVICE_CLASS_COMMUNICATIONS = 0x02, - G_USB_DEVICE_CLASS_HID = 0x03, - G_USB_DEVICE_CLASS_PHYSICAL = 0x05, - G_USB_DEVICE_CLASS_IMAGE = 0x06, - G_USB_DEVICE_CLASS_PRINTER = 0x07, - G_USB_DEVICE_CLASS_MASS_STORAGE = 0x08, - G_USB_DEVICE_CLASS_HUB = 0x09, - G_USB_DEVICE_CLASS_CDC_DATA = 0x0a, - G_USB_DEVICE_CLASS_SMART_CARD = 0x0b, - G_USB_DEVICE_CLASS_CONTENT_SECURITY = 0x0d, - G_USB_DEVICE_CLASS_VIDEO = 0x0e, - G_USB_DEVICE_CLASS_PERSONAL_HEALTHCARE = 0x0f, - G_USB_DEVICE_CLASS_AUDIO_VIDEO = 0x10, - G_USB_DEVICE_CLASS_BILLBOARD = 0x11, - G_USB_DEVICE_CLASS_DIAGNOSTIC = 0xdc, - G_USB_DEVICE_CLASS_WIRELESS_CONTROLLER = 0xe0, - G_USB_DEVICE_CLASS_MISCELLANEOUS = 0xef, - G_USB_DEVICE_CLASS_APPLICATION_SPECIFIC = 0xfe, - G_USB_DEVICE_CLASS_VENDOR_SPECIFIC = 0xff + G_USB_DEVICE_CLASS_INTERFACE_DESC = 0x00, + G_USB_DEVICE_CLASS_AUDIO = 0x01, + G_USB_DEVICE_CLASS_COMMUNICATIONS = 0x02, + G_USB_DEVICE_CLASS_HID = 0x03, + G_USB_DEVICE_CLASS_PHYSICAL = 0x05, + G_USB_DEVICE_CLASS_IMAGE = 0x06, + G_USB_DEVICE_CLASS_PRINTER = 0x07, + G_USB_DEVICE_CLASS_MASS_STORAGE = 0x08, + G_USB_DEVICE_CLASS_HUB = 0x09, + G_USB_DEVICE_CLASS_CDC_DATA = 0x0a, + G_USB_DEVICE_CLASS_SMART_CARD = 0x0b, + G_USB_DEVICE_CLASS_CONTENT_SECURITY = 0x0d, + G_USB_DEVICE_CLASS_VIDEO = 0x0e, + G_USB_DEVICE_CLASS_PERSONAL_HEALTHCARE = 0x0f, + G_USB_DEVICE_CLASS_AUDIO_VIDEO = 0x10, + G_USB_DEVICE_CLASS_BILLBOARD = 0x11, + G_USB_DEVICE_CLASS_DIAGNOSTIC = 0xdc, + G_USB_DEVICE_CLASS_WIRELESS_CONTROLLER = 0xe0, + G_USB_DEVICE_CLASS_MISCELLANEOUS = 0xef, + G_USB_DEVICE_CLASS_APPLICATION_SPECIFIC = 0xfe, + G_USB_DEVICE_CLASS_VENDOR_SPECIFIC = 0xff } GUsbDeviceClassCode; - /** * GUsbDeviceLangid: * * The USB language ID. **/ typedef enum { - G_USB_DEVICE_LANGID_INVALID = 0x0000, - G_USB_DEVICE_LANGID_ENGLISH_UNITED_STATES = 0x0409, + G_USB_DEVICE_LANGID_INVALID = 0x0000, + G_USB_DEVICE_LANGID_ENGLISH_UNITED_STATES = 0x0409, } GUsbDeviceLangid; -struct _GUsbDevice -{ - GObject parent; - GUsbDevicePrivate *priv; -}; - -struct _GUsbDeviceClass -{ - GObjectClass parent_class; +struct _GUsbDeviceClass { + GObjectClass parent_class; /*< private >*/ /* * If adding fields to this struct, remove corresponding @@ -146,159 +134,208 @@ gchar _gusb_reserved64; }; -GType g_usb_device_get_type (void); -GQuark g_usb_device_error_quark (void); - -const gchar *g_usb_device_get_platform_id (GUsbDevice *device); -GUsbDevice *g_usb_device_get_parent (GUsbDevice *device); -GPtrArray *g_usb_device_get_children (GUsbDevice *device); - -guint8 g_usb_device_get_bus (GUsbDevice *device); -guint8 g_usb_device_get_address (GUsbDevice *device); -guint8 g_usb_device_get_port_number (GUsbDevice *device); - -guint16 g_usb_device_get_vid (GUsbDevice *device); -guint16 g_usb_device_get_pid (GUsbDevice *device); -guint16 g_usb_device_get_release (GUsbDevice *device); -guint16 g_usb_device_get_spec (GUsbDevice *device); -const gchar *g_usb_device_get_vid_as_str (GUsbDevice *device); -const gchar *g_usb_device_get_pid_as_str (GUsbDevice *device); -guint8 g_usb_device_get_device_class (GUsbDevice *device); -guint8 g_usb_device_get_device_subclass (GUsbDevice *device); -guint8 g_usb_device_get_device_protocol (GUsbDevice *device); - -guint8 g_usb_device_get_configuration_index (GUsbDevice *device); -guint8 g_usb_device_get_manufacturer_index (GUsbDevice *device); -guint8 g_usb_device_get_product_index (GUsbDevice *device); -guint8 g_usb_device_get_serial_number_index (GUsbDevice *device); -guint8 g_usb_device_get_custom_index (GUsbDevice *device, - guint8 class_id, - guint8 subclass_id, - guint8 protocol_id, - GError **error); - -GUsbInterface *g_usb_device_get_interface (GUsbDevice *device, - guint8 class_id, - guint8 subclass_id, - guint8 protocol_id, - GError **error); -GPtrArray *g_usb_device_get_interfaces (GUsbDevice *device, - GError **error); - -gboolean g_usb_device_open (GUsbDevice *device, - GError **error); -gboolean g_usb_device_close (GUsbDevice *device, - GError **error); - -gboolean g_usb_device_reset (GUsbDevice *device, - GError **error); - -gint g_usb_device_get_configuration (GUsbDevice *device, - GError **error); -gboolean g_usb_device_set_configuration (GUsbDevice *device, - gint configuration, - GError **error); - -gboolean g_usb_device_claim_interface (GUsbDevice *device, - gint interface, - GUsbDeviceClaimInterfaceFlags flags, - GError **error); -gboolean g_usb_device_release_interface (GUsbDevice *device, - gint interface, - GUsbDeviceClaimInterfaceFlags flags, - GError **error); -gboolean g_usb_device_set_interface_alt (GUsbDevice *device, - gint interface, - guint8 alt, - GError **error); - -gchar *g_usb_device_get_string_descriptor (GUsbDevice *device, - guint8 desc_index, - GError **error); -GBytes *g_usb_device_get_string_descriptor_bytes (GUsbDevice *device, - guint8 desc_index, - guint16 langid, - GError **error);
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-endpoint-private.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-endpoint-private.h
Changed
@@ -1,18 +1,25 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2020 Emmanuel Pacaud <emmanuel@gnome.org> + * Copyright (C) 2022 Richard Hughes <richard@hughsie.com> * * SPDX-License-Identifier: LGPL-2.1+ */ #pragma once -#include <libusb.h> - #include <gusb/gusb-endpoint.h> +#include <json-glib/json-glib.h> +#include <libusb.h> G_BEGIN_DECLS -GUsbEndpoint *_g_usb_endpoint_new (const struct libusb_endpoint_descriptor *endpoint); +GUsbEndpoint * +_g_usb_endpoint_new(const struct libusb_endpoint_descriptor *endpoint); + +gboolean +_g_usb_endpoint_load(GUsbEndpoint *self, JsonObject *json_object, GError **error); +gboolean +_g_usb_endpoint_save(GUsbEndpoint *self, JsonBuilder *json_builder, GError **error); G_END_DECLS
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-endpoint.c -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-endpoint.c
Changed
@@ -19,40 +19,126 @@ #include <string.h> -#include "gusb-endpoint.h" #include "gusb-endpoint-private.h" +#include "gusb-json-common.h" -struct _GUsbEndpoint -{ +struct _GUsbEndpoint { GObject parent_instance; struct libusb_endpoint_descriptor endpoint_descriptor; GBytes *extra; }; -G_DEFINE_TYPE (GUsbEndpoint, g_usb_endpoint, G_TYPE_OBJECT) +G_DEFINE_TYPE(GUsbEndpoint, g_usb_endpoint, G_TYPE_OBJECT) static void -g_usb_endpoint_finalize (GObject *object) +g_usb_endpoint_finalize(GObject *object) { - GUsbEndpoint *endpoint = G_USB_ENDPOINT (object); + GUsbEndpoint *self = G_USB_ENDPOINT(object); - g_bytes_unref (endpoint->extra); + g_bytes_unref(self->extra); - G_OBJECT_CLASS (g_usb_endpoint_parent_class)->finalize (object); + G_OBJECT_CLASS(g_usb_endpoint_parent_class)->finalize(object); } static void -g_usb_endpoint_class_init (GUsbEndpointClass *klass) +g_usb_endpoint_class_init(GUsbEndpointClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); object_class->finalize = g_usb_endpoint_finalize; } static void -g_usb_endpoint_init (GUsbEndpoint *endpoint) +g_usb_endpoint_init(GUsbEndpoint *self) +{ +} + +gboolean +_g_usb_endpoint_load(GUsbEndpoint *self, JsonObject *json_object, GError **error) { + const gchar *str; + + g_return_val_if_fail(G_USB_IS_ENDPOINT(self), FALSE); + g_return_val_if_fail(json_object != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + /* optional properties */ + self->endpoint_descriptor.bDescriptorType = + json_object_get_int_member_with_default(json_object, "DescriptorType", 0x0); + self->endpoint_descriptor.bEndpointAddress = + json_object_get_int_member_with_default(json_object, "EndpointAddress", 0x0); + self->endpoint_descriptor.bRefresh = + json_object_get_int_member_with_default(json_object, "Refresh", 0x0); + self->endpoint_descriptor.bInterval = + json_object_get_int_member_with_default(json_object, "Interval", 0x0); + self->endpoint_descriptor.bSynchAddress = + json_object_get_int_member_with_default(json_object, "SynchAddress", 0x0); + self->endpoint_descriptor.wMaxPacketSize = + json_object_get_int_member_with_default(json_object, "MaxPacketSize", 0x0); + + /* extra data */ + str = json_object_get_string_member_with_default(json_object, "ExtraData", NULL); + if (str != NULL) { + gsize bufsz = 0; + g_autofree guchar *buf = g_base64_decode(str, &bufsz); + if (self->extra != NULL) + g_bytes_unref(self->extra); + self->extra = g_bytes_new_take(g_steal_pointer(&buf), bufsz); + } + + /* success */ + return TRUE; +} + +gboolean +_g_usb_endpoint_save(GUsbEndpoint *self, JsonBuilder *json_builder, GError **error) +{ + g_return_val_if_fail(G_USB_IS_ENDPOINT(self), FALSE); + g_return_val_if_fail(json_builder != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + /* start */ + json_builder_begin_object(json_builder); + + /* optional properties */ + if (self->endpoint_descriptor.bDescriptorType != 0) { + json_builder_set_member_name(json_builder, "DescriptorType"); + json_builder_add_int_value(json_builder, self->endpoint_descriptor.bDescriptorType); + } + if (self->endpoint_descriptor.bEndpointAddress != 0) { + json_builder_set_member_name(json_builder, "EndpointAddress"); + json_builder_add_int_value(json_builder, + self->endpoint_descriptor.bEndpointAddress); + } + if (self->endpoint_descriptor.bRefresh != 0) { + json_builder_set_member_name(json_builder, "Refresh"); + json_builder_add_int_value(json_builder, self->endpoint_descriptor.bRefresh); + } + if (self->endpoint_descriptor.bInterval != 0) { + json_builder_set_member_name(json_builder, "Interval"); + json_builder_add_int_value(json_builder, self->endpoint_descriptor.bInterval); + } + if (self->endpoint_descriptor.bSynchAddress != 0) { + json_builder_set_member_name(json_builder, "SynchAddress"); + json_builder_add_int_value(json_builder, self->endpoint_descriptor.bSynchAddress); + } + if (self->endpoint_descriptor.wMaxPacketSize != 0) { + json_builder_set_member_name(json_builder, "MaxPacketSize"); + json_builder_add_int_value(json_builder, self->endpoint_descriptor.wMaxPacketSize); + } + + /* extra data */ + if (self->extra != NULL && g_bytes_get_size(self->extra) > 0) { + g_autofree gchar *str = g_base64_encode(g_bytes_get_data(self->extra, NULL), + g_bytes_get_size(self->extra)); + json_builder_set_member_name(json_builder, "ExtraData"); + json_builder_add_string_value(json_builder, str); + } + + /* success */ + json_builder_end_object(json_builder); + return TRUE; } /** @@ -63,23 +149,23 @@ * Since: 0.3.3 **/ GUsbEndpoint * -_g_usb_endpoint_new (const struct libusb_endpoint_descriptor *endpoint_descriptor) +_g_usb_endpoint_new(const struct libusb_endpoint_descriptor *endpoint_descriptor) { - GUsbEndpoint *endpoint; - endpoint = g_object_new (G_USB_TYPE_ENDPOINT, NULL); + GUsbEndpoint *self; + self = g_object_new(G_USB_TYPE_ENDPOINT, NULL); /* copy the data */ - memcpy (&endpoint->endpoint_descriptor, - endpoint_descriptor, - sizeof (struct libusb_endpoint_descriptor)); - endpoint->extra = g_bytes_new (endpoint_descriptor->extra, endpoint_descriptor->extra_length); + memcpy(&self->endpoint_descriptor, + endpoint_descriptor, + sizeof(struct libusb_endpoint_descriptor)); + self->extra = g_bytes_new(endpoint_descriptor->extra, endpoint_descriptor->extra_length); - return G_USB_ENDPOINT (endpoint); + return G_USB_ENDPOINT(self); } /** * g_usb_endpoint_get_kind: - * @endpoint: a #GUsbEndpoint + * @self: a #GUsbEndpoint * * Gets the type of endpoint. * @@ -88,15 +174,15 @@ * Since: 0.3.3 **/ guint8 -g_usb_endpoint_get_kind (GUsbEndpoint *endpoint) +g_usb_endpoint_get_kind(GUsbEndpoint *self) { - g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), 0); - return endpoint->endpoint_descriptor.bDescriptorType; + g_return_val_if_fail(G_USB_IS_ENDPOINT(self), 0); + return self->endpoint_descriptor.bDescriptorType; } /** * g_usb_endpoint_get_maximum_packet_size: - * @endpoint: a #GUsbEndpoint + * @self: a #GUsbEndpoint * * Gets the maximum packet size this endpoint is capable of sending/receiving. * @@ -105,15 +191,15 @@ * Since: 0.3.3 **/ guint16 -g_usb_endpoint_get_maximum_packet_size (GUsbEndpoint *endpoint) +g_usb_endpoint_get_maximum_packet_size(GUsbEndpoint *self) { - g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), 0); - return endpoint->endpoint_descriptor.wMaxPacketSize;
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-endpoint.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-endpoint.h
Changed
@@ -7,23 +7,30 @@ #pragma once -#include <glib-object.h> -#include <gio/gio.h> #include <gusb/gusb-device.h> G_BEGIN_DECLS -#define G_USB_TYPE_ENDPOINT (g_usb_endpoint_get_type ()) -G_DECLARE_FINAL_TYPE (GUsbEndpoint, g_usb_endpoint, G_USB, ENDPOINT, GObject) +#define G_USB_TYPE_ENDPOINT (g_usb_endpoint_get_type()) +G_DECLARE_FINAL_TYPE(GUsbEndpoint, g_usb_endpoint, G_USB, ENDPOINT, GObject) -guint8 g_usb_endpoint_get_kind (GUsbEndpoint *endpoint); -guint16 g_usb_endpoint_get_maximum_packet_size (GUsbEndpoint *endpoint); -guint8 g_usb_endpoint_get_polling_interval (GUsbEndpoint *endpoint); -guint8 g_usb_endpoint_get_refresh (GUsbEndpoint *endpoint); -guint8 g_usb_endpoint_get_synch_address (GUsbEndpoint *endpoint); -guint8 g_usb_endpoint_get_address (GUsbEndpoint *endpoint); -guint8 g_usb_endpoint_get_number (GUsbEndpoint *endpoint); -GUsbDeviceDirection g_usb_endpoint_get_direction (GUsbEndpoint *endpoint); -GBytes * g_usb_endpoint_get_extra (GUsbEndpoint *endpoint); +guint8 +g_usb_endpoint_get_kind(GUsbEndpoint *self); +guint16 +g_usb_endpoint_get_maximum_packet_size(GUsbEndpoint *self); +guint8 +g_usb_endpoint_get_polling_interval(GUsbEndpoint *self); +guint8 +g_usb_endpoint_get_refresh(GUsbEndpoint *self); +guint8 +g_usb_endpoint_get_synch_address(GUsbEndpoint *self); +guint8 +g_usb_endpoint_get_address(GUsbEndpoint *self); +guint8 +g_usb_endpoint_get_number(GUsbEndpoint *self); +GUsbDeviceDirection +g_usb_endpoint_get_direction(GUsbEndpoint *self); +GBytes * +g_usb_endpoint_get_extra(GUsbEndpoint *self); G_END_DECLS
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-interface-private.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-interface-private.h
Changed
@@ -7,12 +7,18 @@ #pragma once -#include <libusb.h> - #include <gusb/gusb-interface.h> +#include <json-glib/json-glib.h> +#include <libusb.h> G_BEGIN_DECLS -GUsbInterface *_g_usb_interface_new (const struct libusb_interface_descriptor *iface); +GUsbInterface * +_g_usb_interface_new(const struct libusb_interface_descriptor *iface); + +gboolean +_g_usb_interface_load(GUsbInterface *self, JsonObject *json_object, GError **error); +gboolean +_g_usb_interface_save(GUsbInterface *self, JsonBuilder *json_builder, GError **error); G_END_DECLS
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-interface.c -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-interface.c
Changed
@@ -20,12 +20,11 @@ #include <string.h> -#include "gusb-interface.h" -#include "gusb-interface-private.h" #include "gusb-endpoint-private.h" +#include "gusb-interface-private.h" +#include "gusb-json-common.h" -struct _GUsbInterface -{ +struct _GUsbInterface { GObject parent_instance; struct libusb_interface_descriptor iface; @@ -34,30 +33,155 @@ GPtrArray *endpoints; }; -G_DEFINE_TYPE (GUsbInterface, g_usb_interface, G_TYPE_OBJECT) +G_DEFINE_TYPE(GUsbInterface, g_usb_interface, G_TYPE_OBJECT) static void -g_usb_interface_finalize (GObject *object) +g_usb_interface_finalize(GObject *object) { - GUsbInterface *interface = G_USB_INTERFACE (object); + GUsbInterface *self = G_USB_INTERFACE(object); - g_bytes_unref (interface->extra); - g_ptr_array_unref (interface->endpoints); + if (self->extra != NULL) + g_bytes_unref(self->extra); + if (self->endpoints != NULL) + g_ptr_array_unref(self->endpoints); - G_OBJECT_CLASS (g_usb_interface_parent_class)->finalize (object); + G_OBJECT_CLASS(g_usb_interface_parent_class)->finalize(object); } static void -g_usb_interface_class_init (GUsbInterfaceClass *klass) +g_usb_interface_class_init(GUsbInterfaceClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS(klass); object_class->finalize = g_usb_interface_finalize; } static void -g_usb_interface_init (GUsbInterface *interface) +g_usb_interface_init(GUsbInterface *self) +{ +} + +gboolean +_g_usb_interface_load(GUsbInterface *self, JsonObject *json_object, GError **error) { + const gchar *str; + + g_return_val_if_fail(G_USB_IS_INTERFACE(self), FALSE); + g_return_val_if_fail(json_object != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, -1); + + /* optional properties */ + self->iface.bLength = json_object_get_int_member_with_default(json_object, "Length", 0x0); + self->iface.bDescriptorType = + json_object_get_int_member_with_default(json_object, "DescriptorType", 0x0); + self->iface.bInterfaceNumber = + json_object_get_int_member_with_default(json_object, "InterfaceNumber", 0x0); + self->iface.bAlternateSetting = + json_object_get_int_member_with_default(json_object, "AlternateSetting", 0x0); + self->iface.bInterfaceClass = + json_object_get_int_member_with_default(json_object, "InterfaceClass", 0x0); + self->iface.bInterfaceSubClass = + json_object_get_int_member_with_default(json_object, "InterfaceSubClass", 0x0); + self->iface.bInterfaceProtocol = + json_object_get_int_member_with_default(json_object, "InterfaceProtocol", 0x0); + self->iface.iInterface = + json_object_get_int_member_with_default(json_object, "Interface", 0x0); + + /* array of endpoints */ + if (json_object_has_member(json_object, "UsbEndpoints")) { + JsonArray *json_array = json_object_get_array_member(json_object, "UsbEndpoints"); + self->endpoints = g_ptr_array_new_with_free_func(g_object_unref); + for (guint i = 0; i < json_array_get_length(json_array); i++) { + JsonNode *node_tmp = json_array_get_element(json_array, i); + JsonObject *obj_tmp = json_node_get_object(node_tmp); + g_autoptr(GUsbEndpoint) endpoint = g_object_new(G_USB_TYPE_ENDPOINT, NULL); + if (!_g_usb_endpoint_load(endpoint, obj_tmp, error)) + return FALSE; + g_ptr_array_add(self->endpoints, g_object_ref(endpoint)); + } + } + + /* extra data */ + str = json_object_get_string_member_with_default(json_object, "ExtraData", NULL); + if (str != NULL) { + gsize bufsz = 0; + g_autofree guchar *buf = g_base64_decode(str, &bufsz); + if (self->extra != NULL) + g_bytes_unref(self->extra); + self->extra = g_bytes_new_take(g_steal_pointer(&buf), bufsz); + } + + /* success */ + return TRUE; +} + +gboolean +_g_usb_interface_save(GUsbInterface *self, JsonBuilder *json_builder, GError **error) +{ + g_return_val_if_fail(G_USB_IS_INTERFACE(self), FALSE); + g_return_val_if_fail(json_builder != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + /* start */ + json_builder_begin_object(json_builder); + + /* optional properties */ + if (self->iface.bLength != 0) { + json_builder_set_member_name(json_builder, "Length"); + json_builder_add_int_value(json_builder, self->iface.bLength); + } + if (self->iface.bDescriptorType != 0) { + json_builder_set_member_name(json_builder, "DescriptorType"); + json_builder_add_int_value(json_builder, self->iface.bDescriptorType); + } + if (self->iface.bInterfaceNumber != 0) { + json_builder_set_member_name(json_builder, "InterfaceNumber"); + json_builder_add_int_value(json_builder, self->iface.bInterfaceNumber); + } + if (self->iface.bAlternateSetting != 0) { + json_builder_set_member_name(json_builder, "AlternateSetting"); + json_builder_add_int_value(json_builder, self->iface.bAlternateSetting); + } + if (self->iface.bInterfaceClass != 0) { + json_builder_set_member_name(json_builder, "InterfaceClass"); + json_builder_add_int_value(json_builder, self->iface.bInterfaceClass); + } + if (self->iface.bInterfaceSubClass != 0) { + json_builder_set_member_name(json_builder, "InterfaceSubClass"); + json_builder_add_int_value(json_builder, self->iface.bInterfaceSubClass); + } + if (self->iface.bInterfaceProtocol != 0) { + json_builder_set_member_name(json_builder, "InterfaceProtocol"); + json_builder_add_int_value(json_builder, self->iface.bInterfaceProtocol); + } + if (self->iface.iInterface != 0) { + json_builder_set_member_name(json_builder, "Interface"); + json_builder_add_int_value(json_builder, self->iface.iInterface); + } + + /* array of endpoints */ + if (self->endpoints != NULL && self->endpoints->len > 0) { + json_builder_set_member_name(json_builder, "UsbEndpoints"); + json_builder_begin_array(json_builder); + for (guint i = 0; i < self->endpoints->len; i++) { + GUsbEndpoint *endpoint = g_ptr_array_index(self->endpoints, i); + if (!_g_usb_endpoint_save(endpoint, json_builder, error)) + return FALSE; + } + json_builder_end_array(json_builder); + } + + /* extra data */ + if (self->extra != NULL && g_bytes_get_size(self->extra) > 0) { + g_autofree gchar *str = g_base64_encode(g_bytes_get_data(self->extra, NULL), + g_bytes_get_size(self->extra)); + json_builder_set_member_name(json_builder, "ExtraData"); + json_builder_add_string_value(json_builder, str); + } + + /* success */ + json_builder_end_object(json_builder); + return TRUE; } /** @@ -68,27 +192,25 @@ * Since: 0.2.8 **/ GUsbInterface * -_g_usb_interface_new (const struct libusb_interface_descriptor *iface) +_g_usb_interface_new(const struct libusb_interface_descriptor *iface) { - GUsbInterface *interface; - interface = g_object_new (G_USB_TYPE_INTERFACE, NULL); + GUsbInterface *self; + self = g_object_new(G_USB_TYPE_INTERFACE, NULL); /* copy the data */ - memcpy (&interface->iface, - iface, - sizeof (struct libusb_interface_descriptor)); - interface->extra = g_bytes_new (iface->extra, iface->extra_length); + memcpy(&self->iface, iface, sizeof(struct libusb_interface_descriptor)); + self->extra = g_bytes_new(iface->extra, iface->extra_length);
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-interface.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-interface.h
Changed
@@ -9,22 +9,31 @@ #pragma once #include <glib-object.h> -#include <gio/gio.h> G_BEGIN_DECLS -#define G_USB_TYPE_INTERFACE (g_usb_interface_get_type ()) -G_DECLARE_FINAL_TYPE (GUsbInterface, g_usb_interface, G_USB, INTERFACE, GObject) +#define G_USB_TYPE_INTERFACE (g_usb_interface_get_type()) +G_DECLARE_FINAL_TYPE(GUsbInterface, g_usb_interface, G_USB, INTERFACE, GObject) -guint8 g_usb_interface_get_length (GUsbInterface *interface); -guint8 g_usb_interface_get_kind (GUsbInterface *interface); -guint8 g_usb_interface_get_number (GUsbInterface *interface); -guint8 g_usb_interface_get_alternate (GUsbInterface *interface); -guint8 g_usb_interface_get_class (GUsbInterface *interface); -guint8 g_usb_interface_get_subclass (GUsbInterface *interface); -guint8 g_usb_interface_get_protocol (GUsbInterface *interface); -guint8 g_usb_interface_get_index (GUsbInterface *interface); -GBytes *g_usb_interface_get_extra (GUsbInterface *interface); -GPtrArray *g_usb_interface_get_endpoints (GUsbInterface *interface); +guint8 +g_usb_interface_get_length(GUsbInterface *self); +guint8 +g_usb_interface_get_kind(GUsbInterface *self); +guint8 +g_usb_interface_get_number(GUsbInterface *self); +guint8 +g_usb_interface_get_alternate(GUsbInterface *self); +guint8 +g_usb_interface_get_class(GUsbInterface *self); +guint8 +g_usb_interface_get_subclass(GUsbInterface *self); +guint8 +g_usb_interface_get_protocol(GUsbInterface *self); +guint8 +g_usb_interface_get_index(GUsbInterface *self); +GBytes * +g_usb_interface_get_extra(GUsbInterface *self); +GPtrArray * +g_usb_interface_get_endpoints(GUsbInterface *self); G_END_DECLS
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-json-common.c
Added
@@ -0,0 +1,33 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2023 Collabora Ltd. + * @author Frédéric Danis <frederic.danis@collabora.com> + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#include "config.h" + +#include "gusb-json-common.h" + +#if !JSON_CHECK_VERSION(1, 6, 0) +const char * +json_object_get_string_member_with_default(JsonObject *json_object, + const char *member_name, + const char *default_value) +{ + if (!json_object_has_member(json_object, member_name)) + return default_value; + return json_object_get_string_member(json_object, member_name); +} + +gint64 +json_object_get_int_member_with_default(JsonObject *json_object, + const char *member_name, + gint64 default_value) +{ + if (!json_object_has_member(json_object, member_name)) + return default_value; + return json_object_get_int_member(json_object, member_name); +} +#endif
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-json-common.h
Added
@@ -0,0 +1,27 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2023 Collabora Ltd. + * @author Frédéric Danis <frederic.danis@collabora.com> + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#pragma once + +#include <glib.h> +#include <json-glib/json-glib.h> + +G_BEGIN_DECLS + +#if !JSON_CHECK_VERSION(1, 6, 0) +const char * +json_object_get_string_member_with_default(JsonObject *json_object, + const char *member_name, + const char *default_value); +gint64 +json_object_get_int_member_with_default(JsonObject *json_object, + const char *member_name, + gint64 default_value); +#endif + +G_END_DECLS
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-private.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-private.h
Changed
@@ -9,8 +9,8 @@ #define __GUSB_INSIDE__ -#include <gusb/gusb.h> #include <gusb/gusb-context-private.h> #include <gusb/gusb-device-private.h> +#include <gusb/gusb.h> #undef __GUSB_INSIDE__
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-self-test.c -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-self-test.c
Changed
@@ -7,535 +7,706 @@ #include "config.h" -#include <glib-object.h> - -#include "gusb-context.h" #include "gusb-context-private.h" -#include "gusb-device.h" static void -gusb_device_func (void) +gusb_device_func(void) { - GError *error = NULL; - GPtrArray *array; - GUsbContext *ctx; GUsbDevice *device; + g_autoptr(GError) error = NULL; + g_autoptr(GPtrArray) array = NULL; + g_autoptr(GUsbContext) ctx = NULL; #ifdef __FreeBSD__ - g_test_skip ("Root hubs on FreeBSD have vid and pid set to zero"); + g_test_skip("Root hubs on FreeBSD have vid and pid set to zero"); return; #endif - ctx = g_usb_context_new (&error); - g_assert_no_error (error); - g_assert (ctx != NULL); + ctx = g_usb_context_new(&error); + g_assert_no_error(error); + g_assert(ctx != NULL); - g_usb_context_set_debug (ctx, G_LOG_LEVEL_ERROR); + g_usb_context_set_debug(ctx, G_LOG_LEVEL_ERROR); - array = g_usb_context_get_devices (ctx); - g_assert (array != NULL); - g_assert_cmpint (array->len, >, 0); - device = G_USB_DEVICE (g_ptr_array_index (array, 0)); + array = g_usb_context_get_devices(ctx); + g_assert(array != NULL); + g_assert_cmpint(array->len, >, 0); + device = G_USB_DEVICE(g_ptr_array_index(array, 0)); - g_assert_cmpint (g_usb_device_get_vid (device), >, 0x0000); - g_assert_cmpint (g_usb_device_get_pid (device), >, 0x0000); + g_assert_cmpint(g_usb_device_get_vid(device), >, 0x0000); + g_assert_cmpint(g_usb_device_get_pid(device), >, 0x0000); - g_ptr_array_unref (array); + g_assert_false(g_usb_device_has_tag(device, "foobar")); + g_usb_device_add_tag(device, "foobar"); + g_usb_device_add_tag(device, "foobar"); + g_assert_true(g_usb_device_has_tag(device, "foobar")); + g_usb_device_remove_tag(device, "foobar"); + g_assert_false(g_usb_device_has_tag(device, "foobar")); } static void -gusb_context_lookup_func (void) +gusb_context_lookup_func(void) { - GUsbContext *ctx = NULL; GError *error = NULL; const gchar *tmp; - - ctx = g_usb_context_new (&error); - g_assert_no_error (error); - g_assert (ctx != NULL); - - tmp = _g_usb_context_lookup_vendor (ctx, 0x04d8, &error); - g_assert_no_error (error); - g_assert_cmpstr (tmp, ==, "Microchip Technology, Inc."); - tmp = _g_usb_context_lookup_product (ctx, 0x04d8, 0xf8da, &error); - g_assert_no_error (error); - g_assert_cmpstr (tmp, ==, "Hughski Ltd. ColorHug"); - g_object_unref (ctx); + g_autoptr(GUsbContext) ctx = NULL; + + ctx = g_usb_context_new(&error); + g_assert_no_error(error); + g_assert(ctx != NULL); + + tmp = _g_usb_context_lookup_vendor(ctx, 0x04d8, &error); + g_assert_no_error(error); + g_assert_cmpstr(tmp, ==, "Microchip Technology, Inc."); + tmp = _g_usb_context_lookup_product(ctx, 0x04d8, 0xf8da, &error); + g_assert_no_error(error); + g_assert_cmpstr(tmp, ==, "Hughski Ltd. ColorHug"); } static void -gusb_context_func (void) +gusb_context_func(void) { - GUsbContext *ctx; - GError *error = NULL; GPtrArray *array; guint old_number_of_devices; guint8 bus, address; GUsbDevice *device; - gchar *manufacturer; - gchar *product; - guint i; + g_autoptr(GError) error = NULL; + g_autoptr(GUsbContext) ctx = NULL; #ifdef __FreeBSD__ - g_test_skip ("Root hubs on FreeBSD have vid and pid set to zero"); + g_test_skip("Root hubs on FreeBSD have vid and pid set to zero"); return; #endif - ctx = g_usb_context_new (&error); - g_assert_no_error (error); - g_assert (ctx != NULL); + ctx = g_usb_context_new(&error); + g_assert_no_error(error); + g_assert(ctx != NULL); - g_usb_context_set_debug (ctx, G_LOG_LEVEL_ERROR); + g_usb_context_set_debug(ctx, G_LOG_LEVEL_ERROR); /* coldplug, and ensure we got some devices */ - array = g_usb_context_get_devices (ctx); - g_assert (array != NULL); - g_assert_cmpint (array->len, >, 0); + array = g_usb_context_get_devices(ctx); + g_assert(array != NULL); + g_assert_cmpint(array->len, >, 0); old_number_of_devices = array->len; /* Print a list (also exercising various bits of g_usb_device) */ - g_print ("\n"); - for (i = 0; i < array->len; i++) { - device = G_USB_DEVICE (g_ptr_array_index (array, i)); + g_print("\n"); + for (guint i = 0; i < array->len; i++) { + g_autofree gchar *manufacturer = NULL; + g_autofree gchar *product = NULL; + + device = G_USB_DEVICE(g_ptr_array_index(array, i)); - g_assert_cmpint (g_usb_device_get_vid (device), >, 0x0000); - g_assert_cmpint (g_usb_device_get_pid (device), >, 0x0000); + g_assert_cmpint(g_usb_device_get_vid(device), >, 0x0000); + g_assert_cmpint(g_usb_device_get_pid(device), >, 0x0000); /* Needed for g_usb_device_get_string_descriptor below, not error checked to allow running basic tests without needing r/w rights on /dev/bus/usb nodes */ - g_usb_context_set_debug (ctx, 0); - g_usb_device_open (device, NULL); - g_usb_context_set_debug (ctx, G_LOG_LEVEL_ERROR); + g_usb_context_set_debug(ctx, 0); + g_usb_device_open(device, NULL); + g_usb_context_set_debug(ctx, G_LOG_LEVEL_ERROR); /* We don't error check these as not all devices have these (and the device_open may have failed). */ - manufacturer = g_usb_device_get_string_descriptor (device, - g_usb_device_get_manufacturer_index (device), - NULL); - product = g_usb_device_get_string_descriptor (device, - g_usb_device_get_product_index (device), - NULL); - - g_usb_device_close (device, NULL); - - g_print ("Found %04x:%04x, %s %s\n", - g_usb_device_get_vid (device), - g_usb_device_get_pid (device), - manufacturer ? manufacturer : "", - product ? product : ""); - - g_free (manufacturer); - g_free (product); + manufacturer = + g_usb_device_get_string_descriptor(device, + g_usb_device_get_manufacturer_index(device), + NULL); + product = g_usb_device_get_string_descriptor(device, + g_usb_device_get_product_index(device), + NULL); + + g_usb_device_close(device, NULL); + + g_print("Found %04x:%04x, %s %s\n", + g_usb_device_get_vid(device), + g_usb_device_get_pid(device), + manufacturer ? manufacturer : "", + product ? product : ""); } - g_ptr_array_unref (array); + g_ptr_array_unref(array); /* coldplug again, and ensure we did not duplicate devices */
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-source.c -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-source.c
Changed
@@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2010-2014 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2010 Richard Hughes <richard@hughsie.com> * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com> * * SPDX-License-Identifier: LGPL-2.1+ @@ -26,17 +26,17 @@ * Since: 0.1.0 **/ GQuark -g_usb_source_error_quark (void) +g_usb_source_error_quark(void) { static GQuark quark = 0; if (!quark) - quark = g_quark_from_static_string ("g_usb_source_error"); + quark = g_quark_from_static_string("g_usb_source_error"); return quark; } /** * g_usb_source_set_callback: - * @source: a #GUsbSource + * @self: a #GUsbSource * @func: a function to call * @data: data to pass to @func * @notify: a #GDestroyNotify @@ -46,10 +46,7 @@ * Since: 0.1.0 **/ void -g_usb_source_set_callback (GUsbSource *source, - GSourceFunc func, - gpointer data, - GDestroyNotify notify) +g_usb_source_set_callback(GUsbSource *self, GSourceFunc func, gpointer data, GDestroyNotify notify) { - g_source_set_callback ((GSource *)source, func, data, notify); + g_source_set_callback((GSource *)self, func, data, notify); }
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-source.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-source.h
Changed
@@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2010-2014 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2010 Richard Hughes <richard@hughsie.com> * Copyright (C) 2011 Hans de Goede <hdegoede@redhat.com> * * SPDX-License-Identifier: LGPL-2.1+ @@ -12,7 +12,7 @@ G_BEGIN_DECLS -#define G_USB_SOURCE_ERROR (g_usb_source_error_quark ()) +#define G_USB_SOURCE_ERROR (g_usb_source_error_quark()) typedef struct _GUsbSource GUsbSource; @@ -21,17 +21,14 @@ * * The error code. **/ -typedef enum { - G_USB_SOURCE_ERROR_INTERNAL -} GUsbSourceError; +typedef enum { G_USB_SOURCE_ERROR_INTERNAL } GUsbSourceError; G_DEPRECATED_FOR(g_usb_context_error_quark) -GQuark g_usb_source_error_quark (void); +GQuark +g_usb_source_error_quark(void); G_DEPRECATED -void g_usb_source_set_callback (GUsbSource *source, - GSourceFunc func, - gpointer data, - GDestroyNotify notify); +void +g_usb_source_set_callback(GUsbSource *self, GSourceFunc func, gpointer data, GDestroyNotify notify); G_END_DECLS
View file
_service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-umockdev-test.c
Added
@@ -0,0 +1,210 @@ +/* + * libusb umockdev based tests + * + * Copyright (C) 2022 Benjamin Berg <bberg@redhat.com> + * + * SPDX-License-Identifier: LGPL-2.1+ + */ + +#include <glib.h> +#include <string.h> +#include <unistd.h> + +#include "gusb.h" +#include "umockdev.h" + +#define UNUSED_DATA __attribute__((unused)) gconstpointer unused_data + +/* avoid leak reports inside assertions; leaking stuff on assertion failures does not matter in + * tests */ +#if !defined(__clang__) +#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak" +#pragma GCC diagnostic ignored "-Wanalyzer-file-leak" +#endif + +typedef struct { + UMockdevTestbed *testbed; + GUsbContext *ctx; +} UMockdevTestbedFixture; + +static void +test_fixture_setup(UMockdevTestbedFixture *fixture, UNUSED_DATA) +{ + fixture->testbed = umockdev_testbed_new(); + g_assert(fixture->testbed != NULL); +} + +static void +test_fixture_setup_empty(UMockdevTestbedFixture *fixture, UNUSED_DATA) +{ + test_fixture_setup(fixture, NULL); + fixture->ctx = g_usb_context_new(NULL); +} + +static void +test_fixture_teardown(UMockdevTestbedFixture *fixture, UNUSED_DATA) +{ + /* break context -> device -> context cycle */ + if (fixture->ctx) + g_object_run_dispose(G_OBJECT(fixture->ctx)); + g_clear_object(&fixture->ctx); + g_clear_object(&fixture->testbed); + + /* running the mainloop is needed to ensure everything is cleaned up */ + while (g_main_context_iteration(NULL, FALSE)) { + } +} + +static void +test_fixture_add_canon(UMockdevTestbedFixture *fixture) +{ + /* NOTE: there is no device file, so cannot be opened */ + + /* NOTE: add_device would not create a file, needed for device emulation */ + /* XXX: racy, see https://github.com/martinpitt/umockdev/issues/173 */ + umockdev_testbed_add_from_string( + fixture->testbed, + "P: /devices/usb1\n" + "N: bus/usb/001/001\n" + "E: SUBSYSTEM=usb\n" + "E: DRIVER=usb\n" + "E: BUSNUM=001\n" + "E: DEVNUM=001\n" + "E: DEVNAME=/dev/bus/usb/001/001\n" + "E: DEVTYPE=usb_device\n" + "A: bConfigurationValue=1\\n\n" + "A: busnum=1\\n\n" + "A: devnum=1\\n\n" + "A: bConfigurationValue=1\\n\n" + "A: speed=480\\n\n" + /* descriptor from a Canon PowerShot SX200; VID 04a9 PID 31c0 */ + "H: descriptors=" + "1201000200000040a904c03102000102" + "030109022700010100c0010904000003" + "06010100070581020002000705020200" + "020007058303080009\n", + NULL); +} + +static void +test_ctx_enumerate(UMockdevTestbedFixture *fixture, UNUSED_DATA) +{ + g_autoptr(GPtrArray) devices = NULL; + + test_fixture_add_canon(fixture); + + g_usb_context_enumerate(fixture->ctx); + + devices = g_usb_context_get_devices(fixture->ctx); + g_assert_cmpint(devices->len, ==, 1); +} + +static void +count_hotplug_event_cb(GUsbContext *context, GUsbDevice *device, gpointer user_data) +{ + int *counter = user_data; + + *counter += 1; +} + +static void +test_ctx_hotplug(UMockdevTestbedFixture *fixture, UNUSED_DATA) +{ + g_autoptr(GPtrArray) devices = NULL; + gint events = 0; + + g_signal_connect(fixture->ctx, "device-added", G_CALLBACK(count_hotplug_event_cb), &events); + + g_usb_context_enumerate(fixture->ctx); + + devices = g_usb_context_get_devices(fixture->ctx); + g_assert_cmpint(devices->len, ==, 0); + g_assert_cmpint(events, ==, 0); + g_clear_pointer(&devices, g_ptr_array_unref); + + test_fixture_add_canon(fixture); + /* ensure the event was processed by helper thread */ + g_usleep(G_USEC_PER_SEC / 2); + + /* still not returned (and no event fired) */ + devices = g_usb_context_get_devices(fixture->ctx); + g_assert_cmpint(devices->len, ==, 0); + g_assert_cmpint(events, ==, 0); + g_clear_pointer(&devices, g_ptr_array_unref); + + /* run mainloop, which causes the event to be processed */ + while (g_main_context_iteration(NULL, FALSE)) { + } + + devices = g_usb_context_get_devices(fixture->ctx); + g_assert_cmpint(events, ==, 1); + g_assert_cmpint(devices->len, ==, 1); + g_clear_pointer(&devices, g_ptr_array_unref); +} + +static void +test_ctx_hotplug_dispose(UMockdevTestbedFixture *fixture, UNUSED_DATA) +{ + g_autoptr(GPtrArray) devices = NULL; + gint events = 0; + + g_signal_connect(fixture->ctx, "device-added", G_CALLBACK(count_hotplug_event_cb), &events); + + g_usb_context_enumerate(fixture->ctx); + devices = g_usb_context_get_devices(fixture->ctx); + g_assert_cmpint(devices->len, ==, 0); + g_assert_cmpint(events, ==, 0); + g_clear_pointer(&devices, g_ptr_array_unref); + + test_fixture_add_canon(fixture); + /* ensure the event was processed by helper thread */ + g_usleep(G_USEC_PER_SEC / 2); + + /* still not returned (and no event fired) */ + g_usb_context_enumerate(fixture->ctx); + devices = g_usb_context_get_devices(fixture->ctx); + g_assert_cmpint(devices->len, ==, 0); + g_assert_cmpint(events, ==, 0); + g_clear_pointer(&devices, g_ptr_array_unref); + + /* idle handler is pending, we dispose our context reference */ + g_object_run_dispose(G_OBJECT(fixture->ctx)); + + /* run mainloop, which causes the event to be processed */ + while (g_main_context_iteration(NULL, FALSE)) { + } + + /* but no signal is fired */ + g_assert_cmpint(events, ==, 0); + + g_clear_object(&fixture->ctx); +} + +int +main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add("/gusb/ctx/enumerate", + UMockdevTestbedFixture, + NULL, + test_fixture_setup_empty, + test_ctx_enumerate, + test_fixture_teardown); + + g_test_add("/gusb/ctx/hotplug", + UMockdevTestbedFixture, + NULL, + test_fixture_setup_empty, + test_ctx_hotplug,
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-util.c -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-util.c
Changed
@@ -22,7 +22,7 @@ * Since: 0.1.0 **/ const gchar * -g_usb_strerror (gint error_code) +g_usb_strerror(gint error_code) { - return libusb_strerror (error_code); + return libusb_strerror(error_code); }
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-util.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-util.h
Changed
@@ -11,6 +11,7 @@ G_BEGIN_DECLS -const gchar *g_usb_strerror (gint error_code); +const gchar * +g_usb_strerror(gint error_code); G_END_DECLS
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-version.c -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-version.c
Changed
@@ -19,9 +19,8 @@ * Since: 0.3.1 **/ const gchar * -g_usb_version_string (void) +g_usb_version_string(void) { - return G_STRINGIFY(G_USB_MAJOR_VERSION) "." - G_STRINGIFY(G_USB_MINOR_VERSION) "." - G_STRINGIFY(G_USB_MICRO_VERSION); + return G_STRINGIFY(G_USB_MAJOR_VERSION) "." G_STRINGIFY( + G_USB_MINOR_VERSION) "." G_STRINGIFY(G_USB_MICRO_VERSION); }
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb-version.h.in -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb-version.h.in
Changed
@@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2010-2018 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2010 Richard Hughes <richard@hughsie.com> * * SPDX-License-Identifier: LGPL-2.1+ */
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/gusb.h -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/gusb.h
Changed
@@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2010-2011 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2010 Richard Hughes <richard@hughsie.com> * * SPDX-License-Identifier: LGPL-2.1+ */ @@ -9,14 +9,15 @@ #define __GUSB_INSIDE__ -#include <gusb/gusb-autocleanups.h> +#include <gusb/gusb-bos-descriptor.h> #include <gusb/gusb-context.h> -#include <gusb/gusb-interface.h> +#include <gusb/gusb-device-event.h> +#include <gusb/gusb-device-list.h> +#include <gusb/gusb-device.h> #include <gusb/gusb-endpoint.h> +#include <gusb/gusb-interface.h> #include <gusb/gusb-source.h> -#include <gusb/gusb-device.h> -#include <gusb/gusb-device-list.h> -#include <gusb/gusb-version.h> #include <gusb/gusb-util.h> +#include <gusb/gusb-version.h> #undef __GUSB_INSIDE__
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/libgusb.ver -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/libgusb.ver
Changed
@@ -166,3 +166,52 @@ g_usb_context_set_hotplug_poll_interval; local: *; } LIBGUSB_0.3.8; + +LIBGUSB_0.4.0 { + global: + g_usb_bos_descriptor_get_capability; + g_usb_bos_descriptor_get_extra; + g_usb_bos_descriptor_get_type; + g_usb_context_load; + g_usb_context_save; + g_usb_device_event_get_bytes; + g_usb_device_event_get_id; + g_usb_device_event_get_status; + g_usb_device_event_get_type; + g_usb_device_event_set_bytes; + g_usb_device_get_bos_descriptor; + g_usb_device_get_bos_descriptors; + g_usb_device_get_events; + g_usb_device_invalidate; + local: *; +} LIBGUSB_0.3.10; + +LIBGUSB_0.4.1 { + global: + g_usb_context_load_with_tag; + g_usb_context_save_with_tag; + g_usb_device_add_tag; + local: *; +} LIBGUSB_0.4.0; + +LIBGUSB_0.4.3 { + global: + g_usb_device_has_tag; + local: *; +} LIBGUSB_0.4.1; + +LIBGUSB_0.4.4 { + global: + g_usb_device_clear_events; + g_usb_device_get_tags; + g_usb_device_is_emulated; + g_usb_device_remove_tag; + local: *; +} LIBGUSB_0.4.3; + +LIBGUSB_0.4.5 { + global: + g_usb_device_event_get_rc; + g_usb_device_get_created; + local: *; +} LIBGUSB_0.4.4;
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/gusb/meson.build -> _service:tar_scm:libgusb-0.4.6.tar.xz/gusb/meson.build
Changed
@@ -26,14 +26,16 @@ install_headers( gusb_version_h, - 'gusb-autocleanups.h', 'gusb-context.h', 'gusb-context-private.h', 'gusb-device.h', + 'gusb-device-event.h', 'gusb-device-private.h', 'gusb-device-list.h', 'gusb-interface.h', 'gusb-interface-private.h', + 'gusb-bos-descriptor.h', + 'gusb-bos-descriptor-private.h', 'gusb-endpoint.h', 'gusb-endpoint-private.h', 'gusb-source.h', @@ -54,12 +56,15 @@ sources : 'gusb-context.c', 'gusb-device.c', + 'gusb-device-event.c', 'gusb-device-list.c', 'gusb-interface.c', + 'gusb-bos-descriptor.c', 'gusb-endpoint.c', 'gusb-source.c', 'gusb-util.c', 'gusb-version.c', + 'gusb-json-common.c', , soversion : lt_current, version : lt_version, @@ -67,6 +72,7 @@ dependencies : libgio, libusb, + libjsonglib, , c_args : cargs, @@ -91,7 +97,7 @@ pkgg = import('pkgconfig') pkgg.generate(gusb, - requires : 'gio-2.0', 'gobject-2.0', 'libusb-1.0' , + requires : 'gio-2.0', 'gobject-2.0', 'libusb-1.0', 'json-glib-1.0' , subdirs : 'gusb-1', version : meson.project_version(), name : 'gusb', @@ -103,18 +109,23 @@ libgusb_girtarget = gnome.generate_gir(gusb, sources : gusb_version_h, - 'gusb-autocleanups.h', 'gusb-context.c', 'gusb-context.h', 'gusb-context-private.h', 'gusb-device.c', 'gusb-device.h', + 'gusb-device-event.c', + 'gusb-device-event.h', + 'gusb-device-event-private.h', 'gusb-device-list.c', 'gusb-device-list.h', 'gusb-device-private.h', 'gusb-interface.c', 'gusb-interface.h', 'gusb-interface-private.h', + 'gusb-bos-descriptor.c', + 'gusb-bos-descriptor.h', + 'gusb-bos-descriptor-private.h', 'gusb-endpoint.c', 'gusb-endpoint.h', 'gusb-endpoint-private.h', @@ -137,10 +148,12 @@ dependencies : libgio, libusb, + libjsonglib, , includes : 'Gio-2.0', 'GObject-2.0', + 'Json-1.0', , install : true ) @@ -163,7 +176,7 @@ output: 'libgusb.ver', command: py_installation, - join_paths(meson.source_root(), 'contrib', 'generate-version-script.py'), + join_paths(meson.project_source_root(), 'contrib', 'generate-version-script.py'), 'LIBGUSB', '@INPUT@', '@OUTPUT@', @@ -183,7 +196,7 @@ if get_option('vapi') gnome.generate_vapi('gusb', sources: libgusb_girtarget0, - packages: 'gio-2.0', + packages: 'gio-2.0', 'json-glib-1.0', install: true, ) endif @@ -194,12 +207,15 @@ sources : 'gusb-context.c', 'gusb-device.c', + 'gusb-device-event.c', 'gusb-device-list.c', 'gusb-interface.c', + 'gusb-bos-descriptor.c', 'gusb-endpoint.c', 'gusb-self-test.c', 'gusb-source.c', 'gusb-util.c', + 'gusb-json-common.c' , include_directories : root_incdir, @@ -208,10 +224,24 @@ dependencies : libgio, libusb, + libjsonglib, , c_args : cargs, , ) test('gusb-self-test', e) + + # Umockdev based tests + test_env = environment() + test_env.prepend('LD_PRELOAD', 'libumockdev-preload.so.0') + + test_umockdev = executable( + 'gusb-umockdev-test', + 'gusb-umockdev-test.c', + dependencies: umockdev, gusb_dep ) + + test('gusb-umockdev-test', + test_umockdev, + env: test_env) endif
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/meson.build -> _service:tar_scm:libgusb-0.4.6.tar.xz/meson.build
Changed
@@ -1,7 +1,7 @@ project('libgusb', 'c', - version : '0.3.10', + version : '0.4.6', license : 'LGPL-2.1+', - meson_version : '>=0.46.0', + meson_version : '>=0.56.0', default_options : 'c_std=c99' ) @@ -49,6 +49,7 @@ '-Wno-strict-aliasing', '-Wno-suggest-attribute=format', '-Wno-unused-parameter', + '-Wno-gnu-variable-sized-type-not-at-end', '-Wold-style-definition', '-Woverride-init', '-Wpointer-arith', @@ -93,6 +94,11 @@ language: 'c' ) +if get_option('tests') + umockdev = dependency('umockdev-1.0', version: '>= 0.17.7', disabler: true, required: get_option('umockdev')) +else + umockdev = disabler() +endif libgio = dependency('gio-2.0', version : '>= 2.44.0') libusb = dependency('libusb-1.0', version : '>= 1.0.9') if cc.has_header_symbol('libusb.h', 'LIBUSB_CAP_HAS_HOTPLUG', dependencies: libusb) @@ -110,10 +116,12 @@ if cc.has_header_symbol('libusb.h', 'libusb_get_port_number', dependencies: libusb) conf.set('HAVE_LIBUSB_GET_PORT_NUMBER', '1') endif +libjsonglib = dependency('json-glib-1.0', version: '>= 1.1.1') gusb_deps = libgio, libusb, + libjsonglib, gnome = import('gnome') @@ -122,6 +130,7 @@ prefix = get_option('prefix') bindir = join_paths(prefix, get_option('bindir')) +datadir = join_paths(prefix, get_option('datadir')) configure_file( output : 'config.h', @@ -132,4 +141,6 @@ subdir('gusb') subdir('tools') -subdir('docs') +if get_option('docs') + subdir('docs') +endif
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/meson_options.txt -> _service:tar_scm:libgusb-0.4.6.tar.xz/meson_options.txt
Changed
@@ -3,3 +3,4 @@ option('usb_ids', type : 'string', value : '/usr/share/hwdata/usb.ids', description : 'Path to usb.ids file') option('docs', type : 'boolean', value : true, description : 'Generate documentation') option('introspection', type : 'boolean', value : true, description : 'Generate gobject introspection data') +option('umockdev', type : 'feature', value : 'auto', description : 'Build and run umockdev based tests')
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/tools/gusb-main.c -> _service:tar_scm:libgusb-0.4.6.tar.xz/tools/gusb-main.c
Changed
@@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * - * Copyright (C) 2011-2016 Richard Hughes <richard@hughsie.com> + * Copyright (C) 2011 Richard Hughes <richard@hughsie.com> * * SPDX-License-Identifier: LGPL-2.1+ */ @@ -13,507 +13,544 @@ #include <string.h> static void -gusb_log_ignore_cb (const gchar *log_domain, GLogLevelFlags log_level, - const gchar *message, gpointer user_data) +gusb_log_ignore_cb(const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data) { } static void -gusb_log_handler_cb (const gchar *log_domain, GLogLevelFlags log_level, - const gchar *message, gpointer user_data) +gusb_log_handler_cb(const gchar *log_domain, + GLogLevelFlags log_level, + const gchar *message, + gpointer user_data) { gchar str_time255; time_t the_time; /* header always in green */ - time (&the_time); - strftime (str_time, 254, "%H:%M:%S", localtime (&the_time)); - g_print ("%c%dmTI:%s\t", 0x1B, 32, str_time); + time(&the_time); + strftime(str_time, 254, "%H:%M:%S", localtime(&the_time)); + g_print("%c%dmTI:%s\t", 0x1B, 32, str_time); /* critical is also in red */ - if (log_level == G_LOG_LEVEL_CRITICAL || - log_level == G_LOG_LEVEL_WARNING || + if (log_level == G_LOG_LEVEL_CRITICAL || log_level == G_LOG_LEVEL_WARNING || log_level == G_LOG_LEVEL_ERROR) { - g_print ("%c%dm%s\n%c%dm", 0x1B, 31, message, 0x1B, 0); + g_print("%c%dm%s\n%c%dm", 0x1B, 31, message, 0x1B, 0); } else { /* debug in blue */ - g_print ("%c%dm%s\n%c%dm", 0x1B, 34, message, 0x1B, 0); + g_print("%c%dm%s\n%c%dm", 0x1B, 34, message, 0x1B, 0); } } typedef struct { - GOptionContext *context; - GUsbContext *usb_ctx; - GPtrArray *cmd_array; + GOptionContext *context; + GUsbContext *usb_ctx; + GPtrArray *cmd_array; } GUsbCmdPrivate; -typedef gboolean (*GUsbCmdPrivateCb) (GUsbCmdPrivate *cmd, - gchar **values, - GError **error); +typedef gboolean (*GUsbCmdPrivateCb)(GUsbCmdPrivate *cmd, gchar **values, GError **error); typedef struct { - gchar *name; - gchar *description; - GUsbCmdPrivateCb callback; + gchar *name; + gchar *description; + GUsbCmdPrivateCb callback; } GUsbCmdItem; static void -gusb_cmd_item_free (GUsbCmdItem *item) +gusb_cmd_item_free(GUsbCmdItem *item) { - g_free (item->name); - g_free (item->description); - g_slice_free (GUsbCmdItem, item); + g_free(item->name); + g_free(item->description); + g_slice_free(GUsbCmdItem, item); } /* * gusb_sort_command_name_cb: */ static gint -gusb_sort_command_name_cb (GUsbCmdItem **item1, GUsbCmdItem **item2) +gusb_sort_command_name_cb(GUsbCmdItem **item1, GUsbCmdItem **item2) { - return g_strcmp0 ((*item1)->name, (*item2)->name); + return g_strcmp0((*item1)->name, (*item2)->name); } static void -gusb_cmd_add (GPtrArray *array, const gchar *name, const gchar *description, GUsbCmdPrivateCb callback) +gusb_cmd_add(GPtrArray *array, + const gchar *name, + const gchar *description, + GUsbCmdPrivateCb callback) { - gchar **names; - guint i; - GUsbCmdItem *item; - - /* add each one */ - names = g_strsplit (name, ",", -1); - for (i=0; namesi != NULL; i++) { - item = g_slice_new0 (GUsbCmdItem); - item->name = g_strdup (namesi); + g_auto(GStrv) names = g_strsplit(name, ",", -1); + for (guint i = 0; namesi != NULL; i++) { + GUsbCmdItem *item = g_slice_new0(GUsbCmdItem); + item->name = g_strdup(namesi); if (i == 0) { - item->description = g_strdup (description); + item->description = g_strdup(description); } else { /* TRANSLATORS: this is a command alias */ - item->description = g_strdup_printf ("Alias to %s", - names0); + item->description = g_strdup_printf("Alias to %s", names0); } item->callback = callback; - g_ptr_array_add (array, item); + g_ptr_array_add(array, item); } - g_strfreev (names); } static gchar * -gusb_cmd_get_descriptions (GPtrArray *array) +gusb_cmd_get_descriptions(GPtrArray *array) { - guint i; - guint j; guint len; guint max_len = 19; - GUsbCmdItem *item; - GString *string; + g_autoptr(GString) string = NULL; /* print each command */ - string = g_string_new (""); - for (i = 0; i < array->len; i++) { - item = g_ptr_array_index (array, i); - g_string_append (string, " "); - g_string_append (string, item->name); - g_string_append (string, " "); - len = strlen (item->name); - for (j = len; j < max_len+2; j++) - g_string_append_c (string, ' '); - g_string_append (string, item->description); - g_string_append_c (string, '\n'); + string = g_string_new(""); + for (guint i = 0; i < array->len; i++) { + GUsbCmdItem *item = g_ptr_array_index(array, i); + g_string_append(string, " "); + g_string_append(string, item->name); + g_string_append(string, " "); + len = strlen(item->name); + for (guint j = len; j < max_len + 2; j++) + g_string_append_c(string, ' '); + g_string_append(string, item->description); + g_string_append_c(string, '\n'); } /* remove trailing newline */ if (string->len > 0) - g_string_set_size (string, string->len - 1); + g_string_set_size(string, string->len - 1); - return g_string_free (string, FALSE); + return g_string_free(g_steal_pointer(&string), FALSE); } static void -gusb_main_device_open (GUsbDevice *device) +gusb_main_device_open(GUsbDevice *device) { - GError *error = NULL; guint8 idx; + g_autoptr(GError) error = NULL; /* open */ - if (!g_usb_device_open (device, &error)) { - g_print ("failed to open: %s\n", error->message); - g_error_free (error); + if (!g_usb_device_open(device, &error)) { + g_print("failed to open: %s\n", error->message); return; } /* print info we can only get whilst open */
View file
_service:tar_scm:libgusb-0.3.10.tar.xz/tools/meson.build -> _service:tar_scm:libgusb-0.4.6.tar.xz/tools/meson.build
Changed
@@ -12,6 +12,7 @@ dependencies : libgio, libusb, + libjsonglib, , link_with : gusb, c_args :
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2