pax_global_header00006660000000000000000000000064151255306050014514gustar00rootroot0000000000000052 comment=69791f8f2a092d0ec8eb83cbe51dfc3d157c3079 libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/000077500000000000000000000000001512553060500216445ustar00rootroot00000000000000libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/.editorconfig000066400000000000000000000003221512553060500243160ustar00rootroot00000000000000root = true [*] end_of_line = lf trim_trailing_whitespace = true insert_final_newline = true [{*.c,*.h}] indent_style = space indent_size = 4 tab_width = 4 [meson.build] indent_size = 2 indent_style = space libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/.gitignore000066400000000000000000000000351512553060500236320ustar00rootroot00000000000000*~ tags /.vscode /cscope.out libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/.gitlab-ci.yml000066400000000000000000000045461512553060500243110ustar00rootroot00000000000000include: - project: freedesktop/ci-templates ref: 290b79e0e78eab67a83766f4e9691be554fc4afd file: - templates/ubuntu.yml stages: - container prep - precheck - build .common_variables: variables: FDO_UPSTREAM_REPO: mobile-broadband/libqrtr-glib FDO_DISTRIBUTION_VERSION: '24.04' FDO_DISTRIBUTION_TAG: '2025-11-30' FDO_DISTRIBUTION_PACKAGES: ca-certificates git gcc libtool libgirepository1.0-dev libglib2.0-dev gi-docgen gobject-introspection valac meson ninja-build build container: extends: - .fdo.container-build@ubuntu - .common_variables stage: container prep only: - main - merge_requests - tags - schedules verify-dco: stage: precheck extends: - .fdo.distribution-image@ubuntu - .common_variables only: - merge_requests script: | if [[ -n "${CI_MERGE_REQUEST_DIFF_BASE_SHA}" ]]; then export COMMITS=$(git log --no-merges --format="%H" ${CI_MERGE_REQUEST_DIFF_BASE_SHA}.. | xargs) for c in ${COMMITS}; do $(git log --format="%b" -1 ${c} | grep -q "^Signed-off-by: .* <.*@.*>") && rc="$?" || rc="$?" if [[ $rc -ne 0 ]]; then echo "Commit ${c} failed DCO Signed-off-by check" exit $rc fi done fi build-no-introspection: stage: build extends: - .fdo.distribution-image@ubuntu - .common_variables only: - main - merge_requests - tags - schedules script: - meson setup build --prefix=/usr -Dwerror=true -Dgtk_doc=false -Dintrospection=false - ninja -C build - ninja -C build install build-debug: stage: build extends: - .fdo.distribution-image@ubuntu - .common_variables only: - main - merge_requests - tags - schedules script: - meson setup build --prefix=/usr --buildtype=debug -Dwerror=true -Dgtk_doc=true - ninja -C build - ninja -C build install - ninja -C build dist - ninja -C build uninstall build-release: stage: build extends: - .fdo.distribution-image@ubuntu - .common_variables only: - main - merge_requests - tags - schedules script: - meson setup build --prefix=/usr --buildtype=release -Dwerror=true -Dgtk_doc=true - ninja -C build - ninja -C build install - ninja -C build dist - ninja -C build uninstall libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/AUTHORS000066400000000000000000000002421512553060500227120ustar00rootroot00000000000000 Current maintainers: Eric Caruso Andrew Lassalle Aleksander Morgado libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/LICENSES/000077500000000000000000000000001512553060500230515ustar00rootroot00000000000000libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/LICENSES/LGPL-2.1-or-later.txt000066400000000000000000000636421512553060500264040ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/NEWS000066400000000000000000000012731512553060500223460ustar00rootroot00000000000000 Overview of changes in libqrtr 1.2 ---------------------------------------- * Build fully switched to meson. ** There are no longer source tarballs released, builds should be done exclusively from git repository checkouts, e.g. based on release tags. ** The GNU autotools based build is no longer supported. ** See https://modemmanager.org/docs/libqrtr-glib/building/building-meson/ * Build now requires: ** glib2 >= 2.56. * libqrtr-glib: ** Added new qrtr-types.h header including all types in the library, which avoids cross references between the different objects. Overview of changes in libqrtr 1.0 ---------------------------------------- Initial release. libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/README.md000066400000000000000000000012601512553060500231220ustar00rootroot00000000000000 # libqrtr-glib libqrtr-glib is a glib-based library to use and manage the QRTR (Qualcomm IPC Router) bus. ## License: The libqrtr-glib library is released under the LGPL-2.1-or-later license. ## Code of Conduct Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms, which you can find in the following link: https://www.freedesktop.org/wiki/CodeOfConduct CoC issues may be raised to the project maintainers at the following address: libqmi-devel-owner@lists.freedesktop.org libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/RELEASING000066400000000000000000000046401512553060500231040ustar00rootroot00000000000000 The libqrtr releases are generated using meson. 1) For major releases: * Increment minor meson 'version' component (eg 1.x.y -> 1.x+1.0). * Assuming API/ABI compatibility, increment both qrtr_glib_lt_current and qrtr_glib_lt_age. 2) For stable branch releases: * Increment micro meson 'version' component (eg 1.x.y -> 1.x.y+1). 3) Configure and build the whole project, making sure gtk-doc and introspection are enabled: $ meson setup build \ --prefix=/usr \ --buildtype=release \ -Dintrospection=true \ -Dgtk_doc=true $ ninja -C build 4) Run the test suite and install locally: $ ninja -C build test $ sudo ninja -C build install 5) Push changes to a release MR on gitlab * Use a commit title like "release: bump version to 1.4.0" * Once CI passes merge the PR. 6) Add and push a signed tag: $ git tag -s 1.2.0 (use a description like "Release 1.2.0") $ git push tag 1.2.0 7) Create directories for the gtk-doc documentation in freedesktop.org, and also update the 'latest' links: $ ssh fd.o [fd.o] $ cd ${libqmi}/libqrtr-glib/ [fd.o] $ rm latest [fd.o] $ mkdir -p ${VERSION} [fd.o] $ ln -s ${VERSION} latest 8) Copy documentation from /usr/share/gtk-doc and fix online references manually $ mkdir html $ cp -r /usr/share/gtk-doc/html/libqrtr-glib/* html/ $ for FILE in $(ls html/*.html); do \ sed -i 's|]* href="\.\./glib/[^"]*| scan_args = ['--rebuild-types'] toml_data = configuration_data() toml_data.set('VERSION', meson.project_version()) qrtr_toml = configure_file( input: 'libqrtr-glib.toml.in', output: 'libqrtr-glib.toml', configuration: toml_data, ) dependency( 'gi-docgen', version: '>= 2021.1', native: true, required: get_option('gtk_doc'), ) gidocgen = find_program('gi-docgen') docs_dir = qrtr_datadir / 'doc' custom_target( 'libqrtr-glib', input: [qrtr_toml, libqrtr_glib_gir[0]], output: 'libqrtr-glib-@0@'.format(qrtr_gir_version), command: [ gidocgen, 'generate', '--quiet', '--config=@INPUT0@', '--output-dir=@OUTPUT@', '--no-namespace-dir', '--content-dir=@0@'.format(meson.current_source_dir()), '--fatal-warnings', '@INPUT1@', ], build_by_default: true, install: true, install_dir: docs_dir, ) libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/docs/reference/libqrtr-glib/urlmap.js000066400000000000000000000005061512553060500307630ustar00rootroot00000000000000// SPDX-FileCopyrightText: 2021 GNOME Foundation // SPDX-License-Identifier: LGPL-2.1-or-later // A map between namespaces and base URLs for their online documentation baseURLs = [ [ 'GLib', 'https://docs.gtk.org/glib/' ], [ 'GObject', 'https://docs.gtk.org/gobject/' ], [ 'Gio', 'https://docs.gtk.org/gio/' ], ] libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/meson.build000066400000000000000000000104101512553060500240020ustar00rootroot00000000000000# SPDX-License-Identifier: LGPL-2.1-or-later # Copyright (C) 2021 Iñigo Martinez # Copyright (C) 2021 Aleksander Morgado project( 'libqrtr-glib', 'c', version: '1.4.0', license: 'LGPL-2.1-or-later', default_options: [ 'buildtype=debugoptimized', 'c_std=gnu89', 'warning_level=2', ], meson_version: '>= 0.53.0', ) qrtr_version = meson.project_version() version_array = qrtr_version.split('.') qrtr_major_version = version_array[0].to_int() qrtr_minor_version = version_array[1].to_int() qrtr_micro_version = version_array[2].to_int() qrtr_prefix = get_option('prefix') qrtr_datadir = get_option('datadir') qrtr_includedir = get_option('includedir') qrtr_libexecdir = get_option('libexecdir') qrtr_glib_include_subdir = meson.project_name() qrtr_glib_pkgincludedir = qrtr_includedir / qrtr_glib_include_subdir # libtool versioning for libqrtr-glib (-version-info c:r:a) # - If the interface is unchanged, but the implementation has changed or been fixed, then increment r # - Otherwise, increment c and zero r. # - If the interface has grown (that is, the new library is compatible with old code), increment a. # - If the interface has changed in an incompatible way (that is, functions have changed or been removed), then zero a. current = 0 revision = 1 age = 0 qrtr_glib_version = '@0@.@1@.@2@'.format(current - age, age, revision) qrtr_gir_version = '1.0' gnome = import('gnome') pkg = import('pkgconfig') source_root = meson.current_source_dir() top_inc = include_directories('.') cc = meson.get_compiler('c') # compiler flags that are always enabled, even in release builds cc_flags = cc.get_supported_arguments([ # warning on unused parameters is overkill, never do that '-Wno-unused-parameter', # function type cast disabled: used throughout the code especially to # cast GAsyncReadyCallbacks with the real object type instead of GObject '-Wno-cast-function-type', # all message protocol structs are packed, never complain about it '-Wno-packed', ]) # strict flags to use in debug builds if get_option('buildtype').contains('debug') cc_flags += cc.get_supported_arguments([ '-fno-strict-aliasing', '-Waggregate-return', '-Wcast-align', '-Wdeclaration-after-statement', '-Wdouble-promotion', '-Wduplicated-branches', '-Wduplicated-cond', '-Wfloat-equal', '-Wformat=2', '-Wformat-nonliteral', '-Wformat-security', '-Winit-self', '-Winline', '-Wjump-misses-init', '-Wlogical-op', '-Wnested-externs', '-Wmissing-declarations', '-Wmissing-format-attribute', '-Wmissing-include-dirs', '-Wmissing-noreturn', '-Wmissing-prototypes', '-Wnull-dereference', '-Wpointer-arith', '-Wredundant-decls', '-Wrestrict', '-Wreturn-type', '-Wshadow', '-Wstrict-prototypes', '-Wsuggest-attribute=format', '-Wswitch-default', '-Wswitch-enum', '-Wundef', '-Wunused-but-set-variable', '-Wwrite-strings', ]) endif add_project_arguments(cc_flags, language: 'c') glib_version = '2.56' glib_dep = dependency('glib-2.0', version: '>= ' + glib_version) gio_unix_dep = dependency('gio-unix-2.0') deps = [ glib_dep, dependency('gio-2.0'), dependency('gobject-2.0'), ] c_flags = [ '-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_' + glib_version.underscorify(), '-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_' + glib_version.underscorify(), '-DGLIB_DISABLE_DEPRECATION_WARNINGS', ] glib_deps = declare_dependency( dependencies: deps, compile_args: c_flags, ) assert(cc.has_header('linux/qrtr.h'), 'QRTR support not available in the kernel headers') version_conf = { 'QRTR_MAJOR_VERSION': qrtr_major_version, 'QRTR_MINOR_VERSION': qrtr_minor_version, 'QRTR_MICRO_VERSION': qrtr_micro_version, 'VERSION': qrtr_version, } # introspection support enable_gir = get_option('introspection') if enable_gir dependency('gobject-introspection-1.0', version: '>= 0.9.6') endif subdir('src/libqrtr-glib') enable_gtk_doc = get_option('gtk_doc') if enable_gtk_doc subdir('docs/reference/libqrtr-glib') endif summary({ 'compiler': cc.get_id(), 'cflags': cc_flags, 'Documentation': enable_gtk_doc, 'gobject introspection': enable_gir, }, section: 'Build') summary({ 'prefix': qrtr_prefix, }, section: 'System paths') libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/meson_options.txt000066400000000000000000000004631512553060500253040ustar00rootroot00000000000000# SPDX-License-Identifier: LGPL-2.1-or-later # Copyright (C) 2021 Iñigo Martinez option('introspection', type: 'boolean', value: true, description: 'build introspection support') option('gtk_doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation') libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/000077500000000000000000000000001512553060500224335ustar00rootroot00000000000000libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/000077500000000000000000000000001512553060500250255ustar00rootroot00000000000000libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/libqrtr-glib.h000066400000000000000000000010351512553060500275670ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * libqrtr-glib -- GLib/GIO based library to control QRTR devices * * Copyright (C) 2020 Eric Caruso * Copyright (C) 2020 Aleksander Morgado */ #ifndef _LIBQRTR_GLIB_H_ #define _LIBQRTR_GLIB_H_ #define __LIBQRTR_GLIB_H_INSIDE__ #include "qrtr-bus.h" #include "qrtr-node.h" #include "qrtr-client.h" #include "qrtr-utils.h" #endif /* _LIBQRTR_GLIB_H_ */ libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/meson.build000066400000000000000000000036501512553060500271730ustar00rootroot00000000000000# SPDX-License-Identifier: LGPL-2.1-or-later # Copyright (C) 2021 Iñigo Martinez libname = 'qrtr-glib' libqrtr_glib_inc = include_directories('.') headers = files( 'libqrtr-glib.h', 'qrtr-bus.h', 'qrtr-client.h', 'qrtr-node.h', 'qrtr-types.h', 'qrtr-utils.h', ) install_headers( headers, install_dir: qrtr_glib_pkgincludedir, ) version_header = configure_file( input: 'qrtr-version.h.in', output: '@BASENAME@', configuration: version_conf, install_dir: qrtr_glib_pkgincludedir, ) sources = files( 'qrtr-bus.c', 'qrtr-client.c', 'qrtr-node.c', 'qrtr-utils.c', ) c_flags = [ '-DLIBQRTR_GLIB_COMPILATION', '-DG_LOG_DOMAIN="Qrtr"', '-DLIBEXEC_PATH="@0@"'.format(qrtr_prefix / qrtr_libexecdir), ] libqrtr_glib = library( libname, version: qrtr_glib_version, sources: sources + [version_header], include_directories: top_inc, dependencies: glib_deps, c_args: c_flags, install: true, ) libqrtr_glib_dep = declare_dependency( sources: version_header, include_directories: libqrtr_glib_inc, dependencies: glib_deps, link_with: libqrtr_glib, ) pkg.generate( libraries: libqrtr_glib, version: qrtr_version, name: libname, description: 'Library to use and monitor the QRTR bus', subdirs: qrtr_glib_include_subdir, # FIXME: produced by the inhability of meson to use internal dependencies requires: ['glib-2.0', 'gobject-2.0', 'gio-2.0'], variables: 'exec_prefix=${prefix}', ) if enable_gir incs = [ 'Gio-2.0', 'GLib-2.0', 'GObject-2.0', ] ns = 'Qrtr' libqrtr_glib_gir = gnome.generate_gir( libqrtr_glib, sources: sources + headers, includes: incs, namespace: ns, nsversion: qrtr_gir_version, identifier_prefix: ns, symbol_prefix: ns.to_lower() + '_', extra_args: c_flags + ['--identifier-prefix=' + ns.to_upper()], header: 'libqrtr-glib.h', export_packages: libname, install: true, ) endif libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/qrtr-bus.c000066400000000000000000000511341512553060500267540ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * libqrtr-glib -- GLib/GIO based library to control QRTR devices * * Copyright (C) 2019-2021 Eric Caruso * Copyright (C) 2020-2021 Aleksander Morgado */ #include #include #include #include #include #include #include #include "qrtr-bus.h" #include "qrtr-node.h" #include "qrtr-utils.h" static void async_initable_iface_init (GAsyncInitableIface *iface); G_DEFINE_TYPE_EXTENDED (QrtrBus, qrtr_bus, G_TYPE_OBJECT, 0, G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)) enum { PROP_0, PROP_LOOKUP_TIMEOUT, PROP_PORT, PROP_LAST }; enum { SIGNAL_NODE_ADDED, SIGNAL_NODE_REMOVED, SIGNAL_LAST }; static GParamSpec *properties[PROP_LAST]; static guint signals[SIGNAL_LAST] = { 0 }; struct _QrtrBusPrivate { /* Underlying QRTR socket */ GSocket *socket; /* List with full references to the available QrtrNodes; i.e. the nodes are * owned by the bus unconditionally. */ GList *nodes; /* Callback source for when NEW_SERVER/DEL_SERVER control packets come in */ GSource *source; /* initial lookup support */ guint lookup_timeout; GTask *init_task; GSource *init_timeout_source; }; /*****************************************************************************/ static gint node_cmp (QrtrNode *a, QrtrNode *b) { return qrtr_node_get_id (a) - qrtr_node_get_id (b); } static gint node_find_cmp (QrtrNode *a, gpointer user_data) { return qrtr_node_get_id (a) - GPOINTER_TO_UINT (user_data); } static void add_service_info (QrtrBus *self, guint32 node_id, guint32 port, guint32 service, guint32 version, guint32 instance) { GList *list_item; QrtrNode *node; list_item = g_list_find_custom (self->priv->nodes, GUINT_TO_POINTER (node_id), (GCompareFunc)node_find_cmp); if (!list_item) { /* Node objects are exclusively created at this point */ node = QRTR_NODE (g_object_new (QRTR_TYPE_NODE, QRTR_NODE_BUS, self, QRTR_NODE_ID, node_id, NULL)); self->priv->nodes = g_list_insert_sorted (self->priv->nodes, node, (GCompareFunc)node_cmp); g_debug ("[qrtr] created new node %u", node_id); g_signal_emit (self, signals[SIGNAL_NODE_ADDED], 0, node_id); } else node = QRTR_NODE (list_item->data); qrtr_node_add_service_info (node, service, port, version, instance); } static void remove_service_info (QrtrBus *self, guint32 node_id, guint32 port, guint32 service, guint32 version, guint32 instance) { GList *list_item; QrtrNode *node; list_item = g_list_find_custom (self->priv->nodes, GUINT_TO_POINTER (node_id), (GCompareFunc)node_find_cmp); if (!list_item) { g_warning ("[qrtr] cannot remove service info: nonexistent node %u", node_id); return; } node = QRTR_NODE (list_item->data); qrtr_node_remove_service_info (node, service, port, version, instance); if (!qrtr_node_peek_service_info_list (node)) { g_debug ("[qrtr] removing node %u", node_id); g_signal_emit (self, signals[SIGNAL_NODE_REMOVED], 0, node_id); self->priv->nodes = g_list_delete_link (self->priv->nodes, list_item); } } /*****************************************************************************/ static void initable_complete (QrtrBus *self); static gboolean qrtr_ctrl_message_cb (GSocket *gsocket, GIOCondition cond, QrtrBus *self) { GError *error = NULL; struct qrtr_ctrl_pkt ctrl_packet; gssize bytes_received; guint32 type; guint32 node_id; guint32 port; guint32 service; guint32 version; guint32 instance; /* check for message type and add/remove nodes here */ bytes_received = g_socket_receive (gsocket, (gchar *)&ctrl_packet, sizeof (ctrl_packet), NULL, &error); if (bytes_received < 0) { g_warning ("[qrtr] socket i/o failure: %s", error->message); g_error_free (error); return FALSE; } if ((gsize)bytes_received < sizeof (ctrl_packet)) { g_debug ("[qrtr] short packet received: ignoring"); return TRUE; } type = GUINT32_FROM_LE (ctrl_packet.cmd); if (type != QRTR_TYPE_NEW_SERVER && type != QRTR_TYPE_DEL_SERVER) { g_debug ("[qrtr] unknown packet type received: 0x%x", type); return TRUE; } /* type is something we handle, parse the packet */ node_id = GUINT32_FROM_LE (ctrl_packet.server.node); port = GUINT32_FROM_LE (ctrl_packet.server.port); service = GUINT32_FROM_LE (ctrl_packet.server.service); version = GUINT32_FROM_LE (ctrl_packet.server.instance) & 0xff; instance = GUINT32_FROM_LE (ctrl_packet.server.instance) >> 8; if (type == QRTR_TYPE_DEL_SERVER) { g_debug ("[qrtr] removed server on %u:%u -> service %u, version %u, instance %u", node_id, port, service, version, instance); remove_service_info (self, node_id, port, service, version, instance); return TRUE; } g_assert (type == QRTR_TYPE_NEW_SERVER); if (!node_id && !port && !service && !version && !instance) { g_debug ("[qrtr] initial lookup finished"); initable_complete (self); return TRUE; } g_debug ("[qrtr] added server on %u:%u -> service %u, version %u, instance %u", node_id, port, service, version, instance); add_service_info (self, node_id, port, service, version, instance); return TRUE; } /*****************************************************************************/ QrtrNode * qrtr_bus_peek_node (QrtrBus *self, guint32 node_id) { GList *list_item; g_return_val_if_fail (QRTR_IS_BUS (self), NULL); list_item = g_list_find_custom (self->priv->nodes, GUINT_TO_POINTER (node_id), (GCompareFunc)node_find_cmp); return (list_item ? QRTR_NODE (list_item->data) : NULL); } QrtrNode * qrtr_bus_get_node (QrtrBus *self, guint32 node_id) { QrtrNode *node; g_return_val_if_fail (QRTR_IS_BUS (self), NULL); node = qrtr_bus_peek_node (self, node_id); return (node ? g_object_ref (node) : NULL); } GList * qrtr_bus_peek_nodes (QrtrBus *self) { g_return_val_if_fail (QRTR_IS_BUS (self), NULL); return self->priv->nodes; } GList * qrtr_bus_get_nodes (QrtrBus *self) { g_return_val_if_fail (QRTR_IS_BUS (self), NULL); return g_list_copy_deep (self->priv->nodes, (GCopyFunc) g_object_ref, NULL); } /*****************************************************************************/ typedef struct { guint32 node_id; guint added_id; GSource *timeout_source; } WaitForNodeContext; static void wait_for_node_context_cleanup (QrtrBus *self, WaitForNodeContext *ctx) { if (ctx->timeout_source) { g_source_destroy (ctx->timeout_source); g_source_unref (ctx->timeout_source); ctx->timeout_source = NULL; } if (ctx->added_id) { g_signal_handler_disconnect (self, ctx->added_id); ctx->added_id = 0; } } static void wait_for_node_context_free (WaitForNodeContext *ctx) { g_assert (!ctx->added_id); g_assert (!ctx->timeout_source); g_slice_free (WaitForNodeContext, ctx); } QrtrNode * qrtr_bus_wait_for_node_finish (QrtrBus *self, GAsyncResult *res, GError **error) { return g_task_propagate_pointer (G_TASK (res), error); } static gboolean wait_for_node_timeout_cb (GTask *task) { QrtrBus *self; WaitForNodeContext *ctx; self = g_task_get_source_object (task); ctx = g_task_get_task_data (task); /* cleanup the context right away, so that we take exclusive ownership * of the task */ wait_for_node_context_cleanup (self, ctx); g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_TIMED_OUT, "QRTR node %u did not appear on the bus", ctx->node_id); g_object_unref (task); return G_SOURCE_REMOVE; } static void wait_for_node_added_cb (QrtrBus *self, guint node_id, GTask *task) { WaitForNodeContext *ctx; QrtrNode *node; ctx = g_task_get_task_data (task); /* not the one we want, ignore */ if (node_id != ctx->node_id) return; /* cleanup the context right away, so that we take exclusive ownership * of the task */ wait_for_node_context_cleanup (self, ctx); /* get a full node reference */ node = qrtr_bus_get_node (self, node_id); g_task_return_pointer (task, node, g_object_unref); g_object_unref (task); } void qrtr_bus_wait_for_node (QrtrBus *self, guint32 node_id, guint timeout_ms, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; WaitForNodeContext *ctx; QrtrNode *existing_node; g_return_if_fail (QRTR_IS_BUS (self)); g_return_if_fail (timeout_ms > 0); task = g_task_new (self, cancellable, callback, user_data); /* Nothing to do if it already exists */ existing_node = qrtr_bus_get_node (self, node_id); if (existing_node) { g_task_return_pointer (task, existing_node, (GDestroyNotify)g_object_unref); g_object_unref (task); return; } /* The ownership of the task is shared between the signal handler and the timeout; * we need to make sure that we cancel the other one if we're completing the task * from one of them. */ ctx = g_slice_new0 (WaitForNodeContext); ctx->node_id = node_id; /* Monitor added nodes */ ctx->added_id = g_signal_connect (self, QRTR_BUS_SIGNAL_NODE_ADDED, G_CALLBACK (wait_for_node_added_cb), task); /* Setup timeout for the operation */ ctx->timeout_source = g_timeout_source_new (timeout_ms); g_source_set_callback (ctx->timeout_source, (GSourceFunc)wait_for_node_timeout_cb, task, NULL); g_source_attach (ctx->timeout_source, g_main_context_get_thread_default ()); g_task_set_task_data (task, ctx, (GDestroyNotify)wait_for_node_context_free); } /*****************************************************************************/ static gboolean send_new_lookup_ctrl_packet (QrtrBus *self, GError **error) { struct qrtr_ctrl_pkt ctl_packet; struct sockaddr_qrtr addr; int sockfd; socklen_t len; int rc; sockfd = g_socket_get_fd (self->priv->socket); len = sizeof (addr); rc = getsockname (sockfd, (struct sockaddr *)&addr, &len); if (rc < 0) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "Failed to get socket name"); return FALSE; } g_debug ("[qrtr] socket lookup from %d:%d", addr.sq_node, addr.sq_port); g_assert (len == sizeof (addr) && addr.sq_family == AF_QIPCRTR); addr.sq_port = QRTR_PORT_CTRL; memset (&ctl_packet, 0, sizeof (ctl_packet)); ctl_packet.cmd = GUINT32_TO_LE (QRTR_TYPE_NEW_LOOKUP); rc = sendto (sockfd, (void *)&ctl_packet, sizeof (ctl_packet), 0, (struct sockaddr *)&addr, sizeof (addr)); if (rc < 0) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "Failed to send lookup control packet"); return FALSE; } return TRUE; } static void setup_socket_source (QrtrBus *self) { self->priv->source = g_socket_create_source (self->priv->socket, G_IO_IN, NULL); g_source_set_callback (self->priv->source, (GSourceFunc) qrtr_ctrl_message_cb, self, NULL); g_source_attach (self->priv->source, g_main_context_get_thread_default ()); } static gboolean common_init (QrtrBus *self, GError **error) { gint fd; fd = socket (AF_QIPCRTR, SOCK_DGRAM, 0); if (fd < 0) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "Failed to create QRTR socket"); return FALSE; } self->priv->socket = g_socket_new_from_fd (fd, error); if (!self->priv->socket) { close (fd); return FALSE; } g_socket_set_timeout (self->priv->socket, 0); if (!send_new_lookup_ctrl_packet (self, error)) { close (fd); return FALSE; } setup_socket_source (self); return TRUE; } /*****************************************************************************/ typedef struct { } InitContext; static gboolean initable_init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error) { return g_task_propagate_boolean (G_TASK (result), error); } static gboolean initable_timeout (QrtrBus *self) { g_autoptr(GTask) task = NULL; task = g_steal_pointer (&self->priv->init_task); g_assert (task); g_clear_pointer (&self->priv->init_timeout_source, g_source_unref); g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_TIMED_OUT, "Timed out waiting for the initial bus lookup"); return G_SOURCE_REMOVE; } static void initable_complete (QrtrBus *self) { g_autoptr(GTask) task = NULL; task = g_steal_pointer (&self->priv->init_task); if (!task) { g_assert (!self->priv->init_timeout_source); return; } g_assert (self->priv->init_timeout_source); g_source_destroy (self->priv->init_timeout_source); g_clear_pointer (&self->priv->init_timeout_source, g_source_unref); g_task_return_boolean (task, TRUE); } static void initable_init_async (GAsyncInitable *initable, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { QrtrBus *self = QRTR_BUS (initable); GError *error = NULL; g_autoptr(GTask) task = NULL; task = g_task_new (initable, cancellable, callback, user_data); if (!common_init (self, &error)) { g_task_return_error (task, error); return; } /* if lookup timeout is disabled, we're done */ if (!self->priv->lookup_timeout) { g_task_return_boolean (task, TRUE); return; } /* setup wait for the initial lookup completion */ self->priv->init_task = g_steal_pointer (&task); self->priv->init_timeout_source = g_timeout_source_new (self->priv->lookup_timeout); g_source_set_callback (self->priv->init_timeout_source, (GSourceFunc)initable_timeout, self, NULL); g_source_attach (self->priv->init_timeout_source, g_main_context_get_thread_default ()); } /*****************************************************************************/ QrtrBus * qrtr_bus_new_finish (GAsyncResult *res, GError **error) { g_autoptr(GObject) source_object = NULL; source_object = g_async_result_get_source_object (res); return QRTR_BUS (g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, error)); } void qrtr_bus_new (guint lookup_timeout_ms, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { g_async_initable_new_async (QRTR_TYPE_BUS, G_PRIORITY_DEFAULT, cancellable, callback, user_data, QRTR_BUS_LOOKUP_TIMEOUT, lookup_timeout_ms, NULL); } /*****************************************************************************/ static void qrtr_bus_init (QrtrBus *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, QRTR_TYPE_BUS, QrtrBusPrivate); } static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { QrtrBus *self = QRTR_BUS (object); switch (prop_id) { case PROP_LOOKUP_TIMEOUT: self->priv->lookup_timeout = g_value_get_uint (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { QrtrBus *self = QRTR_BUS (object); switch (prop_id) { case PROP_LOOKUP_TIMEOUT: g_value_set_uint (value, self->priv->lookup_timeout); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void dispose (GObject *object) { QrtrBus *self = QRTR_BUS (object); g_assert (!self->priv->init_task); g_assert (!self->priv->init_timeout_source); if (self->priv->source) { g_source_destroy (self->priv->source); g_source_unref (self->priv->source); self->priv->source = NULL; } if (self->priv->socket) { g_socket_close (self->priv->socket, NULL); g_clear_object (&self->priv->socket); } g_list_free_full (self->priv->nodes, g_object_unref); self->priv->nodes = NULL; G_OBJECT_CLASS (qrtr_bus_parent_class)->dispose (object); } static void async_initable_iface_init (GAsyncInitableIface *iface) { iface->init_async = initable_init_async; iface->init_finish = initable_init_finish; } static void qrtr_bus_class_init (QrtrBusClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); g_type_class_add_private (object_class, sizeof (QrtrBusPrivate)); object_class->get_property = get_property; object_class->set_property = set_property; object_class->dispose = dispose; /** * QrtrBus:lookup-timeout: * * Since: 1.0 */ properties[PROP_LOOKUP_TIMEOUT] = g_param_spec_uint (QRTR_BUS_LOOKUP_TIMEOUT, "lookup timeout", "Timeout in ms to wait for the initial lookup to finish, or 0 to disable it", 0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_LOOKUP_TIMEOUT, properties[PROP_LOOKUP_TIMEOUT]); /** * QrtrBus::node-added: * @self: the #QrtrBus * @node: the node ID of the node that has been added * * The ::node-added signal is emitted when a new node registers a service on * the QRTR bus. * * Since: 1.0 */ signals[SIGNAL_NODE_ADDED] = g_signal_new (QRTR_BUS_SIGNAL_NODE_ADDED, G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_UINT); /** * QrtrBus::node-removed: * @self: the #QrtrBus * @node: the node ID of the node that was removed * * The ::node-removed signal is emitted when a node deregisters all services * from the QRTR bus. * * Since: 1.0 */ signals[SIGNAL_NODE_REMOVED] = g_signal_new (QRTR_BUS_SIGNAL_NODE_REMOVED, G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_UINT); } libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/qrtr-bus.h000066400000000000000000000162121512553060500267570ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * libqrtr-glib -- GLib/GIO based library to control QRTR devices * * Copyright (C) 2019-2021 Eric Caruso * Copyright (C) 2020-2021 Aleksander Morgado */ #ifndef _LIBQRTR_GLIB_QRTR_BUS_H_ #define _LIBQRTR_GLIB_QRTR_BUS_H_ #if !defined (__LIBQRTR_GLIB_H_INSIDE__) && !defined (LIBQRTR_GLIB_COMPILATION) #error "Only can be included directly." #endif #include #include #include "qrtr-types.h" G_BEGIN_DECLS /** * SECTION:qrtr-bus * @title: QrtrBus * @short_description: QRTR bus observer and device event listener * * #QrtrBus sets up a socket that uses the QRTR IPC protocol and * can call back into a client to tell them when new devices have appeared on * the QRTR bus. It holds QrtrNodes that can be used to look up service and * port information. */ #define QRTR_TYPE_BUS (qrtr_bus_get_type ()) #define QRTR_BUS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QRTR_TYPE_BUS, QrtrBus)) #define QRTR_BUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QRTR_TYPE_BUS, QrtrBusClass)) #define QRTR_IS_BUS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QRTR_TYPE_BUS)) #define QRTR_IS_BUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QRTR_TYPE_BUS)) #define QRTR_BUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QRTR_TYPE_BUS, QrtrBusClass)) typedef struct _QrtrBusClass QrtrBusClass; typedef struct _QrtrBusPrivate QrtrBusPrivate; /** * QrtrBus: * * The #QrtrBus structure contains private data and should only be accessed * using the provided API. * * Since: 1.0 */ struct _QrtrBus { /*< private >*/ GObject parent; QrtrBusPrivate *priv; }; struct _QrtrBusClass { GObjectClass parent; }; GType qrtr_bus_get_type (void); G_DEFINE_AUTOPTR_CLEANUP_FUNC (QrtrBus, g_object_unref) /** * QRTR_BUS_LOOKUP_TIMEOUT: * * Symbol defining the #QrtrBus:lookup-timeout property. * * Since: 1.0 */ #define QRTR_BUS_LOOKUP_TIMEOUT "lookup-timeout" /** * QRTR_BUS_SIGNAL_NODE_ADDED: * * Symbol defining the #QrtrBus::node-added signal. * * Since: 1.0 */ #define QRTR_BUS_SIGNAL_NODE_ADDED "node-added" /** * QRTR_BUS_SIGNAL_NODE_REMOVED: * * Symbol defining the #QrtrBus::node-removed signal. * * Since: 1.0 */ #define QRTR_BUS_SIGNAL_NODE_REMOVED "node-removed" /** * qrtr_bus_new: * @lookup_timeout_ms: the timeout, in milliseconds, to wait for the initial bus * lookup to complete. A zero timeout disables the lookup. * @cancellable: optional #GCancellable object, %NULL to ignore. * @callback: a #GAsyncReadyCallback to call when the initialization is finished. * @user_data: the data to pass to callback function. * * Asynchronously creates a #QrtrBus object. * * This method will fail if the access to the QRTR bus is not possible, or if * the initial lookup doesn't finish on time. * * When @lookup_timeout_ms is 0, this method does not guarantee that the * initial bus lookup has already finished, the user should wait for the required * #QrtrBus::node-added and #QrtrNode::service-added signals before assuming the * nodes are accessible. * * When the operation is finished, @callback will be invoked. You can then call * qrtr_bus_new_finish() to get the result of the operation. * * Since: 1.0 */ void qrtr_bus_new (guint lookup_timeout_ms, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); /** * qrtr_bus_new_finish: * @res: a #GAsyncResult. * @error: Return location for error or %NULL. * * Finishes an operation started with qrtr_bus_new(). * * Returns: (transfer full): A newly created #QrtrBus, or %NULL if @error is set. * * Since: 1.0 */ QrtrBus *qrtr_bus_new_finish (GAsyncResult *res, GError **error); /** * qrtr_bus_peek_node: * @self: a #QrtrBus. * @node_id: the QRTR bus node ID to get * * Get the #QrtrNode with node ID @node_id, without increasing the reference count * on the returned object. * * This method will fail if there is no node with the given @node_id in the QRTR bus. * * Returns: (transfer none): a #QrtrNode, or %NULL if none available. * Do not free the returned object, it is owned by @self. * * Since: 1.0 */ QrtrNode *qrtr_bus_peek_node (QrtrBus *self, guint32 node_id); /** * qrtr_bus_get_node: * @self: a #QrtrBus. * @node_id: the QRTR bus node ID to get * * Get the #QrtrNode with node ID @node_id. * * This method will fail if there is no node with the given @node_id in the QRTR bus. * * Returns: (transfer full): a #QrtrNode that must be freed with g_object_unref(), * or %NULL if none available * * Since: 1.0 */ QrtrNode *qrtr_bus_get_node (QrtrBus *self, guint32 node_id); /** * qrtr_bus_peek_nodes: * @self: a #QrtrBus. * * Gets a list of all the #QrtrNode objects in the bus, without increasing * the reference count on the returned object or the list. * * Returns: (transfer none)(nullable)(element-type QrtrNode): a list of * #QrtrNode elements. The caller should not free the result, it is * owned by @self. * * Since: 1.0 */ GList *qrtr_bus_peek_nodes (QrtrBus *self); /** * qrtr_bus_get_nodes: * @self: a #QrtrBus. * * Gets a list of all the #QrtrNode objects in the bus. * * Returns: (transfer full)(nullable)(element-type QrtrNode): a list of * #QrtrNode elements. The caller should free the result by using * g_list_free_full() with g_object_unref() as #GDestroyNotify. * * Since: 1.0 */ GList *qrtr_bus_get_nodes (QrtrBus *self); /** * qrtr_bus_wait_for_node: * @self: a #QrtrBus. * @node_id: the QRTR bus node ID to lookup. * @timeout_ms: the timeout, in milliseconds, to wait for the node to appear in * the bus. * @cancellable: a #GCancellable, or #NULL. * @callback: a #GAsyncReadyCallback to call when the request is satisfied. * @user_data: user data to pass to @callback. * * Asynchronously waits for the node with ID @node_id. * * When the operation is finished @callback will be called. You can then call * qrtr_bus_wait_for_node_finish() to get the result of the * operation. * * Since: 1.0 */ void qrtr_bus_wait_for_node (QrtrBus *self, guint32 node_id, guint timeout_ms, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); /** * qrtr_bus_wait_for_node_finish: * @self: a #QrtrBus. * @res: a #GAsyncResult. * @error: Return location for error or %NULL. * * Finishes an operation started with qrtr_bus_wait_for_node(). * * Returns: (transfer full): A #QrtrNode, or %NULL if @error is set. * * Since: 1.0 */ QrtrNode *qrtr_bus_wait_for_node_finish (QrtrBus *self, GAsyncResult *res, GError **error); G_END_DECLS #endif /* _LIBQRTR_GLIB_QRTR_BUS_H_ */ libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/qrtr-client.c000066400000000000000000000260611512553060500274420ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * libqrtr-glib -- GLib/GIO based library to control QRTR devices * * Copyright (C) 2019-2021 Eric Caruso * Copyright (C) 2021 Aleksander Morgado */ #include #include #include #include #include #include #include #include "qrtr-bus.h" #include "qrtr-node.h" #include "qrtr-client.h" static void initable_iface_init (GInitableIface *iface); G_DEFINE_TYPE_EXTENDED (QrtrClient, qrtr_client, G_TYPE_OBJECT, 0, G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)) enum { PROP_0, PROP_NODE, PROP_PORT, PROP_LAST }; enum { SIGNAL_MESSAGE, SIGNAL_LAST }; static GParamSpec *properties[PROP_LAST]; static guint signals [SIGNAL_LAST] = { 0 }; struct _QrtrClientPrivate { QrtrNode *node; guint node_removed_id; gboolean removed; guint port; GSocket *socket; GSource *source; struct sockaddr_qrtr addr; }; /*****************************************************************************/ static void node_removed_cb (QrtrClient *self) { g_debug ("[qrtr client %u:%u] node removed from bus", qrtr_node_get_id (self->priv->node), self->priv->port); self->priv->removed = TRUE; } /*****************************************************************************/ guint32 qrtr_client_get_port (QrtrClient *self) { g_return_val_if_fail (QRTR_IS_CLIENT (self), 0); return self->priv->port; } QrtrNode * qrtr_client_peek_node (QrtrClient *self) { g_return_val_if_fail (QRTR_IS_CLIENT (self), NULL); return self->priv->node; } QrtrNode * qrtr_client_get_node (QrtrClient *self) { g_return_val_if_fail (QRTR_IS_CLIENT (self), NULL); return g_object_ref (self->priv->node); } /*****************************************************************************/ gboolean qrtr_client_send (QrtrClient *self, GByteArray *message, GCancellable *cancellable, GError **error) { gint fd; if (self->priv->removed) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED, "QRTR node was removed from the bus"); return FALSE; } fd = g_socket_get_fd (self->priv->socket); if (sendto (fd, (void *)message->data, message->len, 0, (struct sockaddr *)&self->priv->addr, sizeof (self->priv->addr)) < 0) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "Failed to send QRTR message: %s", g_strerror (errno)); return FALSE; } return TRUE; } /*****************************************************************************/ static gboolean qrtr_message_cb (GSocket *gsocket, GIOCondition cond, QrtrClient *self) { g_autoptr(GError) error = NULL; g_autoptr(GSocketAddress) addr = NULL; struct sockaddr_qrtr sq; g_autoptr(GByteArray) buf = NULL; gssize next_datagram_size; gssize bytes_received; next_datagram_size = g_socket_get_available_bytes (gsocket); buf = g_byte_array_sized_new (next_datagram_size); g_byte_array_set_size (buf, next_datagram_size); bytes_received = g_socket_receive_from (gsocket, &addr, (gchar *)buf->data, next_datagram_size, NULL, &error); if (bytes_received < 0) { g_warning ("[qrtr client %u:%u] socket i/o failure: %s", qrtr_node_get_id (self->priv->node), self->priv->port, error->message); return FALSE; } if (bytes_received != next_datagram_size) { g_warning ("[qrtr client %u:%u] unexpected message size", qrtr_node_get_id (self->priv->node), self->priv->port); return TRUE; } if (!g_socket_address_to_native (addr, &sq, sizeof (sq), &error)) { g_warning ("[qrtr client %u:%u] could not parse QRTR address: %s", qrtr_node_get_id (self->priv->node), self->priv->port, error->message); return TRUE; } if (sq.sq_family != AF_QIPCRTR || sq.sq_node != qrtr_node_get_id (self->priv->node) || sq.sq_port != self->priv->port) { return TRUE; } g_signal_emit (self, signals[SIGNAL_MESSAGE], 0, buf); return TRUE; } /*****************************************************************************/ static gboolean initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { QrtrClient *self = QRTR_CLIENT (initable); gint fd; if (g_cancellable_is_cancelled (cancellable)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED, "Operation cancelled"); return FALSE; } self->priv->addr.sq_family = AF_QIPCRTR; self->priv->addr.sq_node = qrtr_node_get_id (self->priv->node); self->priv->addr.sq_port = (guint) self->priv->port; fd = socket (AF_QIPCRTR, SOCK_DGRAM, 0); if (fd < 0) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "Could not create QRTR socket: %s", g_strerror (errno)); return FALSE; } self->priv->socket = g_socket_new_from_fd (fd, error); if (!self->priv->socket) { g_prefix_error (error, "Could not create QRTR socket: "); close (fd); return FALSE; } g_socket_set_timeout (self->priv->socket, 0); self->priv->source = g_socket_create_source (self->priv->socket, G_IO_IN, NULL); g_source_set_callback (self->priv->source, (GSourceFunc) qrtr_message_cb, self, NULL); g_source_attach (self->priv->source, g_main_context_get_thread_default ()); return TRUE; } /*****************************************************************************/ QrtrClient * qrtr_client_new (QrtrNode *node, guint32 port, GCancellable *cancellable, GError **error) { g_return_val_if_fail (QRTR_IS_NODE (node), NULL); g_return_val_if_fail (port > 0, NULL); return g_initable_new (QRTR_TYPE_CLIENT, cancellable, error, QRTR_CLIENT_NODE, node, QRTR_CLIENT_PORT, port, NULL); } static void qrtr_client_init (QrtrClient *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, QRTR_TYPE_CLIENT, QrtrClientPrivate); } static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { QrtrClient *self = QRTR_CLIENT (object); switch (prop_id) { case PROP_NODE: g_assert (!self->priv->node); self->priv->node = g_value_dup_object (value); self->priv->node_removed_id = g_signal_connect_swapped (self->priv->node, QRTR_NODE_SIGNAL_REMOVED, G_CALLBACK (node_removed_cb), self); break; case PROP_PORT: self->priv->port = (guint32) g_value_get_uint (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { QrtrClient *self = QRTR_CLIENT (object); switch (prop_id) { case PROP_NODE: g_value_set_object (value, self->priv->node); break; case PROP_PORT: g_value_set_uint (value, (guint) self->priv->port); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void dispose (GObject *object) { QrtrClient *self = QRTR_CLIENT (object); if (self->priv->source) { g_source_destroy (self->priv->source); g_clear_pointer (&self->priv->source, g_source_unref); } if (self->priv->socket) { if (!g_socket_is_closed (self->priv->socket)) g_socket_close (self->priv->socket, NULL); g_clear_object (&self->priv->socket); } if (self->priv->node_removed_id) { g_signal_handler_disconnect (self->priv->node, self->priv->node_removed_id); self->priv->node_removed_id = 0; } g_clear_object (&self->priv->node); G_OBJECT_CLASS (qrtr_client_parent_class)->dispose (object); } static void initable_iface_init (GInitableIface *iface) { iface->init = initable_init; } static void qrtr_client_class_init (QrtrClientClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); g_type_class_add_private (object_class, sizeof (QrtrClientPrivate)); object_class->get_property = get_property; object_class->set_property = set_property; object_class->dispose = dispose; /** * QrtrClient:client-node: * * Since: 1.0 */ properties[PROP_NODE] = g_param_spec_object (QRTR_CLIENT_NODE, "node", "The QRTR node", QRTR_TYPE_NODE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_NODE, properties[PROP_NODE]); /** * QrtrClient:client-port: * * Since: 1.0 */ properties[PROP_PORT] = g_param_spec_uint (QRTR_CLIENT_PORT, "port", "The QRTR node port", 0, G_MAXUINT32, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_PORT, properties[PROP_PORT]); /** * QrtrClient::client-message * @self: the #QrtrClient * @message: the message data. * * The ::client-message signal is emitted when a message is received * from the port in the node. * * There must be one single user connected to this signal, because it is * not guaranteed that the contents of the @message byte array aren't * modified by multiple users. In other words, the user connected to this * signal may modify the contents of the @message byte array if needed. * * Since: 1.0 */ signals[SIGNAL_MESSAGE] = g_signal_new (QRTR_CLIENT_SIGNAL_MESSAGE, G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_BYTE_ARRAY); } libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/qrtr-client.h000066400000000000000000000102331512553060500274410ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * libqrtr-glib -- GLib/GIO based library to control QRTR devices * * Copyright (C) 2021 Aleksander Morgado */ #ifndef _LIBQRTR_GLIB_QRTR_CLIENT_H_ #define _LIBQRTR_GLIB_QRTR_CLIENT_H_ #if !defined (__LIBQRTR_GLIB_H_INSIDE__) && !defined (LIBQRTR_GLIB_COMPILATION) #error "Only can be included directly." #endif #include #include "qrtr-types.h" G_BEGIN_DECLS /** * SECTION:qrtr-client * @title: QrtrClient * @short_description: The QRTR client. * * The #QrtrClient object represents a channel that can be used to * communicate with a #QrtrNode in a given port. */ #define QRTR_TYPE_CLIENT (qrtr_client_get_type ()) #define QRTR_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QRTR_TYPE_CLIENT, QrtrClient)) #define QRTR_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QRTR_TYPE_CLIENT, QrtrClientClass)) #define QRTR_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QRTR_TYPE_CLIENT)) #define QRTR_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QRTR_TYPE_CLIENT)) #define QRTR_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QRTR_TYPE_CLIENT, QrtrClientClass)) typedef struct _QrtrClientClass QrtrClientClass; typedef struct _QrtrClientPrivate QrtrClientPrivate; /** * QRTR_CLIENT_NODE: * * The QRTR node this client refers to. * * Since: 1.0 */ #define QRTR_CLIENT_NODE "client-node" /** * QRTR_CLIENT_PORT: * * The QRTR node port this client refers to. * * Since: 1.0 */ #define QRTR_CLIENT_PORT "client-port" /** * QRTR_CLIENT_SIGNAL_MESSAGE: * * Symbol defining the #QrtrClient::client-message signal. * * Since: 1.0 */ #define QRTR_CLIENT_SIGNAL_MESSAGE "client-message" /** * QrtrClient: * * The #QrtrClient structure contains private data and should only be accessed * using the provided API. * * Since: 1.0 */ struct _QrtrClient { /*< private >*/ GObject parent; QrtrClientPrivate *priv; }; struct _QrtrClientClass { /*< private >*/ GObjectClass parent; }; GType qrtr_client_get_type (void); G_DEFINE_AUTOPTR_CLEANUP_FUNC (QrtrClient, g_object_unref) /** * qrtr_client_new: * @node: a #QrtrNode. * @port: a node port. * @cancellable: optional #GCancellable object, %NULL to ignore. * @error: rReturn location for error or %NULL. * * Creates a new #QrtrClient to communicate with @port at #QrtrNode. * * Returns: (transfer full): a newly allocated #QrtrClient, or %NULL if @error is set. * * Since: 1.0 */ QrtrClient *qrtr_client_new (QrtrNode *node, guint32 port, GCancellable *cancellable, GError **error); /** * qrtr_client_peek_node: * @self: a #QrtrClient. * * Get the #QrtrNode that this client refers to, without increasing the * reference count on the returned object. * * Returns: (transfer none): a #QrtrNode. Do not free the returned object, it is * owned by @self. * * Since: 1.0 */ QrtrNode *qrtr_client_peek_node (QrtrClient *self); /** * qrtr_client_get_node: * @self: a #QrtrClient. * * Get the #QrtrNode that this client refers to. * * Returns: (transfer full): a #QrtrNode that must be freed with g_object_unref(). * * Since: 1.0 */ QrtrNode *qrtr_client_get_node (QrtrClient *self); /** * qrtr_client_get_port: * @self: a #QrtrClient. * * Gets the node port where this client communicates. * * Returns: the node port. * * Since: 1.0 */ guint32 qrtr_client_get_port (QrtrClient *self); /** * qrtr_client_send: * @self: a #QrtrClient. * @message: the message. * @cancellable: a #GCancellable. * @error: Return location for #GError or %NULL. * * Sends a message to the port at the node. * * Returns: %TRUE if the message is sent, or %FALSE if @error is set. * * Since: 1.0 */ gboolean qrtr_client_send (QrtrClient *self, GByteArray *message, GCancellable *cancellable, GError **error); G_END_DECLS #endif /* _LIBQRTR_GLIB_QRTR_CLIENT_H_ */ libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/qrtr-node.c000066400000000000000000000446301512553060500271130ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * libqrtr-glib -- GLib/GIO based library to control QRTR devices * * Copyright (C) 2019-2020 Eric Caruso * Copyright (C) 2020 Aleksander Morgado */ #include #include #include #include #include #include #include #include #include "qrtr-bus.h" #include "qrtr-node.h" G_DEFINE_TYPE (QrtrNode, qrtr_node, G_TYPE_OBJECT) enum { PROP_0, PROP_BUS, PROP_NODE_ID, PROP_LAST }; enum { SIGNAL_SERVICE_ADDED, SIGNAL_SERVICE_REMOVED, SIGNAL_REMOVED, SIGNAL_LAST }; static GParamSpec *properties[PROP_LAST]; static guint signals [SIGNAL_LAST] = { 0 }; struct _QrtrNodePrivate { QrtrBus *bus; guint32 node_id; guint node_removed_id; gboolean removed; /* Holds QrtrNodeServiceInfo entries */ GList *service_list; /* Maps service numbers to a list of service entries */ GHashTable *service_index; /* Maps port number to service entry (should only be one) */ GHashTable *port_index; /* Array of QrtrServiceWaiters currently registered. */ GPtrArray *waiters; }; typedef struct { GArray *services; GTask *task; GSource *timeout_source; } QrtrServiceWaiter; /* used to avoid calling the free function when values are overwritten * in the service index */ typedef struct { GList *list; } ListHolder; /*****************************************************************************/ static void node_removed_cb (QrtrNode *self, guint node_id) { guint i; if (node_id != self->priv->node_id) return; self->priv->removed = TRUE; for (i = 0; i < self->priv->waiters->len; i++) { QrtrServiceWaiter *waiter; waiter = g_ptr_array_index (self->priv->waiters, i); g_task_return_new_error (waiter->task, G_IO_ERROR, G_IO_ERROR_CLOSED, "QRTR node was removed from the bus"); } /* waiters was instantiated with qrtr_service_waiter_free as its free function, * so when we get rid of the contents, all of the constitutent waiter entries * (and their tasks) will be unreffed as well. */ g_ptr_array_remove_range (self->priv->waiters, 0, self->priv->waiters->len); g_signal_emit (self, signals[SIGNAL_REMOVED], 0); } /*****************************************************************************/ static void qrtr_service_waiter_free (QrtrServiceWaiter *waiter) { g_array_unref (waiter->services); g_object_unref (waiter->task); if (waiter->timeout_source) { g_source_destroy (waiter->timeout_source); g_source_unref (waiter->timeout_source); } g_slice_free (QrtrServiceWaiter, waiter); } static gboolean service_waiter_timeout_cb (QrtrServiceWaiter *waiter) { QrtrNode *self; self = g_task_get_source_object (waiter->task); g_task_return_new_error (waiter->task, G_IO_ERROR, G_IO_ERROR_TIMED_OUT, "QRTR services did not appear on the bus"); /* This takes care of unreffing the task. */ g_ptr_array_remove_fast (self->priv->waiters, waiter); return G_SOURCE_REMOVE; } static void dispatch_pending_waiters (QrtrNode *self) { guint i; for (i = 0; i < self->priv->waiters->len;) { QrtrServiceWaiter *waiter; guint j; gboolean should_dispatch = TRUE; waiter = g_ptr_array_index (self->priv->waiters, i); for (j = 0; j < waiter->services->len; j++) { guint32 service; service = g_array_index (waiter->services, guint32, j); if (!g_hash_table_lookup (self->priv->service_index, GUINT_TO_POINTER (service))) { should_dispatch = FALSE; break; } } if (should_dispatch) { g_task_return_boolean (waiter->task, TRUE); /* This takes care of unreffing the task. */ g_ptr_array_remove_index_fast (self->priv->waiters, i); } else { i++; } } } /*****************************************************************************/ struct _QrtrNodeServiceInfo { guint32 service; guint32 port; guint32 version; guint32 instance; }; void qrtr_node_service_info_free (QrtrNodeServiceInfo *info) { g_slice_free (QrtrNodeServiceInfo, info); } guint32 qrtr_node_service_info_get_service (QrtrNodeServiceInfo *info) { g_return_val_if_fail (info != NULL, 0); return info->service; } guint32 qrtr_node_service_info_get_port (QrtrNodeServiceInfo *info) { g_return_val_if_fail (info != NULL, 0); return info->port; } guint32 qrtr_node_service_info_get_version (QrtrNodeServiceInfo *info) { g_return_val_if_fail (info != NULL, 0); return info->version; } guint32 qrtr_node_service_info_get_instance (QrtrNodeServiceInfo *info) { g_return_val_if_fail (info != NULL, 0); return info->instance; } static QrtrNodeServiceInfo * node_service_info_copy (const QrtrNodeServiceInfo *src) { return g_slice_copy (sizeof (QrtrNodeServiceInfo), src); } G_DEFINE_BOXED_TYPE (QrtrNodeServiceInfo, qrtr_node_service_info, (GBoxedCopyFunc)node_service_info_copy, (GBoxedFreeFunc)qrtr_node_service_info_free) static gint sort_services_by_version (const QrtrNodeServiceInfo *a, const QrtrNodeServiceInfo *b) { return a->version - b->version; } static void list_holder_free (ListHolder *list_holder) { g_list_free (list_holder->list); g_slice_free (ListHolder, list_holder); } static void service_index_add_info (GHashTable *service_index, guint32 service, QrtrNodeServiceInfo *info) { ListHolder *service_instances; service_instances = g_hash_table_lookup (service_index, GUINT_TO_POINTER (service)); if (!service_instances) { service_instances = g_slice_new0 (ListHolder); g_hash_table_insert (service_index, GUINT_TO_POINTER (service), service_instances); } service_instances->list = g_list_insert_sorted (service_instances->list, info, (GCompareFunc)sort_services_by_version); } static void service_index_remove_info (GHashTable *service_index, guint32 service, QrtrNodeServiceInfo *info) { ListHolder *service_instances; service_instances = g_hash_table_lookup (service_index, GUINT_TO_POINTER (service)); if (!service_instances) return; service_instances->list = g_list_remove (service_instances->list, info); } void qrtr_node_add_service_info (QrtrNode *self, guint32 service, guint32 port, guint32 version, guint32 instance) { QrtrNodeServiceInfo *info; info = g_slice_new (QrtrNodeServiceInfo); info->service = service; info->port = port; info->version = version; info->instance = instance; self->priv->service_list = g_list_append (self->priv->service_list, info); service_index_add_info (self->priv->service_index, service, info); g_hash_table_insert (self->priv->port_index, GUINT_TO_POINTER (port), info); g_signal_emit (self, signals[SIGNAL_SERVICE_ADDED], 0, service); dispatch_pending_waiters (self); } void qrtr_node_remove_service_info (QrtrNode *self, guint32 service, guint32 port, guint32 version, guint32 instance) { QrtrNodeServiceInfo *info; info = g_hash_table_lookup (self->priv->port_index, GUINT_TO_POINTER (port)); if (!info) { g_info ("[qrtr node@%u]: tried to remove unknown service %u, port %u", self->priv->node_id, service, port); return; } service_index_remove_info (self->priv->service_index, service, info); g_hash_table_remove (self->priv->port_index, GUINT_TO_POINTER (port)); self->priv->service_list = g_list_remove (self->priv->service_list, info); qrtr_node_service_info_free (info); g_signal_emit (self, signals[SIGNAL_SERVICE_REMOVED], 0, service); } /*****************************************************************************/ gint32 qrtr_node_lookup_port (QrtrNode *self, guint32 service) { ListHolder *service_instances; QrtrNodeServiceInfo *info; GList *list; g_return_val_if_fail (QRTR_IS_NODE (self), -1); service_instances = g_hash_table_lookup (self->priv->service_index, GUINT_TO_POINTER (service)); if (!service_instances) return -1; list = g_list_last (service_instances->list); if (!list) return -1; info = list->data; return (info) ? (gint32)info->port : -1; } gint32 qrtr_node_lookup_service (QrtrNode *self, guint32 port) { QrtrNodeServiceInfo *info; g_return_val_if_fail (QRTR_IS_NODE (self), -1); info = g_hash_table_lookup (self->priv->port_index, GUINT_TO_POINTER (port)); return info ? (gint32)info->service : -1; } /*****************************************************************************/ GList * qrtr_node_peek_service_info_list (QrtrNode *self) { g_return_val_if_fail (QRTR_IS_NODE (self), NULL); return self->priv->service_list; } GList * qrtr_node_get_service_info_list (QrtrNode *self) { g_return_val_if_fail (QRTR_IS_NODE (self), NULL); return g_list_copy_deep (self->priv->service_list, (GCopyFunc)node_service_info_copy, NULL); } guint32 qrtr_node_get_id (QrtrNode *self) { g_return_val_if_fail (QRTR_IS_NODE (self), 0); return self->priv->node_id; } QrtrBus * qrtr_node_peek_bus (QrtrNode *self) { g_return_val_if_fail (QRTR_IS_NODE (self), NULL); return self->priv->bus; } QrtrBus * qrtr_node_get_bus (QrtrNode *self) { g_return_val_if_fail (QRTR_IS_NODE (self), NULL); return g_object_ref (self->priv->bus); } /*****************************************************************************/ gboolean qrtr_node_wait_for_services_finish (QrtrNode *self, GAsyncResult *result, GError **error) { return g_task_propagate_boolean (G_TASK (result), error); } void qrtr_node_wait_for_services (QrtrNode *self, GArray *services, guint timeout_ms, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; QrtrServiceWaiter *waiter; guint i; gboolean services_present = TRUE; g_return_if_fail (QRTR_IS_NODE (self)); g_return_if_fail (timeout_ms > 0); task = g_task_new (self, cancellable, callback, user_data); if (self->priv->removed) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_CLOSED, "QRTR node was removed from the bus"); g_object_unref (task); return; } for (i = 0; i < services->len; i++) { guint32 service; service = g_array_index (services, guint32, i); if (!g_hash_table_lookup (self->priv->service_index, GUINT_TO_POINTER (service))) { services_present = FALSE; break; } } if (services_present) { g_task_return_boolean (task, TRUE); g_object_unref (task); return; } waiter = g_slice_new0 (QrtrServiceWaiter); waiter->services = g_array_ref (services); waiter->task = task; waiter->timeout_source = g_timeout_source_new (timeout_ms); g_source_set_callback (waiter->timeout_source, (GSourceFunc)service_waiter_timeout_cb, waiter, NULL); g_source_attach (waiter->timeout_source, g_main_context_get_thread_default ()); g_ptr_array_add (self->priv->waiters, waiter); } /*****************************************************************************/ static void qrtr_node_init (QrtrNode *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, QRTR_TYPE_NODE, QrtrNodePrivate); self->priv->removed = FALSE; self->priv->service_index = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)list_holder_free); self->priv->port_index = g_hash_table_new (g_direct_hash, g_direct_equal); self->priv->waiters = g_ptr_array_new_with_free_func ((GDestroyNotify)qrtr_service_waiter_free); } static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { QrtrNode *self = QRTR_NODE (object); switch (prop_id) { case PROP_BUS: g_assert (!self->priv->bus); self->priv->bus = g_value_dup_object (value); self->priv->node_removed_id = g_signal_connect_swapped (self->priv->bus, QRTR_BUS_SIGNAL_NODE_REMOVED, G_CALLBACK (node_removed_cb), self); break; case PROP_NODE_ID: self->priv->node_id = (guint32) g_value_get_uint (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { QrtrNode *self = QRTR_NODE (object); switch (prop_id) { case PROP_BUS: g_value_set_object (value, self->priv->bus); break; case PROP_NODE_ID: g_value_set_uint (value, (guint)self->priv->node_id); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } static void dispose (GObject *object) { QrtrNode *self = QRTR_NODE (object); if (self->priv->node_removed_id) { g_signal_handler_disconnect (self->priv->bus, self->priv->node_removed_id); self->priv->node_removed_id = 0; } g_clear_object (&self->priv->bus); /* We shouldn't have any waiters because they should have been removed when the * node was removed from the bus, and they hold references to self. */ g_assert (self->priv->waiters->len == 0); g_clear_pointer (&self->priv->waiters, (GDestroyNotify)g_ptr_array_unref); G_OBJECT_CLASS (qrtr_node_parent_class)->dispose (object); } static void finalize (GObject *object) { QrtrNode *self = QRTR_NODE (object); g_hash_table_unref (self->priv->service_index); g_hash_table_unref (self->priv->port_index); g_list_free_full (self->priv->service_list, (GDestroyNotify)qrtr_node_service_info_free); G_OBJECT_CLASS (qrtr_node_parent_class)->finalize (object); } static void qrtr_node_class_init (QrtrNodeClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); g_type_class_add_private (object_class, sizeof (QrtrNodePrivate)); object_class->get_property = get_property; object_class->set_property = set_property; object_class->dispose = dispose; object_class->finalize = finalize; /** * QrtrNode:bus: * * Since: 1.0 */ properties[PROP_BUS] = g_param_spec_object (QRTR_NODE_BUS, "bus", "QRTR bus", QRTR_TYPE_BUS, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_BUS, properties[PROP_BUS]); /** * QrtrNode:node-id: * * Since: 1.0 */ properties[PROP_NODE_ID] = g_param_spec_uint (QRTR_NODE_ID, "Node ID", "ID of the QRTR node", 0, G_MAXUINT32, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property (object_class, PROP_NODE_ID, properties[PROP_NODE_ID]); /** * QrtrNode::service-added: * @self: the #QrtrNode * @service: the service ID of the service that has been added * * The ::service-added signal is emitted when a new service registers * on the QRTR node. * * Since: 1.0 */ signals[SIGNAL_SERVICE_ADDED] = g_signal_new (QRTR_NODE_SIGNAL_SERVICE_ADDED, G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_UINT); /** * QrtrNode::service-removed: * @self: the #QrtrNode * @service: the service ID of the service that was removed * * The ::service-removed signal is emitted when a service deregisters * from the QRTR node. * * Since: 1.0 */ signals[SIGNAL_SERVICE_REMOVED] = g_signal_new (QRTR_NODE_SIGNAL_SERVICE_REMOVED, G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_UINT); /** * QrtrNode::node-removed: * @self: the #QrtrNode * * The ::node-removed signal is emitted when the node fully disappears from * the QRTR bus. * * Since: 1.0 */ signals[SIGNAL_REMOVED] = g_signal_new (QRTR_NODE_SIGNAL_REMOVED, G_OBJECT_CLASS_TYPE (G_OBJECT_CLASS (klass)), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/qrtr-node.h000066400000000000000000000217601512553060500271170ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * libqrtr-glib -- GLib/GIO based library to control QRTR devices * * Copyright (C) 2019-2021 Eric Caruso * Copyright (C) 2020-2021 Aleksander Morgado */ #ifndef _LIBQRTR_GLIB_QRTR_NODE_H_ #define _LIBQRTR_GLIB_QRTR_NODE_H_ #if !defined (__LIBQRTR_GLIB_H_INSIDE__) && !defined (LIBQRTR_GLIB_COMPILATION) #error "Only can be included directly." #endif #include #include "qrtr-types.h" G_BEGIN_DECLS /** * SECTION:qrtr-node * @title: QrtrNode * @short_description: QRTR node handler. * * #QrtrNode represents a device on the QRTR bus and can be used to look up * services published by that device. */ #define QRTR_TYPE_NODE (qrtr_node_get_type ()) #define QRTR_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QRTR_TYPE_NODE, QrtrNode)) #define QRTR_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QRTR_TYPE_NODE, QrtrNodeClass)) #define QRTR_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QRTR_TYPE_NODE)) #define QRTR_IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QRTR_TYPE_NODE)) #define QRTR_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QRTR_TYPE_NODE, QrtrNodeClass)) typedef struct _QrtrNodeClass QrtrNodeClass; typedef struct _QrtrNodePrivate QrtrNodePrivate; /** * QRTR_NODE_BUS: * * The QRTR bus. * * Since: 1.0 */ #define QRTR_NODE_BUS "bus" /** * QRTR_NODE_ID: * * The node id. * * Since: 1.0 */ #define QRTR_NODE_ID "node-id" /** * QrtrNode: * * The #QrtrNode structure contains private data and should only be accessed * using the provided API. * * Since: 1.0 */ struct _QrtrNode { /*< private >*/ GObject parent; QrtrNodePrivate *priv; }; struct _QrtrNodeClass { /*< private >*/ GObjectClass parent; }; GType qrtr_node_get_type (void); G_DEFINE_AUTOPTR_CLEANUP_FUNC (QrtrNode, g_object_unref) /** * QRTR_NODE_SIGNAL_SERVICE_ADDED: * * Symbol defining the #QrtrNode::service-added signal. * * Since: 1.0 */ #define QRTR_NODE_SIGNAL_SERVICE_ADDED "service-added" /** * QRTR_NODE_SIGNAL_SERVICE_REMOVED: * * Symbol defining the #QrtrNode::service-removed signal. * * Since: 1.0 */ #define QRTR_NODE_SIGNAL_SERVICE_REMOVED "service-removed" /** * QRTR_NODE_SIGNAL_REMOVED: * * Symbol defining the #QrtrNode::node-removed signal. * * Since: 1.0 */ #define QRTR_NODE_SIGNAL_REMOVED "node-removed" /** * qrtr_node_get_id: * @self: a #QrtrNode. * * Gets the node ID in the QRTR bus. * * Returns: the node id. * * Since: 1.0 */ guint32 qrtr_node_get_id (QrtrNode *self); /** * qrtr_node_peek_bus: * @self: a #QrtrNode. * * Get the #QrtrBus where this node is available, without increasing the * reference count on the returned object. * * Returns: (transfer none): a #QrtrBus. Do not free the returned object, it is * owned by @self. * * Since: 1.0 */ QrtrBus *qrtr_node_peek_bus (QrtrNode *self); /** * qrtr_node_get_bus: * @self: a #QrtrNode. * * Get the #QrtrBus where this node is available. * * Returns: (transfer full): a #QrtrBus that must be freed with g_object_unref(). * * Since: 1.0 */ QrtrBus *qrtr_node_get_bus (QrtrNode *self); /** * QrtrNodeServiceInfo: * * Information for a service instance in the #QrtrNode. * * Since: 1.0 */ typedef struct _QrtrNodeServiceInfo QrtrNodeServiceInfo; #define QRTR_TYPE_NODE_SERVICE_INFO (qrtr_node_service_info_get_type ()) GType qrtr_node_service_info_get_type (void); /** * qrtr_node_service_info_get_service: * @info: a #QrtrNodeServiceInfo. * * Get the service number from the #QrtrNodeServiceInfo. * * Returns: the service number. * * Since: 1.0 */ guint32 qrtr_node_service_info_get_service (QrtrNodeServiceInfo *info); /** * qrtr_node_service_info_get_port: * @info: a #QrtrNodeServiceInfo. * * Get the port number from the #QrtrNodeServiceInfo. * * Returns: the port number. * * Since: 1.0 */ guint32 qrtr_node_service_info_get_port (QrtrNodeServiceInfo *info); /** * qrtr_node_service_info_get_version: * @info: a #QrtrNodeServiceInfo. * * Get the version number from the #QrtrNodeServiceInfo. * * Returns: the version number. * * Since: 1.0 */ guint32 qrtr_node_service_info_get_version (QrtrNodeServiceInfo *info); /** * qrtr_node_service_info_get_instance: * @info: a #QrtrNodeServiceInfo. * * Get the instance number from the #QrtrNodeServiceInfo. * * Returns: the instance number. * * Since: 1.0 */ guint32 qrtr_node_service_info_get_instance (QrtrNodeServiceInfo *info); /** * qrtr_node_service_info_free: * @info: a #QrtrNodeServiceInfo. * * Frees a single #QrtrNodeServiceInfo, as returned by qrtr_node_get_service_info_list(). * * Since: 1.0 */ void qrtr_node_service_info_free (QrtrNodeServiceInfo *info); G_DEFINE_AUTOPTR_CLEANUP_FUNC (QrtrNodeServiceInfo, qrtr_node_service_info_free) /** * qrtr_node_peek_service_info_list: * @self: a #QrtrNode. * * Get the list of services currently supported by the #QrtrNode. * * Returns: (element-type QrtrNodeServiceInfo)(transfer none): a #GList of #QrtrNodeServiceInfo elements. Do not * free the returned object, it is owned by @self. * * Since: 1.0 */ GList *qrtr_node_peek_service_info_list (QrtrNode *self); /** * qrtr_node_get_service_info_list: * @self: a #QrtrNode. * * Get the list of services currently supported by the #QrtrNode. * * Returns: (element-type QrtrNodeServiceInfo)(transfer full): a #GList of #QrtrNodeServiceInfo elements, that * must be freed with g_list_free_full() using qrtr_node_service_info_free() * as #GDestroyNotify. * * Since: 1.0 */ GList *qrtr_node_get_service_info_list (QrtrNode *self); /** * qrtr_node_lookup_port: * @self: a #QrtrNode. * @service: a service number. * * If a server has announced itself for the given node and service number, * return the port number of that service. * * If multiple instances are registered, this method returns the port number * for the service with the highest version number. * * Returns: the port number of the service in the node, or -1 if not found. * * Since: 1.0 */ gint32 qrtr_node_lookup_port (QrtrNode *self, guint32 service); /** * qrtr_node_lookup_service: * @self: a #QrtrNode. * @port: a port number. * * If a server has announced itself for the given node and port number, * return the service it serves. * * Returns: the service number, or -1 if not found. * * Since: 1.0 */ gint32 qrtr_node_lookup_service (QrtrNode *self, guint32 port); /** * qrtr_node_wait_for_services: * @self: a #QrtrNode. * @services: (in)(element-type guint32): a #GArray of service types * @timeout_ms: the timeout, in milliseconds, to wait for the the services to * be exposed in the node. * @cancellable: a #GCancellable, or #NULL. * @callback: a #GAsyncReadyCallback to call when the request is satisfied. * @user_data: user data to pass to @callback. * * Asynchronously waits until all the services listed in @services are present * on the node. * * The operation may fail if any of the requested services isn't notified, or * if the node is removed from the bus while waiting. * * When the operation is finished @callback will be called. You can then call * qrtr_node_wait_for_services_finish() to get the result of the * operation. * * Since: 1.0 */ void qrtr_node_wait_for_services (QrtrNode *self, GArray *services, guint timeout_ms, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); /** * qrtr_node_wait_for_services_finish: * @self: a #QrtrNode. * @result: a #GAsyncResult. * @error: Return location for #GError or %NULL. * * Finishes an operation started with qrtr_node_wait_for_services(). * * Returns: %TRUE if all requested services are present on this node, * or %FALSE if @error is set. * * Since: 1.0 */ gboolean qrtr_node_wait_for_services_finish (QrtrNode *self, GAsyncResult *result, GError **error); G_END_DECLS /* Other private methods */ #if defined (LIBQRTR_GLIB_COMPILATION) G_GNUC_INTERNAL void qrtr_node_add_service_info (QrtrNode *node, guint32 service, guint32 port, guint32 version, guint32 instance); G_GNUC_INTERNAL void qrtr_node_remove_service_info (QrtrNode *node, guint32 service, guint32 port, guint32 version, guint32 instance); #endif /* defined (LIBQRTR_GLIB_COMPILATION) */ #endif /* _LIBQRTR_GLIB_QRTR_NODE_H_ */ libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/qrtr-types.h000066400000000000000000000012571512553060500273350ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * libqrtr-glib -- GLib/GIO based library to control QRTR devices * * Copyright (C) 2021 Andrew Lassalle */ #ifndef _LIBQRTR_GLIB_QRTR_TYPES_H_ #define _LIBQRTR_GLIB_QRTR_TYPES_H_ #if !defined (__LIBQRTR_GLIB_H_INSIDE__) && !defined (LIBQRTR_GLIB_COMPILATION) #error "Only can be included directly." #endif G_BEGIN_DECLS typedef struct _QrtrBus QrtrBus; typedef struct _QrtrClient QrtrClient; typedef struct _QrtrNode QrtrNode; G_END_DECLS #endif /* _LIBQRTR_GLIB_QRTR_TYPES_H_ */ libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/qrtr-utils.c000066400000000000000000000023231512553060500273170ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * libqrtr-glib -- GLib/GIO based library to control QRTR devices * * Copyright (C) 2019-2020 Eric Caruso * Copyright (C) 2020 Aleksander Morgado */ #include "qrtr-utils.h" #include #include /* Some kernels expose the qrtr header but not the address family macro. */ #if !defined AF_QIPCRTR # define AF_QIPCRTR 42 #endif #define QRTR_URI_SCHEME "qrtr" #define QRTR_URI_PREFIX QRTR_URI_SCHEME "://" gchar * qrtr_get_uri_for_node (guint32 node_id) { return g_strdup_printf (QRTR_URI_PREFIX "%" G_GUINT32_FORMAT, node_id); } gboolean qrtr_get_node_for_uri (const gchar *name, guint32 *node_id) { const gchar *start; gchar *endp = NULL; guint tmp_node_id; if (g_ascii_strncasecmp (name, QRTR_URI_PREFIX, strlen (QRTR_URI_PREFIX)) != 0) return FALSE; start = name + strlen (QRTR_URI_PREFIX); tmp_node_id = strtoul (start, &endp, 10); if (endp == start) return FALSE; if (node_id) *node_id = tmp_node_id; return TRUE; } libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/qrtr-utils.h000066400000000000000000000024111512553060500273220ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * libqrtr-glib -- GLib/GIO based library to control QRTR devices * * Copyright (C) 2019-2020 Eric Caruso * Copyright (C) 2020 Aleksander Morgado */ #ifndef _LIBQRTR_GLIB_QRTR_UTILS_H_ #define _LIBQRTR_GLIB_QRTR_UTILS_H_ #include #include #include "qrtr-types.h" /** * SECTION:qrtr-utils * @title: QRTR utilities * @short_description: Utilities in the library. * * Common utilities in the libqrtr-glib library. */ /** * qrtr_get_uri_for_node: * @node_id: node id. * * Build a URI for the given QRTR node. * * Returns: a string with the URI, or %NULL if none given. The returned value * should be freed with g_free(). * * Since: 1.0 */ gchar *qrtr_get_uri_for_node (guint32 node_id); /** * qrtr_get_node_for_uri: * @uri: a URI. * @node_id: (out): return location for the node id. * * Get the QRTR node id from the specified URI. * * Returns: %TRUE if @node_id is set, %FALSE otherwise. * * Since: 1.0 */ gboolean qrtr_get_node_for_uri (const gchar *uri, guint32 *node_id); #endif /* _LIBQRTR_GLIB_QRTR_UTILS_H_ */ libqrtr-glib-1.4.0-69791f8f2a092d0ec8eb83cbe51dfc3d157c3079/src/libqrtr-glib/qrtr-version.h.in000066400000000000000000000033731512553060500302640ustar00rootroot00000000000000/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021 Aleksander Morgado */ #ifndef _QRTR_VERSION_H_ #define _QRTR_VERSION_H_ /** * SECTION:qrtr-version * @short_description: Version information in the API. * * This section defines types that are used to identify the libqrtr-glib version. **/ /** * QRTR_MAJOR_VERSION: * * Evaluates to the major version number of libqrtr-glib which this source * is compiled against. * * Since: 1.0 */ #define QRTR_MAJOR_VERSION (@QRTR_MAJOR_VERSION@) /** * QRTR_MINOR_VERSION: * * Evaluates to the minor version number of libqrtr-glib which this source * is compiled against. * * Since: 1.0 */ #define QRTR_MINOR_VERSION (@QRTR_MINOR_VERSION@) /** * QRTR_MICRO_VERSION: * * Evaluates to the micro version number of libqrtr-glib which this source * compiled against. * * Since: 1.0 */ #define QRTR_MICRO_VERSION (@QRTR_MICRO_VERSION@) /** * QRTR_CHECK_VERSION: * @major: major version (e.g. 1 for version 1.2.5) * @minor: minor version (e.g. 2 for version 1.2.5) * @micro: micro version (e.g. 5 for version 1.2.5) * * Checks the version of the libqrtr library that is being compiled against. * * Returns: %TRUE if the version of the libqrtr-glib header files * is the same as or newer than the passed-in version. * * Since: 1.0 */ #define QRTR_CHECK_VERSION(major,minor,micro) \ (QRTR_MAJOR_VERSION > (major) || \ (QRTR_MAJOR_VERSION == (major) && QRTR_MINOR_VERSION > (minor)) || \ (QRTR_MAJOR_VERSION == (major) && QRTR_MINOR_VERSION == (minor) && QRTR_MICRO_VERSION >= (micro))) #endif /* _QRTR_VERSION_H_ */