diff --git a/LICENSES/LGPL-2.1-only.txt b/LICENSES/LGPL-2.1-only.txt new file mode 100644 index 0000000..130dffb --- /dev/null +++ b/LICENSES/LGPL-2.1-only.txt @@ -0,0 +1,467 @@ +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. + +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. + +< one line to give the library's name and an idea of what it does. > + +Copyright (C) < year > < name of author > + +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. + +< signature of Ty Coon > , 1 April 1990 + +Ty Coon, President of Vice + +That's all there is to it! diff --git a/LICENSES/LGPL-2.1-or-later.txt b/LICENSES/LGPL-2.1-or-later.txt new file mode 100644 index 0000000..04bb156 --- /dev/null +++ b/LICENSES/LGPL-2.1-or-later.txt @@ -0,0 +1,468 @@ +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. + +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. + +< signature of Ty Coon > , 1 April 1990 + +Ty Coon, President of Vice + +That's all there is to it! diff --git a/LICENSES/LGPL-3.0-only.txt b/LICENSES/LGPL-3.0-only.txt new file mode 100644 index 0000000..bd405af --- /dev/null +++ b/LICENSES/LGPL-3.0-only.txt @@ -0,0 +1,163 @@ +GNU LESSER GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +This version of the GNU Lesser General Public License incorporates the terms +and conditions of version 3 of the GNU General Public License, supplemented +by the additional permissions listed below. + + 0. Additional Definitions. + + + +As used herein, "this License" refers to version 3 of the GNU Lesser General +Public License, and the "GNU GPL" refers to version 3 of the GNU General Public +License. + + + +"The Library" refers to a covered work governed by this License, other than +an Application or a Combined Work as defined below. + + + +An "Application" is any work that makes use of an interface provided by the +Library, but which is not otherwise based on the Library. Defining a subclass +of a class defined by the Library is deemed a mode of using an interface provided +by the Library. + + + +A "Combined Work" is a work produced by combining or linking an Application +with the Library. The particular version of the Library with which the Combined +Work was made is also called the "Linked Version". + + + +The "Minimal Corresponding Source" for a Combined Work means the Corresponding +Source for the Combined Work, excluding any source code for portions of the +Combined Work that, considered in isolation, are based on the Application, +and not on the Linked Version. + + + +The "Corresponding Application Code" for a Combined Work means the object +code and/or source code for the Application, including any data and utility +programs needed for reproducing the Combined Work from the Application, but +excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + +You may convey a covered work under sections 3 and 4 of this License without +being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + +If you modify a copy of the Library, and, in your modifications, a facility +refers to a function or data to be supplied by an Application that uses the +facility (other than as an argument passed when the facility is invoked), +then you may convey a copy of the modified version: + +a) under this License, provided that you make a good faith effort to ensure +that, in the event an Application does not supply the function or data, the +facility still operates, and performs whatever part of its purpose remains +meaningful, or + +b) under the GNU GPL, with none of the additional permissions of this License +applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + +The object code form of an Application may incorporate material from a header +file that is part of the Library. You may convey such object code under terms +of your choice, provided that, if the incorporated material is not limited +to numerical parameters, data structure layouts and accessors, or small macros, +inline functions and templates (ten or fewer lines in length), you do both +of the following: + +a) Give prominent notice with each copy of the object code that the Library +is used in it and that the Library and its use are covered by this License. + +b) Accompany the object code with a copy of the GNU GPL and this license document. + + 4. Combined Works. + +You may convey a Combined Work under terms of your choice that, taken together, +effectively do not restrict modification of the portions of the Library contained +in the Combined Work and reverse engineering for debugging such modifications, +if you also do each of the following: + +a) Give prominent notice with each copy of the Combined Work that the Library +is used in it and that the Library and its use are covered by this License. + +b) Accompany the Combined Work with a copy of the GNU GPL and this license +document. + +c) For a Combined Work that displays copyright notices during execution, include +the copyright notice for the Library among these notices, as well as a reference +directing the user to the copies of the GNU GPL and this license document. + + d) Do one of the following: + +0) Convey the Minimal Corresponding Source under the terms of this License, +and the Corresponding Application Code in a form suitable for, and under terms +that permit, the user to recombine or relink the Application with a modified +version of the Linked Version to produce a modified Combined Work, in the +manner specified by section 6 of the GNU GPL for conveying Corresponding Source. + +1) Use a suitable shared library mechanism for linking with the Library. A +suitable mechanism is one that (a) uses at run time a copy of the Library +already present on the user's computer system, and (b) will operate properly +with a modified version of the Library that is interface-compatible with the +Linked Version. + +e) Provide Installation Information, but only if you would otherwise be required +to provide such information under section 6 of the GNU GPL, and only to the +extent that such information is necessary to install and execute a modified +version of the Combined Work produced by recombining or relinking the Application +with a modified version of the Linked Version. (If you use option 4d0, the +Installation Information must accompany the Minimal Corresponding Source and +Corresponding Application Code. If you use option 4d1, you must provide the +Installation Information in the manner specified by section 6 of the GNU GPL +for conveying Corresponding Source.) + + 5. Combined Libraries. + +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 that are +not Applications and are not covered by this License, and convey such a combined +library under terms of your choice, if you do both of the following: + +a) Accompany the combined library with a copy of the same work based on the +Library, uncombined with any other library facilities, conveyed under the +terms of this License. + +b) Give prominent notice with the combined library that part of it is a work +based on the Library, and explaining where to find the accompanying uncombined +form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + +The Free Software Foundation may publish revised and/or new versions of the +GNU 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 as you +received it specifies that a certain numbered version of the GNU Lesser General +Public License "or any later version" applies to it, you have the option of +following the terms and conditions either of that published version or of +any later version published by the Free Software Foundation. If the Library +as you received it does not specify a version number of the GNU Lesser General +Public License, you may choose any version of the GNU Lesser General Public +License ever published by the Free Software Foundation. + +If the Library as you received it specifies that a proxy can decide whether +future versions of the GNU Lesser General Public License shall apply, that +proxy's public statement of acceptance of any version is permanent authorization +for you to choose that version for the Library. diff --git a/LICENSES/LicenseRef-KDE-Accepted-LGPL.txt b/LICENSES/LicenseRef-KDE-Accepted-LGPL.txt new file mode 100644 index 0000000..232b3c5 --- /dev/null +++ b/LICENSES/LicenseRef-KDE-Accepted-LGPL.txt @@ -0,0 +1,12 @@ +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 3 of the license or (at your option) any later version +that is accepted by the membership of KDE e.V. (or its successor +approved by the membership of KDE e.V.), which shall act as a +proxy as defined in Section 6 of version 3 of the license. + +This program 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 General Public License for more details. diff --git a/autotests/adaptertest.cpp b/autotests/adaptertest.cpp index 447f492..22d2edf 100644 --- a/autotests/adaptertest.cpp +++ b/autotests/adaptertest.cpp @@ -1,382 +1,368 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "adaptertest.h" #include "autotests.h" #include "device.h" #include "pendingcall.h" #include "initmanagerjob.h" #include #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; AdapterTest::AdapterTest() : m_manager(nullptr) { Autotests::registerMetatypes(); } void AdapterTest::initTestCase() { QDBusConnection connection = QDBusConnection::sessionBus(); QString service = QStringLiteral("org.kde.bluezqt.fakebluez"); bluezqt_initFakeBluezTestRun(); FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapters QDBusObjectPath adapter1path = QDBusObjectPath(QStringLiteral("/org/bluez/hci0")); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); adapterProps[QStringLiteral("Alias")] = QStringLiteral("TestAlias"); adapterProps[QStringLiteral("Class")] = QVariant::fromValue(quint32(101)); adapterProps[QStringLiteral("Powered")] = false; adapterProps[QStringLiteral("Discoverable")] = false; adapterProps[QStringLiteral("Pairable")] = false; adapterProps[QStringLiteral("PairableTimeout")] = QVariant::fromValue(quint32(0)); adapterProps[QStringLiteral("DiscoverableTimeout")] = QVariant::fromValue(quint32(0)); adapterProps[QStringLiteral("Discovering")] = false; adapterProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("00001200-0000-1000-8000-00805f9b34fb")); adapterProps[QStringLiteral("Modalias")] = QStringLiteral("usb:v2D6Bp1236d0215"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); QDBusObjectPath adapter2path = QDBusObjectPath(QStringLiteral("/org/bluez/hci1")); adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter2path); adapterProps[QStringLiteral("Address")] = QStringLiteral("2E:3A:C3:BC:85:7C"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter2"); adapterProps[QStringLiteral("Alias")] = QStringLiteral("TestAlias2"); adapterProps[QStringLiteral("Class")] = QVariant::fromValue(quint32(201)); adapterProps[QStringLiteral("Powered")] = true; adapterProps[QStringLiteral("Discoverable")] = true; adapterProps[QStringLiteral("Pairable")] = true; adapterProps[QStringLiteral("PairableTimeout")] = QVariant::fromValue(quint32(150)); adapterProps[QStringLiteral("DiscoverableTimeout")] = QVariant::fromValue(quint32(120)); adapterProps[QStringLiteral("Discovering")] = false; adapterProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("0000110c-0000-1000-8000-00805f9b34fb")); adapterProps[QStringLiteral("Modalias")] = QStringLiteral("usb:v1D3Bp1134d0214"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); // Create devices QVariantMap deviceProps; deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci0/dev_40_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(adapter1path); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci1/dev_50_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(adapter2path); deviceProps[QStringLiteral("Address")] = QStringLiteral("50:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice2"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); m_manager = new Manager(); InitManagerJob *initJob = m_manager->init(); initJob->exec(); QVERIFY(!initJob->error()); for (AdapterPtr adapter : m_manager->adapters()) { QVERIFY(!adapter->ubi().isEmpty()); AdapterUnit u; u.adapter = adapter; u.dbusAdapter = new org::bluez::Adapter1(service, adapter->ubi(), connection, this); u.dbusProperties = new org::freedesktop::DBus::Properties(service, adapter->ubi(), connection, this); m_units.append(u); } QCOMPARE(m_manager->adapters().count(), 2); } void AdapterTest::cleanupTestCase() { for (const AdapterUnit &unit : m_units) { delete unit.dbusAdapter; delete unit.dbusProperties; } delete m_manager; FakeBluez::stop(); } static void compareUuids(const QStringList &actual, const QStringList &expected) { QCOMPARE(actual.size(), expected.size()); for (int i = 0; i < actual.size(); ++i) { QCOMPARE(actual.at(i).toUpper(), expected.at(i).toUpper()); } } void AdapterTest::getPropertiesTest() { for (const AdapterUnit &unit : m_units) { QCOMPARE(unit.adapter->ubi(), unit.dbusAdapter->path()); QCOMPARE(unit.adapter->address(), unit.dbusAdapter->address()); QCOMPARE(unit.adapter->name(), unit.dbusAdapter->alias()); QCOMPARE(unit.adapter->systemName(), unit.dbusAdapter->name()); QCOMPARE(unit.adapter->adapterClass(), unit.dbusAdapter->adapterClass()); QCOMPARE(unit.adapter->isPowered(), unit.dbusAdapter->powered()); QCOMPARE(unit.adapter->isDiscoverable(), unit.dbusAdapter->discoverable()); QCOMPARE(unit.adapter->discoverableTimeout(), unit.dbusAdapter->discoverableTimeout()); QCOMPARE(unit.adapter->isPairable(), unit.dbusAdapter->pairable()); QCOMPARE(unit.adapter->pairableTimeout(), unit.dbusAdapter->pairableTimeout()); QCOMPARE(unit.adapter->isDiscovering(), unit.dbusAdapter->discovering()); QCOMPARE(unit.adapter->modalias(), unit.dbusAdapter->modalias()); compareUuids(unit.adapter->uuids(), unit.dbusAdapter->uUIDs()); } } void AdapterTest::setAliasTest() { for (const AdapterUnit &unit : m_units) { QSignalSpy adapterSpy(unit.adapter.data(), SIGNAL(nameChanged(QString))); QSignalSpy dbusSpy(unit.dbusProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList))); QString value = unit.adapter->name() + QLatin1String("_tst_alias"); unit.adapter->setName(value); QTRY_COMPARE(adapterSpy.count(), 1); QList adapterArguments = adapterSpy.takeFirst(); QCOMPARE(adapterArguments.at(0).toString(), value); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("Alias"), value); QCOMPARE(unit.adapter->name(), value); QCOMPARE(unit.dbusAdapter->alias(), value); } } void AdapterTest::setPoweredTest() { for (const AdapterUnit &unit : m_units) { QSignalSpy adapterSpy(unit.adapter.data(), SIGNAL(poweredChanged(bool))); QSignalSpy dbusSpy(unit.dbusProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList))); bool value = !unit.adapter->isPowered(); unit.adapter->setPowered(value); QTRY_COMPARE(adapterSpy.count(), 1); QVERIFY(dbusSpy.count() >= 1); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("Powered"), value); QList adapterArguments = adapterSpy.takeFirst(); QCOMPARE(adapterArguments.at(0).toBool(), value); QCOMPARE(unit.adapter->isPowered(), value); QCOMPARE(unit.dbusAdapter->powered(), value); } } void AdapterTest::setDiscoverableTest() { // Discoverable cannot be changed when Adapter is off for (const AdapterUnit &unit : m_units) { unit.adapter->setPowered(true)->waitForFinished(); QSignalSpy adapterSpy(unit.adapter.data(), SIGNAL(discoverableChanged(bool))); QSignalSpy dbusSpy(unit.dbusProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList))); bool value = !unit.adapter->isDiscoverable(); unit.adapter->setDiscoverable(value); QTRY_COMPARE(adapterSpy.count(), 1); QList adapterArguments = adapterSpy.takeFirst(); QCOMPARE(adapterArguments.at(0).toBool(), value); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("Discoverable"), value); QCOMPARE(unit.adapter->isDiscoverable(), value); QCOMPARE(unit.dbusAdapter->discoverable(), value); } } void AdapterTest::setDiscoverableTimeoutTest() { for (const AdapterUnit &unit : m_units) { QSignalSpy adapterSpy(unit.adapter.data(), SIGNAL(discoverableTimeoutChanged(quint32))); QSignalSpy dbusSpy(unit.dbusProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList))); quint32 value = unit.adapter->discoverableTimeout() + 1; unit.adapter->setDiscoverableTimeout(value); QTRY_COMPARE(adapterSpy.count(), 1); QVERIFY(dbusSpy.count() >= 1); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("DiscoverableTimeout"), value); QList adapterArguments = adapterSpy.takeFirst(); QCOMPARE(adapterArguments.at(0).toUInt(), value); QCOMPARE(unit.adapter->discoverableTimeout(), value); QCOMPARE(unit.dbusAdapter->discoverableTimeout(), value); } } void AdapterTest::setPairableTest() { for (const AdapterUnit &unit : m_units) { QSignalSpy adapterSpy(unit.adapter.data(), SIGNAL(pairableChanged(bool))); QSignalSpy dbusSpy(unit.dbusProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList))); bool value = !unit.adapter->isPairable(); unit.adapter->setPairable(value); QTRY_COMPARE(adapterSpy.count(), 1); QList adapterArguments = adapterSpy.takeFirst(); QCOMPARE(adapterArguments.at(0).toBool(), value); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("Pairable"), value); QCOMPARE(unit.adapter->isPairable(), value); QCOMPARE(unit.dbusAdapter->pairable(), value); } } void AdapterTest::setPairableTimeoutTest() { for (const AdapterUnit &unit : m_units) { QSignalSpy adapterSpy(unit.adapter.data(), SIGNAL(pairableTimeoutChanged(quint32))); QSignalSpy dbusSpy(unit.dbusProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList))); quint32 value = unit.adapter->pairableTimeout() + 1; unit.adapter->setPairableTimeout(value); QTRY_COMPARE(adapterSpy.count(), 1); QVERIFY(dbusSpy.count() >= 1); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("PairableTimeout"), value); QList adapterArguments = adapterSpy.takeFirst(); QCOMPARE(adapterArguments.at(0).toUInt(), value); QCOMPARE(unit.adapter->pairableTimeout(), value); QCOMPARE(unit.dbusAdapter->pairableTimeout(), value); } } void AdapterTest::discoveryTest() { // Discovery needs Adapter powered on for (const AdapterUnit &unit : m_units) { // Make sure the Adapter is powered on and not discovering unit.adapter->setPowered(true)->waitForFinished(); if (unit.adapter->isDiscovering()) { unit.adapter->stopDiscovery()->waitForFinished(); } QSignalSpy adapterSpy(unit.adapter.data(), SIGNAL(discoveringChanged(bool))); QSignalSpy dbusSpy(unit.dbusProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList))); // Start Discovery unit.adapter->startDiscovery(); QTRY_COMPARE(adapterSpy.count(), 1); QVERIFY(dbusSpy.count() >= 1); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("Discovering"), true); QList adapterArguments = adapterSpy.takeFirst(); QCOMPARE(adapterArguments.at(0).toBool(), true); QCOMPARE(unit.adapter->isDiscovering(), true); QCOMPARE(unit.dbusAdapter->discovering(), true); adapterSpy.clear(); dbusSpy.clear(); // Stop Discovery unit.adapter->stopDiscovery(); QTRY_COMPARE(adapterSpy.count(), 1); QVERIFY(dbusSpy.count() >= 1); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("Discovering"), false); adapterArguments = adapterSpy.takeFirst(); QCOMPARE(adapterArguments.at(0).toBool(), false); QCOMPARE(unit.adapter->isDiscovering(), false); QCOMPARE(unit.dbusAdapter->discovering(), false); } } void AdapterTest::removeDeviceTest() { for (const AdapterUnit &unit : m_units) { while (!unit.adapter->devices().isEmpty()) { DevicePtr device = unit.adapter->devices().first(); QSignalSpy managerSpy(m_manager, SIGNAL(deviceRemoved(DevicePtr))); QSignalSpy adapterSpy(unit.adapter.data(), SIGNAL(deviceRemoved(DevicePtr))); QSignalSpy deviceSpy(device.data(), SIGNAL(deviceRemoved(DevicePtr))); unit.adapter->removeDevice(device); QTRY_COMPARE(managerSpy.count(), 1); QTRY_COMPARE(adapterSpy.count(), 1); QTRY_COMPARE(deviceSpy.count(), 1); QCOMPARE(managerSpy.at(0).at(0).value(), device); QCOMPARE(adapterSpy.at(0).at(0).value(), device); QCOMPARE(deviceSpy.at(0).at(0).value(), device); } } } void AdapterTest::adapterRemovedTest() { for (const AdapterUnit &unit : m_units) { QSignalSpy managerSpy(m_manager, SIGNAL(adapterRemoved(AdapterPtr))); QSignalSpy adapterSpy(unit.adapter.data(), SIGNAL(adapterRemoved(AdapterPtr))); QVariantMap properties; properties[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(unit.adapter->ubi())); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("remove-adapter"), properties); QTRY_COMPARE(managerSpy.count(), 1); QTRY_COMPARE(adapterSpy.count(), 1); QCOMPARE(managerSpy.at(0).at(0).value(), unit.adapter); QCOMPARE(adapterSpy.at(0).at(0).value(), unit.adapter); } } QTEST_MAIN(AdapterTest) diff --git a/autotests/adaptertest.h b/autotests/adaptertest.h index 1300edd..31eda7d 100644 --- a/autotests/adaptertest.h +++ b/autotests/adaptertest.h @@ -1,68 +1,54 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef ADAPTERTEST_H #define ADAPTERTEST_H #include #include #include "bluezadapter1_tst.h" #include "dbusproperties_tst.h" #include "manager.h" #include "adapter.h" class AdapterTest : public QObject { Q_OBJECT public: explicit AdapterTest(); private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void getPropertiesTest(); void setAliasTest(); void setPoweredTest(); void setDiscoverableTest(); void setDiscoverableTimeoutTest(); void setPairableTest(); void setPairableTimeoutTest(); void discoveryTest(); void removeDeviceTest(); void adapterRemovedTest(); private: struct AdapterUnit { BluezQt::AdapterPtr adapter; org::bluez::Adapter1 *dbusAdapter; org::freedesktop::DBus::Properties *dbusProperties; }; BluezQt::Manager *m_manager; QList m_units; }; #endif // ADAPTERTEST_H diff --git a/autotests/agentmanagertest.cpp b/autotests/agentmanagertest.cpp index 959bb60..f99361e 100644 --- a/autotests/agentmanagertest.cpp +++ b/autotests/agentmanagertest.cpp @@ -1,271 +1,257 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "agentmanagertest.h" #include "autotests.h" #include "manager.h" #include "initmanagerjob.h" #include "pendingcall.h" #include "services.h" #include #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; // TestAgent TestAgent::TestAgent(QObject *parent) : Agent(parent) , m_pinRequested(false) , m_passkeyRequested(false) , m_authorizationRequested(false) , m_cancelCalled(false) , m_releaseCalled(false) { } QDBusObjectPath TestAgent::objectPath() const { return QDBusObjectPath(QStringLiteral("/testagent")); } void TestAgent::requestPinCode(DevicePtr device, const BluezQt::Request &request) { m_device = device; m_pinRequested = true; request.accept(QString()); } void TestAgent::displayPinCode(DevicePtr device, const QString &pinCode) { m_device = device; m_displayedPinCode = pinCode; } void TestAgent::requestPasskey(DevicePtr device, const BluezQt::Request &request) { m_device = device; m_passkeyRequested = true; request.accept(0); } void TestAgent::displayPasskey(DevicePtr device, const QString &passkey, const QString &entered) { m_device = device; m_displayedPasskey = passkey; m_enteredPasskey = entered; } void TestAgent::requestConfirmation(DevicePtr device, const QString &passkey, const BluezQt::Request<> &request) { m_device = device; m_requestedPasskey = passkey; request.accept(); } void TestAgent::requestAuthorization(DevicePtr device, const BluezQt::Request<> &request) { m_device = device; m_authorizationRequested = true; request.accept(); } void TestAgent::authorizeService(DevicePtr device, const QString &uuid, const BluezQt::Request<> &request) { m_device = device; m_authorizedUuid = uuid; request.accept(); } void TestAgent::cancel() { m_cancelCalled = true; } void TestAgent::release() { m_releaseCalled = true; } // AgentManagerTest void AgentManagerTest::initTestCase() { bluezqt_initFakeBluezTestRun(); FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapter QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(QStringLiteral("/org/bluez/hci0"))); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); // Create device m_device = QDBusObjectPath(QStringLiteral("/org/bluez/hci0/dev_40_79_6A_0C_39_75")); QVariantMap deviceProps; deviceProps[QStringLiteral("Path")] = QVariant::fromValue(m_device); deviceProps[QStringLiteral("Adapter")] = adapterProps.value(QStringLiteral("Path")); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); Manager *manager = new Manager(this); InitManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); QCOMPARE(manager->adapters().count(), 1); QCOMPARE(manager->devices().count(), 1); m_agent = new TestAgent(this); manager->registerAgent(m_agent)->waitForFinished(); } void AgentManagerTest::cleanupTestCase() { FakeBluez::stop(); } void AgentManagerTest::requestPinCodeTest() { QCOMPARE(m_agent->m_pinRequested, false); QVariantMap props; props.insert(QStringLiteral("Device"), QVariant::fromValue(m_device)); FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("request-pincode"), props); QTRY_COMPARE(m_agent->m_pinRequested, true); QTRY_COMPARE(m_agent->m_device->name(), QStringLiteral("TestDevice")); } void AgentManagerTest::displayPinCodeTest() { QCOMPARE(m_agent->m_displayedPinCode, QString()); QVariantMap props; props.insert(QStringLiteral("Device"), QVariant::fromValue(m_device)); props.insert(QStringLiteral("PinCode"), QStringLiteral("123456")); FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("display-pincode"), props); QTRY_COMPARE(m_agent->m_displayedPinCode, QStringLiteral("123456")); QTRY_COMPARE(m_agent->m_device->name(), QStringLiteral("TestDevice")); } void AgentManagerTest::requestPasskeyTest() { QCOMPARE(m_agent->m_passkeyRequested, false); QVariantMap props; props.insert(QStringLiteral("Device"), QVariant::fromValue(m_device)); FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("request-passkey"), props); QTRY_COMPARE(m_agent->m_passkeyRequested, true); QTRY_COMPARE(m_agent->m_device->name(), QStringLiteral("TestDevice")); } void AgentManagerTest::displayPasskeyTest() { QCOMPARE(m_agent->m_displayedPasskey, QString()); QCOMPARE(m_agent->m_enteredPasskey, QString()); QVariantMap props; props.insert(QStringLiteral("Device"), QVariant::fromValue(m_device)); props.insert(QStringLiteral("Passkey"), QVariant::fromValue(quint32(654321))); props.insert(QStringLiteral("EnteredPasskey"), QVariant::fromValue(quint16(43))); FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("display-passkey"), props); QTRY_COMPARE(m_agent->m_displayedPasskey, QStringLiteral("654321")); QTRY_COMPARE(m_agent->m_enteredPasskey, QStringLiteral("43")); QTRY_COMPARE(m_agent->m_device->name(), QStringLiteral("TestDevice")); } void AgentManagerTest::requestConfirmationTest() { QCOMPARE(m_agent->m_requestedPasskey, QString()); QVariantMap props; props.insert(QStringLiteral("Device"), QVariant::fromValue(m_device)); props.insert(QStringLiteral("Passkey"), QVariant::fromValue(quint32(12))); FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("request-confirmation"), props); QTRY_COMPARE(m_agent->m_requestedPasskey, QStringLiteral("000012")); QTRY_COMPARE(m_agent->m_device->name(), QStringLiteral("TestDevice")); } void AgentManagerTest::requestAuthorizationTest() { QCOMPARE(m_agent->m_authorizationRequested, false); QVariantMap props; props.insert(QStringLiteral("Device"), QVariant::fromValue(m_device)); FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("request-authorization"), props); QTRY_COMPARE(m_agent->m_authorizationRequested, true); QTRY_COMPARE(m_agent->m_device->name(), QStringLiteral("TestDevice")); } void AgentManagerTest::authorizeServiceTest() { QCOMPARE(m_agent->m_authorizedUuid, QString()); QVariantMap props; props.insert(QStringLiteral("Device"), QVariant::fromValue(m_device)); props.insert(QStringLiteral("UUID"), Services::ObexFileTransfer); FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("authorize-service"), props); QTRY_COMPARE(m_agent->m_authorizedUuid, Services::ObexFileTransfer); QTRY_COMPARE(m_agent->m_device->name(), QStringLiteral("TestDevice")); } void AgentManagerTest::cancelTest() { QCOMPARE(m_agent->m_cancelCalled, false); FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("cancel")); QTRY_COMPARE(m_agent->m_cancelCalled, true); QTRY_COMPARE(m_agent->m_device->name(), QStringLiteral("TestDevice")); } void AgentManagerTest::releaseTest() { QCOMPARE(m_agent->m_releaseCalled, false); FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("release")); QTRY_COMPARE(m_agent->m_releaseCalled, true); QTRY_COMPARE(m_agent->m_device->name(), QStringLiteral("TestDevice")); } QTEST_MAIN(AgentManagerTest) diff --git a/autotests/agentmanagertest.h b/autotests/agentmanagertest.h index 97f194e..132470f 100644 --- a/autotests/agentmanagertest.h +++ b/autotests/agentmanagertest.h @@ -1,104 +1,90 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef AGENTMANAGERTEST_H #define AGENTMANAGERTEST_H #include #include #include "agent.h" #include "device.h" class TestAgent : public BluezQt::Agent { Q_OBJECT public: explicit TestAgent(QObject *parent = nullptr); QDBusObjectPath objectPath() const override; void requestPinCode(BluezQt::DevicePtr device, const BluezQt::Request &request) override; void displayPinCode(BluezQt::DevicePtr device, const QString &pinCode) override; void requestPasskey(BluezQt::DevicePtr device, const BluezQt::Request &request) override; void displayPasskey(BluezQt::DevicePtr device, const QString &passkey, const QString &entered) override; void requestConfirmation(BluezQt::DevicePtr device, const QString &passkey, const BluezQt::Request<> &request) override; void requestAuthorization(BluezQt::DevicePtr device, const BluezQt::Request<> &request) override; void authorizeService(BluezQt::DevicePtr device, const QString &uuid, const BluezQt::Request<> &request) override; void cancel() override; void release() override; BluezQt::DevicePtr m_device; // requestPinCode bool m_pinRequested; // displayPinCode QString m_displayedPinCode; // requestPasskey bool m_passkeyRequested; // displayPasskey QString m_displayedPasskey; QString m_enteredPasskey; // requestConfirmation QString m_requestedPasskey; // requestAuthorization bool m_authorizationRequested; // authorizeService QString m_authorizedUuid; // cancel bool m_cancelCalled; // release bool m_releaseCalled; }; class AgentManagerTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void requestPinCodeTest(); void displayPinCodeTest(); void requestPasskeyTest(); void displayPasskeyTest(); void requestConfirmationTest(); void requestAuthorizationTest(); void authorizeServiceTest(); void cancelTest(); void releaseTest(); private: TestAgent *m_agent; QDBusObjectPath m_device; }; #endif // AGENTMANAGERTEST_H diff --git a/autotests/autotests.cpp b/autotests/autotests.cpp index 489dd68..186f7f0 100644 --- a/autotests/autotests.cpp +++ b/autotests/autotests.cpp @@ -1,206 +1,192 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "autotests.h" #include "device.h" #include "adapter.h" #include "battery.h" #include "mediaplayer.h" #include "mediaplayertrack.h" #include "mediatransport.h" #include "bluezqt_dbustypes.h" #include #include #include #include #include #include QProcess *FakeBluez::s_process = nullptr; class StartJob : public QObject { Q_OBJECT public: explicit StartJob(); void exec(); bool foundFakeBluez() const { return !m_fakebluezPath.isEmpty(); } private Q_SLOTS: void processError(QProcess::ProcessError error); void processFinished(int code, QProcess::ExitStatus status); private: QString m_fakebluezPath; QEventLoop m_eventLoop; }; StartJob::StartJob() : QObject(nullptr) , m_fakebluezPath(QCoreApplication::applicationDirPath() + QStringLiteral("/fakebluez")) { } void StartJob::exec() { QDBusServiceWatcher watcher(QStringLiteral("org.kde.bluezqt.test"), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration); connect(&watcher, &QDBusServiceWatcher::serviceRegistered, &m_eventLoop, &QEventLoop::quit); connect(FakeBluez::s_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError))); connect(FakeBluez::s_process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus))); FakeBluez::s_process->start(m_fakebluezPath, QStringList()); m_eventLoop.exec(); } void StartJob::processError(QProcess::ProcessError error) { QString errorString; switch (error) { case QProcess::FailedToStart: errorString = QStringLiteral("Failed to Start"); break; case QProcess::Crashed: errorString = QStringLiteral("Crashed"); break; case QProcess::Timedout: errorString = QStringLiteral("Timedout"); break; default: errorString = QStringLiteral("Unknown"); } qWarning() << "Fakebluez binary:" << m_fakebluezPath; qWarning() << "Process error:" << error << errorString; qWarning() << "Error output:" << FakeBluez::s_process->readAllStandardError(); m_eventLoop.quit(); } void StartJob::processFinished(int code, QProcess::ExitStatus status) { QString statusString = status == QProcess::NormalExit ? QStringLiteral("Normal Exit") : QStringLiteral("Crash Exit"); qWarning() << "Fakebluez binary:" << m_fakebluezPath; qWarning() << "Process finished:" << code << statusString; qWarning() << "Error output:" << FakeBluez::s_process->readAllStandardError(); m_eventLoop.quit(); } void FakeBluez::start() { if (isRunning()) { return; } if (!s_process) { s_process = new QProcess(); } StartJob job; QVERIFY(job.foundFakeBluez()); job.exec(); } void FakeBluez::stop() { if (s_process && s_process->state() == QProcess::Running) { s_process->terminate(); s_process->waitForFinished(); } } bool FakeBluez::isRunning() { return s_process && s_process->state() == QProcess::Running; } void FakeBluez::runTest(const QString &testName) { if (!isRunning()) { return; } QDBusMessage call = QDBusMessage::createMethodCall(QStringLiteral("org.kde.bluezqt.test"), QStringLiteral("/"), QStringLiteral("org.kde.bluezqt.fakebluez.Test"), QStringLiteral("runTest")); call << testName; QDBusConnection::sessionBus().call(call); } void FakeBluez::runAction(const QString &object, const QString &actionName, const QVariantMap &properties) { if (!isRunning()) { return; } QDBusMessage call = QDBusMessage::createMethodCall(QStringLiteral("org.kde.bluezqt.test"), QStringLiteral("/"), QStringLiteral("org.kde.bluezqt.fakebluez.Test"), QStringLiteral("runAction")); call << object; call << actionName; call << properties; QDBusConnection::sessionBus().call(call); } void Autotests::registerMetatypes() { qRegisterMetaType("DevicePtr"); qRegisterMetaType("AdapterPtr"); qRegisterMetaType("BatteryPtr"); qRegisterMetaType("MediaPlayerPtr"); qRegisterMetaType("MediaTransportPtr"); } void Autotests::verifyPropertiesChangedSignal(const QSignalSpy &spy, const QString &propertyName, const QVariant &propertyValue) { int changes = 0; for (int i = 0; i < spy.count(); ++i) { QList arguments = spy.at(i); QVariantMap properties = arguments.at(1).toMap(); QVariantMap::const_iterator it; for (it = properties.constBegin(); it != properties.constEnd(); ++it) { const QVariant &changedValue = it.value(); const QString &property = it.key(); if (property == propertyName && changedValue == propertyValue) { changes++; } } } QCOMPARE(changes, 1); } #include "autotests.moc" diff --git a/autotests/autotests.h b/autotests/autotests.h index 87bd83d..dcb195e 100644 --- a/autotests/autotests.h +++ b/autotests/autotests.h @@ -1,51 +1,37 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef AUTOTESTS_H #define AUTOTESTS_H #include #include #include #include #include class FakeBluez { public: static void start(); static void stop(); static bool isRunning(); static void runTest(const QString &testName); static void runAction(const QString &object, const QString &actionName, const QVariantMap &properties = QVariantMap()); static QProcess *s_process; }; namespace Autotests { void registerMetatypes(); void verifyPropertiesChangedSignal(const QSignalSpy &spy, const QString &propertyName, const QVariant &propertyValue); } #endif // AUTOTESTS_H diff --git a/autotests/batterytest.cpp b/autotests/batterytest.cpp index ac0af11..39b7c95 100644 --- a/autotests/batterytest.cpp +++ b/autotests/batterytest.cpp @@ -1,142 +1,128 @@ /* - * Copyright (C) 2019 Kai Uwe Broulik + * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "batterytest.h" #include "autotests.h" #include "pendingcall.h" #include "initmanagerjob.h" #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; BatteryTest::BatteryTest() : m_manager(nullptr) { Autotests::registerMetatypes(); } void BatteryTest::initTestCase() { QDBusConnection connection = QDBusConnection::sessionBus(); QString service = QStringLiteral("org.kde.bluezqt.fakebluez"); bluezqt_initFakeBluezTestRun(); FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapter QString adapter = QStringLiteral("/org/bluez/hci0"); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(adapter)); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); // Create devices QVariantMap deviceProps; QVariantMap batteryProps; QString device1 = adapter + QLatin1String("/dev_40_79_6A_0C_39_75"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device1)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); deviceProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("00001124-0000-1000-8000-00805F9B34FB")); batteryProps[QStringLiteral("Percentage")] = uchar(42); deviceProps[QStringLiteral("Battery")] = batteryProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); QString device2 = adapter + QLatin1String("/dev_50_79_6A_0C_39_75"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device2)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("50:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice2"); deviceProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("00001124-0000-1000-8000-00805F9B34FB")); batteryProps[QStringLiteral("Percentage")] = uchar(0); deviceProps[QStringLiteral("Battery")] = batteryProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); QString device3 = adapter + QLatin1String("/dev_60_79_6B_0C_39_55"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device3)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("60:79:6B:0C:39:55"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice3"); deviceProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("00001124-0000-1000-8000-00805F9B34FB")); batteryProps[QStringLiteral("Percentage")] = uchar(99); deviceProps[QStringLiteral("Battery")] = batteryProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); QString device4 = adapter + QLatin1String("/dev_70_79_6B_0C_39_55"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device4)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("70:79:6B:0C:39:55"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice4"); deviceProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("00001124-0000-1000-8000-00805F9B34FB")); batteryProps[QStringLiteral("Percentage")] = uchar(100); deviceProps[QStringLiteral("Battery")] = batteryProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); m_manager = new Manager(); InitManagerJob *initJob = m_manager->init(); initJob->exec(); QVERIFY(!initJob->error()); for (DevicePtr device : m_manager->devices()) { QVERIFY(device->battery()); BatteryUnit u; u.device = device; u.dbusBattery = new org::bluez::Battery1(service, device->ubi(), connection, this); m_units.append(u); } QCOMPARE(m_manager->adapters().count(), 1); QCOMPARE(m_manager->devices().count(), 4); } void BatteryTest::cleanupTestCase() { for (const BatteryUnit &unit : m_units) { delete unit.dbusBattery; } delete m_manager; FakeBluez::stop(); } void BatteryTest::getPropertiesTest() { for (const BatteryUnit &unit : m_units) { QCOMPARE(unit.device->battery()->percentage(), unit.dbusBattery->percentage()); } } QTEST_MAIN(BatteryTest) diff --git a/autotests/batterytest.h b/autotests/batterytest.h index f9f73dc..8d23861 100644 --- a/autotests/batterytest.h +++ b/autotests/batterytest.h @@ -1,56 +1,42 @@ /* - * Copyright (C) 2019 Kai Uwe Broulik + * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BATTERYTEST_H #define BATTERYTEST_H #include #include "bluezbattery1_tst.h" #include "manager.h" #include "device.h" #include "battery.h" class BatteryTest : public QObject { Q_OBJECT public: explicit BatteryTest(); private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void getPropertiesTest(); private: struct BatteryUnit { BluezQt::DevicePtr device; org::bluez::Battery1 *dbusBattery; }; BluezQt::Manager *m_manager; QList m_units; }; #endif // BATTERYTEST_H diff --git a/autotests/devicetest.cpp b/autotests/devicetest.cpp index 59e43e0..4b9b02f 100644 --- a/autotests/devicetest.cpp +++ b/autotests/devicetest.cpp @@ -1,283 +1,269 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "devicetest.h" #include "autotests.h" #include "pendingcall.h" #include "initmanagerjob.h" #include #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; DeviceTest::DeviceTest() : m_manager(nullptr) { Autotests::registerMetatypes(); } void DeviceTest::initTestCase() { QDBusConnection connection = QDBusConnection::sessionBus(); QString service = QStringLiteral("org.kde.bluezqt.fakebluez"); bluezqt_initFakeBluezTestRun(); FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapters QDBusObjectPath adapter1 = QDBusObjectPath(QStringLiteral("/org/bluez/hci0")); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter1); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); QDBusObjectPath adapter2 = QDBusObjectPath(QStringLiteral("/org/bluez/hci1")); adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter2); adapterProps[QStringLiteral("Address")] = QStringLiteral("2E:3A:C3:BC:85:7C"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter2"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); // Create devices QVariantMap deviceProps; deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci0/dev_40_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci0")); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); deviceProps[QStringLiteral("Alias")] = QStringLiteral("TestAlias"); deviceProps[QStringLiteral("Icon")] = QStringLiteral("phone"); deviceProps[QStringLiteral("Class")] = QVariant::fromValue(quint32(101)); deviceProps[QStringLiteral("Appearance")] = QVariant::fromValue(quint16(25)); deviceProps[QStringLiteral("UUIDs")] = QStringList(); deviceProps[QStringLiteral("Paired")] = false; deviceProps[QStringLiteral("Connected")] = false; deviceProps[QStringLiteral("Trusted")] = false; deviceProps[QStringLiteral("Blocked")] = false; deviceProps[QStringLiteral("LegacyPairing")] = false; deviceProps[QStringLiteral("RSSI")] = QVariant::fromValue(qint16(20)); deviceProps[QStringLiteral("Modalias")] = QStringLiteral("bluetooth:v001Dp1200d1236"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci1/dev_50_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci1")); deviceProps[QStringLiteral("Address")] = QStringLiteral("50:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice2"); deviceProps[QStringLiteral("Alias")] = QStringLiteral("TestAlias2"); deviceProps[QStringLiteral("Icon")] = QStringLiteral("joypad"); deviceProps[QStringLiteral("Class")] = QVariant::fromValue(quint32(201)); deviceProps[QStringLiteral("Appearance")] = QVariant::fromValue(quint16(32)); deviceProps[QStringLiteral("UUIDs")] = QStringList(); deviceProps[QStringLiteral("Paired")] = true; deviceProps[QStringLiteral("Connected")] = false; deviceProps[QStringLiteral("Trusted")] = true; deviceProps[QStringLiteral("Blocked")] = false; deviceProps[QStringLiteral("LegacyPairing")] = false; deviceProps[QStringLiteral("RSSI")] = QVariant::fromValue(qint16(-15)); deviceProps[QStringLiteral("Modalias")] = QStringLiteral("bluetooth:v001Dp1100d1236"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); m_manager = new Manager(); InitManagerJob *initJob = m_manager->init(); initJob->exec(); QVERIFY(!initJob->error()); for (const AdapterPtr &adapter : m_manager->adapters()) { QVERIFY(!adapter->ubi().isEmpty()); for (const DevicePtr &device : adapter->devices()) { QVERIFY(!device->ubi().isEmpty()); DeviceUnit u; u.device = device; u.dbusDevice = new org::bluez::Device1(service, device->ubi(), connection, this); u.dbusProperties = new org::freedesktop::DBus::Properties(service, device->ubi(), connection, this); m_units.append(u); } } QCOMPARE(m_manager->adapters().count(), 2); QCOMPARE(m_manager->devices().count(), 2); } void DeviceTest::cleanupTestCase() { for (const DeviceUnit &unit : m_units) { delete unit.dbusDevice; delete unit.dbusProperties; } delete m_manager; FakeBluez::stop(); } static void compareUuids(const QStringList &actual, const QStringList &expected) { QCOMPARE(actual.size(), expected.size()); for (int i = 0; i < actual.size(); ++i) { QCOMPARE(actual.at(i).toUpper(), expected.at(i).toUpper()); } } void DeviceTest::getPropertiesTest() { for (const DeviceUnit &unit : m_units) { QCOMPARE(unit.device->ubi(), unit.dbusDevice->path()); QCOMPARE(unit.device->address(), unit.dbusDevice->address()); QCOMPARE(unit.device->name(), unit.dbusDevice->alias()); QCOMPARE(unit.device->remoteName(), unit.dbusDevice->name()); QCOMPARE(unit.device->deviceClass(), unit.dbusDevice->deviceClass()); QCOMPARE(unit.device->appearance(), unit.dbusDevice->appearance()); QCOMPARE(unit.device->icon(), deviceIcon(unit.dbusDevice)); QCOMPARE(unit.device->isPaired(), unit.dbusDevice->paired()); QCOMPARE(unit.device->isTrusted(), unit.dbusDevice->trusted()); QCOMPARE(unit.device->isBlocked(), unit.dbusDevice->blocked()); QCOMPARE(unit.device->hasLegacyPairing(), unit.dbusDevice->legacyPairing()); QCOMPARE(unit.device->rssi(), deviceRssi(unit.dbusDevice)); QCOMPARE(unit.device->isConnected(), unit.dbusDevice->connected()); QCOMPARE(unit.device->modalias(), unit.dbusDevice->modalias()); QCOMPARE(unit.device->adapter()->ubi(), unit.dbusDevice->adapter().path()); compareUuids(unit.device->uuids(), unit.dbusDevice->uUIDs()); } } void DeviceTest::setAliasTest() { for (const DeviceUnit &unit : m_units) { QSignalSpy deviceSpy(unit.device.data(), SIGNAL(nameChanged(QString))); QSignalSpy dbusSpy(unit.dbusProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList))); QString value = unit.device->name() + QLatin1String("_tst_alias"); unit.device->setName(value); QTRY_COMPARE(deviceSpy.count(), 1); QList arguments = deviceSpy.takeFirst(); QCOMPARE(arguments.at(0).toString(), value); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("Alias"), value); QCOMPARE(unit.device->name(), value); QCOMPARE(unit.dbusDevice->alias(), value); } } void DeviceTest::setTrustedTest() { for (const DeviceUnit &unit : m_units) { QSignalSpy deviceSpy(unit.device.data(), SIGNAL(trustedChanged(bool))); QSignalSpy dbusSpy(unit.dbusProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList))); bool value = !unit.device->isTrusted(); unit.device->setTrusted(value); QTRY_COMPARE(deviceSpy.count(), 1); QList arguments = deviceSpy.takeFirst(); QCOMPARE(arguments.at(0).toBool(), value); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("Trusted"), value); QCOMPARE(unit.device->isTrusted(), value); QCOMPARE(unit.dbusDevice->trusted(), value); } } void DeviceTest::setBlockedTest() { for (const DeviceUnit &unit : m_units) { QSignalSpy deviceSpy(unit.device.data(), SIGNAL(blockedChanged(bool))); QSignalSpy dbusSpy(unit.dbusProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList))); bool value = !unit.device->isBlocked(); unit.device->setBlocked(value); QTRY_COMPARE(deviceSpy.count(), 1); QList arguments = deviceSpy.takeFirst(); QCOMPARE(arguments.at(0).toBool(), value); Autotests::verifyPropertiesChangedSignal(dbusSpy, QStringLiteral("Blocked"), value); QCOMPARE(unit.device->isBlocked(), value); QCOMPARE(unit.dbusDevice->blocked(), value); } } void DeviceTest::deviceRemovedTest() { for (const DeviceUnit &unit : m_units) { QSignalSpy managerSpy(m_manager, SIGNAL(deviceRemoved(DevicePtr))); QSignalSpy adapterSpy(unit.device->adapter().data(), SIGNAL(deviceRemoved(DevicePtr))); QSignalSpy deviceSpy(unit.device.data(), SIGNAL(deviceRemoved(DevicePtr))); QVariantMap properties; properties[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(unit.device->ubi())); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("remove-device"), properties); QTRY_COMPARE(managerSpy.count(), 1); QTRY_COMPARE(adapterSpy.count(), 1); QTRY_COMPARE(deviceSpy.count(), 1); QCOMPARE(managerSpy.at(0).at(0).value(), unit.device); QCOMPARE(adapterSpy.at(0).at(0).value(), unit.device); QCOMPARE(deviceSpy.at(0).at(0).value(), unit.device); } } QString DeviceTest::deviceIcon(org::bluez::Device1 *device) const { quint32 classNum = device->deviceClass(); switch ((classNum & 0x1f00) >> 8) { case 0x04: switch ((classNum & 0xfc) >> 2) { case 0x01: case 0x02: return QStringLiteral("audio-headset"); case 0x06: return QStringLiteral("audio-headphones"); } } return device->icon(); } qint16 DeviceTest::deviceRssi(org::bluez::Device1 *device) const { qint16 rssi = device->rSSI(); if (!rssi) { rssi = -32768; } return rssi; } QTEST_MAIN(DeviceTest) diff --git a/autotests/devicetest.h b/autotests/devicetest.h index 160ff77..79272e0 100644 --- a/autotests/devicetest.h +++ b/autotests/devicetest.h @@ -1,67 +1,53 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DEVICETEST_H #define DEVICETEST_H #include #include #include "bluezdevice1_tst.h" #include "dbusproperties_tst.h" #include "manager.h" #include "adapter.h" #include "device.h" class DeviceTest : public QObject { Q_OBJECT public: explicit DeviceTest(); private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void getPropertiesTest(); void setAliasTest(); void setTrustedTest(); void setBlockedTest(); void deviceRemovedTest(); private: struct DeviceUnit { BluezQt::DevicePtr device; org::bluez::Device1 *dbusDevice; org::freedesktop::DBus::Properties *dbusProperties; }; QString deviceIcon(org::bluez::Device1 *device) const; qint16 deviceRssi(org::bluez::Device1 *device) const; BluezQt::Manager *m_manager; QList m_units; }; #endif // DEVICETEST_H diff --git a/autotests/fakebluez/adapterinterface.cpp b/autotests/fakebluez/adapterinterface.cpp index 736c7d9..91d11b5 100644 --- a/autotests/fakebluez/adapterinterface.cpp +++ b/autotests/fakebluez/adapterinterface.cpp @@ -1,200 +1,186 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "adapterinterface.h" #include "objectmanager.h" #include "mediainterface.h" #include "leadvertisingmanagerinterface.h" #include "gattmanagerinterface.h" #include #include // AdapterObject AdapterObject::AdapterObject(const QDBusObjectPath &path, QObject *parent) : QObject(parent) { QDBusConnection::sessionBus().registerObject(path.path(), this); } // AdapterInterface AdapterInterface::AdapterInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent) : QDBusAbstractAdaptor(parent) { setPath(path); setObjectParent(parent); setProperties(properties); setName(QStringLiteral("org.bluez.Adapter1")); // Alias needs special handling setAlias(properties.value(QStringLiteral("Alias")).toString()); // Media interface m_media = new MediaInterface(path, parent); ObjectManager *manager = ObjectManager::self(); manager->addObject(m_media); // LEAdvertisingManager interface m_leAdvertisingManager = new LEAdvertisingManagerInterface(path, parent); manager->addObject(m_leAdvertisingManager); // GattManager interface m_gattManager = new GattManagerInterface(path, parent); manager->addObject(m_gattManager); } QString AdapterInterface::address() const { return Object::property(QStringLiteral("Address")).toString(); } QString AdapterInterface::name() const { return Object::property(QStringLiteral("Name")).toString(); } QString AdapterInterface::alias() const { return Object::property(QStringLiteral("Alias")).toString(); } void AdapterInterface::setAlias(const QString &alias) { Object::changeProperty(QStringLiteral("Alias"), alias.isEmpty() ? name() : alias); } quint32 AdapterInterface::adapterClass() const { return Object::property(QStringLiteral("Class")).toUInt(); } bool AdapterInterface::powered() const { return Object::property(QStringLiteral("Powered")).toBool(); } void AdapterInterface::setPowered(bool powered) { Object::changeProperty(QStringLiteral("Powered"), powered); } bool AdapterInterface::discoverable() const { return Object::property(QStringLiteral("Discoverable")).toBool(); } void AdapterInterface::setDiscoverable(bool discoverable) { Object::changeProperty(QStringLiteral("Discoverable"), discoverable); if (discoverable && discoverableTimeout() != 0) { QTimer::singleShot(discoverableTimeout() * 1000, this, SLOT(resetDiscoverable())); } } bool AdapterInterface::pairable() const { return Object::property(QStringLiteral("Pairable")).toBool(); } void AdapterInterface::setPairable(bool pairable) { Object::changeProperty(QStringLiteral("Pairable"), pairable); if (pairable && pairableTimeout() != 0) { QTimer::singleShot(pairableTimeout() * 1000, this, SLOT(resetPairable())); } } quint32 AdapterInterface::pairableTimeout() const { return Object::property(QStringLiteral("PairableTimeout")).toUInt(); } void AdapterInterface::setPairableTimeout(quint32 timeout) { Object::changeProperty(QStringLiteral("PairableTimeout"), timeout); } quint32 AdapterInterface::discoverableTimeout() const { return Object::property(QStringLiteral("DiscoverableTimeout")).toUInt(); } void AdapterInterface::setDiscoverableTimeout(quint32 timeout) { Object::changeProperty(QStringLiteral("DiscoverableTimeout"), timeout); } bool AdapterInterface::discovering() const { return Object::property(QStringLiteral("Discovering")).toBool(); } QStringList AdapterInterface::uuids() const { return Object::property(QStringLiteral("UUIDs")).toStringList(); } QString AdapterInterface::modalias() const { return Object::property(QStringLiteral("Modalias")).toString(); } MediaInterface *AdapterInterface::media() const { return m_media; } LEAdvertisingManagerInterface *AdapterInterface::leAdvertisingManager() const { return m_leAdvertisingManager; } GattManagerInterface *AdapterInterface::gattManager() const { return m_gattManager; } void AdapterInterface::StartDiscovery() { Object::changeProperty(QStringLiteral("Discovering"), true); } void AdapterInterface::StopDiscovery() { Object::changeProperty(QStringLiteral("Discovering"), false); } void AdapterInterface::RemoveDevice(const QDBusObjectPath &device) { ObjectManager *manager = ObjectManager::self(); manager->removeObject(manager->objectByPath(device)); } void AdapterInterface::resetPairable() { setPairable(false); } void AdapterInterface::resetDiscoverable() { setDiscoverable(false); } diff --git a/autotests/fakebluez/adapterinterface.h b/autotests/fakebluez/adapterinterface.h index 897b31e..961bbb9 100644 --- a/autotests/fakebluez/adapterinterface.h +++ b/autotests/fakebluez/adapterinterface.h @@ -1,111 +1,97 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef ADAPTERINTERFACE_H #define ADAPTERINTERFACE_H #include "object.h" #include class QDBusObjectPath; class GattManagerInterface; class LEAdvertisingManagerInterface; class MediaInterface; class AdapterObject : public QObject { public: explicit AdapterObject(const QDBusObjectPath &path, QObject *parent = nullptr); }; class AdapterInterface : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.Adapter1") Q_PROPERTY(QString Address READ address) Q_PROPERTY(QString Name READ name) Q_PROPERTY(QString Alias READ alias WRITE setAlias) Q_PROPERTY(quint32 Class READ adapterClass) Q_PROPERTY(bool Powered READ powered WRITE setPowered) Q_PROPERTY(bool Discoverable READ discoverable WRITE setDiscoverable) Q_PROPERTY(bool Pairable READ pairable WRITE setPairable) Q_PROPERTY(quint32 PairableTimeout READ pairableTimeout WRITE setPairableTimeout) Q_PROPERTY(quint32 DiscoverableTimeout READ discoverableTimeout WRITE setDiscoverableTimeout) Q_PROPERTY(bool Discovering READ discovering) Q_PROPERTY(QStringList UUIDs READ uuids) Q_PROPERTY(QString Modalias READ modalias) public: explicit AdapterInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent = nullptr); QString address() const; QString name() const; QString alias() const; void setAlias(const QString &alias); quint32 adapterClass() const; bool powered() const; void setPowered(bool powered); bool discoverable() const; void setDiscoverable(bool discoverable); bool pairable() const; void setPairable(bool pairable); quint32 pairableTimeout() const; void setPairableTimeout(quint32 timeout); quint32 discoverableTimeout() const; void setDiscoverableTimeout(quint32 timeout); bool discovering() const; QStringList uuids() const; QString modalias() const; MediaInterface *media() const; LEAdvertisingManagerInterface *leAdvertisingManager() const; GattManagerInterface *gattManager() const; public Q_SLOTS: void StartDiscovery(); void StopDiscovery(); void RemoveDevice(const QDBusObjectPath &device); private Q_SLOTS: void resetPairable(); void resetDiscoverable(); private: MediaInterface *m_media; LEAdvertisingManagerInterface *m_leAdvertisingManager; GattManagerInterface *m_gattManager; }; #endif // ADAPTERINTERFACE_H diff --git a/autotests/fakebluez/agentmanager.cpp b/autotests/fakebluez/agentmanager.cpp index ea4cc00..32fc965 100644 --- a/autotests/fakebluez/agentmanager.cpp +++ b/autotests/fakebluez/agentmanager.cpp @@ -1,177 +1,163 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "agentmanager.h" #include #include #include #include AgentManager::AgentManager(QObject *parent) : QDBusAbstractAdaptor(parent) { setName(QStringLiteral("org.bluez.AgentManager1")); setPath(QDBusObjectPath(QStringLiteral("/org/bluez"))); } void AgentManager::runAction(const QString &actionName, const QVariantMap &properties) { if (actionName == QLatin1String("request-pincode")) { runRequestPinCodeAction(properties); } else if (actionName == QLatin1String("display-pincode")) { runDisplayPinCodeAction(properties); } else if (actionName == QLatin1String("request-passkey")) { runRequestPasskeyAction(properties); } else if (actionName == QLatin1String("display-passkey")) { runDisplayPasskeyAction(properties); } else if (actionName == QLatin1String("request-confirmation")) { runRequestConfirmationAction(properties); } else if (actionName == QLatin1String("request-authorization")) { runRequestAuthorizationAction(properties); } else if (actionName == QLatin1String("authorize-service")) { runAuthorizeServiceAction(properties); } else if (actionName == QLatin1String("cancel")) { runCancelAction(); } else if (actionName == QLatin1String("release")) { runReleaseAction(); } } void AgentManager::RegisterAgent(const QDBusObjectPath &path, const QString &capability, const QDBusMessage &msg) { m_agent = path; m_service = msg.service(); m_capability = capability; } void AgentManager::UnregisterAgent(const QDBusObjectPath &path, const QDBusMessage &msg) { if (m_agent == path && m_service == msg.service()) { m_agent = QDBusObjectPath(); m_service.clear(); m_capability.clear(); } } void AgentManager::RequestDefaultAgent(const QDBusObjectPath &path) { qDebug() << "RequestDefaultAgent" << path.path(); } void AgentManager::runRequestPinCodeAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("RequestPinCode")); call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value()); QDBusConnection::sessionBus().asyncCall(call); } void AgentManager::runDisplayPinCodeAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("DisplayPinCode")); call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value()); call << properties.value(QStringLiteral("PinCode")); QDBusConnection::sessionBus().asyncCall(call); } void AgentManager::runRequestPasskeyAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("RequestPasskey")); call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value()); QDBusConnection::sessionBus().asyncCall(call); } void AgentManager::runDisplayPasskeyAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("DisplayPasskey")); call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value()); call << properties.value(QStringLiteral("Passkey")); call << properties.value(QStringLiteral("EnteredPasskey")); QDBusConnection::sessionBus().asyncCall(call); } void AgentManager::runRequestConfirmationAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("RequestConfirmation")); call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value()); call << properties.value(QStringLiteral("Passkey")); QDBusConnection::sessionBus().asyncCall(call); } void AgentManager::runRequestAuthorizationAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("RequestAuthorization")); call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value()); QDBusConnection::sessionBus().asyncCall(call); } void AgentManager::runAuthorizeServiceAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("AuthorizeService")); call << QVariant::fromValue(properties.value(QStringLiteral("Device")).value()); call << properties.value(QStringLiteral("UUID")); QDBusConnection::sessionBus().asyncCall(call); } void AgentManager::runCancelAction() { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("Cancel")); QDBusConnection::sessionBus().asyncCall(call); } void AgentManager::runReleaseAction() { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.Agent1"), QStringLiteral("Release")); QDBusConnection::sessionBus().asyncCall(call); } diff --git a/autotests/fakebluez/agentmanager.h b/autotests/fakebluez/agentmanager.h index d7f8ab9..94a4ce2 100644 --- a/autotests/fakebluez/agentmanager.h +++ b/autotests/fakebluez/agentmanager.h @@ -1,61 +1,47 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef AGENTMANAGER_H #define AGENTMANAGER_H #include "object.h" #include class QDBusMessage; class AgentManager : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.AgentManager1") public: explicit AgentManager(QObject *parent = nullptr); void runAction(const QString &actionName, const QVariantMap &properties); public Q_SLOTS: void RegisterAgent(const QDBusObjectPath &path, const QString &capability, const QDBusMessage &msg); void UnregisterAgent(const QDBusObjectPath &path, const QDBusMessage &msg); void RequestDefaultAgent(const QDBusObjectPath &path); private: void runRequestPinCodeAction(const QVariantMap &properties); void runDisplayPinCodeAction(const QVariantMap &properties); void runRequestPasskeyAction(const QVariantMap &properties); void runDisplayPasskeyAction(const QVariantMap &properties); void runRequestConfirmationAction(const QVariantMap &properties); void runRequestAuthorizationAction(const QVariantMap &properties); void runAuthorizeServiceAction(const QVariantMap &properties); void runCancelAction(); void runReleaseAction(); QDBusObjectPath m_agent; QString m_service; QString m_capability; }; #endif // AGENTMANAGER_H diff --git a/autotests/fakebluez/batteryinterface.cpp b/autotests/fakebluez/batteryinterface.cpp index 5e892fb..1bb0867 100644 --- a/autotests/fakebluez/batteryinterface.cpp +++ b/autotests/fakebluez/batteryinterface.cpp @@ -1,45 +1,31 @@ /* - * Copyright (C) 2019 Kai Uwe Broulik + * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "batteryinterface.h" #include // BatteryObject BatteryObject::BatteryObject(const QDBusObjectPath &path, QObject *parent) : QObject(parent) { QDBusConnection::sessionBus().registerObject(path.path(), this); } // BatteryInterface BatteryInterface::BatteryInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent) : QDBusAbstractAdaptor(parent) { setPath(path); setObjectParent(parent); setProperties(properties); setName(QStringLiteral("org.bluez.Battery1")); } uchar BatteryInterface::percentage() const { return Object::property(QStringLiteral("Percentage")).value(); } diff --git a/autotests/fakebluez/batteryinterface.h b/autotests/fakebluez/batteryinterface.h index 19c1302..47d0704 100644 --- a/autotests/fakebluez/batteryinterface.h +++ b/autotests/fakebluez/batteryinterface.h @@ -1,49 +1,35 @@ /* - * Copyright (C) 2019 Kai Uwe Broulik + * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BATTERYINTERFACE_H #define BATTERYINTERFACE_H #include "object.h" #include class QDBusMessage; class QDBusObjectPath; class BatteryObject : public QObject { public: explicit BatteryObject(const QDBusObjectPath &path, QObject *parent = nullptr); }; class BatteryInterface : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.Battery1") Q_PROPERTY(uchar Percentage READ percentage) public: explicit BatteryInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent = nullptr); uchar percentage() const; }; #endif // BATTERYINTERFACE_H diff --git a/autotests/fakebluez/deviceinterface.cpp b/autotests/fakebluez/deviceinterface.cpp index ce94fea..152d81c 100644 --- a/autotests/fakebluez/deviceinterface.cpp +++ b/autotests/fakebluez/deviceinterface.cpp @@ -1,312 +1,298 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "deviceinterface.h" #include "objectmanager.h" #include "batteryinterface.h" #include "mediaplayerinterface.h" #include "mediatransportinterface.h" #include "inputinterface.h" #include #include #include static const QLatin1String MediaPlayerUuid ("0000110E-0000-1000-8000-00805F9B34FB"); static const QLatin1String MediaTransportUuid ("0000110B-0000-1000-8000-00805F9B34FB"); // DeviceObject DeviceObject::DeviceObject(const QDBusObjectPath &path, QObject *parent) : QObject(parent) { QDBusConnection::sessionBus().registerObject(path.path(), this); } // DeviceInterface DeviceInterface::DeviceInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent) : QDBusAbstractAdaptor(parent) { setPath(path); setObjectParent(parent); setProperties(properties); setName(QStringLiteral("org.bluez.Device1")); // Alias needs special handling setAlias(properties.value(QStringLiteral("Alias")).toString()); // Create Battery1 if (properties.contains(QStringLiteral("Battery"))) { const QVariantMap &inputProps = qdbus_cast(properties.value(QStringLiteral("Battery"))); BatteryInterface *input = new BatteryInterface(path, inputProps, parent); ObjectManager *manager = ObjectManager::self(); manager->addObject(input); QVariantMap props = properties; props.remove(QStringLiteral("Battery")); setProperties(props); } // Create Input1 if (properties.contains(QStringLiteral("Input"))) { const QVariantMap &inputProps = qdbus_cast(properties.value(QStringLiteral("Input"))); InputInterface *input = new InputInterface(path, inputProps, parent); ObjectManager *manager = ObjectManager::self(); manager->addObject(input); QVariantMap props = properties; props.remove(QStringLiteral("Input")); setProperties(props); } } QString DeviceInterface::address() const { return Object::property(QStringLiteral("Address")).toString(); } QString DeviceInterface::name() const { return Object::property(QStringLiteral("Name")).toString(); } QString DeviceInterface::alias() const { return Object::property(QStringLiteral("Alias")).toString(); } void DeviceInterface::setAlias(const QString &alias) { Object::changeProperty(QStringLiteral("Alias"), alias.isEmpty() ? name() : alias); } QString DeviceInterface::icon() const { return Object::property(QStringLiteral("Icon")).toString(); } quint32 DeviceInterface::deviceClass() const { return Object::property(QStringLiteral("Class")).toUInt(); } quint16 DeviceInterface::appearance() const { return Object::property(QStringLiteral("Appearance")).toUInt(); } bool DeviceInterface::paired() const { return Object::property(QStringLiteral("Paired")).toBool(); } bool DeviceInterface::connected() const { return Object::property(QStringLiteral("Connected")).toBool(); } bool DeviceInterface::trusted() const { return Object::property(QStringLiteral("Trusted")).toBool(); } void DeviceInterface::setTrusted(bool trusted) { Object::changeProperty(QStringLiteral("Trusted"), trusted); } bool DeviceInterface::blocked() const { return Object::property(QStringLiteral("Blocked")).toBool(); } void DeviceInterface::setBlocked(bool blocked) { Object::changeProperty(QStringLiteral("Blocked"), blocked); } QDBusObjectPath DeviceInterface::adapter() const { return Object::property(QStringLiteral("Adapter")).value(); } bool DeviceInterface::legacyPairing() const { return Object::property(QStringLiteral("LegacyPairing")).toBool(); } qint16 DeviceInterface::rssi() const { return Object::property(QStringLiteral("RSSI")).toInt(); } QStringList DeviceInterface::uuids() const { return Object::property(QStringLiteral("UUIDs")).toStringList(); } QString DeviceInterface::modalias() const { return Object::property(QStringLiteral("Modalias")).toString(); } MediaTransportInterface *DeviceInterface::mediaTransport() const { return m_mediaTransport; } void DeviceInterface::Connect() { if (uuids().contains(MediaPlayerUuid)) { connectMediaPlayer(); } if (uuids().contains(MediaTransportUuid)) { connectMediaTransport(); } Object::changeProperty(QStringLiteral("Connected"), true); } void DeviceInterface::Disconnect() { if (uuids().contains(MediaPlayerUuid)) { disconnectMediaPlayer(); } if (uuids().contains(MediaTransportUuid)) { disconnectMediaTransport(); } Object::changeProperty(QStringLiteral("Connected"), false); } void DeviceInterface::ConnectProfile(const QString &uuid, const QDBusMessage &msg) { if (!uuids().contains(uuid)) { QDBusMessage error = msg.createErrorReply(QStringLiteral("org.bluez.Error.DoesNotExist"), QStringLiteral("Profile UUID not supported")); QDBusConnection::sessionBus().send(error); return; } if (m_connectedUuids.contains(uuid)) { QDBusMessage error = msg.createErrorReply(QStringLiteral("org.bluez.Error.AlreadyConnected"), QStringLiteral("Profile already connected")); QDBusConnection::sessionBus().send(error); return; } if (uuid == MediaPlayerUuid) { connectMediaPlayer(); } else if (uuid == MediaTransportUuid) { connectMediaTransport(); } else { Q_UNIMPLEMENTED(); } Object::changeProperty(QStringLiteral("Connected"), true); } void DeviceInterface::DisconnectProfile(const QString &uuid, const QDBusMessage &msg) { if (!uuids().contains(uuid)) { QDBusMessage error = msg.createErrorReply(QStringLiteral("org.bluez.Error.DoesNotExist"), QStringLiteral("Profile UUID not supported")); QDBusConnection::sessionBus().send(error); return; } if (!m_connectedUuids.contains(uuid)) { QDBusMessage error = msg.createErrorReply(QStringLiteral("org.bluez.Error.NotConnected"), QStringLiteral("Profile not connected")); QDBusConnection::sessionBus().send(error); return; } if (uuid == MediaPlayerUuid) { disconnectMediaPlayer(); } else if (uuid == MediaTransportUuid) { disconnectMediaTransport(); } else { Q_UNIMPLEMENTED(); } Object::changeProperty(QStringLiteral("Connected"), false); } void DeviceInterface::Pair() { Q_UNIMPLEMENTED(); } void DeviceInterface::CancelPairing() { Q_UNIMPLEMENTED(); } void DeviceInterface::connectMediaPlayer() { const QVariantMap &properties = qdbus_cast(Object::property(QStringLiteral("MediaPlayer"))); const QDBusObjectPath &path = properties.value(QStringLiteral("Path")).value(); QVariantMap props = properties; props.remove(QStringLiteral("Path")); MediaPlayerObject *mediaPlayerObj = new MediaPlayerObject(path); m_mediaPlayer = new MediaPlayerInterface(path, props, mediaPlayerObj); ObjectManager *manager = ObjectManager::self(); manager->addObject(m_mediaPlayer); manager->addAutoDeleteObject(mediaPlayerObj); m_connectedUuids.append(MediaPlayerUuid); } void DeviceInterface::disconnectMediaPlayer() { ObjectManager *manager = ObjectManager::self(); manager->removeObject(m_mediaPlayer); m_connectedUuids.removeOne(MediaPlayerUuid); m_mediaPlayer = nullptr; } void DeviceInterface::connectMediaTransport() { const QVariantMap &properties = qdbus_cast(Object::property(QStringLiteral("MediaTransport"))); const QDBusObjectPath &path = properties.value(QStringLiteral("Path")).value(); QVariantMap props = properties; props.remove(QStringLiteral("Path")); MediaTransportObject *transportObj = new MediaTransportObject(path); m_mediaTransport = new MediaTransportInterface(path, props, transportObj); ObjectManager *manager = ObjectManager::self(); manager->addObject(m_mediaTransport); manager->addAutoDeleteObject(transportObj); m_connectedUuids.append(MediaTransportUuid); } void DeviceInterface::disconnectMediaTransport() { ObjectManager *manager = ObjectManager::self(); manager->removeObject(m_mediaTransport); m_connectedUuids.removeOne(MediaTransportUuid); m_mediaTransport = nullptr; } diff --git a/autotests/fakebluez/deviceinterface.h b/autotests/fakebluez/deviceinterface.h index acf3c43..d3dd781 100644 --- a/autotests/fakebluez/deviceinterface.h +++ b/autotests/fakebluez/deviceinterface.h @@ -1,118 +1,104 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DEVICEINTERFACE_H #define DEVICEINTERFACE_H #include "object.h" #include #include class QDBusMessage; class QDBusObjectPath; class MediaTransportInterface; class DeviceObject : public QObject { public: explicit DeviceObject(const QDBusObjectPath &path, QObject *parent = nullptr); }; class DeviceInterface : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.Device1") Q_PROPERTY(QString Address READ address) Q_PROPERTY(QString Name READ name) Q_PROPERTY(QString Alias READ alias WRITE setAlias) Q_PROPERTY(QString Icon READ icon) Q_PROPERTY(quint32 Class READ deviceClass) Q_PROPERTY(quint16 Appearance READ appearance) Q_PROPERTY(bool Paired READ paired) Q_PROPERTY(bool Connected READ connected) Q_PROPERTY(bool Trusted READ trusted WRITE setTrusted) Q_PROPERTY(bool Blocked READ blocked WRITE setBlocked) Q_PROPERTY(QDBusObjectPath Adapter READ adapter) Q_PROPERTY(bool LegacyPairing READ legacyPairing) Q_PROPERTY(qint16 RSSI READ rssi) Q_PROPERTY(QStringList UUIDs READ uuids) Q_PROPERTY(QString Modalias READ modalias) public: explicit DeviceInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent = nullptr); QString address() const; QString name() const; QString alias() const; void setAlias(const QString &alias); QString icon() const; quint32 deviceClass() const; quint16 appearance() const; bool paired() const; bool connected() const; bool trusted() const; void setTrusted(bool trusted); bool blocked() const; void setBlocked(bool blocked); QDBusObjectPath adapter() const; bool legacyPairing() const; qint16 rssi() const; QStringList uuids() const; QString modalias() const; MediaTransportInterface *mediaTransport() const; public Q_SLOTS: void Connect(); void Disconnect(); void ConnectProfile(const QString &uuid, const QDBusMessage &msg); void DisconnectProfile(const QString &uuid, const QDBusMessage &msg); void Pair(); void CancelPairing(); private: void connectMediaPlayer(); void disconnectMediaPlayer(); void connectMediaTransport(); void disconnectMediaTransport(); QStringList m_connectedUuids; Object *m_mediaPlayer = nullptr; MediaTransportInterface *m_mediaTransport = nullptr; friend class DeviceManager; }; #endif // DEVICEINTERFACE_H diff --git a/autotests/fakebluez/devicemanager.cpp b/autotests/fakebluez/devicemanager.cpp index 9b763d3..632b254 100644 --- a/autotests/fakebluez/devicemanager.cpp +++ b/autotests/fakebluez/devicemanager.cpp @@ -1,177 +1,163 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "devicemanager.h" #include "objectmanager.h" #include "adapterinterface.h" #include "deviceinterface.h" #include "mediainterface.h" #include "mediatransportinterface.h" #include "leadvertisingmanagerinterface.h" #include "gattmanagerinterface.h" DeviceManager::DeviceManager(ObjectManager *parent) : QObject(parent) , m_objectManager(parent) { } void DeviceManager::runAction(const QString &actionName, const QVariantMap &properties) { if (actionName == QLatin1String("create-adapter")) { runCreateAdapterAction(properties); } else if (actionName == QLatin1String("create-device")) { runCreateDeviceAction(properties); } else if (actionName == QLatin1String("remove-adapter")) { runRemoveAdapterAction(properties); } else if (actionName == QLatin1String("remove-device")) { runRemoveDeviceAction(properties); } else if (actionName == QLatin1String("change-adapter-property")) { runChangeAdapterProperty(properties); } else if (actionName == QLatin1String("change-device-property")) { runChangeDeviceProperty(properties); } else if (actionName.startsWith(QLatin1String("adapter-media:"))) { runAdapterMediaAction(actionName.mid(14), properties); } else if (actionName.startsWith(QLatin1String("adapter-leadvertisingmanager:"))) { runAdapterLeAdvertisingManagerAction(actionName.mid(29), properties); } else if (actionName.startsWith(QLatin1String("adapter-gattmanager:"))) { runAdapterGattManagerAction(actionName.mid(20), properties); } else if (actionName == QLatin1String("bug377405")) { runBug377405(); } else if (actionName == QLatin1String("bug403289")) { runBug403289(properties); } } void DeviceManager::runCreateAdapterAction(const QVariantMap &properties) { const QDBusObjectPath &path = properties.value(QStringLiteral("Path")).value(); QVariantMap props = properties; props.remove(QStringLiteral("Path")); AdapterObject *adapterObj = new AdapterObject(path); AdapterInterface *adapter = new AdapterInterface(path, props, adapterObj); m_objectManager->addObject(adapter); m_objectManager->addAutoDeleteObject(adapterObj); } void DeviceManager::runCreateDeviceAction(const QVariantMap &properties) { const QDBusObjectPath &path = properties.value(QStringLiteral("Path")).value(); QVariantMap props = properties; props.remove(QStringLiteral("Path")); DeviceObject *deviceObj = new DeviceObject(path); DeviceInterface *device = new DeviceInterface(path, props, deviceObj); m_objectManager->addObject(device); m_objectManager->addAutoDeleteObject(deviceObj); } void DeviceManager::runRemoveAdapterAction(const QVariantMap &properties) { const QDBusObjectPath &path = properties.value(QStringLiteral("Path")).value(); m_objectManager->removeObject(m_objectManager->objectByPath(path)); } void DeviceManager::runRemoveDeviceAction(const QVariantMap &properties) { const QDBusObjectPath &path = properties.value(QStringLiteral("Path")).value(); m_objectManager->removeObject(m_objectManager->objectByPath(path)); } void DeviceManager::runChangeAdapterProperty(const QVariantMap &properties) { const QDBusObjectPath &path = properties.value(QStringLiteral("Path")).value(); Object *adapter = m_objectManager->objectByPath(path); if (!adapter || adapter->name() != QLatin1String("org.bluez.Adapter1")) { return; } adapter->changeProperty(properties.value(QStringLiteral("Name")).toString(), properties.value(QStringLiteral("Value"))); } void DeviceManager::runChangeDeviceProperty(const QVariantMap &properties) { const QDBusObjectPath &path = properties.value(QStringLiteral("Path")).value(); Object *device = m_objectManager->objectByPath(path); if (!device || device->name() != QLatin1String("org.bluez.Device1")) { return; } device->changeProperty(properties.value(QStringLiteral("Name")).toString(), properties.value(QStringLiteral("Value"))); } void DeviceManager::runAdapterMediaAction(const QString action, const QVariantMap &properties) { const QDBusObjectPath &path = properties.value(QStringLiteral("AdapterPath")).value(); AdapterInterface *adapter = dynamic_cast(m_objectManager->objectByPath(path)); if (!adapter) { return; } adapter->media()->runAction(action, properties); } void DeviceManager::runAdapterLeAdvertisingManagerAction(const QString action, const QVariantMap &properties) { const QDBusObjectPath &path = properties.value(QStringLiteral("AdapterPath")).value(); AdapterInterface *adapter = dynamic_cast(m_objectManager->objectByPath(path)); if (!adapter) { return; } adapter->leAdvertisingManager()->runAction(action, properties); } void DeviceManager::runAdapterGattManagerAction(const QString action, const QVariantMap &properties) { const QDBusObjectPath &path = properties.value(QStringLiteral("AdapterPath")).value(); AdapterInterface *adapter = dynamic_cast(m_objectManager->objectByPath(path)); if (!adapter) { return; } adapter->gattManager()->runAction(action, properties); } void DeviceManager::runBug377405() { QDBusObjectPath adapter1path = QDBusObjectPath(QStringLiteral("/org/bluez/hci0")); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); adapterProps[QStringLiteral("Powered")] = false; runCreateAdapterAction(adapterProps); QVariantMap properties; properties[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); properties[QStringLiteral("Name")] = QStringLiteral("Powered"); properties[QStringLiteral("Value")] = true; runChangeAdapterProperty(properties); } void DeviceManager::runBug403289(const QVariantMap &properties) { const QDBusObjectPath &path = properties.value(QStringLiteral("DevicePath")).value(); DeviceInterface *device = dynamic_cast(m_objectManager->objectByPath(path)); if (!device) { return; } device->connectMediaPlayer(); Q_EMIT m_objectManager->InterfacesRemoved(path, QStringList(QStringLiteral("org.bluez.MediaPlayer1"))); } diff --git a/autotests/fakebluez/devicemanager.h b/autotests/fakebluez/devicemanager.h index 915248e..6a2b487 100644 --- a/autotests/fakebluez/devicemanager.h +++ b/autotests/fakebluez/devicemanager.h @@ -1,54 +1,40 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DEVICEMANAGER_H #define DEVICEMANAGER_H #include class ObjectManager; class DeviceManager : public QObject { Q_OBJECT public: explicit DeviceManager(ObjectManager *parent = nullptr); void runAction(const QString &actionName, const QVariantMap &properties); private: void runCreateAdapterAction(const QVariantMap &properties); void runCreateDeviceAction(const QVariantMap &properties); void runRemoveAdapterAction(const QVariantMap &properties); void runRemoveDeviceAction(const QVariantMap &properties); void runChangeAdapterProperty(const QVariantMap &properties); void runChangeDeviceProperty(const QVariantMap &properties); void runAdapterMediaAction(const QString action, const QVariantMap &properties); void runAdapterLeAdvertisingManagerAction(const QString action, const QVariantMap &properties); void runAdapterGattManagerAction(const QString action, const QVariantMap &properties); void runBug377405(); void runBug403289(const QVariantMap &properties); ObjectManager *m_objectManager; }; #endif // DEVICEMANAGER_H diff --git a/autotests/fakebluez/fakebluez.cpp b/autotests/fakebluez/fakebluez.cpp index dc7c487..fe83bcd 100644 --- a/autotests/fakebluez/fakebluez.cpp +++ b/autotests/fakebluez/fakebluez.cpp @@ -1,216 +1,202 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "fakebluez.h" #include "testinterface.h" #include "objectmanager.h" #include "agentmanager.h" #include "profilemanager.h" #include "devicemanager.h" #include "obexagentmanager.h" #include "obexclient.h" #include #include #include // ObexObject class ObexObject : public QObject { public: explicit ObexObject(QObject *parent = nullptr) : QObject(parent) { QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/bluez/obex"), this); } }; // FakeBluez FakeBluez::FakeBluez(QObject *parent) : QObject(parent) , m_testInterface(new TestInterface(this)) , m_objectManager(nullptr) , m_agentManager(nullptr) , m_profileManager(nullptr) , m_deviceManager(nullptr) , m_obexObject(nullptr) , m_obexAgentManager(nullptr) , m_obexClient(nullptr) { QDBusConnection::sessionBus().registerObject(QStringLiteral("/"), this); } void FakeBluez::runTest(const QString &testName) { if (testName == QLatin1String("bluez-not-exporting-interfaces")) { runBluezNotExportingInterfacesTest(); } else if (testName == QLatin1String("bluez-empty-managed-objects")) { runBluezEmptyManagedObjectsTest(); } else if (testName == QLatin1String("bluez-no-adapters")) { runBluezNoAdaptersTest(); } else if (testName == QLatin1String("bluez-standard")) { runBluezStandardTest(); } if (testName == QLatin1String("obex-not-exporting-interfaces")) { runObexNotExportingInterfacesTest(); } else if (testName == QLatin1String("obex-empty-managed-objects")) { runObexEmptyManagedObjectsTest(); } else if (testName == QLatin1String("obex-no-client")) { runObexNoClientTest(); } else if (testName == QLatin1String("obex-no-agentmanager")) { runObexNoAgentManagerTest(); } else if (testName == QLatin1String("obex-standard")) { runObexStandardTest(); } if (!QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.bluezqt.fakebluez"))) { qWarning() << "Cannot register org.kde.bluezqt.fakebluez service!"; } } void FakeBluez::runAction(const QString &object, const QString &actionName, const QVariantMap &properties) { m_actionObject = object; m_actionName = actionName; m_actionProperties = properties; QTimer::singleShot(0, this, SLOT(doRunAction())); } void FakeBluez::doRunAction() { if (m_actionObject == QLatin1String("agentmanager")) { m_agentManager->runAction(m_actionName, m_actionProperties); } else if (m_actionObject == QLatin1String("devicemanager")) { m_deviceManager->runAction(m_actionName, m_actionProperties); } QTimer::singleShot(0, m_testInterface, SLOT(emitActionFinished())); } void FakeBluez::clear() { // Everything is parented to ObjectManager delete m_objectManager; m_objectManager = nullptr; } void FakeBluez::createObjectManager() { m_objectManager = new ObjectManager(this); } void FakeBluez::createAgentManager() { m_agentManager = new AgentManager(m_objectManager); m_objectManager->addObject(m_agentManager); } void FakeBluez::createProfileManager() { m_profileManager = new ProfileManager(m_objectManager); m_objectManager->addObject(m_profileManager); } void FakeBluez::createDeviceManager() { m_deviceManager = new DeviceManager(m_objectManager); } void FakeBluez::createObexObjectManager() { createObjectManager(); m_obexObject = new ObexObject(this); m_objectManager->addAutoDeleteObject(m_obexObject); } void FakeBluez::createObexAgentManager() { m_obexAgentManager = new ObexAgentManager(m_obexObject); m_objectManager->addObject(m_obexAgentManager); } void FakeBluez::createObexClient() { m_obexClient = new ObexClient(m_obexObject); m_objectManager->addObject(m_obexClient); } void FakeBluez::runBluezNotExportingInterfacesTest() { clear(); } void FakeBluez::runBluezEmptyManagedObjectsTest() { clear(); createObjectManager(); } void FakeBluez::runBluezNoAdaptersTest() { clear(); createObjectManager(); createAgentManager(); createProfileManager(); } void FakeBluez::runBluezStandardTest() { clear(); createObjectManager(); createDeviceManager(); createAgentManager(); createProfileManager(); } void FakeBluez::runObexNotExportingInterfacesTest() { clear(); } void FakeBluez::runObexEmptyManagedObjectsTest() { clear(); createObexObjectManager(); } void FakeBluez::runObexNoClientTest() { clear(); createObexObjectManager(); createObexAgentManager(); } void FakeBluez::runObexNoAgentManagerTest() { clear(); createObexObjectManager(); createObexClient(); } void FakeBluez::runObexStandardTest() { clear(); createObexObjectManager(); createObexClient(); createObexAgentManager(); } diff --git a/autotests/fakebluez/fakebluez.h b/autotests/fakebluez/fakebluez.h index b6e53c6..54c05ba 100644 --- a/autotests/fakebluez/fakebluez.h +++ b/autotests/fakebluez/fakebluez.h @@ -1,85 +1,71 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef FAKEBLUEZ_H #define FAKEBLUEZ_H #include #include class TestInterface; class ObjectManager; class AgentManager; class ProfileManager; class DeviceManager; class ObexObject; class ObexAgentManager; class ObexClient; class FakeBluez : public QObject { Q_OBJECT public: explicit FakeBluez(QObject *parent = nullptr); void runTest(const QString &testName); void runAction(const QString &object, const QString &actionName, const QVariantMap &properties); private Q_SLOTS: void doRunAction(); private: void clear(); void createObjectManager(); void createAgentManager(); void createProfileManager(); void createDeviceManager(); void createObexObjectManager(); void createObexAgentManager(); void createObexClient(); void runBluezNotExportingInterfacesTest(); void runBluezEmptyManagedObjectsTest(); void runBluezNoAdaptersTest(); void runBluezStandardTest(); void runObexNotExportingInterfacesTest(); void runObexEmptyManagedObjectsTest(); void runObexNoClientTest(); void runObexNoAgentManagerTest(); void runObexStandardTest(); TestInterface *m_testInterface; ObjectManager *m_objectManager; AgentManager *m_agentManager; ProfileManager *m_profileManager; DeviceManager *m_deviceManager; ObexObject *m_obexObject; ObexAgentManager *m_obexAgentManager; ObexClient *m_obexClient; QString m_actionObject; QString m_actionName; QVariantMap m_actionProperties; }; #endif // FAKEBLUEZ_H diff --git a/autotests/fakebluez/gattmanagerinterface.cpp b/autotests/fakebluez/gattmanagerinterface.cpp index 3f21d7c..0ee9f53 100644 --- a/autotests/fakebluez/gattmanagerinterface.cpp +++ b/autotests/fakebluez/gattmanagerinterface.cpp @@ -1,105 +1,91 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattmanagerinterface.h" #include "objectmanager.h" #include #include #include #include GattManagerInterface::GattManagerInterface(const QDBusObjectPath &path, QObject *parent) : QDBusAbstractAdaptor(parent) { setName(QStringLiteral("org.bluez.GattManager1")); setPath(path); } void GattManagerInterface::runAction(const QString &actionName, const QVariantMap &properties) { if (actionName == QLatin1String("get-objects")) { runGetObjectsAction(); } else if (actionName == QLatin1String("read-charc")) { runReadCharcAction(properties); } else if (actionName == QLatin1String("write-charc")) { runWriteCharcAction(properties); } } void GattManagerInterface::RegisterApplication(const QDBusObjectPath &path, const QVariantMap &/*options*/, const QDBusMessage &msg) { m_application = path; m_service = msg.service(); } void GattManagerInterface::UnregisterApplication(const QDBusObjectPath &path, const QDBusMessage &msg) { if (m_application == path && m_service == msg.service()) { m_application = QDBusObjectPath(); m_service.clear(); } } void GattManagerInterface::runGetObjectsAction() { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_application.path(), QStringLiteral("org.freedesktop.DBus.ObjectManager"), QStringLiteral("GetManagedObjects")); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(QDBusConnection::sessionBus().asyncCall(call)); connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher *watcher) { const QDBusPendingReply &reply = *watcher; watcher->deleteLater(); if (reply.isError()) { return; } DBusManagerStruct objects = reply.value(); for (const auto& object : objects.keys()) { if (object.path().contains(QLatin1String("char"))) { m_characteristic = object; break; } } }); } void GattManagerInterface::runReadCharcAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_characteristic.path(), QStringLiteral("org.bluez.GattCharacteristic1"), QStringLiteral("ReadValue")); call << properties.value(QStringLiteral("Options")); QDBusConnection::sessionBus().asyncCall(call); } void GattManagerInterface::runWriteCharcAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_characteristic.path(), QStringLiteral("org.bluez.GattCharacteristic1"), QStringLiteral("WriteValue")); call << properties.value(QStringLiteral("Value")); call << properties.value(QStringLiteral("Options")); QDBusConnection::sessionBus().asyncCall(call); } diff --git a/autotests/fakebluez/gattmanagerinterface.h b/autotests/fakebluez/gattmanagerinterface.h index ea5ad03..0a23425 100644 --- a/autotests/fakebluez/gattmanagerinterface.h +++ b/autotests/fakebluez/gattmanagerinterface.h @@ -1,52 +1,38 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "object.h" #include class QDBusMessage; class GattManagerInterface : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.GattManager1") public: explicit GattManagerInterface(const QDBusObjectPath &path, QObject *parent = nullptr); void runAction(const QString &actionName, const QVariantMap &properties); public Q_SLOTS: void RegisterApplication(const QDBusObjectPath &path, const QVariantMap &options, const QDBusMessage &msg); void UnregisterApplication(const QDBusObjectPath &path, const QDBusMessage &msg); private: void runGetObjectsAction(); void runReadCharcAction(const QVariantMap &properties); void runWriteCharcAction(const QVariantMap &properties); QDBusObjectPath m_application; QDBusObjectPath m_characteristic; QString m_service; QVariantMap m_properties; }; diff --git a/autotests/fakebluez/inputinterface.cpp b/autotests/fakebluez/inputinterface.cpp index 6731207..49a3026 100644 --- a/autotests/fakebluez/inputinterface.cpp +++ b/autotests/fakebluez/inputinterface.cpp @@ -1,45 +1,31 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "inputinterface.h" #include // InputObject InputObject::InputObject(const QDBusObjectPath &path, QObject *parent) : QObject(parent) { QDBusConnection::sessionBus().registerObject(path.path(), this); } // InputInterface InputInterface::InputInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent) : QDBusAbstractAdaptor(parent) { setPath(path); setObjectParent(parent); setProperties(properties); setName(QStringLiteral("org.bluez.Input1")); } QString InputInterface::reconnectMode() const { return Object::property(QStringLiteral("ReconnectMode")).toString(); } diff --git a/autotests/fakebluez/inputinterface.h b/autotests/fakebluez/inputinterface.h index da170e0..5e10816 100644 --- a/autotests/fakebluez/inputinterface.h +++ b/autotests/fakebluez/inputinterface.h @@ -1,49 +1,35 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef INPUTINTERFACE_H #define INPUTINTERFACE_H #include "object.h" #include class QDBusMessage; class QDBusObjectPath; class InputObject : public QObject { public: explicit InputObject(const QDBusObjectPath &path, QObject *parent = nullptr); }; class InputInterface : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.Input1") Q_PROPERTY(QString ReconnectMode READ reconnectMode) public: explicit InputInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent = nullptr); QString reconnectMode() const; }; #endif // INPUTINTERFACE_H diff --git a/autotests/fakebluez/leadvertisingmanagerinterface.cpp b/autotests/fakebluez/leadvertisingmanagerinterface.cpp index 4b57cc6..4ca7326 100644 --- a/autotests/fakebluez/leadvertisingmanagerinterface.cpp +++ b/autotests/fakebluez/leadvertisingmanagerinterface.cpp @@ -1,62 +1,48 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "leadvertisingmanagerinterface.h" #include #include #include LEAdvertisingManagerInterface::LEAdvertisingManagerInterface(const QDBusObjectPath &path, QObject *parent) : QDBusAbstractAdaptor(parent) { setName(QStringLiteral("org.bluez.LEAdvertisingManager1")); setPath(path); } void LEAdvertisingManagerInterface::runAction(const QString &actionName, const QVariantMap &/*properties*/) { if (actionName == QLatin1String("release")) { runReleaseAction(); } } void LEAdvertisingManagerInterface::RegisterAdvertisement(const QDBusObjectPath &path, const QVariantMap &/*options*/, const QDBusMessage &msg) { m_advertisement = path; m_service = msg.service(); } void LEAdvertisingManagerInterface::UnregisterAdvertisement(const QDBusObjectPath &path, const QDBusMessage &msg) { if (m_advertisement == path && m_service == msg.service()) { m_advertisement = QDBusObjectPath(); m_service.clear(); } } void LEAdvertisingManagerInterface::runReleaseAction() { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_advertisement.path(), QStringLiteral("org.bluez.LEAdvertisement1"), QStringLiteral("Release")); QDBusConnection::sessionBus().asyncCall(call); } diff --git a/autotests/fakebluez/leadvertisingmanagerinterface.h b/autotests/fakebluez/leadvertisingmanagerinterface.h index e574864..ebab29a 100644 --- a/autotests/fakebluez/leadvertisingmanagerinterface.h +++ b/autotests/fakebluez/leadvertisingmanagerinterface.h @@ -1,48 +1,34 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "object.h" #include class QDBusMessage; class LEAdvertisingManagerInterface : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.LEAdvertisingManager1") public: explicit LEAdvertisingManagerInterface(const QDBusObjectPath &path, QObject *parent = nullptr); void runAction(const QString &actionName, const QVariantMap &properties); public Q_SLOTS: void RegisterAdvertisement(const QDBusObjectPath &path, const QVariantMap &options, const QDBusMessage &msg); void UnregisterAdvertisement(const QDBusObjectPath &path, const QDBusMessage &msg); private: void runReleaseAction(); QDBusObjectPath m_advertisement; QString m_service; }; diff --git a/autotests/fakebluez/main.cpp b/autotests/fakebluez/main.cpp index 5e00cbf..e551d68 100644 --- a/autotests/fakebluez/main.cpp +++ b/autotests/fakebluez/main.cpp @@ -1,39 +1,25 @@ /* - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "fakebluez.h" #include #include #include int main(int argc, char **argv) { QCoreApplication app(argc, argv); new FakeBluez(&app); if (!QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.bluezqt.test"))) { qWarning() << "Cannot register org.kde.bluezqt.test service!"; return 1; } return app.exec(); } diff --git a/autotests/fakebluez/mediainterface.cpp b/autotests/fakebluez/mediainterface.cpp index 4b84eb5..b3062c1 100644 --- a/autotests/fakebluez/mediainterface.cpp +++ b/autotests/fakebluez/mediainterface.cpp @@ -1,101 +1,87 @@ /* - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediainterface.h" #include #include #include MediaInterface::MediaInterface(const QDBusObjectPath &path, QObject *parent) : QDBusAbstractAdaptor(parent) { setName(QStringLiteral("org.bluez.Media1")); setPath(path); } void MediaInterface::runAction(const QString &actionName, const QVariantMap &properties) { if (actionName == QLatin1String("set-configuration")) { runSetConfigurationAction(properties); } else if (actionName == QLatin1String("select-configuration")) { runSelectConfigurationAction(properties); } else if (actionName == QLatin1String("clear-configuration")) { runClearConfigurationAction(properties); } else if (actionName == QLatin1String("release")) { runReleaseAction(); } } void MediaInterface::RegisterEndpoint(const QDBusObjectPath &path, const QVariantMap &properties, const QDBusMessage &msg) { m_endpoint = path; m_service = msg.service(); m_properties = properties; } void MediaInterface::UnregisterEndpoint(const QDBusObjectPath &path, const QDBusMessage &msg) { if (m_endpoint == path && m_service == msg.service()) { m_endpoint = QDBusObjectPath(); m_service.clear(); m_properties.clear(); } } void MediaInterface::runSetConfigurationAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("SetConfiguration")); call << QVariant::fromValue(properties.value(QStringLiteral("Transport")).value()); call << properties.value(QStringLiteral("Properties")); QDBusConnection::sessionBus().asyncCall(call); } void MediaInterface::runSelectConfigurationAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("SelectConfiguration")); call << properties.value(QStringLiteral("Capabilities")); QDBusConnection::sessionBus().asyncCall(call); } void MediaInterface::runClearConfigurationAction(const QVariantMap &properties) { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("ClearConfiguration")); call << QVariant::fromValue(properties.value(QStringLiteral("Transport")).value()); QDBusConnection::sessionBus().asyncCall(call); } void MediaInterface::runReleaseAction() { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_endpoint.path(), QStringLiteral("org.bluez.MediaEndpoint1"), QStringLiteral("Release")); QDBusConnection::sessionBus().asyncCall(call); } diff --git a/autotests/fakebluez/mediainterface.h b/autotests/fakebluez/mediainterface.h index 625fc06..b28d1ef 100644 --- a/autotests/fakebluez/mediainterface.h +++ b/autotests/fakebluez/mediainterface.h @@ -1,52 +1,38 @@ /* - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "object.h" #include class QDBusMessage; class MediaInterface : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.Media1") public: explicit MediaInterface(const QDBusObjectPath &path, QObject *parent = nullptr); void runAction(const QString &actionName, const QVariantMap &properties); public Q_SLOTS: void RegisterEndpoint(const QDBusObjectPath &path, const QVariantMap &properties, const QDBusMessage &msg); void UnregisterEndpoint(const QDBusObjectPath &path, const QDBusMessage &msg); private: void runSetConfigurationAction(const QVariantMap &properties); void runSelectConfigurationAction(const QVariantMap &properties); void runClearConfigurationAction(const QVariantMap &properties); void runReleaseAction(); QDBusObjectPath m_endpoint; QString m_service; QVariantMap m_properties; }; diff --git a/autotests/fakebluez/mediaplayerinterface.cpp b/autotests/fakebluez/mediaplayerinterface.cpp index fa21240..a4e14c1 100644 --- a/autotests/fakebluez/mediaplayerinterface.cpp +++ b/autotests/fakebluez/mediaplayerinterface.cpp @@ -1,140 +1,126 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediaplayerinterface.h" #include "objectmanager.h" #include #include // MediaPlayerObject MediaPlayerObject::MediaPlayerObject(const QDBusObjectPath &path, QObject *parent) : QObject(parent) { QDBusConnection::sessionBus().registerObject(path.path(), this); } // MediaPlayerInterface MediaPlayerInterface::MediaPlayerInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent) : QDBusAbstractAdaptor(parent) { setPath(path); setObjectParent(parent); setProperties(properties); setName(QStringLiteral("org.bluez.MediaPlayer1")); } QString MediaPlayerInterface::name() const { return Object::property(QStringLiteral("Name")).toString(); } QString MediaPlayerInterface::equalizer() const { return Object::property(QStringLiteral("Equalizer")).toString(); } void MediaPlayerInterface::setEqualizer(const QString &equalizer) { Object::changeProperty(QStringLiteral("Equalizer"), equalizer); } QString MediaPlayerInterface::repeat() const { return Object::property(QStringLiteral("Repeat")).toString(); } void MediaPlayerInterface::setRepeat(const QString &repeat) { Object::changeProperty(QStringLiteral("Repeat"), repeat); } QString MediaPlayerInterface::shuffle() const { return Object::property(QStringLiteral("Shuffle")).toString(); } void MediaPlayerInterface::setShuffle(const QString &shuffle) { Object::changeProperty(QStringLiteral("Shuffle"), shuffle); } QString MediaPlayerInterface::status() const { return Object::property(QStringLiteral("Status")).toString(); } QVariantMap MediaPlayerInterface::track() const { return qdbus_cast(Object::property(QStringLiteral("Track"))); } quint32 MediaPlayerInterface::position() const { return Object::property(QStringLiteral("Position")).toUInt(); } QDBusObjectPath MediaPlayerInterface::device() const { return Object::property(QStringLiteral("Device")).value(); } void MediaPlayerInterface::Play() { Object::changeProperty(QStringLiteral("Status"), QStringLiteral("playing")); } void MediaPlayerInterface::Pause() { Object::changeProperty(QStringLiteral("Status"), QStringLiteral("paused")); } void MediaPlayerInterface::Stop() { Object::changeProperty(QStringLiteral("Status"), QStringLiteral("stopped")); } void MediaPlayerInterface::Next() { QVariantMap t = track(); t[QStringLiteral("Title")] = QVariant(t[QStringLiteral("Title")].toString() + QLatin1String("_next")); t[QStringLiteral("TrackNumber")] = t[QStringLiteral("TrackNumber")].toUInt() + 1; Object::changeProperty(QStringLiteral("Track"), t); } void MediaPlayerInterface::Previous() { QVariantMap t = track(); t[QStringLiteral("Title")] = QVariant(t[QStringLiteral("Title")].toString() + QLatin1String("_prev")); t[QStringLiteral("TrackNumber")] = t[QStringLiteral("TrackNumber")].toUInt() - 1; Object::changeProperty(QStringLiteral("Track"), t); } void MediaPlayerInterface::FastForward() { Object::changeProperty(QStringLiteral("Status"), QStringLiteral("forward-seek")); } void MediaPlayerInterface::Rewind() { Object::changeProperty(QStringLiteral("Status"), QStringLiteral("reverse-seek")); } diff --git a/autotests/fakebluez/mediaplayerinterface.h b/autotests/fakebluez/mediaplayerinterface.h index dff3f3c..ecc2198 100644 --- a/autotests/fakebluez/mediaplayerinterface.h +++ b/autotests/fakebluez/mediaplayerinterface.h @@ -1,82 +1,68 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef MEDIAPLAYERINTERFACE_H #define MEDIAPLAYERINTERFACE_H #include "object.h" #include class QDBusMessage; class QDBusObjectPath; class MediaPlayerObject : public QObject { public: explicit MediaPlayerObject(const QDBusObjectPath &path, QObject *parent = nullptr); }; class MediaPlayerInterface : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.MediaPlayer1") Q_PROPERTY(QString Name READ name) Q_PROPERTY(QString Equalizer READ equalizer WRITE setEqualizer) Q_PROPERTY(QString Repeat READ repeat WRITE setRepeat) Q_PROPERTY(QString Shuffle READ shuffle WRITE setShuffle) Q_PROPERTY(QString Status READ status) Q_PROPERTY(QVariantMap Track READ track) Q_PROPERTY(quint32 Position READ position) Q_PROPERTY(QDBusObjectPath Device READ device) public: explicit MediaPlayerInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent = nullptr); QString name() const; QString equalizer() const; void setEqualizer(const QString &equalizer); QString repeat() const; void setRepeat(const QString &repeat); QString shuffle() const; void setShuffle(const QString &shuffle); QString status() const; QVariantMap track() const; quint32 position() const; QDBusObjectPath device() const; public Q_SLOTS: void Play(); void Pause(); void Stop(); void Next(); void Previous(); void FastForward(); void Rewind(); }; #endif // MEDIAPLAYERINTERFACE_H diff --git a/autotests/fakebluez/mediatransportinterface.cpp b/autotests/fakebluez/mediatransportinterface.cpp index 11fad31..e754178 100644 --- a/autotests/fakebluez/mediatransportinterface.cpp +++ b/autotests/fakebluez/mediatransportinterface.cpp @@ -1,72 +1,58 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediatransportinterface.h" #include "objectmanager.h" #include #include MediaTransportObject::MediaTransportObject(const QDBusObjectPath &path, QObject *parent) : QObject(parent) { QDBusConnection::sessionBus().registerObject(path.path(), this); } MediaTransportInterface::MediaTransportInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent) : QDBusAbstractAdaptor(parent) { setPath(path); setObjectParent(parent); setProperties(properties); setName(QStringLiteral("org.bluez.MediaTransport1")); } quint8 MediaTransportInterface::codec() const { return Object::property(QStringLiteral("Codec")).toUInt(); } QByteArray MediaTransportInterface::configuration() const { return Object::property(QStringLiteral("Configuration")).toByteArray(); } QString MediaTransportInterface::state() const { return Object::property(QStringLiteral("State")).toString(); } quint16 MediaTransportInterface::volume() const { return Object::property(QStringLiteral("Volume")).toUInt(); } void MediaTransportInterface::Acquire(const QDBusMessage &msg) { } void MediaTransportInterface::TryAcquire(const QDBusMessage &msg) { } void MediaTransportInterface::Release() { } diff --git a/autotests/fakebluez/mediatransportinterface.h b/autotests/fakebluez/mediatransportinterface.h index 9ac5b5f..167c0fe 100644 --- a/autotests/fakebluez/mediatransportinterface.h +++ b/autotests/fakebluez/mediatransportinterface.h @@ -1,56 +1,42 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "object.h" #include class QDBusMessage; class MediaTransportObject : public QObject { public: explicit MediaTransportObject(const QDBusObjectPath &path, QObject *parent = nullptr); }; class MediaTransportInterface : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.MediaTransport1") Q_PROPERTY(quint8 Codec READ codec) Q_PROPERTY(QByteArray Configuration READ configuration) Q_PROPERTY(QString State READ state) Q_PROPERTY(quint16 Volume READ volume) public: explicit MediaTransportInterface(const QDBusObjectPath &path, const QVariantMap &properties, QObject *parent = nullptr); quint8 codec() const; QByteArray configuration() const; QString state() const; quint16 volume() const; public Q_SLOTS: void Acquire(const QDBusMessage &msg); void TryAcquire(const QDBusMessage &msg); void Release(); }; diff --git a/autotests/fakebluez/obexagentmanager.cpp b/autotests/fakebluez/obexagentmanager.cpp index 6b24203..dcaaa7a 100644 --- a/autotests/fakebluez/obexagentmanager.cpp +++ b/autotests/fakebluez/obexagentmanager.cpp @@ -1,84 +1,70 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexagentmanager.h" #include #include ObexAgentManager::ObexAgentManager(QObject *parent) : QDBusAbstractAdaptor(parent) { setName(QStringLiteral("org.bluez.obex.AgentManager1")); setPath(QDBusObjectPath(QStringLiteral("/org/bluez/obex"))); } void ObexAgentManager::runAction(const QString &actionName, const QVariantMap &properties) { if (actionName == QLatin1String("authorize-push")) { runAuthorizePushAction(properties); } } void ObexAgentManager::RegisterAgent(const QDBusObjectPath &path, const QDBusMessage &msg) { m_agent = path; m_service = msg.service(); } void ObexAgentManager::UnregisterAgent(const QDBusObjectPath &path, const QDBusMessage &msg) { if (m_agent == path && m_service == msg.service()) { m_agent = QDBusObjectPath(); m_service.clear(); } } void ObexAgentManager::runAuthorizePushAction(const QVariantMap &properties) { Q_UNUSED(properties) QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.obex.Agent1"), QStringLiteral("AuthorizePush")); call << QVariant::fromValue(QDBusObjectPath(QStringLiteral("/org/bluez/session1/transfer1"))); const QString &fileName = QDBusConnection::sessionBus().call(call).arguments().first().toString(); Q_UNUSED(fileName) } void ObexAgentManager::runCancelAction() { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.obex.Agent1"), QStringLiteral("Cancel")); QDBusConnection::sessionBus().call(call); } void ObexAgentManager::runReleaseAction() { QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.obex.Agent1"), QStringLiteral("Release")); QDBusConnection::sessionBus().call(call); } diff --git a/autotests/fakebluez/obexagentmanager.h b/autotests/fakebluez/obexagentmanager.h index 940d63e..de81565 100644 --- a/autotests/fakebluez/obexagentmanager.h +++ b/autotests/fakebluez/obexagentmanager.h @@ -1,53 +1,39 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef OBEXAGENTMANAGER_H #define OBEXAGENTMANAGER_H #include "object.h" #include class QDBusMessage; class ObexAgentManager : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.obex.AgentManager1") public: explicit ObexAgentManager(QObject *parent = nullptr); void runAction(const QString &actionName, const QVariantMap &properties); public Q_SLOTS: void RegisterAgent(const QDBusObjectPath &path, const QDBusMessage &msg); void UnregisterAgent(const QDBusObjectPath &path, const QDBusMessage &msg); private: void runAuthorizePushAction(const QVariantMap &properties); void runCancelAction(); void runReleaseAction(); QDBusObjectPath m_agent; QString m_service; }; #endif // OBEXAGENTMANAGER_H diff --git a/autotests/fakebluez/obexclient.cpp b/autotests/fakebluez/obexclient.cpp index 083c781..b9983ce 100644 --- a/autotests/fakebluez/obexclient.cpp +++ b/autotests/fakebluez/obexclient.cpp @@ -1,49 +1,35 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexclient.h" #include ObexClient::ObexClient(QObject *parent) : QDBusAbstractAdaptor(parent) { setName(QStringLiteral("org.bluez.obex.Client1")); setPath(QDBusObjectPath(QStringLiteral("/org/bluez/obex"))); } void ObexClient::runAction(const QString &actionName, const QVariantMap &properties) { Q_UNUSED(actionName) Q_UNUSED(properties) } void ObexClient::CreateSession(const QString &destination, const QVariantMap &args, const QDBusMessage &msg) { Q_UNUSED(destination) Q_UNUSED(args) Q_UNUSED(msg) } void ObexClient::RemoveSession(const QDBusObjectPath &session, const QDBusMessage &msg) { Q_UNUSED(session) Q_UNUSED(msg) } diff --git a/autotests/fakebluez/obexclient.h b/autotests/fakebluez/obexclient.h index 5d760c0..e0d3cee 100644 --- a/autotests/fakebluez/obexclient.h +++ b/autotests/fakebluez/obexclient.h @@ -1,45 +1,31 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef OBEXCLIENT_H #define OBEXCLIENT_H #include "object.h" #include class QDBusMessage; class ObexClient : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.obex.Client1") public: explicit ObexClient(QObject *parent = nullptr); void runAction(const QString &actionName, const QVariantMap &properties); public Q_SLOTS: void CreateSession(const QString &destination, const QVariantMap &args, const QDBusMessage &msg); void RemoveSession(const QDBusObjectPath &session, const QDBusMessage &msg); }; #endif // OBEXCLIENT_H diff --git a/autotests/fakebluez/object.cpp b/autotests/fakebluez/object.cpp index 1e235c7..82df21d 100644 --- a/autotests/fakebluez/object.cpp +++ b/autotests/fakebluez/object.cpp @@ -1,99 +1,85 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "object.h" #include #include Object::Object() : m_parent(nullptr) { } QObject *Object::objectParent() const { return m_parent; } void Object::setObjectParent(QObject *parent) { m_parent = parent; } QDBusObjectPath Object::path() const { return m_path; } void Object::setPath(const QDBusObjectPath &path) { m_path = path; } QString Object::name() const { return m_name; } void Object::setName(const QString &name) { m_name = name; } bool Object::haveProperties() const { return !m_properties.isEmpty(); } QVariantMap Object::properties() const { return m_properties; } void Object::setProperties(const QVariantMap &properties) { m_properties = properties; } QVariant Object::property(const QString &name) const { return m_properties.value(name); } void Object::changeProperty(const QString &name, const QVariant &value) { if (m_properties.value(name) == value) { return; } QVariantMap updatedProperties; updatedProperties[name] = value; m_properties[name] = value; QDBusMessage signal = QDBusMessage::createSignal(m_path.path(), QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged")); signal << m_name; signal << updatedProperties; signal << QStringList(); QDBusConnection::sessionBus().send(signal); } diff --git a/autotests/fakebluez/object.h b/autotests/fakebluez/object.h index 7f8333a..daf59e6 100644 --- a/autotests/fakebluez/object.h +++ b/autotests/fakebluez/object.h @@ -1,57 +1,43 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef OBJECT_H #define OBJECT_H #include #include class Object { public: explicit Object(); virtual ~Object() = default; QObject *objectParent() const; void setObjectParent(QObject *parent); QDBusObjectPath path() const; void setPath(const QDBusObjectPath &path); QString name() const; void setName(const QString &name); bool haveProperties() const; QVariantMap properties() const; void setProperties(const QVariantMap &properties); QVariant property(const QString &name) const; void changeProperty(const QString &name, const QVariant &value); private: QObject *m_parent; QDBusObjectPath m_path; QString m_name; QVariantMap m_properties; }; #endif // OBJECT_H diff --git a/autotests/fakebluez/objectmanager.cpp b/autotests/fakebluez/objectmanager.cpp index 15938ff..64e2732 100644 --- a/autotests/fakebluez/objectmanager.cpp +++ b/autotests/fakebluez/objectmanager.cpp @@ -1,95 +1,81 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "objectmanager.h" #include "object.h" #include #include ObjectManager *s_instance = nullptr; ObjectManager::ObjectManager(QObject *parent) : QDBusAbstractAdaptor(parent) { s_instance = this; qDBusRegisterMetaType(); qDBusRegisterMetaType(); QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/bluez"), this); } ObjectManager::~ObjectManager() { s_instance = nullptr; qDeleteAll(m_autoDeleteObjects); } void ObjectManager::addObject(Object *object) { m_objects.insert(object->path().path(), object); QVariantMapMap interfaces; interfaces.insert(object->name(), object->properties()); Q_EMIT InterfacesAdded(object->path(), interfaces); } void ObjectManager::removeObject(Object *object) { m_objects.remove(object->path().path()); m_autoDeleteObjects.removeOne(object->objectParent()); Q_EMIT InterfacesRemoved(object->path(), QStringList(object->name())); delete object->objectParent(); } void ObjectManager::addAutoDeleteObject(QObject *object) { m_autoDeleteObjects.append(object); } Object *ObjectManager::objectByPath(const QDBusObjectPath &path) const { return m_objects.value(path.path()); } ObjectManager *ObjectManager::self() { return s_instance; } DBusManagerStruct ObjectManager::GetManagedObjects() { DBusManagerStruct objects; for (Object *object : m_objects.values()) { if (objects.value(object->path()).isEmpty()) { objects[object->path()].insert(QStringLiteral("org.freedesktop.DBus.Introspectable"), QVariantMap()); if (object->haveProperties()) { objects[object->path()].insert(QStringLiteral("org.freedesktop.DBus.Properties"), QVariantMap()); } } objects[object->path()].insert(object->name(), object->properties()); } return objects; } diff --git a/autotests/fakebluez/objectmanager.h b/autotests/fakebluez/objectmanager.h index ef8c2c0..5a7d5ed 100644 --- a/autotests/fakebluez/objectmanager.h +++ b/autotests/fakebluez/objectmanager.h @@ -1,66 +1,52 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef OBJECTMANAGER_H #define OBJECTMANAGER_H #include #include #include typedef QMap QVariantMapMap; Q_DECLARE_METATYPE(QVariantMapMap) typedef QMap DBusManagerStruct; Q_DECLARE_METATYPE(DBusManagerStruct) class Object; class ObjectManager : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.freedesktop.DBus.ObjectManager") public: explicit ObjectManager(QObject *parent = nullptr); ~ObjectManager(); void addObject(Object *object); void removeObject(Object *object); void addAutoDeleteObject(QObject *object); Object *objectByPath(const QDBusObjectPath &path) const; static ObjectManager *self(); public Q_SLOTS: DBusManagerStruct GetManagedObjects(); Q_SIGNALS: void InterfacesAdded(const QDBusObjectPath &object, const QVariantMapMap &interfaces); void InterfacesRemoved(const QDBusObjectPath &object, const QStringList &interfaces); private: QMultiMap m_objects; QList m_autoDeleteObjects; }; #endif // OBJECTMANAGER_H diff --git a/autotests/fakebluez/profilemanager.cpp b/autotests/fakebluez/profilemanager.cpp index 4502b27..9eebc65 100644 --- a/autotests/fakebluez/profilemanager.cpp +++ b/autotests/fakebluez/profilemanager.cpp @@ -1,44 +1,30 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "profilemanager.h" #include ProfileManager::ProfileManager(QObject *parent) : QDBusAbstractAdaptor(parent) { setName(QStringLiteral("org.bluez.ProfileManager1")); setPath(QDBusObjectPath(QStringLiteral("/org/bluez"))); } void ProfileManager::RegisterProfile(const QDBusObjectPath &path, const QString &uuid, const QVariantMap &options, const QDBusMessage &msg) { Q_UNUSED(path) Q_UNUSED(uuid) Q_UNUSED(options) Q_UNUSED(msg) } void ProfileManager::UnregisterProfile(const QDBusObjectPath &path, const QDBusMessage &msg) { Q_UNUSED(path) Q_UNUSED(msg) } diff --git a/autotests/fakebluez/profilemanager.h b/autotests/fakebluez/profilemanager.h index 7fdbd42..a965bc1 100644 --- a/autotests/fakebluez/profilemanager.h +++ b/autotests/fakebluez/profilemanager.h @@ -1,43 +1,29 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef PROFILEMANAGER_H #define PROFILEMANAGER_H #include "object.h" #include class QDBusMessage; class ProfileManager : public QDBusAbstractAdaptor, public Object { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.ProfileManager1") public: explicit ProfileManager(QObject *parent = nullptr); public Q_SLOTS: void RegisterProfile(const QDBusObjectPath &path, const QString &uuid, const QVariantMap &options, const QDBusMessage &msg); void UnregisterProfile(const QDBusObjectPath &path, const QDBusMessage &msg); }; #endif // PROFILEMANAGER_H diff --git a/autotests/fakebluez/testinterface.cpp b/autotests/fakebluez/testinterface.cpp index 4b0ed36..3cec828 100644 --- a/autotests/fakebluez/testinterface.cpp +++ b/autotests/fakebluez/testinterface.cpp @@ -1,48 +1,34 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "testinterface.h" #include "fakebluez.h" #include TestInterface::TestInterface(FakeBluez *parent) : QDBusAbstractAdaptor(parent) , m_fakeBluez(parent) { } void TestInterface::runTest(const QString &testName) { m_fakeBluez->runTest(testName); } void TestInterface::runAction(const QString &object, const QString &actionName, const QVariantMap &properties, const QDBusMessage &msg) { m_msg = msg; m_msg.setDelayedReply(true); m_fakeBluez->runAction(object, actionName, properties); } void TestInterface::emitActionFinished() { QDBusConnection::sessionBus().send(m_msg.createReply()); } diff --git a/autotests/fakebluez/testinterface.h b/autotests/fakebluez/testinterface.h index 003528a..ac2bbc2 100644 --- a/autotests/fakebluez/testinterface.h +++ b/autotests/fakebluez/testinterface.h @@ -1,48 +1,34 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef TESTINTERFACE_H #define TESTINTERFACE_H #include #include class FakeBluez; class TestInterface : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.bluezqt.fakebluez.Test") public: explicit TestInterface(FakeBluez *parent); public Q_SLOTS: void runTest(const QString &testName); void runAction(const QString &object, const QString &actionName, const QVariantMap &properties, const QDBusMessage &msg); void emitActionFinished(); private: FakeBluez *m_fakeBluez; QDBusMessage m_msg; }; #endif // TESTINTERFACE_H diff --git a/autotests/gattmanagertest.cpp b/autotests/gattmanagertest.cpp index da4e780..74cad74 100644 --- a/autotests/gattmanagertest.cpp +++ b/autotests/gattmanagertest.cpp @@ -1,110 +1,96 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattmanagertest.h" #include "autotests.h" #include "initmanagerjob.h" #include "manager.h" #include "pendingcall.h" #include "gattmanager.h" #include "gattservice.h" #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; void GattManagerTest::initTestCase() { bluezqt_initFakeBluezTestRun(); FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapter QString adapter = QStringLiteral("/org/bluez/hci0"); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(adapter)); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); Manager *manager = new Manager(this); InitManagerJob *initJob = manager->init(); initJob->exec(); QVERIFY(!initJob->error()); QCOMPARE(manager->adapters().count(), 1); m_adapter = manager->adapters().at(0); QVERIFY(m_adapter->gattManager()); m_application = new GattApplication(QStringLiteral("/org/kde/bluezqt"), this); auto service = new GattService(QStringLiteral("ad100000-d901-11e8-9f8b-f2801f1b9fd1"), true, m_application); m_characteristic = new GattCharacteristic(QStringLiteral("ad10e100-d901-11e8-9f8b-f2801f1b9fd1"), service); m_adapter->gattManager()->registerApplication(m_application)->waitForFinished(); // Let FakeBluez read local characteristic QVariantMap params; params.insert(QStringLiteral("AdapterPath"), QVariant::fromValue(QDBusObjectPath(m_adapter->ubi()))); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("adapter-gattmanager:get-objects"), params); // Process events to let getManagedObjects call from FakeBluez be finished QTest::qWait(0); } void GattManagerTest::cleanupTestCase() { FakeBluez::stop(); } void GattManagerTest::readCharcTest() { QCOMPARE(m_characteristic->readValue(), QByteArray()); bool readCallbackCalled = false; m_characteristic->setReadCallback([&readCallbackCalled]() { readCallbackCalled = true; return QByteArray("1234"); }); QVariantMap params; params.insert(QStringLiteral("AdapterPath"), QVariant::fromValue(QDBusObjectPath(m_adapter->ubi()))); params.insert(QStringLiteral("Options"), QVariant::fromValue(QVariantMap())); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("adapter-gattmanager:read-charc"), params); QTRY_COMPARE(readCallbackCalled, true); QTRY_COMPARE(m_characteristic->readValue(), QByteArray("1234")); } void GattManagerTest::writeCharcTest() { m_characteristic->setReadCallback(nullptr); QVariantMap params; params.insert(QStringLiteral("AdapterPath"), QVariant::fromValue(QDBusObjectPath(m_adapter->ubi()))); params.insert(QStringLiteral("Value"), QVariant::fromValue(QByteArray("4321"))); params.insert(QStringLiteral("Options"), QVariant::fromValue(QVariantMap())); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("adapter-gattmanager:write-charc"), params); QTRY_COMPARE(m_characteristic->readValue(), QByteArray("4321")); } QTEST_MAIN(GattManagerTest) diff --git a/autotests/gattmanagertest.h b/autotests/gattmanagertest.h index c900b6d..64bcd82 100644 --- a/autotests/gattmanagertest.h +++ b/autotests/gattmanagertest.h @@ -1,42 +1,28 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "gattapplication.h" #include "gattcharacteristic.h" #include "adapter.h" class GattManagerTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void readCharcTest(); void writeCharcTest(); private: BluezQt::GattApplication *m_application; BluezQt::GattCharacteristic *m_characteristic; BluezQt::AdapterPtr m_adapter; }; diff --git a/autotests/inputtest.cpp b/autotests/inputtest.cpp index 3d93f4d..1c3619f 100644 --- a/autotests/inputtest.cpp +++ b/autotests/inputtest.cpp @@ -1,160 +1,146 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "inputtest.h" #include "autotests.h" #include "pendingcall.h" #include "initmanagerjob.h" #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; Q_DECLARE_METATYPE(Input::ReconnectMode) InputTest::InputTest() : m_manager(nullptr) { Autotests::registerMetatypes(); qRegisterMetaType("ReconnectMode"); } void InputTest::initTestCase() { QDBusConnection connection = QDBusConnection::sessionBus(); QString service = QStringLiteral("org.kde.bluezqt.fakebluez"); bluezqt_initFakeBluezTestRun(); FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapter QString adapter = QStringLiteral("/org/bluez/hci0"); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(adapter)); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); // Create devices QVariantMap deviceProps; QVariantMap inputProps; QString device1 = adapter + QLatin1String("/dev_40_79_6A_0C_39_75"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device1)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); deviceProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("00001124-0000-1000-8000-00805F9B34FB")); inputProps[QStringLiteral("ReconnectMode")] = QStringLiteral("none"); deviceProps[QStringLiteral("Input")] = inputProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); QString device2 = adapter + QLatin1String("/dev_50_79_6A_0C_39_75"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device2)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("50:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice2"); deviceProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("00001124-0000-1000-8000-00805F9B34FB")); inputProps[QStringLiteral("ReconnectMode")] = QStringLiteral("host"); deviceProps[QStringLiteral("Input")] = inputProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); QString device3 = adapter + QLatin1String("/dev_60_79_6B_0C_39_55"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device3)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("60:79:6B:0C:39:55"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice3"); deviceProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("00001124-0000-1000-8000-00805F9B34FB")); inputProps[QStringLiteral("ReconnectMode")] = QStringLiteral("device"); deviceProps[QStringLiteral("Input")] = inputProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); QString device4 = adapter + QLatin1String("/dev_70_79_6B_0C_39_55"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device4)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("70:79:6B:0C:39:55"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice4"); deviceProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("00001124-0000-1000-8000-00805F9B34FB")); inputProps[QStringLiteral("ReconnectMode")] = QStringLiteral("any"); deviceProps[QStringLiteral("Input")] = inputProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); m_manager = new Manager(); InitManagerJob *initJob = m_manager->init(); initJob->exec(); QVERIFY(!initJob->error()); for (DevicePtr device : m_manager->devices()) { QVERIFY(device->input()); InputUnit u; u.device = device; u.dbusInput = new org::bluez::Input1(service, device->ubi(), connection, this); m_units.append(u); } QCOMPARE(m_manager->adapters().count(), 1); QCOMPARE(m_manager->devices().count(), 4); } void InputTest::cleanupTestCase() { for (const InputUnit &unit : m_units) { delete unit.dbusInput; } delete m_manager; FakeBluez::stop(); } void InputTest::getPropertiesTest() { for (const InputUnit &unit : m_units) { QCOMPARE(reconnectModeString(unit.device->input()), unit.dbusInput->reconnectMode()); } } QString InputTest::reconnectModeString(const InputPtr &input) const { switch (input->reconnectMode()) { case Input::NoReconnect: return QStringLiteral("none"); case Input::HostReconnect: return QStringLiteral("host"); case Input::DeviceReconnect: return QStringLiteral("device"); default: return QStringLiteral("any"); } } QTEST_MAIN(InputTest) diff --git a/autotests/inputtest.h b/autotests/inputtest.h index 68667ee..cd36980 100644 --- a/autotests/inputtest.h +++ b/autotests/inputtest.h @@ -1,58 +1,44 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef INPUTTEST_H #define INPUTTEST_H #include #include "bluezinput1_tst.h" #include "manager.h" #include "device.h" #include "input.h" class InputTest : public QObject { Q_OBJECT public: explicit InputTest(); private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void getPropertiesTest(); private: QString reconnectModeString(const BluezQt::InputPtr &input) const; struct InputUnit { BluezQt::DevicePtr device; org::bluez::Input1 *dbusInput; }; BluezQt::Manager *m_manager; QList m_units; }; #endif // INPUTTEST_H diff --git a/autotests/jobstest.cpp b/autotests/jobstest.cpp index 56ff317..c5aa41e 100644 --- a/autotests/jobstest.cpp +++ b/autotests/jobstest.cpp @@ -1,109 +1,95 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "jobstest.h" #include "manager.h" #include "initmanagerjob.h" #include "obexmanager.h" #include "initobexmanagerjob.h" #include "device.h" #include #include using namespace BluezQt; void JobsTest::deleteManagerTest() { Manager *manager = new Manager(); InitManagerJob *job = manager->init(); QSignalSpy jobSpy(job, SIGNAL(result(InitManagerJob*))); job->start(); delete manager; // Deleting manager while init job is in progress should emit error QTRY_COMPARE(jobSpy.count(), 1); } void JobsTest::deleteInitManagerJobTest() { Manager *manager = new Manager(); InitManagerJob *job = manager->init(); QSignalSpy jobSpy(job, SIGNAL(result(InitManagerJob*))); job->start(); delete job; // Deleting the job should emit error QTRY_COMPARE(jobSpy.count(), 1); delete manager; manager = new Manager(); job = manager->init(); QSignalSpy jobSpy2(job, SIGNAL(result(InitManagerJob*))); job->start(); job->kill(); // Killing the job should NOT emit error QTRY_COMPARE(jobSpy2.count(), 0); } void JobsTest::deleteObexManagerTest() { ObexManager *manager = new ObexManager(); InitObexManagerJob *job = manager->init(); QSignalSpy jobSpy(job, SIGNAL(result(InitObexManagerJob*))); job->start(); delete manager; // Deleting manager while init job is in progress should emit error QTRY_COMPARE(jobSpy.count(), 1); } void JobsTest::deleteInitObexManagerJobTest() { ObexManager *manager = new ObexManager(); InitObexManagerJob *job = manager->init(); QSignalSpy jobSpy(job, SIGNAL(result(InitObexManagerJob*))); job->start(); delete job; // Deleting the job should emit error QTRY_COMPARE(jobSpy.count(), 1); delete manager; manager = new ObexManager(); job = manager->init(); QSignalSpy jobSpy2(job, SIGNAL(result(InitObexManagerJob*))); job->start(); job->kill(); // Killing the job should NOT emit error QTRY_COMPARE(jobSpy2.count(), 0); } QTEST_MAIN(JobsTest) diff --git a/autotests/jobstest.h b/autotests/jobstest.h index cfde793..8e31b1f 100644 --- a/autotests/jobstest.h +++ b/autotests/jobstest.h @@ -1,37 +1,23 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef JOBSTEST_H #define JOBSTEST_H #include class JobsTest : public QObject { Q_OBJECT private Q_SLOTS: void deleteManagerTest(); void deleteInitManagerJobTest(); void deleteObexManagerTest(); void deleteInitObexManagerJobTest(); }; #endif // JOBSTEST_H diff --git a/autotests/leadvertisingmanagertest.cpp b/autotests/leadvertisingmanagertest.cpp index 728eb6d..44fd31d 100644 --- a/autotests/leadvertisingmanagertest.cpp +++ b/autotests/leadvertisingmanagertest.cpp @@ -1,87 +1,73 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "leadvertisingmanagertest.h" #include "autotests.h" #include "initmanagerjob.h" #include "leadvertisingmanager.h" #include "manager.h" #include "pendingcall.h" #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; void TestAdvertisement::release() { m_releaseCalled = true; } void LEAdvertisingManagerTest::initTestCase() { bluezqt_initFakeBluezTestRun(); FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapter QString adapter = QStringLiteral("/org/bluez/hci0"); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(adapter)); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); Manager *manager = new Manager(this); InitManagerJob *initJob = manager->init(); initJob->exec(); QVERIFY(!initJob->error()); QCOMPARE(manager->adapters().count(), 1); m_adapter = manager->adapters().at(0); QVERIFY(m_adapter->leAdvertisingManager()); m_advertisement = new TestAdvertisement({QStringLiteral("ad100000-d901-11e8-9f8b-f2801f1b9fd1")}, this); auto call = m_adapter->leAdvertisingManager()->registerAdvertisement(m_advertisement); call->waitForFinished(); QVERIFY(!call->error()); } void LEAdvertisingManagerTest::cleanupTestCase() { FakeBluez::stop(); } void LEAdvertisingManagerTest::releaseTest() { QCOMPARE(m_advertisement->m_releaseCalled, false); QVariantMap params; params.insert(QStringLiteral("AdapterPath"), QVariant::fromValue(QDBusObjectPath(m_adapter->ubi()))); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("adapter-leadvertisingmanager:release"), params); QTRY_COMPARE(m_advertisement->m_releaseCalled, true); } QTEST_MAIN(LEAdvertisingManagerTest) diff --git a/autotests/leadvertisingmanagertest.h b/autotests/leadvertisingmanagertest.h index aa98bb2..851e093 100644 --- a/autotests/leadvertisingmanagertest.h +++ b/autotests/leadvertisingmanagertest.h @@ -1,51 +1,37 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "leadvertisement.h" #include "adapter.h" class TestAdvertisement : public BluezQt::LEAdvertisement { Q_OBJECT public: using BluezQt::LEAdvertisement::LEAdvertisement; void release() override; // release bool m_releaseCalled = false; }; class LEAdvertisingManagerTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void releaseTest(); private: TestAdvertisement* m_advertisement; BluezQt::AdapterPtr m_adapter; }; diff --git a/autotests/managertest.cpp b/autotests/managertest.cpp index 760fcc5..bef8294 100644 --- a/autotests/managertest.cpp +++ b/autotests/managertest.cpp @@ -1,461 +1,447 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "managertest.h" #include "autotests.h" #include "manager.h" #include "initmanagerjob.h" #include "adapter.h" #include "device.h" #include #include #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; void ManagerTest::initTestCase() { bluezqt_initFakeBluezTestRun(); FakeBluez::start(); // to check that it works Autotests::registerMetatypes(); } void ManagerTest::cleanup() { FakeBluez::stop(); } void ManagerTest::bluezNotRunningTest() { // org.bluez is not running at all // expected: init successful Manager *manager = new Manager; InitManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); QVERIFY(manager->isInitialized()); QVERIFY(!manager->isOperational()); QVERIFY(!manager->isBluetoothOperational()); delete manager; } void ManagerTest::bluezNotExportingInterfacesTest() { // org.bluez is running, but it does not export any interfaces // expected: init error FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-not-exporting-interfaces")); Manager *manager = new Manager; InitManagerJob *job = manager->init(); job->exec(); QVERIFY(job->error()); QVERIFY(!manager->isInitialized()); QVERIFY(!manager->isOperational()); QVERIFY(!manager->isBluetoothOperational()); delete manager; } void ManagerTest::bluezEmptyManagedObjectsTest() { // org.bluez exports ObjectManager, but there is no AgentManager1 // expected: init error FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-empty-managed-objects")); Manager *manager = new Manager; InitManagerJob *job = manager->init(); job->exec(); QVERIFY(job->error()); QVERIFY(!manager->isInitialized()); QVERIFY(!manager->isOperational()); QVERIFY(!manager->isBluetoothOperational()); delete manager; } void ManagerTest::bluezNoAdaptersTest() { // org.bluez exports ObjectManager with AgentManager1, but there are no adapters // expected: init successful FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-no-adapters")); Manager *manager = new Manager; InitManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); QVERIFY(manager->isInitialized()); QVERIFY(manager->isOperational()); QVERIFY(!manager->isBluetoothOperational()); delete manager; } void ManagerTest::bluezShutdownTest() { // tests whether the adapter/device removed signals work correctly FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapters QDBusObjectPath adapter1path = QDBusObjectPath(QStringLiteral("/org/bluez/hci0")); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); adapterProps[QStringLiteral("Powered")] = true; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); QDBusObjectPath adapter2path = QDBusObjectPath(QStringLiteral("/org/bluez/hci1")); adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter2path); adapterProps[QStringLiteral("Address")] = QStringLiteral("2E:3A:C3:BC:85:7C"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter2"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); // Create devices QVariantMap deviceProps; deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci0/dev_40_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(adapter1path); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci1/dev_50_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(adapter2path); deviceProps[QStringLiteral("Address")] = QStringLiteral("50:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice2"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); Manager *manager = new Manager; QSignalSpy btOperationalChangedSpy(manager, SIGNAL(bluetoothOperationalChanged(bool))); InitManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); QVERIFY(manager->isInitialized()); QVERIFY(manager->isOperational()); QVERIFY(manager->isBluetoothOperational()); QCOMPARE(manager->adapters().count(), 2); QCOMPARE(manager->devices().count(), 2); QCOMPARE(btOperationalChangedSpy.count(), 1); QCOMPARE(btOperationalChangedSpy.first().first().toBool(), true); AdapterPtr adapter1 = manager->adapterForAddress(QStringLiteral("1C:E5:C3:BC:94:7E")); AdapterPtr adapter2 = manager->adapterForAddress(QStringLiteral("2E:3A:C3:BC:85:7C")); DevicePtr device1 = manager->deviceForAddress(QStringLiteral("40:79:6A:0C:39:75")); DevicePtr device2 = manager->deviceForAddress(QStringLiteral("50:79:6A:0C:39:75")); QVERIFY(adapter1); QVERIFY(adapter2); QVERIFY(device1); QVERIFY(device2); QSignalSpy allAdaptersRemovedSpy(manager, SIGNAL(allAdaptersRemoved())); QSignalSpy adapterRemovedSpy(manager, SIGNAL(adapterRemoved(AdapterPtr))); QSignalSpy device1RemovedSpy(adapter1.data(), SIGNAL(deviceRemoved(DevicePtr))); QSignalSpy device2RemovedSpy(adapter2.data(), SIGNAL(deviceRemoved(DevicePtr))); btOperationalChangedSpy.clear(); FakeBluez::stop(); // allAdaptersRemoved will be last signal QTRY_COMPARE(allAdaptersRemovedSpy.count(), 1); QCOMPARE(adapterRemovedSpy.count(), 2); QCOMPARE(device1RemovedSpy.count(), 1); QCOMPARE(device2RemovedSpy.count(), 1); QCOMPARE(btOperationalChangedSpy.count(), 1); QCOMPARE(btOperationalChangedSpy.first().first().toBool(), false); delete manager; } void ManagerTest::usableAdapterTest() { FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapters QDBusObjectPath adapter1path = QDBusObjectPath(QStringLiteral("/org/bluez/hci0")); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); adapterProps[QStringLiteral("Powered")] = false; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); QDBusObjectPath adapter2path = QDBusObjectPath(QStringLiteral("/org/bluez/hci1")); adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter2path); adapterProps[QStringLiteral("Address")] = QStringLiteral("2E:3A:C3:BC:85:7C"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter2"); adapterProps[QStringLiteral("Powered")] = false; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); Manager *manager = new Manager; QSignalSpy usableAdapterChangedSpy(manager, SIGNAL(usableAdapterChanged(AdapterPtr))); InitManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); QVERIFY(manager->isInitialized()); QVERIFY(manager->isOperational()); QVERIFY(!manager->isBluetoothOperational()); QCOMPARE(usableAdapterChangedSpy.count(), 0); QCOMPARE(manager->adapters().count(), 2); QCOMPARE(manager->devices().count(), 0); QVariantMap properties; properties[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); properties[QStringLiteral("Name")] = QStringLiteral("Powered"); properties[QStringLiteral("Value")] = true; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("change-adapter-property"), properties); QTRY_COMPARE(usableAdapterChangedSpy.count(), 1); QCOMPARE(manager->usableAdapter()->ubi(), adapter1path.path()); usableAdapterChangedSpy.clear(); properties[QStringLiteral("Value")] = false; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("change-adapter-property"), properties); QTRY_COMPARE(usableAdapterChangedSpy.count(), 1); QVERIFY(manager->usableAdapter().isNull()); usableAdapterChangedSpy.clear(); properties[QStringLiteral("Path")] = QVariant::fromValue(adapter2path); properties[QStringLiteral("Value")] = true; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("change-adapter-property"), properties); QTRY_COMPARE(usableAdapterChangedSpy.count(), 1); QCOMPARE(manager->usableAdapter()->ubi(), adapter2path.path()); delete manager; } void ManagerTest::deviceForAddressTest() { // tests whether the deviceForAddress correctly prefer powered adapters FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapters QDBusObjectPath adapter1path = QDBusObjectPath(QStringLiteral("/org/bluez/hci0")); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); adapterProps[QStringLiteral("Powered")] = false; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); QDBusObjectPath adapter2path = QDBusObjectPath(QStringLiteral("/org/bluez/hci1")); adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter2path); adapterProps[QStringLiteral("Address")] = QStringLiteral("2E:3A:C3:BC:85:7C"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter2"); adapterProps[QStringLiteral("Powered")] = true; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); // Create devices QVariantMap deviceProps; deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci0/dev_40_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(adapter1path); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci1/dev_40_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(adapter2path); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); Manager *manager = new Manager; InitManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); QString address(QStringLiteral("40:79:6A:0C:39:75")); AdapterPtr adapter1 = manager->adapterForUbi(QStringLiteral("/org/bluez/hci0")); AdapterPtr adapter2 = manager->adapterForUbi(QStringLiteral("/org/bluez/hci1")); QVERIFY(adapter1); QVERIFY(adapter2); QSignalSpy adapter1Spy(adapter1.data(), SIGNAL(poweredChanged(bool))); QSignalSpy adapter2Spy(adapter2.data(), SIGNAL(poweredChanged(bool))); QCOMPARE(manager->deviceForAddress(address)->adapter(), adapter2); QVariantMap properties; properties[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); properties[QStringLiteral("Name")] = QStringLiteral("Powered"); properties[QStringLiteral("Value")] = true; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("change-adapter-property"), properties); properties[QStringLiteral("Path")] = QVariant::fromValue(adapter2path); properties[QStringLiteral("Value")] = false; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("change-adapter-property"), properties); QTRY_COMPARE(adapter1Spy.count(), 1); QTRY_COMPARE(adapter2Spy.count(), 1); QCOMPARE(manager->deviceForAddress(address)->adapter(), adapter1); properties[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); properties[QStringLiteral("Value")] = false; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("change-adapter-property"), properties); QTRY_COMPARE(adapter1Spy.count(), 2); QVERIFY(manager->deviceForAddress(address)); delete manager; } void ManagerTest::adapterWithDevicesRemovedTest() { // tests whether the devices are always removed from the adapter before removing adapter FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapters QDBusObjectPath adapter1path = QDBusObjectPath(QStringLiteral("/org/bluez/hci0")); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); adapterProps[QStringLiteral("Powered")] = false; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); // Create devices QVariantMap deviceProps; deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci0/dev_40_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(adapter1path); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci0/dev_50_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(adapter1path); deviceProps[QStringLiteral("Address")] = QStringLiteral("50:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice2"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); Manager *manager = new Manager; InitManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); AdapterPtr adapter = manager->adapterForAddress(QStringLiteral("1C:E5:C3:BC:94:7E")); DevicePtr device1 = manager->deviceForAddress(QStringLiteral("40:79:6A:0C:39:75")); DevicePtr device2 = manager->deviceForAddress(QStringLiteral("50:79:6A:0C:39:75")); QVERIFY(adapter); QVERIFY(device1); QVERIFY(device2); QSignalSpy adapterRemovedSpy(manager, SIGNAL(adapterRemoved(AdapterPtr))); QSignalSpy deviceRemovedSpy(manager, SIGNAL(deviceRemoved(DevicePtr))); QVariantMap properties; properties[QStringLiteral("Path")] = QVariant::fromValue(adapter1path); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("remove-adapter"), properties); QTRY_COMPARE(adapterRemovedSpy.count(), 1); QTRY_COMPARE(deviceRemovedSpy.count(), 2); QCOMPARE(manager->adapters().count(), 0); QCOMPARE(manager->devices().count(), 0); QCOMPARE(adapter->devices().count(), 0); delete manager; } void ManagerTest::bug364416() { // Bug 364416: Crash when device is added with adapter that is unknown to Manager FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); Manager *manager = new Manager; InitManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); // Add device to invalid adapter QVariantMap deviceProps; deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath("/org/bluez/hci0/dev_40_79_6A_0C_39_75")); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(QStringLiteral("/org/bluez/hci0"))); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); // Wait for Manager to receive the interfacesAdded signal QTest::qWait(100); delete manager; } void ManagerTest::bug377405() { // Bug 377405: Property changes immediately after adapter is added are lost FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); Manager *manager = new Manager; InitManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("bug377405")); // Adapter property Powered is changed to true immediately after being added QTRY_COMPARE(manager->isBluetoothOperational(), true); } QTEST_MAIN(ManagerTest) diff --git a/autotests/managertest.h b/autotests/managertest.h index 9de8ae1..b241691 100644 --- a/autotests/managertest.h +++ b/autotests/managertest.h @@ -1,48 +1,34 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef MANAGERTEST_H #define MANAGERTEST_H #include class ManagerTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void cleanup(); void bluezNotRunningTest(); void bluezNotExportingInterfacesTest(); void bluezEmptyManagedObjectsTest(); void bluezNoAdaptersTest(); void bluezShutdownTest(); void usableAdapterTest(); void deviceForAddressTest(); void adapterWithDevicesRemovedTest(); void bug364416(); void bug377405(); }; #endif // MANAGERTEST_H diff --git a/autotests/mediaplayertest.cpp b/autotests/mediaplayertest.cpp index e5a31f3..41169d6 100644 --- a/autotests/mediaplayertest.cpp +++ b/autotests/mediaplayertest.cpp @@ -1,436 +1,422 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediaplayertest.h" #include "autotests.h" #include "pendingcall.h" #include "initmanagerjob.h" #include "services.h" #include #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; Q_DECLARE_METATYPE(MediaPlayer::Equalizer) Q_DECLARE_METATYPE(MediaPlayer::Repeat) Q_DECLARE_METATYPE(MediaPlayer::Shuffle) Q_DECLARE_METATYPE(MediaPlayer::Status) MediaPlayerTest::MediaPlayerTest() : m_manager(nullptr) { Autotests::registerMetatypes(); qRegisterMetaType("Equalizer"); qRegisterMetaType("Repeat"); qRegisterMetaType("Shuffle"); qRegisterMetaType("Status"); qRegisterMetaType("MediaPlayerTrack"); } void MediaPlayerTest::initTestCase() { bluezqt_initFakeBluezTestRun(); FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapter QString adapter = QStringLiteral("/org/bluez/hci0"); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(adapter)); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); // Create devices QVariantMap deviceProps; QVariantMap mediaPlayerProps; QVariantMap trackProps; QString device1 = adapter + QLatin1String("/dev_40_79_6A_0C_39_75"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device1)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); deviceProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("0000110E-0000-1000-8000-00805F9B34FB")); mediaPlayerProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device1 + QLatin1String("/player0"))); mediaPlayerProps[QStringLiteral("Name")] = QStringLiteral("Player1"); mediaPlayerProps[QStringLiteral("Equalizer")] = QStringLiteral("on"); mediaPlayerProps[QStringLiteral("Repeat")] = QStringLiteral("singletrack"); mediaPlayerProps[QStringLiteral("Shuffle")] = QStringLiteral("group"); mediaPlayerProps[QStringLiteral("Status")] = QStringLiteral("stopped"); mediaPlayerProps[QStringLiteral("Position")] = QVariant::fromValue(quint32(150)); mediaPlayerProps[QStringLiteral("Device")] = QVariant::fromValue(QDBusObjectPath(device1)); trackProps[QStringLiteral("Title")] = QStringLiteral("Song1"); trackProps[QStringLiteral("Artist")] = QStringLiteral("Band1"); trackProps[QStringLiteral("Album")] = QStringLiteral("First Album"); trackProps[QStringLiteral("Genre")] = QStringLiteral("Rock"); trackProps[QStringLiteral("NumberOfTracks")] = 24; trackProps[QStringLiteral("TrackNumber")] = 4; trackProps[QStringLiteral("Duration")] = 12403; mediaPlayerProps[QStringLiteral("Track")] = trackProps; deviceProps[QStringLiteral("MediaPlayer")] = mediaPlayerProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); QString device2 = adapter + QLatin1String("/dev_50_79_6A_0C_39_75"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device2)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("50:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice2"); deviceProps[QStringLiteral("UUIDs")] = QStringList(QStringLiteral("0000110E-0000-1000-8000-00805F9B34FB")); mediaPlayerProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device2 + QLatin1String("/player0"))); mediaPlayerProps[QStringLiteral("Name")] = QStringLiteral("Player2"); mediaPlayerProps[QStringLiteral("Equalizer")] = QStringLiteral("off"); mediaPlayerProps[QStringLiteral("Repeat")] = QStringLiteral("alltracks"); mediaPlayerProps[QStringLiteral("Shuffle")] = QStringLiteral("off"); mediaPlayerProps[QStringLiteral("Status")] = QStringLiteral("paused"); mediaPlayerProps[QStringLiteral("Position")] = QVariant::fromValue(quint32(2500)); mediaPlayerProps[QStringLiteral("Device")] = QVariant::fromValue(QDBusObjectPath(device2)); trackProps[QStringLiteral("Title")] = QStringLiteral("Song2"); trackProps[QStringLiteral("Artist")] = QStringLiteral("Band2"); trackProps[QStringLiteral("Album")] = QStringLiteral("Second Album"); trackProps[QStringLiteral("Genre")] = QStringLiteral("Heavy Metal"); trackProps[QStringLiteral("NumberOfTracks")] = 666; trackProps[QStringLiteral("TrackNumber")] = 22; trackProps[QStringLiteral("Duration")] = 22403; mediaPlayerProps[QStringLiteral("Track")] = trackProps; deviceProps[QStringLiteral("MediaPlayer")] = mediaPlayerProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); m_manager = new Manager(); InitManagerJob *initJob = m_manager->init(); initJob->exec(); QVERIFY(!initJob->error()); QCOMPARE(m_manager->adapters().count(), 1); QCOMPARE(m_manager->devices().count(), 2); } void MediaPlayerTest::cleanupTestCase() { for (const MediaPlayerUnit &unit : m_units) { delete unit.dbusMediaPlayer; delete unit.dbusProperties; } delete m_manager; FakeBluez::stop(); } void MediaPlayerTest::connectTest() { for (DevicePtr device : m_manager->devices()) { QVERIFY(!device->ubi().isEmpty()); QVERIFY(!device->mediaPlayer()); QSignalSpy deviceSpy(device.data(), SIGNAL(mediaPlayerChanged(MediaPlayerPtr))); device->connectToDevice(); QTRY_COMPARE(deviceSpy.count(), 1); QVERIFY(device->mediaPlayer()); } } void MediaPlayerTest::disconnectTest() { for (DevicePtr device : m_manager->devices()) { QVERIFY(device->mediaPlayer()); QSignalSpy deviceSpy(device.data(), SIGNAL(mediaPlayerChanged(MediaPlayerPtr))); device->disconnectFromDevice(); QTRY_COMPARE(deviceSpy.count(), 1); QVERIFY(!device->mediaPlayer()); } } void MediaPlayerTest::connectProfileTest() { QDBusConnection connection = QDBusConnection::sessionBus(); QString service = QStringLiteral("org.kde.bluezqt.fakebluez"); for (DevicePtr device : m_manager->devices()) { QVERIFY(!device->ubi().isEmpty()); QVERIFY(!device->mediaPlayer()); QSignalSpy deviceSpy(device.data(), SIGNAL(mediaPlayerChanged(MediaPlayerPtr))); device->connectProfile(Services::AudioVideoRemoteControl); QTRY_COMPARE(deviceSpy.count(), 1); QVERIFY(device->mediaPlayer()); QString path = device->ubi() + QLatin1String("/player0"); MediaPlayerUnit u; u.device = device; u.dbusMediaPlayer = new org::bluez::MediaPlayer1(service, path, connection, this); u.dbusProperties = new org::freedesktop::DBus::Properties(service, path, connection, this); m_units.append(u); } } void MediaPlayerTest::getPropertiesTest() { for (const MediaPlayerUnit &unit : m_units) { QCOMPARE(unit.device->mediaPlayer()->name(), unit.dbusMediaPlayer->name()); QCOMPARE(equalizerString(unit.device->mediaPlayer()), unit.dbusMediaPlayer->equalizer()); QCOMPARE(repeatString(unit.device->mediaPlayer()), unit.dbusMediaPlayer->repeat()); QCOMPARE(shuffleString(unit.device->mediaPlayer()), unit.dbusMediaPlayer->shuffle()); QCOMPARE(statusString(unit.device->mediaPlayer()), unit.dbusMediaPlayer->status()); QCOMPARE(trackMap(unit.device->mediaPlayer()), unit.dbusMediaPlayer->track()); QCOMPARE(unit.device->mediaPlayer()->position(), unit.dbusMediaPlayer->position()); } } void MediaPlayerTest::setEqualizerTest() { for (const MediaPlayerUnit &unit : m_units) { MediaPlayerPtr mediaPlayer = unit.device->mediaPlayer(); MediaPlayer::Equalizer value = mediaPlayer->equalizer() == MediaPlayer::EqualizerOff ? MediaPlayer::EqualizerOn : MediaPlayer::EqualizerOff; QSignalSpy equalizerSpy(mediaPlayer.data(), SIGNAL(equalizerChanged(Equalizer))); mediaPlayer->setEqualizer(value); QTRY_COMPARE(equalizerSpy.count(), 1); QCOMPARE(equalizerSpy.at(0).at(0).value(), value); QCOMPARE(mediaPlayer->equalizer(), value); } } void MediaPlayerTest::setRepeatTest() { for (const MediaPlayerUnit &unit : m_units) { MediaPlayerPtr mediaPlayer = unit.device->mediaPlayer(); MediaPlayer::Repeat value = mediaPlayer->repeat() == MediaPlayer::RepeatGroup ? MediaPlayer::RepeatSingleTrack : MediaPlayer::RepeatGroup; QSignalSpy equalizerSpy(mediaPlayer.data(), SIGNAL(repeatChanged(Repeat))); mediaPlayer->setRepeat(value); QTRY_COMPARE(equalizerSpy.count(), 1); QCOMPARE(equalizerSpy.at(0).at(0).value(), value); QCOMPARE(mediaPlayer->repeat(), value); } } void MediaPlayerTest::setShuffleTest() { for (const MediaPlayerUnit &unit : m_units) { MediaPlayerPtr mediaPlayer = unit.device->mediaPlayer(); MediaPlayer::Shuffle value = mediaPlayer->shuffle() == MediaPlayer::ShuffleAllTracks ? MediaPlayer::ShuffleOff : MediaPlayer::ShuffleAllTracks; QSignalSpy equalizerSpy(mediaPlayer.data(), SIGNAL(shuffleChanged(Shuffle))); mediaPlayer->setShuffle(value); QTRY_COMPARE(equalizerSpy.count(), 1); QCOMPARE(equalizerSpy.at(0).at(0).value(), value); QCOMPARE(mediaPlayer->shuffle(), value); } } void MediaPlayerTest::changeStatusTest() { for (const MediaPlayerUnit &unit : m_units) { MediaPlayerPtr mediaPlayer = unit.device->mediaPlayer(); QSignalSpy statusSpy(mediaPlayer.data(), SIGNAL(statusChanged(Status))); if (mediaPlayer->status() != MediaPlayer::Stopped) { mediaPlayer->stop(); QTRY_COMPARE(statusSpy.count(), 1); QCOMPARE(statusSpy.at(0).at(0).value(), MediaPlayer::Stopped); QCOMPARE(mediaPlayer->status(), MediaPlayer::Stopped); } statusSpy.clear(); mediaPlayer->play(); QTRY_COMPARE(statusSpy.count(), 1); QCOMPARE(statusSpy.at(0).at(0).value(), MediaPlayer::Playing); QCOMPARE(mediaPlayer->status(), MediaPlayer::Playing); statusSpy.clear(); mediaPlayer->pause(); QTRY_COMPARE(statusSpy.count(), 1); QCOMPARE(statusSpy.at(0).at(0).value(), MediaPlayer::Paused); QCOMPARE(mediaPlayer->status(), MediaPlayer::Paused); statusSpy.clear(); mediaPlayer->fastForward(); QTRY_COMPARE(statusSpy.count(), 1); QCOMPARE(statusSpy.at(0).at(0).value(), MediaPlayer::ForwardSeek); QCOMPARE(mediaPlayer->status(), MediaPlayer::ForwardSeek); statusSpy.clear(); mediaPlayer->rewind(); QTRY_COMPARE(statusSpy.count(), 1); QCOMPARE(statusSpy.at(0).at(0).value(), MediaPlayer::ReverseSeek); QCOMPARE(mediaPlayer->status(), MediaPlayer::ReverseSeek); statusSpy.clear(); mediaPlayer->stop(); QTRY_COMPARE(statusSpy.count(), 1); QCOMPARE(statusSpy.at(0).at(0).value(), MediaPlayer::Stopped); QCOMPARE(mediaPlayer->status(), MediaPlayer::Stopped); } } void MediaPlayerTest::changeTrackTest() { for (const MediaPlayerUnit &unit : m_units) { MediaPlayerPtr mediaPlayer = unit.device->mediaPlayer(); QSignalSpy trackSpy(mediaPlayer.data(), SIGNAL(trackChanged(MediaPlayerTrack))); trackSpy.clear(); mediaPlayer->next(); QTRY_COMPARE(trackSpy.count(), 1); QCOMPARE(mediaPlayer->track().isValid(), true); trackSpy.clear(); mediaPlayer->previous(); QTRY_COMPARE(trackSpy.count(), 1); QCOMPARE(mediaPlayer->track().isValid(), true); } } void MediaPlayerTest::disconnectProfileTest() { for (const MediaPlayerUnit &unit : m_units) { QVERIFY(unit.device->mediaPlayer()); QSignalSpy deviceSpy(unit.device.data(), SIGNAL(mediaPlayerChanged(MediaPlayerPtr))); unit.device->disconnectProfile(Services::AudioVideoRemoteControl); QTRY_COMPARE(deviceSpy.count(), 1); QVERIFY(!unit.device->mediaPlayer()); } } void MediaPlayerTest::bug403289() { // Bug 403289: MediaPlayer interface path is not checked in InterfacesRemoved signal QDBusConnection connection = QDBusConnection::sessionBus(); QString service = QStringLiteral("org.kde.bluezqt.fakebluez"); for (DevicePtr device : m_manager->devices()) { QVERIFY(!device->mediaPlayer()); QSignalSpy deviceSpy(device.data(), SIGNAL(mediaPlayerChanged(MediaPlayerPtr))); const QVariantMap props = { { QStringLiteral("DevicePath"), QVariant::fromValue(QDBusObjectPath(device->ubi())) } }; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("bug403289"), props); QTRY_COMPARE(deviceSpy.count(), 1); QVERIFY(deviceSpy.at(0).at(0).value()); QTest::qWait(100); QCOMPARE(deviceSpy.count(), 1); device->disconnectProfile(Services::AudioVideoRemoteControl); QTRY_COMPARE(deviceSpy.count(), 2); QVERIFY(!deviceSpy.at(1).at(0).value()); } } QString MediaPlayerTest::equalizerString(const MediaPlayerPtr &mediaPlayer) const { switch (mediaPlayer->equalizer()) { case MediaPlayer::EqualizerOn: return QStringLiteral("on"); default: return QStringLiteral("off"); } } QString MediaPlayerTest::repeatString(const MediaPlayerPtr &mediaPlayer) const { switch (mediaPlayer->repeat()) { case MediaPlayer::RepeatSingleTrack: return QStringLiteral("singletrack"); case MediaPlayer::RepeatAllTracks: return QStringLiteral("alltracks"); case MediaPlayer::RepeatGroup: return QStringLiteral("group"); default: return QStringLiteral("off"); } } QString MediaPlayerTest::shuffleString(const MediaPlayerPtr &mediaPlayer) const { switch (mediaPlayer->shuffle()) { case MediaPlayer::ShuffleAllTracks: return QStringLiteral("alltracks"); case MediaPlayer::ShuffleGroup: return QStringLiteral("group"); default: return QStringLiteral("off"); } } QString MediaPlayerTest::statusString(const MediaPlayerPtr &mediaPlayer) const { switch (mediaPlayer->status()) { case MediaPlayer::Playing: return QStringLiteral("playing"); case MediaPlayer::Stopped: return QStringLiteral("stopped"); case MediaPlayer::Paused: return QStringLiteral("paused"); case MediaPlayer::ForwardSeek: return QStringLiteral("forward-seek"); case MediaPlayer::ReverseSeek: return QStringLiteral("reverse-seek"); default: return QStringLiteral("error"); } } QVariantMap MediaPlayerTest::trackMap(const MediaPlayerPtr &mediaPlayer) const { QVariantMap out; if (!mediaPlayer->track().isValid()) { return out; } out[QStringLiteral("Title")] = mediaPlayer->track().title(); out[QStringLiteral("Artist")] = mediaPlayer->track().artist(); out[QStringLiteral("Album")] = mediaPlayer->track().album(); out[QStringLiteral("Genre")] = mediaPlayer->track().genre(); out[QStringLiteral("NumberOfTracks")] = mediaPlayer->track().numberOfTracks(); out[QStringLiteral("TrackNumber")] = mediaPlayer->track().trackNumber(); out[QStringLiteral("Duration")] = mediaPlayer->track().duration(); return out; } QTEST_MAIN(MediaPlayerTest) diff --git a/autotests/mediaplayertest.h b/autotests/mediaplayertest.h index 6ae9a97..227f458 100644 --- a/autotests/mediaplayertest.h +++ b/autotests/mediaplayertest.h @@ -1,79 +1,65 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef MEDIAPLAYERTEST_H #define MEDIAPLAYERTEST_H #include #include #include "bluezdevice1_tst.h" #include "bluezmediaplayer1_tst.h" #include "dbusproperties_tst.h" #include "manager.h" #include "device.h" #include "mediaplayer.h" class MediaPlayerTest : public QObject { Q_OBJECT public: explicit MediaPlayerTest(); private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void connectTest(); void disconnectTest(); void connectProfileTest(); void getPropertiesTest(); void setEqualizerTest(); void setRepeatTest(); void setShuffleTest(); void changeStatusTest(); void changeTrackTest(); void disconnectProfileTest(); void bug403289(); private: QString equalizerString(const BluezQt::MediaPlayerPtr &mediaPlayer) const; QString repeatString(const BluezQt::MediaPlayerPtr &mediaPlayer) const; QString shuffleString(const BluezQt::MediaPlayerPtr &mediaPlayer) const; QString statusString(const BluezQt::MediaPlayerPtr &mediaPlayer) const; QVariantMap trackMap(const BluezQt::MediaPlayerPtr &mediaPlayer) const; struct MediaPlayerUnit { BluezQt::DevicePtr device; org::bluez::MediaPlayer1 *dbusMediaPlayer; org::freedesktop::DBus::Properties *dbusProperties; }; BluezQt::Manager *m_manager; QList m_units; }; #endif // MEDIAPLAYERTEST_H diff --git a/autotests/mediatest.cpp b/autotests/mediatest.cpp index c33fcb3..a8bbafd 100644 --- a/autotests/mediatest.cpp +++ b/autotests/mediatest.cpp @@ -1,149 +1,135 @@ /* - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediatest.h" #include "a2dp-codecs.h" #include "autotests.h" #include "initmanagerjob.h" #include "manager.h" #include "media.h" #include "mediaendpoint.h" #include "pendingcall.h" #include #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; void TestEndpoint::release() { m_releaseCalled = true; } void MediaTest::initTestCase() { bluezqt_initFakeBluezTestRun(); FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapter QString adapter = QStringLiteral("/org/bluez/hci0"); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(adapter)); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); Manager *manager = new Manager(this); InitManagerJob *initJob = manager->init(); initJob->exec(); QVERIFY(!initJob->error()); QCOMPARE(manager->adapters().count(), 1); m_adapter = manager->adapters().at(0); QVERIFY(m_adapter->media()); m_endpoint = new TestEndpoint({MediaEndpoint::Role::AudioSink, MediaEndpoint::Codec::Sbc}, this); m_adapter->media()->registerEndpoint(m_endpoint)->waitForFinished(); } void MediaTest::cleanupTestCase() { FakeBluez::stop(); } void MediaTest::setConfigurationTest() { QSignalSpy endpointSpy(m_endpoint, SIGNAL(configurationSet(QString,QVariantMap))); QVariantMap props; props.insert(QStringLiteral("Key"), QVariant::fromValue(int(123))); QVariantMap params; params.insert(QStringLiteral("AdapterPath"), QVariant::fromValue(QDBusObjectPath(m_adapter->ubi()))); params.insert(QStringLiteral("Transport"), QVariant::fromValue(m_endpoint->objectPath())); params.insert(QStringLiteral("Properties"), props); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("adapter-media:set-configuration"), params); endpointSpy.wait(); auto args = endpointSpy.takeFirst(); QCOMPARE(args.at(0).toString(), m_endpoint->objectPath().path()); QCOMPARE(args.at(1).value(), props); } void MediaTest::selectConfigurationTest() { QSignalSpy endpointSpy(m_endpoint, SIGNAL(configurationSelected(QByteArray,QByteArray))); a2dp_sbc_t sbcConfiguration; sbcConfiguration.frequency = SBC_SAMPLING_FREQ_44100; sbcConfiguration.channel_mode = SBC_CHANNEL_MODE_STEREO; sbcConfiguration.block_length = SBC_BLOCK_LENGTH_16; sbcConfiguration.subbands = SBC_SUBBANDS_8; sbcConfiguration.allocation_method = SBC_ALLOCATION_LOUDNESS; sbcConfiguration.min_bitpool = 2; sbcConfiguration.max_bitpool = 53; QVariantMap params; params.insert(QStringLiteral("AdapterPath"), QVariant::fromValue(QDBusObjectPath(m_adapter->ubi()))); params.insert(QStringLiteral("Capabilities"), QByteArray(reinterpret_cast(&sbcCapabilities), sizeof(sbcCapabilities))); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("adapter-media:select-configuration"), params); endpointSpy.wait(); auto args = endpointSpy.takeFirst(); QCOMPARE(args.at(0).toByteArray(), QByteArray(reinterpret_cast(&sbcCapabilities), sizeof(sbcCapabilities))); QCOMPARE(args.at(1).toByteArray(), QByteArray(reinterpret_cast(&sbcConfiguration), sizeof(sbcConfiguration))); params.insert(QStringLiteral("Capabilities"), QByteArray()); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("adapter-media:select-configuration"), params); endpointSpy.wait(); args = endpointSpy.takeFirst(); QCOMPARE(args.at(0).toByteArray(), QByteArray()); QCOMPARE(args.at(1).toByteArray(), QByteArray()); } void MediaTest::clearConfigurationTest() { QSignalSpy endpointSpy(m_endpoint, SIGNAL(configurationCleared(QString))); QVariantMap params; params.insert(QStringLiteral("AdapterPath"), QVariant::fromValue(QDBusObjectPath(m_adapter->ubi()))); params.insert(QStringLiteral("Transport"), QVariant::fromValue(m_endpoint->objectPath())); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("adapter-media:clear-configuration"), params); endpointSpy.wait(); auto args = endpointSpy.takeFirst(); QCOMPARE(args.at(0).toString(), m_endpoint->objectPath().path()); } void MediaTest::releaseTest() { QCOMPARE(m_endpoint->m_releaseCalled, false); QVariantMap params; params.insert(QStringLiteral("AdapterPath"), QVariant::fromValue(QDBusObjectPath(m_adapter->ubi()))); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("adapter-media:release"), params); QTRY_COMPARE(m_endpoint->m_releaseCalled, true); } QTEST_MAIN(MediaTest) diff --git a/autotests/mediatest.h b/autotests/mediatest.h index 697dc07..e3d5c08 100644 --- a/autotests/mediatest.h +++ b/autotests/mediatest.h @@ -1,57 +1,43 @@ /* - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef MEDIATEST_H #define MEDIATEST_H #include "mediaendpoint.h" #include "adapter.h" class TestEndpoint : public BluezQt::MediaEndpoint { Q_OBJECT public: using BluezQt::MediaEndpoint::MediaEndpoint; void release() override; // release bool m_releaseCalled = false; }; class MediaTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void setConfigurationTest(); void selectConfigurationTest(); void clearConfigurationTest(); void releaseTest(); private: TestEndpoint* m_endpoint; BluezQt::AdapterPtr m_adapter; }; #endif // MEDIATEST_H diff --git a/autotests/mediatransporttest.cpp b/autotests/mediatransporttest.cpp index 4888ce6..13591ec 100644 --- a/autotests/mediatransporttest.cpp +++ b/autotests/mediatransporttest.cpp @@ -1,271 +1,257 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediatransporttest.h" #include "a2dp-codecs.h" #include "autotests.h" #include "pendingcall.h" #include "initmanagerjob.h" #include "services.h" #include #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; Q_DECLARE_METATYPE(MediaTransport::State) static a2dp_sbc_t sbcConfiguration; static a2dp_aac_t aacConfiguration; static AudioCodec charToCodec(uchar value) { switch (value) { case A2DP_CODEC_SBC: return AudioCodec::Sbc; break; case A2DP_CODEC_MPEG24: return AudioCodec::Aac; break; } return AudioCodec::Invalid; } static AudioSampleRate byteArrayToSampleRate(AudioCodec codec, const QByteArray &buffer) { switch (codec) { case AudioCodec::Sbc: { if (buffer.size() != sizeof(a2dp_sbc_t)) { return AudioSampleRate::Invalid; } a2dp_sbc_t sbcConfig = *reinterpret_cast(buffer.constData()); switch (sbcConfig.frequency) { case SBC_SAMPLING_FREQ_44100: return AudioSampleRate::Rate44100; break; case SBC_SAMPLING_FREQ_48000: return AudioSampleRate::Rate48000; break; } break; } case AudioCodec::Aac: { if (buffer.size() != sizeof(a2dp_aac_t)) { return AudioSampleRate::Invalid; } a2dp_aac_t aacConfig = *reinterpret_cast(buffer.constData()); switch (AAC_GET_FREQUENCY(aacConfig)) { case AAC_SAMPLING_FREQ_44100: return AudioSampleRate::Rate44100; break; case AAC_SAMPLING_FREQ_48000: return AudioSampleRate::Rate48000; break; } break; } } return AudioSampleRate::Invalid; } QString stateString(MediaTransport::State state) { switch (state) { case MediaTransport::State::Idle: return QStringLiteral("idle"); case MediaTransport::State::Pending: return QStringLiteral("pending"); case MediaTransport::State::Active: return QStringLiteral("active"); } return {}; } MediaTransportTest::MediaTransportTest() : m_manager(nullptr) { Autotests::registerMetatypes(); qRegisterMetaType("State"); sbcConfiguration.frequency = SBC_SAMPLING_FREQ_44100; AAC_SET_FREQUENCY(aacConfiguration, AAC_SAMPLING_FREQ_48000); } void MediaTransportTest::initTestCase() { bluezqt_initFakeBluezTestRun(); FakeBluez::start(); FakeBluez::runTest(QStringLiteral("bluez-standard")); // Create adapter QString adapter = QStringLiteral("/org/bluez/hci0"); QVariantMap adapterProps; adapterProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(adapter)); adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); // Create devices QVariantMap deviceProps; QVariantMap mediaTransportProps; QString device1 = adapter + QLatin1String("/dev_40_79_6A_0C_39_75"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device1)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); deviceProps[QStringLiteral("UUIDs")] = QStringList(Services::AudioSink); mediaTransportProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device1 + QLatin1String("/fd0"))); mediaTransportProps[QStringLiteral("Device")] = QVariant::fromValue(QDBusObjectPath(device1)); mediaTransportProps[QStringLiteral("UUID")] = Services::AudioSink; mediaTransportProps[QStringLiteral("Codec")] = QVariant::fromValue(quint8(A2DP_CODEC_SBC)); // SBC mediaTransportProps[QStringLiteral("Configuration")] = QVariant::fromValue(QByteArray(reinterpret_cast(&sbcConfiguration), sizeof(sbcConfiguration))); mediaTransportProps[QStringLiteral("State")] = QStringLiteral("pending"); mediaTransportProps[QStringLiteral("Volume")] = QVariant::fromValue(quint16(63)); deviceProps[QStringLiteral("MediaTransport")] = mediaTransportProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); QString device2 = adapter + QLatin1String("/dev_50_79_6A_0C_39_75"); deviceProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device2)); deviceProps[QStringLiteral("Adapter")] = QVariant::fromValue(QDBusObjectPath(adapter)); deviceProps[QStringLiteral("Address")] = QStringLiteral("50:79:6A:0C:39:75"); deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice2"); deviceProps[QStringLiteral("UUIDs")] = QStringList(Services::AudioSink); mediaTransportProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(device2 + QLatin1String("/fd0"))); mediaTransportProps[QStringLiteral("Device")] = QVariant::fromValue(QDBusObjectPath(device2)); mediaTransportProps[QStringLiteral("UUID")] = Services::AudioSink; mediaTransportProps[QStringLiteral("Codec")] = QVariant::fromValue(quint8(A2DP_CODEC_MPEG24)); // AAC mediaTransportProps[QStringLiteral("Configuration")] = QVariant::fromValue(QByteArray(reinterpret_cast(&aacConfiguration), sizeof(aacConfiguration))); mediaTransportProps[QStringLiteral("State")] = QStringLiteral("active"); mediaTransportProps[QStringLiteral("Volume")] = QVariant::fromValue(quint16(127)); deviceProps[QStringLiteral("MediaTransport")] = mediaTransportProps; FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); m_manager = new Manager(); InitManagerJob *initJob = m_manager->init(); initJob->exec(); QVERIFY(!initJob->error()); QCOMPARE(m_manager->adapters().count(), 1); QCOMPARE(m_manager->devices().count(), 2); } void MediaTransportTest::cleanupTestCase() { for (const MediaTransportUnit &unit : m_units) { delete unit.dbusMediaTransport; delete unit.dbusProperties; } delete m_manager; FakeBluez::stop(); } void MediaTransportTest::connectTest() { for (DevicePtr device : m_manager->devices()) { QVERIFY(!device->ubi().isEmpty()); QVERIFY(!device->mediaTransport()); QSignalSpy deviceSpy(device.data(), SIGNAL(mediaTransportChanged(MediaTransportPtr))); device->connectToDevice(); QTRY_COMPARE(deviceSpy.count(), 1); QVERIFY(device->mediaTransport()); } } void MediaTransportTest::disconnectTest() { for (DevicePtr device : m_manager->devices()) { QVERIFY(device->mediaTransport()); QSignalSpy deviceSpy(device.data(), SIGNAL(mediaTransportChanged(MediaTransportPtr))); device->disconnectFromDevice(); QTRY_COMPARE(deviceSpy.count(), 1); QVERIFY(!device->mediaTransport()); } } void MediaTransportTest::connectProfileTest() { QDBusConnection connection = QDBusConnection::sessionBus(); QString service = QStringLiteral("org.kde.bluezqt.fakebluez"); for (DevicePtr device : m_manager->devices()) { QVERIFY(!device->ubi().isEmpty()); QVERIFY(!device->mediaTransport()); QSignalSpy deviceSpy(device.data(), SIGNAL(mediaTransportChanged(MediaTransportPtr))); device->connectProfile(Services::AudioSink); QTRY_COMPARE(deviceSpy.count(), 1); QVERIFY(device->mediaTransport()); QString path = device->ubi() + QLatin1String("/fd0"); MediaTransportUnit unit; unit.device = device; unit.dbusMediaTransport = new org::bluez::MediaTransport1(service, path, connection, this); unit.dbusProperties = new org::freedesktop::DBus::Properties(service, path, connection, this); m_units.append(unit); } } void MediaTransportTest::getPropertiesTest() { for (const MediaTransportUnit &unit : m_units) { QCOMPARE(unit.device->mediaTransport()->audioConfiguration().codec, charToCodec(unit.dbusMediaTransport->codec())); QCOMPARE(unit.device->mediaTransport()->audioConfiguration().sampleRate, byteArrayToSampleRate(unit.device->mediaTransport()->audioConfiguration().codec, unit.dbusMediaTransport->configuration())); QCOMPARE(stateString(unit.device->mediaTransport()->state()), unit.dbusMediaTransport->state()); QCOMPARE(unit.device->mediaTransport()->volume(), unit.dbusMediaTransport->volume()); } } void MediaTransportTest::disconnectProfileTest() { for (const MediaTransportUnit &unit : m_units) { QVERIFY(unit.device->mediaTransport()); QSignalSpy deviceSpy(unit.device.data(), SIGNAL(mediaTransportChanged(MediaTransportPtr))); unit.device->disconnectProfile(Services::AudioSink); QTRY_COMPARE(deviceSpy.count(), 1); QVERIFY(!unit.device->mediaTransport()); } } QTEST_MAIN(MediaTransportTest) diff --git a/autotests/mediatransporttest.h b/autotests/mediatransporttest.h index cf34ccb..4ad05e7 100644 --- a/autotests/mediatransporttest.h +++ b/autotests/mediatransporttest.h @@ -1,63 +1,49 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include #include #include "bluezdevice1_tst.h" #include "bluezmediatransport1_tst.h" #include "dbusproperties_tst.h" #include "manager.h" #include "device.h" #include "mediatransport.h" class MediaTransportTest : public QObject { Q_OBJECT public: explicit MediaTransportTest(); private Q_SLOTS: void initTestCase(); void cleanupTestCase(); void connectTest(); void disconnectTest(); void connectProfileTest(); void getPropertiesTest(); void disconnectProfileTest(); private: struct MediaTransportUnit { BluezQt::DevicePtr device; org::bluez::MediaTransport1 *dbusMediaTransport; org::freedesktop::DBus::Properties *dbusProperties; }; BluezQt::Manager *m_manager; QList m_units; }; diff --git a/autotests/obexmanagertest.cpp b/autotests/obexmanagertest.cpp index fc3e68e..29892e1 100644 --- a/autotests/obexmanagertest.cpp +++ b/autotests/obexmanagertest.cpp @@ -1,151 +1,137 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexmanagertest.h" #include "autotests.h" #include "obexmanager.h" #include "initobexmanagerjob.h" #include namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } using namespace BluezQt; void ObexManagerTest::initTestCase() { bluezqt_initFakeBluezTestRun(); FakeBluez::start(); // to check that it works } void ObexManagerTest::cleanup() { FakeBluez::stop(); } void ObexManagerTest::obexNotRunningTest() { // org.bluez.obex is not running at all // expected: init successful ObexManager *manager = new ObexManager; InitObexManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); QVERIFY(manager->isInitialized()); QVERIFY(!manager->isOperational()); delete manager; } void ObexManagerTest::obexNotExportingInterfacesTest() { // org.bluez.obex is running, but it does not export any interfaces // expected: init error FakeBluez::start(); FakeBluez::runTest(QStringLiteral("obex-not-exporting-interfaces")); ObexManager *manager = new ObexManager; InitObexManagerJob *job = manager->init(); job->exec(); QVERIFY(job->error()); QVERIFY(!manager->isInitialized()); QVERIFY(!manager->isOperational()); delete manager; } void ObexManagerTest::obexEmptyManagedObjectsTest() { // org.bluez.obex exports ObjectManager, but there is no AgentManager1 nor Client1 // expected: init error FakeBluez::start(); FakeBluez::runTest(QStringLiteral("obex-empty-managed-objects")); ObexManager *manager = new ObexManager; InitObexManagerJob *job = manager->init(); job->exec(); QVERIFY(job->error()); QVERIFY(!manager->isInitialized()); QVERIFY(!manager->isOperational()); delete manager; } void ObexManagerTest::obexNoClientTest() { // org.bluez.obex exports ObjectManager and AgentManager1, but there is no Client1 // expected: init error FakeBluez::start(); FakeBluez::runTest(QStringLiteral("obex-no-client")); ObexManager *manager = new ObexManager; InitObexManagerJob *job = manager->init(); job->exec(); QVERIFY(job->error()); QVERIFY(!manager->isInitialized()); QVERIFY(!manager->isOperational()); delete manager; } void ObexManagerTest::obexNoAgentManagerTest() { // org.bluez.obex exports ObjectManager and Client1, but there is no AgentManager1 // expected: init error FakeBluez::start(); FakeBluez::runTest(QStringLiteral("obex-no-agentmanager")); ObexManager *manager = new ObexManager; InitObexManagerJob *job = manager->init(); job->exec(); QVERIFY(job->error()); QVERIFY(!manager->isInitialized()); QVERIFY(!manager->isOperational()); delete manager; } void ObexManagerTest::obexServiceOkTest() { // org.bluez.obex is running and exports all used interfaces // expected: init successful FakeBluez::start(); FakeBluez::runTest(QStringLiteral("obex-standard")); ObexManager *manager = new ObexManager; InitObexManagerJob *job = manager->init(); job->exec(); QVERIFY(!job->error()); QVERIFY(manager->isInitialized()); QVERIFY(manager->isOperational()); delete manager; } QTEST_MAIN(ObexManagerTest) diff --git a/autotests/obexmanagertest.h b/autotests/obexmanagertest.h index 5fdbf87..af261f3 100644 --- a/autotests/obexmanagertest.h +++ b/autotests/obexmanagertest.h @@ -1,43 +1,29 @@ /* - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef OBEXMANAGERTEST_H #define OBEXMANAGERTEST_H #include class ObexManagerTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void cleanup(); void obexNotRunningTest(); void obexNotExportingInterfacesTest(); void obexEmptyManagedObjectsTest(); void obexNoClientTest(); void obexNoAgentManagerTest(); void obexServiceOkTest(); }; #endif // OBEXMANAGERTEST_H diff --git a/autotests/qml/tst_adapter.qml b/autotests/qml/tst_adapter.qml index 05e86d8..d2d455f 100644 --- a/autotests/qml/tst_adapter.qml +++ b/autotests/qml/tst_adapter.qml @@ -1,273 +1,259 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ import QtTest 1.0 import QtQuick 2.2 import org.kde.bluezqt.fakebluez 1.0 import org.kde.bluezqt 1.0 as BluezQt TestCase { name: "Adapter" property QtObject manager : BluezQt.Manager; property var adapter1props; property var adapter2props; function initTestCase() { FakeBluez.start(); FakeBluez.runTest("bluez-standard"); // Create adapters var adapter1path = "/org/bluez/hci0"; adapter1props = { Path: adapter1path, Address: "1C:E5:C3:BC:94:7E", Name: "TestAdapter", Alias: "TestAlias", Class: 101, Powered: false, Discoverable: false, Pairable: false, PairableTimeout: 0, DiscoverableTimeout: 0, Discovering: false, UUIDs: [ "00001200-0000-1000-8000-00805f9b34fb" ], Modalias: "usb:v2D6Bp1236d0215", _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "create-adapter", adapter1props); var adapter2path = "/org/bluez/hci1"; adapter2props = { Path: adapter2path, Address: "2E:3A:C3:BC:85:7C", Name: "TestAdapter2", Alias: "TestAlias2", Class: 201, Powered: true, Discoverable: true, Pairable: true, PairableTimeout: 150, DiscoverableTimeout: 120, Discovering: false, UUIDs: [ "0000110c-0000-1000-8000-00805f9b34fb" ], Modalias: "usb:v1D3Bp1134d0214", _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "create-adapter", adapter2props); // Create devices var device1props = { Path: "/org/bluez/hci0/dev_40_79_6A_0C_39_75", Adapter: adapter1path, Address: "40:79:6A:0C:39:75", Name: "TestDevice", _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device1props); var device2props = { Path: "/org/bluez/hci1/dev_50_79_6A_0C_39_75", Adapter: adapter2path, Address: "50:79:6A:0C:39:75", Name: "TestDevice2", _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device2props); tryCompare(manager, "operational", true); compare(manager.adapters.length, 2, "adapters-length"); compare(manager.devices.length, 2, "devices-length"); } function cleanupTestCase() { FakeBluez.stop(); } function compareProperties(adapter, props) { compare(adapter.ubi, props.Path, "ubi"); compare(adapter.address, props.Address, "address"); compare(adapter.name, props.Alias, "name"); compare(adapter.systemName, props.Name, "systemName"); compare(adapter.adapterClass, props.Class, "adapterClass"); compare(adapter.powered, props.Powered, "powered"); compare(adapter.discoverable, props.Discoverable, "discoverable"); compare(adapter.pairable, props.Pairable, "pairable"); compare(adapter.pairableTimeout, props.PairableTimeout, "pairableTimeout"); compare(adapter.discoverableTimeout, props.DiscoverableTimeout, "discoverableTimeout"); compare(adapter.discovering, props.Discovering, "discovering"); compare(adapter.modalias, props.Modalias, "modalias"); for (var i = 0; i < adapter.uuids.length; ++i) { compare(adapter.uuids[i], props.UUIDs[i].toUpperCase(), "uuids" + i); } } function test_getProperties() { var adapter1 = manager.adapterForUbi(adapter1props.Path); var adapter2 = manager.adapterForUbi(adapter2props.Path); compareProperties(adapter1, adapter1props); compareProperties(adapter2, adapter2props); } SignalSpy { id: nameChangedSpy signalName: "nameChanged" } function test_setName() { for (var i = 0; i < manager.adapters.length; ++i) { var adapter = manager.adapters[i]; var value = adapter.name + "tst_name"; nameChangedSpy.clear(); nameChangedSpy.target = adapter; adapter.name = value; tryCompare(nameChangedSpy, "count", 1); compare(adapter.name, value); } } SignalSpy { id: poweredChangedSpy signalName: "poweredChanged" } function test_setPowered() { for (var i = 0; i < manager.adapters.length; ++i) { var adapter = manager.adapters[i]; var value = !adapter.powered; poweredChangedSpy.clear(); poweredChangedSpy.target = adapter; adapter.powered = value; tryCompare(poweredChangedSpy, "count", 1); compare(adapter.powered, value); } } SignalSpy { id: discoveringChangedSpy signalName: "discoveringChanged" } function test_discovery() { for (var i = 0; i < manager.adapters.length; ++i) { var adapter = manager.adapters[i]; discoveringChangedSpy.clear(); discoveringChangedSpy.target = adapter; adapter.startDiscovery(); tryCompare(discoveringChangedSpy, "count", 1); compare(adapter.discovering, true); discoveringChangedSpy.clear(); adapter.stopDiscovery(); tryCompare(discoveringChangedSpy, "count", 1); compare(adapter.discovering, false); } } SignalSpy { id: managerDeviceRemovedSpy signalName: "deviceRemoved" } SignalSpy { id: adapterDeviceRemovedSpy signalName: "deviceRemoved" } SignalSpy { id: deviceDeviceRemovedSpy signalName: "deviceRemoved" } // za prefix to force test order - second last function test_za_RemoveDevice() { for (var i = 0; i < manager.adapters.length; ++i) { var adapter = manager.adapters[i]; while (adapter.devices.length > 0) { var device = adapter.devices[0]; managerDeviceRemovedSpy.clear(); managerDeviceRemovedSpy.target = manager; adapterDeviceRemovedSpy.clear(); adapterDeviceRemovedSpy.target = adapter; deviceDeviceRemovedSpy.clear(); deviceDeviceRemovedSpy.target = device; adapter.removeDevice(device); tryCompare(managerDeviceRemovedSpy, "count", 1); tryCompare(adapterDeviceRemovedSpy, "count", 1); tryCompare(deviceDeviceRemovedSpy, "count", 1); } } } SignalSpy { id: managerAdapterRemovedSpy signalName: "adapterRemoved" } SignalSpy { id: adapterAdapterRemovedSpy signalName: "adapterRemoved" } // zb prefix to force test order - last function test_zb_AdapterRemoved() { while (manager.adapters.length > 0) { var adapter = manager.adapters[0]; managerAdapterRemovedSpy.clear(); managerAdapterRemovedSpy.target = manager; adapterAdapterRemovedSpy.clear(); adapterAdapterRemovedSpy.target = adapter; var props = { Path: adapter.ubi, _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "remove-adapter", props); tryCompare(managerAdapterRemovedSpy, "count", 1); tryCompare(adapterAdapterRemovedSpy, "count", 1); } } } diff --git a/autotests/qml/tst_device.qml b/autotests/qml/tst_device.qml index ad6a804..cd62418 100644 --- a/autotests/qml/tst_device.qml +++ b/autotests/qml/tst_device.qml @@ -1,222 +1,208 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ import QtTest 1.0 import QtQuick 2.2 import org.kde.bluezqt.fakebluez 1.0 import org.kde.bluezqt 1.0 as BluezQt TestCase { name: "Device" property QtObject manager : BluezQt.Manager; property var device1props; property var device2props; function initTestCase() { FakeBluez.start(); FakeBluez.runTest("bluez-standard"); // Create adapters var adapter1path = "/org/bluez/hci0"; var adapter1props = { Path: adapter1path, Address: "1C:E5:C3:BC:94:7E", Name: "TestAdapter", _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "create-adapter", adapter1props); var adapter2path = "/org/bluez/hci1"; var adapter2props = { Path: adapter2path, Address: "2E:3A:C3:BC:85:7C", Name: "TestAdapter2", _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "create-adapter", adapter2props); // Create devices device1props = { Path: "/org/bluez/hci0/dev_40_79_6A_0C_39_75", Adapter: adapter1path, Address: "40:79:6A:0C:39:75", Name: "TestDevice", Alias: "TestAlias", Icon: "phone", Class: 101, Appearance: 25, UUIDs: [ "00001200-0000-1000-8000-00805f9b34fb" ], Paired: false, Connected: false, Trusted: false, Blocked: false, LegacyPairing: false, RSSI: 20, Modalias: "bluetooth:v001Dp1200d1236", _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device1props); device2props = { Path: "/org/bluez/hci1/dev_50_79_6A_0C_39_75", Adapter: adapter2path, Address: "50:79:6A:0C:39:75", Name: "TestDevice2", Alias: "TestAlias2", Icon: "joypad", Class: 201, Appearance: 32, UUIDs: [ "00001124-0000-1000-8000-00805f9b34fb" ], Paired: true, Connected: false, Trusted: true, Blocked: false, LegacyPairing: true, RSSI: -15, Modalias: "bluetooth:v001Dp1200d1136", _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device2props); tryCompare(manager, "operational", true); compare(manager.adapters.length, 2, "adapters-length"); compare(manager.devices.length, 2, "devices-length"); } function cleanupTestCase() { FakeBluez.stop(); } function compareProperties(device, props) { compare(device.ubi, props.Path, "ubi"); compare(device.address, props.Address, "address"); compare(device.name, props.Alias, "name"); compare(device.remoteName, props.Name, "remoteName"); compare(device.icon, props.Icon, "icon"); compare(device.deviceClass, props.Class, "deviceClass"); compare(device.appearance, props.Appearance, "appearance"); compare(device.paired, props.Paired, "paired"); compare(device.connected, props.Connected, "connected"); compare(device.trusted, props.Trusted, "trusted"); compare(device.blocked, props.Blocked, "blocked"); compare(device.legacyPairing, props.LegacyPairing, "legacyPairing"); compare(device.rssi, props.RSSI, "rssi"); compare(device.modalias, props.Modalias, "modalias"); compare(device.adapter.ubi, props.Adapter, "adapter"); for (var i = 0; i < device.uuids.length; ++i) { compare(device.uuids[i], props.UUIDs[i].toUpperCase(), "uuids" + i); } } function test_getProperties() { var device1 = manager.deviceForUbi(device1props.Path); var device2 = manager.deviceForUbi(device2props.Path); compareProperties(device1, device1props); compareProperties(device2, device2props); } SignalSpy { id: nameChangedSpy signalName: "nameChanged" } function test_setName() { for (var i = 0; i < manager.devices.length; ++i) { var device = manager.devices[i]; var value = device.name + "tst_name"; nameChangedSpy.clear(); nameChangedSpy.target = device; device.name = value; tryCompare(nameChangedSpy, "count", 1); compare(device.name, value); } } SignalSpy { id: trustedChangedSpy signalName: "trustedChanged" } function test_setTrusted() { for (var i = 0; i < manager.devices.length; ++i) { var device = manager.devices[i]; var value = !device.trusted; trustedChangedSpy.clear(); trustedChangedSpy.target = device; device.trusted = value; tryCompare(trustedChangedSpy, "count", 1); compare(device.trusted, value); } } SignalSpy { id: managerDeviceRemovedSpy signalName: "deviceRemoved" } SignalSpy { id: adapterDeviceRemovedSpy signalName: "deviceRemoved" } SignalSpy { id: deviceDeviceRemovedSpy signalName: "deviceRemoved" } // za prefix to force test order - last function test_za_DeviceRemoved() { while (manager.devices.length > 0) { var device = manager.devices[0]; managerDeviceRemovedSpy.clear(); managerDeviceRemovedSpy.target = manager; adapterDeviceRemovedSpy.clear(); adapterDeviceRemovedSpy.target = device.adapter; deviceDeviceRemovedSpy.clear(); deviceDeviceRemovedSpy.target = device; var props = { Path: device.ubi, _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "remove-device", props); tryCompare(managerDeviceRemovedSpy, "count", 1); tryCompare(adapterDeviceRemovedSpy, "count", 1); tryCompare(deviceDeviceRemovedSpy, "count", 1); } } } diff --git a/autotests/qml/tst_input.qml b/autotests/qml/tst_input.qml index 091566d..6650c15 100644 --- a/autotests/qml/tst_input.qml +++ b/autotests/qml/tst_input.qml @@ -1,152 +1,138 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ import QtTest 1.0 import QtQuick 2.2 import org.kde.bluezqt.fakebluez 1.0 import org.kde.bluezqt 1.0 as BluezQt TestCase { name: "Input" property QtObject manager : BluezQt.Manager; property var input1props; property var input2props; property var input3props; property var input4props; property var device1props; property var device2props; property var device3props; property var device4props; function initTestCase() { FakeBluez.start(); FakeBluez.runTest("bluez-standard"); // Create adapter var adapter1path = "/org/bluez/hci0"; var adapter1props = { Path: adapter1path, Address: "1C:E5:C3:BC:94:7E", Name: "TestAdapter", _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "create-adapter", adapter1props); // Create devices input1props = { ReconnectMode: "none" } device1props = { Path: "/org/bluez/hci0/dev_40_79_6A_0C_39_75", Adapter: adapter1path, Address: "40:79:6A:0C:39:75", Name: "TestDevice", UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ], Input: input1props, _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device1props); input2props = { ReconnectMode: "none" } device2props = { Path: "/org/bluez/hci0/dev_50_79_6A_0C_39_75", Adapter: adapter1path, Address: "50:79:6A:0C:39:75", Name: "TestDevice2", UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ], Input: input2props, _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device2props); input3props = { ReconnectMode: "none" } device3props = { Path: "/org/bluez/hci0/dev_60_79_6A_0C_39_75", Adapter: adapter1path, Address: "60:79:6A:0C:39:75", Name: "TestDevice2", UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ], Input: input3props, _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device3props); input4props = { ReconnectMode: "none" } device4props = { Path: "/org/bluez/hci0/dev_70_79_6A_0C_39_75", Adapter: adapter1path, Address: "70:79:6A:0C:39:75", Name: "TestDevice2", UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ], Input: input4props, _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device4props); tryCompare(manager, "operational", true); compare(manager.adapters.length, 1, "adapters-length"); compare(manager.devices.length, 4, "devices-length"); } function cleanupTestCase() { FakeBluez.stop(); } function compareProperties(input, props) { compare(modeString(input), props.ReconnectMode, "reconnectMode"); } function test_getProperties() { var device1 = manager.deviceForUbi(device1props.Path); var device2 = manager.deviceForUbi(device2props.Path); var device3 = manager.deviceForUbi(device3props.Path); var device4 = manager.deviceForUbi(device4props.Path); compareProperties(device1.input, input1props); compareProperties(device2.input, input2props); compareProperties(device3.input, input3props); compareProperties(device4.input, input4props); } function modeString(input) { switch (input.reconnectMode) { case BluezQt.Input.NoReconnect: return "none"; case BluezQt.Input.HostReconnect: return "host"; case BluezQt.Input.DeviceReconnect: return "device"; default: return "any"; } } } diff --git a/autotests/qml/tst_manager.qml b/autotests/qml/tst_manager.qml index 8ac949d..66807ed 100644 --- a/autotests/qml/tst_manager.qml +++ b/autotests/qml/tst_manager.qml @@ -1,204 +1,190 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ import QtTest 1.0 import QtQuick 2.2 import org.kde.bluezqt.fakebluez 1.0 import org.kde.bluezqt 1.0 as BluezQt TestCase { name: "Manager" function cleanup() { FakeBluez.stop(); } function test_bluezNotRunning() { var manager = BluezQt.Manager; tryCompare(manager, "operational", false); verify(!manager.operational, "operational"); verify(!manager.bluetoothOperational, "btOperational"); } function test_bluezNotExportingInterfaces() { FakeBluez.start(); FakeBluez.runTest("bluez-not-exporting-interfaces"); var manager = BluezQt.Manager; tryCompare(manager, "operational", false); verify(!manager.operational, "operational"); verify(!manager.bluetoothOperational, "btOperational"); } function test_bluezNoAdapters() { FakeBluez.start(); FakeBluez.runTest("bluez-no-adapters"); var manager = BluezQt.Manager; tryCompare(manager, "operational", true); verify(manager.operational, "operational"); verify(!manager.bluetoothOperational, "btOperational"); } SignalSpy { id: usableAdapterChangedSpy signalName: "usableAdapterChanged" } function test_usableAdapter() { FakeBluez.start(); FakeBluez.runTest("bluez-standard"); var adapter1path = "/org/bluez/hci0"; var adapter1props = { Path: adapter1path, Address: "1C:E5:C3:BC:94:7E", Name: "TestAdapter", Powered: false, _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "create-adapter", adapter1props); var adapter2path = "/org/bluez/hci1"; var adapter2props = { Path: adapter2path, Address: "2E:3A:C3:BC:85:7C", Name: "TestAdapter2", Powered: false, _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "create-adapter", adapter2props); var manager = BluezQt.Manager; tryCompare(manager, "operational", true); verify(!manager.bluetoothOperational, "btOperational"); usableAdapterChangedSpy.target = manager; var properties = { Path: adapter1path, Name: "Powered", Value: true, _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "change-adapter-property", properties); tryCompare(usableAdapterChangedSpy, "count", 1); compare(manager.usableAdapter.ubi, adapter1path); usableAdapterChangedSpy.clear(); properties.Value = false; FakeBluez.runAction("devicemanager", "change-adapter-property", properties); tryCompare(usableAdapterChangedSpy, "count", 1); compare(manager.usableAdapter, null); usableAdapterChangedSpy.clear(); properties.Path = adapter2path; properties.Value = true; FakeBluez.runAction("devicemanager", "change-adapter-property", properties); tryCompare(usableAdapterChangedSpy, "count", 1); compare(manager.usableAdapter.ubi, adapter2path); } SignalSpy { id: managerAdapterRemovedSpy signalName: "adapterRemoved" } SignalSpy { id: managerDeviceRemovedSpy signalName: "deviceRemoved" } function test_adapterWithDevicesRemoved() { FakeBluez.start(); FakeBluez.runTest("bluez-standard"); var adapter1path = "/org/bluez/hci0"; var adapterProps = { Path: adapter1path, Address: "1C:E5:C3:BC:94:7E", Name: "TestAdapter", Powered: false, _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "create-adapter", adapterProps); var device1props = { Path: "/org/bluez/hci0/dev_40_79_6A_0C_39_75", Adapter: adapter1path, Address: "40:79:6A:0C:39:75", Name: "TestDevice", _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device1props); var device2props = { Path: "/org/bluez/hci0/dev_50_79_6A_0C_39_75", Adapter: adapter1path, Address: "50:79:6A:0C:39:75", Name: "TestDevice2", _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device2props); var manager = BluezQt.Manager; tryCompare(manager, "operational", true); var adapter = manager.adapterForAddress("1C:E5:C3:BC:94:7E"); var device1 = manager.deviceForAddress("40:79:6A:0C:39:75"); var device2 = manager.deviceForAddress("50:79:6A:0C:39:75"); verify(adapter); verify(device1); verify(device2); managerAdapterRemovedSpy.target = manager; managerDeviceRemovedSpy.target = manager; var properties = { Path: adapter1path, _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "remove-adapter", properties); tryCompare(managerAdapterRemovedSpy, "count", 1); tryCompare(managerDeviceRemovedSpy, "count", 2); compare(manager.adapters.length, 0); compare(manager.devices.length, 0); } } diff --git a/autotests/qml/tst_mediaplayer.qml b/autotests/qml/tst_mediaplayer.qml index abae4cc..7afcbde 100644 --- a/autotests/qml/tst_mediaplayer.qml +++ b/autotests/qml/tst_mediaplayer.qml @@ -1,374 +1,360 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ import QtTest 1.0 import QtQuick 2.2 import org.kde.bluezqt.fakebluez 1.0 import org.kde.bluezqt 1.0 as BluezQt TestCase { name: "MediaPlayer" property QtObject manager : BluezQt.Manager; property var mediaPlayer1props; property var mediaPlayer2props; function initTestCase() { FakeBluez.start(); FakeBluez.runTest("bluez-standard"); // Create adapter var adapter1path = "/org/bluez/hci0"; var adapter1props = { Path: adapter1path, Address: "1C:E5:C3:BC:94:7E", Name: "TestAdapter", _toDBusObjectPath: [ "Path" ] } FakeBluez.runAction("devicemanager", "create-adapter", adapter1props); // Create devices mediaPlayer1props = { Path: "/org/bluez/hci0/dev_40_79_6A_0C_39_75/player0", Name: "Player1", Equalizer: "on", Repeat: "singletrack", Shuffle: "group", Status: "stopped", Position: 150, Device: "/org/bluez/hci0/dev_40_79_6A_0C_39_75", Track: { Title: "Song1", Artist: "Band1", Album: "First Album", Genre: "Rock", NumberOfTracks: 24, TrackNumber: 4, Duration: 12403 }, _toDBusObjectPath: [ "Path", "Device" ] } var device1props = { Path: "/org/bluez/hci0/dev_40_79_6A_0C_39_75", Adapter: adapter1path, Address: "40:79:6A:0C:39:75", Name: "TestDevice", UUIDs: [ "0000110E-0000-1000-8000-00805F9B34FB" ], MediaPlayer: mediaPlayer1props, _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device1props); mediaPlayer2props = { Path: "/org/bluez/hci0/dev_50_79_6A_0C_39_75/player0", Name: "Player2", Equalizer: "off", Repeat: "alltracks", Shuffle: "off", Status: "paused", Position: 2500, Device: "/org/bluez/hci0/dev_50_79_6A_0C_39_75", Track: { Title: "Song2", Artist: "Band2", Album: "Second Album", Genre: "Heavy Metal", NumberOfTracks: 666, TrackNumber: 22, Duration: 22403 }, _toDBusObjectPath: [ "Path", "Device" ] } var device2props = { Path: "/org/bluez/hci0/dev_50_79_6A_0C_39_75", Adapter: adapter1path, Address: "50:79:6A:0C:39:75", Name: "TestDevice2", UUIDs: [ "0000110E-0000-1000-8000-00805F9B34FB" ], MediaPlayer: mediaPlayer2props, _toDBusObjectPath: [ "Path", "Adapter" ] } FakeBluez.runAction("devicemanager", "create-device", device2props); tryCompare(manager, "operational", true); compare(manager.adapters.length, 1, "adapters-length"); compare(manager.devices.length, 2, "devices-length"); } function cleanupTestCase() { FakeBluez.stop(); } SignalSpy { id: mediaPlayerChangedSpy signalName: "mediaPlayerChanged" } function test_a_connect() { for (var i = 0; i < manager.devices.length; ++i) { var device = manager.devices[i]; verify(!device.mediaPlayer); mediaPlayerChangedSpy.clear(); mediaPlayerChangedSpy.target = device; device.connectToDevice(); tryCompare(mediaPlayerChangedSpy, "count", 1, 100 * 1000); verify(device.mediaPlayer); } } function compareProperties(mediaPlayer, props) { compare(mediaPlayer.name, props.Name, "name"); compare(equalizerString(mediaPlayer), props.Equalizer, "equalizer"); compare(repeatString(mediaPlayer), props.Repeat, "repeat"); compare(shuffleString(mediaPlayer), props.Shuffle, "shuffle"); compare(statusString(mediaPlayer), props.Status, "status"); compare(mediaPlayer.position, props.Position, "position"); compare(mediaPlayer.track.title, props.Track.Title, "track-title"); compare(mediaPlayer.track.artist, props.Track.Artist, "track-artist"); compare(mediaPlayer.track.album, props.Track.Album, "track-album"); compare(mediaPlayer.track.genre, props.Track.Genre, "track-genre"); compare(mediaPlayer.track.numberOfTracks, props.Track.NumberOfTracks, "track-#tracks"); compare(mediaPlayer.track.trackNumber, props.Track.TrackNumber, "track-trackNumber"); compare(mediaPlayer.track.duration, props.Track.Duration, "track-duration"); } function test_getProperties() { var mediaPlayer1 = manager.deviceForUbi(mediaPlayer1props.Device).mediaPlayer; var mediaPlayer2 = manager.deviceForUbi(mediaPlayer2props.Device).mediaPlayer; compareProperties(mediaPlayer1, mediaPlayer1props); compareProperties(mediaPlayer2, mediaPlayer2props); } SignalSpy { id: equalizerChangedSpy signalName: "equalizerChanged" } function test_setEqualizer() { for (var i = 0; i < manager.devices.length; ++i) { var mediaPlayer = manager.devices[i].mediaPlayer; var value = mediaPlayer.equalizer === BluezQt.MediaPlayer.EqualizerOff ? BluezQt.MediaPlayer.EqualizerOn : BluezQt.MediaPlayer.EqualizerOff; equalizerChangedSpy.clear(); equalizerChangedSpy.target = mediaPlayer; mediaPlayer.equalizer = value; tryCompare(equalizerChangedSpy, "count", 1); compare(mediaPlayer.equalizer, value); } } SignalSpy { id: repeatChangedSpy signalName: "repeatChanged" } function test_setRepeat() { for (var i = 0; i < manager.devices.length; ++i) { var mediaPlayer = manager.devices[i].mediaPlayer; var value = mediaPlayer.repeat === BluezQt.MediaPlayer.RepeatGroup ? BluezQt.MediaPlayer.RepeatSingleTrack : BluezQt.MediaPlayer.RepeatGroup; repeatChangedSpy.clear(); repeatChangedSpy.target = mediaPlayer; mediaPlayer.repeat = value; tryCompare(repeatChangedSpy, "count", 1); compare(mediaPlayer.repeat, value); } } SignalSpy { id: shuffleChangedSpy signalName: "shuffleChanged" } function test_setShuffle() { for (var i = 0; i < manager.devices.length; ++i) { var mediaPlayer = manager.devices[i].mediaPlayer; var value = mediaPlayer.shuffle === BluezQt.MediaPlayer.ShuffleAllTracks ? BluezQt.MediaPlayer.ShuffleOff : BluezQt.MediaPlayer.ShuffleAllTracks; shuffleChangedSpy.clear(); shuffleChangedSpy.target = mediaPlayer; mediaPlayer.shuffle = value; tryCompare(shuffleChangedSpy, "count", 1); compare(mediaPlayer.shuffle, value); } } SignalSpy { id: trackChangedSpy signalName: "trackChanged" } function test_za_changeTrack() { for (var i = 0; i < manager.devices.length; ++i) { var mediaPlayer = manager.devices[i].mediaPlayer; trackChangedSpy.target = mediaPlayer; trackChangedSpy.clear(); mediaPlayer.next(); tryCompare(trackChangedSpy, "count", 1); compare(mediaPlayer.track.valid, true); trackChangedSpy.clear(); mediaPlayer.previous(); tryCompare(trackChangedSpy, "count", 1); compare(mediaPlayer.track.valid, true); } } SignalSpy { id: statusChangedSpy signalName: "statusChanged" } function test_zb_changeStatus() { for (var i = 0; i < manager.devices.length; ++i) { var mediaPlayer = manager.devices[i].mediaPlayer; statusChangedSpy.clear(); statusChangedSpy.target = mediaPlayer; if (mediaPlayer.status !== BluezQt.MediaPlayer.Stopped) { mediaPlayer.stop(); tryCompare(statusChangedSpy, "count", 1); compare(mediaPlayer.status, BluezQt.MediaPlayer.Stopped); } statusChangedSpy.clear(); mediaPlayer.play(); tryCompare(statusChangedSpy, "count", 1); compare(mediaPlayer.status, BluezQt.MediaPlayer.Playing); statusChangedSpy.clear(); mediaPlayer.pause(); tryCompare(statusChangedSpy, "count", 1); compare(mediaPlayer.status, BluezQt.MediaPlayer.Paused); statusChangedSpy.clear(); mediaPlayer.fastForward(); tryCompare(statusChangedSpy, "count", 1); compare(mediaPlayer.status, BluezQt.MediaPlayer.ForwardSeek); statusChangedSpy.clear(); mediaPlayer.rewind(); tryCompare(statusChangedSpy, "count", 1); compare(mediaPlayer.status, BluezQt.MediaPlayer.ReverseSeek); statusChangedSpy.clear(); mediaPlayer.stop(); tryCompare(statusChangedSpy, "count", 1); compare(mediaPlayer.status, BluezQt.MediaPlayer.Stopped); } } function test_zz_disconnect() { for (var i = 0; i < manager.devices.length; ++i) { var device = manager.devices[i]; verify(device.mediaPlayer); mediaPlayerChangedSpy.clear(); mediaPlayerChangedSpy.target = device; device.disconnectFromDevice(); tryCompare(mediaPlayerChangedSpy, "count", 1, 100 * 1000); verify(!device.mediaPlayer); } } function equalizerString(mediaPlayer) { switch (mediaPlayer.equalizer) { case BluezQt.MediaPlayer.EqualizerOn: return "on"; default: return "off"; } } function repeatString(mediaPlayer) { switch (mediaPlayer.repeat) { case BluezQt.MediaPlayer.RepeatSingleTrack: return "singletrack"; case BluezQt.MediaPlayer.RepeatAllTracks: return "alltracks"; case BluezQt.MediaPlayer.RepeatGroup: return "group"; default: return "off"; } } function shuffleString(mediaPlayer) { switch (mediaPlayer.shuffle) { case BluezQt.MediaPlayer.ShuffleAllTracks: return "alltracks"; case BluezQt.MediaPlayer.ShuffleGroup: return "group"; default: return "off"; } } function statusString(mediaPlayer) { switch (mediaPlayer.status) { case BluezQt.MediaPlayer.Playing: return "playing"; case BluezQt.MediaPlayer.Stopped: return "stopped"; case BluezQt.MediaPlayer.Paused: return "paused"; case BluezQt.MediaPlayer.ForwardSeek: return "forward-seek"; case BluezQt.MediaPlayer.ReverseSeek: return "reverse-seek"; default: return "error"; } } } diff --git a/autotests/qmltests.cpp b/autotests/qmltests.cpp index 4e7febe..aec1f14 100644 --- a/autotests/qmltests.cpp +++ b/autotests/qmltests.cpp @@ -1,107 +1,93 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "autotests.h" #include #include // krazy:exclude=includes #include // krazy:exclude=includes class FakeBluezObject : public QObject { Q_OBJECT public Q_SLOTS: void start() { FakeBluez::start(); } void stop() { FakeBluez::stop(); } bool isRunning() { return FakeBluez::isRunning(); } void runTest(const QString &testName) { FakeBluez::runTest(testName); } static void processProperties(QVariantMap &properties) { const QStringList &toDBusObjectPath = properties.value(QStringLiteral("_toDBusObjectPath")).toStringList(); for (const QString &name : toDBusObjectPath) { const QString &val = properties.value(name).toString(); properties[name] = QVariant::fromValue(QDBusObjectPath(val)); } properties.remove(QStringLiteral("_toDBusObjectPath")); QMapIterator it(properties); while (it.hasNext()) { it.next(); if (it.key() == QLatin1String("UUIDs")) { properties[it.key()] = it.value().toStringList(); } else if (it.value().type() == QVariant::Map) { QVariantMap props = it.value().toMap(); processProperties(props); properties[it.key()] = props; } } } void runAction(const QString &object, const QString &actionName, QVariantMap properties = QVariantMap()) { processProperties(properties); FakeBluez::runAction(object, actionName, properties); } }; static QObject *fakebluez_singleton(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new FakeBluezObject; } namespace BluezQt { extern void bluezqt_initFakeBluezTestRun(); } int main(int argc, char *argv[]) { qmlRegisterSingletonType("org.kde.bluezqt.fakebluez", 1, 0, "FakeBluez", fakebluez_singleton); BluezQt::bluezqt_initFakeBluezTestRun(); qputenv("QML2_IMPORT_PATH", QByteArrayLiteral(BLUEZQT_QML_IMPORT_PATH)); const QString &testsDir = QFileInfo(QFINDTESTDATA("qml/tst_device.qml")).absolutePath(); return quick_test_main(argc, argv, "qmltests", testsDir.toUtf8().constData()); } #include "qmltests.moc" diff --git a/src/a2dp-codecs.c b/src/a2dp-codecs.c index fe6e7f3..682f446 100644 --- a/src/a2dp-codecs.c +++ b/src/a2dp-codecs.c @@ -1,77 +1,63 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "a2dp-codecs.h" /* Currently our capabilities are limited to the most common use cases. iOS has a fixed stream configuration anyway (for SBC and AAC). */ const a2dp_sbc_t sbcCapabilities = { .frequency = /*SBC_SAMPLING_FREQ_16000 | SBC_SAMPLING_FREQ_32000 |*/ SBC_SAMPLING_FREQ_44100 | SBC_SAMPLING_FREQ_48000, .channel_mode = /*SBC_CHANNEL_MODE_MONO | SBC_CHANNEL_MODE_DUAL_CHANNEL |*/ SBC_CHANNEL_MODE_STEREO | SBC_CHANNEL_MODE_JOINT_STEREO, .block_length = SBC_BLOCK_LENGTH_4 | SBC_BLOCK_LENGTH_8 | SBC_BLOCK_LENGTH_12 | SBC_BLOCK_LENGTH_16, .subbands = SBC_SUBBANDS_4 | SBC_SUBBANDS_8, .allocation_method = SBC_ALLOCATION_SNR | SBC_ALLOCATION_LOUDNESS, .min_bitpool = MIN_BITPOOL, .max_bitpool = MAX_BITPOOL, }; const a2dp_aac_t aacCapabilities = { .object_type = AAC_OBJECT_TYPE_MPEG2_AAC_LC | AAC_OBJECT_TYPE_MPEG4_AAC_LC, /*AAC_OBJECT_TYPE_MPEG4_AAC_LTP | AAC_OBJECT_TYPE_MPEG4_AAC_SCA, */ AAC_INIT_FREQUENCY( /*AAC_SAMPLING_FREQ_8000 | AAC_SAMPLING_FREQ_11025 | AAC_SAMPLING_FREQ_12000 | AAC_SAMPLING_FREQ_16000 | AAC_SAMPLING_FREQ_22050 | AAC_SAMPLING_FREQ_24000 | AAC_SAMPLING_FREQ_32000 |*/ AAC_SAMPLING_FREQ_44100 | AAC_SAMPLING_FREQ_48000) /*AAC_SAMPLING_FREQ_64000 | AAC_SAMPLING_FREQ_88200 | AAC_SAMPLING_FREQ_96000)*/ .channels = /*AAC_CHANNELS_1 |*/ AAC_CHANNELS_2, .vbr = 1, AAC_INIT_BITRATE(0xFFFF) }; diff --git a/src/a2dp-codecs.h b/src/a2dp-codecs.h index de1f2f9..0cc4706 100644 --- a/src/a2dp-codecs.h +++ b/src/a2dp-codecs.h @@ -1,264 +1,249 @@ /* - * * BlueZ - Bluetooth protocol stack for Linux * - * Copyright (C) 2006-2010 Nokia Corporation - * Copyright (C) 2004-2010 Marcel Holtmann - * - * - * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * SPDX-FileCopyrightText: 2006-2010 Nokia Corporation + * SPDX-FileCopyrightText: 2004-2010 Marcel Holtmann * + * SPDX-License-Identifier: LGPL-2.1-or-later */ #ifndef BLUEZQT_A2DPCODECS_H #define BLUEZQT_A2DPCODECS_H #include #define A2DP_CODEC_SBC 0x00 #define A2DP_CODEC_MPEG12 0x01 #define A2DP_CODEC_MPEG24 0x02 #define A2DP_CODEC_ATRAC 0x04 #define A2DP_CODEC_VENDOR 0xFF #define SBC_SAMPLING_FREQ_16000 (1 << 3) #define SBC_SAMPLING_FREQ_32000 (1 << 2) #define SBC_SAMPLING_FREQ_44100 (1 << 1) #define SBC_SAMPLING_FREQ_48000 1 #define SBC_CHANNEL_MODE_MONO (1 << 3) #define SBC_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) #define SBC_CHANNEL_MODE_STEREO (1 << 1) #define SBC_CHANNEL_MODE_JOINT_STEREO 1 #define SBC_BLOCK_LENGTH_4 (1 << 3) #define SBC_BLOCK_LENGTH_8 (1 << 2) #define SBC_BLOCK_LENGTH_12 (1 << 1) #define SBC_BLOCK_LENGTH_16 1 #define SBC_SUBBANDS_4 (1 << 1) #define SBC_SUBBANDS_8 1 #define SBC_ALLOCATION_SNR (1 << 1) #define SBC_ALLOCATION_LOUDNESS 1 #define MAX_BITPOOL 64 #define MIN_BITPOOL 2 #define MPEG_CHANNEL_MODE_MONO (1 << 3) #define MPEG_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) #define MPEG_CHANNEL_MODE_STEREO (1 << 1) #define MPEG_CHANNEL_MODE_JOINT_STEREO 1 #define MPEG_LAYER_MP1 (1 << 2) #define MPEG_LAYER_MP2 (1 << 1) #define MPEG_LAYER_MP3 1 #define MPEG_SAMPLING_FREQ_16000 (1 << 5) #define MPEG_SAMPLING_FREQ_22050 (1 << 4) #define MPEG_SAMPLING_FREQ_24000 (1 << 3) #define MPEG_SAMPLING_FREQ_32000 (1 << 2) #define MPEG_SAMPLING_FREQ_44100 (1 << 1) #define MPEG_SAMPLING_FREQ_48000 1 #define MPEG_BIT_RATE_VBR 0x8000 #define MPEG_BIT_RATE_320000 0x4000 #define MPEG_BIT_RATE_256000 0x2000 #define MPEG_BIT_RATE_224000 0x1000 #define MPEG_BIT_RATE_192000 0x0800 #define MPEG_BIT_RATE_160000 0x0400 #define MPEG_BIT_RATE_128000 0x0200 #define MPEG_BIT_RATE_112000 0x0100 #define MPEG_BIT_RATE_96000 0x0080 #define MPEG_BIT_RATE_80000 0x0040 #define MPEG_BIT_RATE_64000 0x0020 #define MPEG_BIT_RATE_56000 0x0010 #define MPEG_BIT_RATE_48000 0x0008 #define MPEG_BIT_RATE_40000 0x0004 #define MPEG_BIT_RATE_32000 0x0002 #define MPEG_BIT_RATE_FREE 0x0001 #define AAC_OBJECT_TYPE_MPEG2_AAC_LC 0x80 #define AAC_OBJECT_TYPE_MPEG4_AAC_LC 0x40 #define AAC_OBJECT_TYPE_MPEG4_AAC_LTP 0x20 #define AAC_OBJECT_TYPE_MPEG4_AAC_SCA 0x10 #define AAC_SAMPLING_FREQ_8000 0x0800 #define AAC_SAMPLING_FREQ_11025 0x0400 #define AAC_SAMPLING_FREQ_12000 0x0200 #define AAC_SAMPLING_FREQ_16000 0x0100 #define AAC_SAMPLING_FREQ_22050 0x0080 #define AAC_SAMPLING_FREQ_24000 0x0040 #define AAC_SAMPLING_FREQ_32000 0x0020 #define AAC_SAMPLING_FREQ_44100 0x0010 #define AAC_SAMPLING_FREQ_48000 0x0008 #define AAC_SAMPLING_FREQ_64000 0x0004 #define AAC_SAMPLING_FREQ_88200 0x0002 #define AAC_SAMPLING_FREQ_96000 0x0001 #define AAC_CHANNELS_1 0x02 #define AAC_CHANNELS_2 0x01 #define AAC_GET_BITRATE(a) ((a).bitrate1 << 16 | \ (a).bitrate2 << 8 | (a).bitrate3) #define AAC_GET_FREQUENCY(a) ((a).frequency1 << 4 | (a).frequency2) #define AAC_SET_BITRATE(a, b) \ do { \ (a).bitrate1 = (b >> 16) & 0x7f; \ (a).bitrate2 = (b >> 8) & 0xff; \ (a).bitrate3 = b & 0xff; \ } while (0) #define AAC_SET_FREQUENCY(a, f) \ do { \ (a).frequency1 = (f >> 4) & 0xff; \ (a).frequency2 = f & 0x0f; \ } while (0) #define AAC_INIT_BITRATE(b) \ .bitrate1 = (b >> 16) & 0x7f, \ .bitrate2 = (b >> 8) & 0xff, \ .bitrate3 = b & 0xff, #define AAC_INIT_FREQUENCY(f) \ .frequency1 = (f >> 4) & 0xff, \ .frequency2 = f & 0x0f, #define APTX_VENDOR_ID 0x0000004f #define APTX_CODEC_ID 0x0001 #define APTX_CHANNEL_MODE_MONO 0x01 #define APTX_CHANNEL_MODE_STEREO 0x02 #define APTX_SAMPLING_FREQ_16000 0x08 #define APTX_SAMPLING_FREQ_32000 0x04 #define APTX_SAMPLING_FREQ_44100 0x02 #define APTX_SAMPLING_FREQ_48000 0x01 #define LDAC_VENDOR_ID 0x0000012d #define LDAC_CODEC_ID 0x00aa typedef struct { uint32_t vendor_id; uint16_t codec_id; } __attribute__ ((packed)) a2dp_vendor_codec_t; #if __BYTE_ORDER == __LITTLE_ENDIAN typedef struct { uint8_t channel_mode:4; uint8_t frequency:4; uint8_t allocation_method:2; uint8_t subbands:2; uint8_t block_length:4; uint8_t min_bitpool; uint8_t max_bitpool; } __attribute__ ((packed)) a2dp_sbc_t; typedef struct { uint8_t channel_mode:4; uint8_t crc:1; uint8_t layer:3; uint8_t frequency:6; uint8_t mpf:1; uint8_t rfa:1; uint16_t bitrate; } __attribute__ ((packed)) a2dp_mpeg_t; typedef struct { uint8_t object_type; uint8_t frequency1; uint8_t rfa:2; uint8_t channels:2; uint8_t frequency2:4; uint8_t bitrate1:7; uint8_t vbr:1; uint8_t bitrate2; uint8_t bitrate3; } __attribute__ ((packed)) a2dp_aac_t; typedef struct { a2dp_vendor_codec_t info; uint8_t channel_mode:4; uint8_t frequency:4; } __attribute__ ((packed)) a2dp_aptx_t; typedef struct { a2dp_vendor_codec_t info; uint8_t unknown[2]; } __attribute__ ((packed)) a2dp_ldac_t; #elif __BYTE_ORDER == __BIG_ENDIAN typedef struct { uint8_t frequency:4; uint8_t channel_mode:4; uint8_t block_length:4; uint8_t subbands:2; uint8_t allocation_method:2; uint8_t min_bitpool; uint8_t max_bitpool; } __attribute__ ((packed)) a2dp_sbc_t; typedef struct { uint8_t layer:3; uint8_t crc:1; uint8_t channel_mode:4; uint8_t rfa:1; uint8_t mpf:1; uint8_t frequency:6; uint16_t bitrate; } __attribute__ ((packed)) a2dp_mpeg_t; typedef struct { uint8_t object_type; uint8_t frequency1; uint8_t frequency2:4; uint8_t channels:2; uint8_t rfa:2; uint8_t vbr:1; uint8_t bitrate1:7; uint8_t bitrate2; uint8_t bitrate3; } __attribute__ ((packed)) a2dp_aac_t; typedef struct { a2dp_vendor_codec_t info; uint8_t frequency:4; uint8_t channel_mode:4; } __attribute__ ((packed)) a2dp_aptx_t; typedef struct { a2dp_vendor_codec_t info; uint8_t unknown[2]; } __attribute__ ((packed)) a2dp_ldac_t; #else #error "Unknown byte order" #endif #ifdef __cplusplus extern "C" { #endif #include "bluezqt_export.h" BLUEZQT_EXPORT extern const a2dp_sbc_t sbcCapabilities; BLUEZQT_EXPORT extern const a2dp_aac_t aacCapabilities; #ifdef __cplusplus } #endif #endif diff --git a/src/adapter.cpp b/src/adapter.cpp index 5fd70cc..48f1a74 100644 --- a/src/adapter.cpp +++ b/src/adapter.cpp @@ -1,197 +1,183 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "adapter.h" #include "adapter_p.h" #include "device.h" #include "device_p.h" #include "pendingcall.h" namespace BluezQt { Adapter::Adapter(const QString &path, const QVariantMap &properties) : QObject() , d(new AdapterPrivate(path, properties)) { } Adapter::~Adapter() { delete d; } AdapterPtr Adapter::toSharedPtr() const { return d->q.toStrongRef(); } QString Adapter::ubi() const { return d->m_bluezAdapter->path(); } QString Adapter::address() const { return d->m_address; } QString Adapter::name() const { return d->m_alias; } PendingCall *Adapter::setName(const QString &name) { return new PendingCall(d->setDBusProperty(QStringLiteral("Alias"), name), PendingCall::ReturnVoid, this); } QString Adapter::systemName() const { return d->m_name; } quint32 Adapter::adapterClass() const { return d->m_adapterClass; } bool Adapter::isPowered() const { return d->m_powered; } PendingCall *Adapter::setPowered(bool powered) { return new PendingCall(d->setDBusProperty(QStringLiteral("Powered"), powered), PendingCall::ReturnVoid, this); } bool Adapter::isDiscoverable() const { return d->m_discoverable; } PendingCall *Adapter::setDiscoverable(bool discoverable) { return new PendingCall(d->setDBusProperty(QStringLiteral("Discoverable"), discoverable), PendingCall::ReturnVoid, this); } quint32 Adapter::discoverableTimeout() const { return d->m_discoverableTimeout; } PendingCall *Adapter::setDiscoverableTimeout(quint32 timeout) { return new PendingCall(d->setDBusProperty(QStringLiteral("DiscoverableTimeout"), timeout), PendingCall::ReturnVoid, this); } bool Adapter::isPairable() const { return d->m_pairable; } PendingCall *Adapter::setPairable(bool pairable) { return new PendingCall(d->setDBusProperty(QStringLiteral("Pairable"), pairable), PendingCall::ReturnVoid, this); } quint32 Adapter::pairableTimeout() const { return d->m_pairableTimeout; } PendingCall *Adapter::setPairableTimeout(quint32 timeout) { return new PendingCall(d->setDBusProperty(QStringLiteral("PairableTimeout"), timeout), PendingCall::ReturnVoid, this); } bool Adapter::isDiscovering() { return d->m_discovering; } QStringList Adapter::uuids() const { return d->m_uuids; } QString Adapter::modalias() const { return d->m_modalias; } GattManagerPtr Adapter::gattManager() const { return d->m_gattManager; } LEAdvertisingManagerPtr Adapter::leAdvertisingManager() const { return d->m_leAdvertisingManager; } MediaPtr Adapter::media() const { return d->m_media; } QList Adapter::devices() const { return d->m_devices; } DevicePtr Adapter::deviceForAddress(const QString &address) const { for (DevicePtr device : qAsConst(d->m_devices)) { if (device->address() == address) { return device; } } return DevicePtr(); } PendingCall *Adapter::startDiscovery() { return new PendingCall(d->m_bluezAdapter->StartDiscovery(), PendingCall::ReturnVoid, this); } PendingCall *Adapter::stopDiscovery() { return new PendingCall(d->m_bluezAdapter->StopDiscovery(), PendingCall::ReturnVoid, this); } PendingCall *Adapter::removeDevice(DevicePtr device) { return new PendingCall(d->m_bluezAdapter->RemoveDevice(QDBusObjectPath(device->ubi())), PendingCall::ReturnVoid, this); } } // namespace BluezQt diff --git a/src/adapter.h b/src/adapter.h index 07ef3d3..b04d5e3 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -1,410 +1,396 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_ADAPTER_H #define BLUEZQT_ADAPTER_H #include #include #include #include "types.h" #include "bluezqt_export.h" namespace BluezQt { class Device; class PendingCall; /** * @class BluezQt::Adapter adapter.h * * Bluetooth adapter. * * This class represents a Bluetooth adapter. */ class BLUEZQT_EXPORT Adapter : public QObject { Q_OBJECT Q_PROPERTY(QString ubi READ ubi) Q_PROPERTY(QString address READ address) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString systemName READ systemName NOTIFY systemNameChanged) Q_PROPERTY(quint32 adapterClass READ adapterClass NOTIFY adapterClassChanged) Q_PROPERTY(bool powered READ isPowered WRITE setPowered NOTIFY poweredChanged) Q_PROPERTY(bool discoverable READ isDiscoverable WRITE setDiscoverable NOTIFY discoverableChanged) Q_PROPERTY(quint32 discoverableTimeout READ discoverableTimeout WRITE setDiscoverableTimeout NOTIFY discoverableTimeoutChanged) Q_PROPERTY(bool pairable READ isPairable WRITE setPairable NOTIFY pairableChanged) Q_PROPERTY(quint32 pairableTimeout READ pairableTimeout WRITE setPairableTimeout NOTIFY pairableTimeoutChanged) Q_PROPERTY(bool discovering READ isDiscovering NOTIFY discoveringChanged) Q_PROPERTY(QStringList uuids READ uuids NOTIFY uuidsChanged) Q_PROPERTY(QString modalias READ modalias NOTIFY modaliasChanged) Q_PROPERTY(LEAdvertisingManagerPtr leAdvertisingManager READ leAdvertisingManager NOTIFY leAdvertisingManagerChanged) Q_PROPERTY(MediaPtr media READ media NOTIFY mediaChanged) Q_PROPERTY(QList devices READ devices) public: /** * Destroys an Adapter object. */ ~Adapter(); /** * Returns a shared pointer from this. * * @return AdapterPtr */ AdapterPtr toSharedPtr() const; /** * Returns an UBI of the adapter. * * Example UBI: "/org/bluez/hci0" * * @return UBI of adapter */ QString ubi() const; /** * Returns an address of the adapter. * * Example address: "1C:E5:C3:BC:94:7E" * * @return address of adapter */ QString address() const; /** * Returns a name of the adapter. * * @return name of adapter */ QString name() const; /** * Sets the name of the adapter. * * @param name name of adapter * @return void pending call */ PendingCall *setName(const QString &name); /** * Returns a system name (hostname) of the adapter. * * @return system name of adapter */ QString systemName() const; /** * Returns a class of the adapter. * * @return class of adapter */ quint32 adapterClass() const; /** * Returns whether the adapter is powered on. * * @return true if adapter is powered on */ bool isPowered() const; /** * Sets the powered state of the adapter. * * @param powered powered state * @return void pending call */ PendingCall *setPowered(bool powered); /** * Returns whether the adapter is discoverable by other devices. * * @return true if adapter is discoverable */ bool isDiscoverable() const; /** * Sets the discoverable state of the adapter. * * @param discoverable discoverable state * @return void pending call */ PendingCall *setDiscoverable(bool discoverable); /** * Returns the discoverable timeout in seconds of the adapter. * * Discoverable timeout defines how long the adapter stays in * discoverable state after calling setDiscoverable(true). * * Timeout 0 means infinitely. * * @return discoverable timeout of adapter */ quint32 discoverableTimeout() const; /** * Sets the discoverable timeout of the adapter. * * @param timeout timeout in seconds * @return void pending call */ PendingCall *setDiscoverableTimeout(quint32 timeout); /** * Returns whether the adapter is pairable with other devices. * * @return true if adapter is pairable */ bool isPairable() const; /** * Sets the pairable state of the adapter. * * @param pairable pairable state * @return void pending call */ PendingCall *setPairable(bool pairable); /** * Returns the pairable timeout in seconds of the adapter. * * Pairable timeout defines how long the adapter stays in * pairable state after calling setPairable(true). * * Timeout 0 means infinitely. * * @return pairable timeout of adapter */ quint32 pairableTimeout() const; /** * Sets the pairable timeout of the adapter. * * @param timeout timeout in seconds * @return void pending call */ PendingCall *setPairableTimeout(quint32 timeout); /** * Returns whether the adapter is discovering for other devices * * @return true if adapter is discovering */ bool isDiscovering(); /** * Returns UUIDs of supported services by the adapter. * * UUIDs will always be returned in uppercase. * * @return UUIDs of supported services */ QStringList uuids() const; /** * Returns local device ID in modalias format. * * @return adapter modalias */ QString modalias() const; /** * Returns the GATT manager interface for the adapter. * * @return null if adapter have no GATT manager */ GattManagerPtr gattManager() const; /** * Returns the LE advertising manager interface for the adapter. * * @return null if adapter have no Bluetooth LE */ LEAdvertisingManagerPtr leAdvertisingManager() const; /** * Returns the media interface for the adapter. * * @return null if adapter have no media */ MediaPtr media() const; /** * Returns list of devices known by the adapter. * * @return list of devices */ QList devices() const; /** * Returns a device for specified address. * * @param address address of device (eg. "40:79:6A:0C:39:75") * @return null if there is no device with specified address */ DevicePtr deviceForAddress(const QString &address) const; /** * Starts device discovery. * * Possible errors: PendingCall::NotReady, PendingCall::Failed * * @return void pending call * @see discoverableTimeout() const */ PendingCall *startDiscovery(); /** * Stops device discovery. * * Possible errors: PendingCall::NotReady, PendingCall::Failed, PendingCall::NotAuthorized * * @return void pending call */ PendingCall *stopDiscovery(); /** * Removes the specified device. * * It will also remove the pairing information. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param device device to be removed * @return void pending call */ PendingCall *removeDevice(DevicePtr device); Q_SIGNALS: /** * Indicates that the adapter was removed. */ void adapterRemoved(AdapterPtr adapter); /** * Indicates that at least one of the adapter's properties have changed. */ void adapterChanged(AdapterPtr adapter); /** * Indicates that adapter's name have changed. */ void nameChanged(const QString &name); /** * Indicates that adapter's system name have changed. */ void systemNameChanged(const QString &systemName); /** * Indicates that adapter's class have changed. */ void adapterClassChanged(quint32 adapterClass); /** * Indicates that adapter's powered state have changed. */ void poweredChanged(bool powered); /** * Indicates that adapter's discoverable state have changed. */ void discoverableChanged(bool discoverable); /** * Indicates that adapter's discoverable timeout have changed. */ void discoverableTimeoutChanged(quint32 timeout); /** * Indicates that adapter's pairable state have changed. */ void pairableChanged(bool pairable); /** * Indicates that adapter's pairable timeout have changed. */ void pairableTimeoutChanged(quint32 timeout); /** * Indicates that adapter's discovering state have changed. */ void discoveringChanged(bool discovering); /** * Indicates that adapter's UUIDs have changed. */ void uuidsChanged(const QStringList &uuids); /** * Indicates that adapter's modalias have changed. */ void modaliasChanged(const QString &modalias); /** * Indicates that adapter's GATT manager have changed. */ void gattManagerChanged(GattManagerPtr gattManager); /** * Indicates that adapter's LE advertising manager have changed. */ void leAdvertisingManagerChanged(LEAdvertisingManagerPtr leAdvertisingManager); /** * Indicates that adapter's media have changed. */ void mediaChanged(MediaPtr media); /** * Indicates that a new device was added (eg. found by discovery). */ void deviceAdded(DevicePtr device); /** * Indicates that a device was removed. */ void deviceRemoved(DevicePtr device); /** * Indicates that at least one of the device's properties have changed. */ void deviceChanged(DevicePtr device); private: explicit Adapter(const QString &path, const QVariantMap &properties); class AdapterPrivate *const d; friend class AdapterPrivate; friend class ManagerPrivate; friend class InitAdaptersJobPrivate; }; } // namespace BluezQt #endif // BLUEZQT_ADAPTER_H diff --git a/src/adapter_p.cpp b/src/adapter_p.cpp index a0abe38..0aefe2b 100644 --- a/src/adapter_p.cpp +++ b/src/adapter_p.cpp @@ -1,184 +1,170 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "adapter_p.h" #include "adapter.h" #include "utils.h" #include "macros.h" #include "gattmanager.h" #include "leadvertisingmanager.h" #include "leadvertisingmanager_p.h" #include "media.h" #include "media_p.h" namespace BluezQt { AdapterPrivate::AdapterPrivate(const QString &path, const QVariantMap &properties) : QObject() , m_dbusProperties(nullptr) , m_adapterClass(0) , m_powered(0) , m_discoverable(false) , m_discoverableTimeout(0) , m_pairable(false) , m_pairableTimeout(0) { m_bluezAdapter = new BluezAdapter(Strings::orgBluez(), path, DBusConnection::orgBluez(), this); init(properties); } void AdapterPrivate::init(const QVariantMap &properties) { m_dbusProperties = new DBusProperties(Strings::orgBluez(), m_bluezAdapter->path(), DBusConnection::orgBluez(), this); // Init properties m_address = properties.value(QStringLiteral("Address")).toString(); m_name = properties.value(QStringLiteral("Name")).toString(); m_alias = properties.value(QStringLiteral("Alias")).toString(); m_adapterClass = properties.value(QStringLiteral("Class")).toUInt(); m_powered = properties.value(QStringLiteral("Powered")).toBool(); m_discoverable = properties.value(QStringLiteral("Discoverable")).toBool(); m_discoverableTimeout = properties.value(QStringLiteral("DiscoverableTimeout")).toUInt(); m_pairable = properties.value(QStringLiteral("Pairable")).toBool(); m_pairableTimeout = properties.value(QStringLiteral("PairableTimeout")).toUInt(); m_discovering = properties.value(QStringLiteral("Discovering")).toBool(); m_uuids = stringListToUpper(properties.value(QStringLiteral("UUIDs")).toStringList()); m_modalias = properties.value(QStringLiteral("Modalias")).toString(); } void AdapterPrivate::interfacesAdded(const QString &path, const QVariantMapMap &interfaces) { bool changed = false; for (auto it = interfaces.cbegin(); it != interfaces.cend(); ++it) { if (it.key() == Strings::orgBluezMedia1()) { m_media = MediaPtr(new Media(path)); Q_EMIT q.lock()->mediaChanged(m_media); changed = true; } else if (it.key() == Strings::orgBluezLEAdvertisingManager1()) { m_leAdvertisingManager = LEAdvertisingManagerPtr(new LEAdvertisingManager(path)); Q_EMIT q.lock()->leAdvertisingManagerChanged(m_leAdvertisingManager); changed = true; } else if (it.key() == Strings::orgBluezGattManager1()) { m_gattManager = GattManagerPtr(new GattManager(path)); Q_EMIT q.lock()->gattManagerChanged(m_gattManager); changed = true; } } if (changed) { Q_EMIT q.lock()->adapterChanged(q.toStrongRef()); } } void AdapterPrivate::interfacesRemoved(const QString &path, const QStringList &interfaces) { bool changed = false; for (const QString &interface : interfaces) { if (interface == Strings::orgBluezMedia1() && m_media && m_media->d->m_path == path) { m_media.clear(); Q_EMIT q.lock()->mediaChanged(m_media); changed = true; } else if (interface == Strings::orgBluezLEAdvertisingManager1() && m_leAdvertisingManager && m_leAdvertisingManager->d->m_path == path) { m_leAdvertisingManager.clear(); Q_EMIT q.lock()->leAdvertisingManagerChanged(m_leAdvertisingManager); changed = true; } } if (changed) { Q_EMIT q.lock()->adapterChanged(q.toStrongRef()); } } void AdapterPrivate::addDevice(const DevicePtr &device) { m_devices.append(device); Q_EMIT q.lock()->deviceAdded(device); connect(device.data(), &Device::deviceChanged, q.lock().data(), &Adapter::deviceChanged); } void AdapterPrivate::removeDevice(const DevicePtr &device) { m_devices.removeOne(device); Q_EMIT device->deviceRemoved(device); Q_EMIT q.lock()->deviceRemoved(device); disconnect(device.data(), &Device::deviceChanged, q.lock().data(), &Adapter::deviceChanged); } QDBusPendingReply<> AdapterPrivate::setDBusProperty(const QString &name, const QVariant &value) { return m_dbusProperties->Set(Strings::orgBluezAdapter1(), name, QDBusVariant(value)); } void AdapterPrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated) { if (interface != Strings::orgBluezAdapter1()) { return; } QVariantMap::const_iterator i; for (i = changed.constBegin(); i != changed.constEnd(); ++i) { const QVariant &value = i.value(); const QString &property = i.key(); if (property == QLatin1String("Name")) { PROPERTY_CHANGED(m_name, toString, systemNameChanged); } else if (property == QLatin1String("Alias")) { PROPERTY_CHANGED(m_alias, toString, nameChanged); } else if (property == QLatin1String("Class")) { PROPERTY_CHANGED(m_adapterClass, toUInt, adapterClassChanged); } else if (property == QLatin1String("Powered")) { PROPERTY_CHANGED(m_powered, toBool, poweredChanged); } else if (property == QLatin1String("Discoverable")) { PROPERTY_CHANGED(m_discoverable, toBool, discoverableChanged); } else if (property == QLatin1String("DiscoverableTimeout")) { PROPERTY_CHANGED(m_discoverableTimeout, toUInt, discoverableTimeoutChanged); } else if (property == QLatin1String("Pairable")) { PROPERTY_CHANGED(m_pairable, toBool, pairableChanged); } else if (property == QLatin1String("PairableTimeout")) { PROPERTY_CHANGED(m_pairableTimeout, toUInt, pairableTimeoutChanged); } else if (property == QLatin1String("Discovering")) { PROPERTY_CHANGED(m_discovering, toBool, discoveringChanged); } else if (property == QLatin1String("Modalias")) { PROPERTY_CHANGED(m_modalias, toString, modaliasChanged); } else if (property == QLatin1String("UUIDs")) { PROPERTY_CHANGED2(m_uuids, stringListToUpper(value.toStringList()), uuidsChanged); } } for (const QString &property : invalidated) { if (property == QLatin1String("Modalias")) { PROPERTY_INVALIDATED(m_modalias, QString(), modaliasChanged); } } Q_EMIT q.lock()->adapterChanged(q.toStrongRef()); } } // namespace BluezQt diff --git a/src/adapter_p.h b/src/adapter_p.h index 5317056..9fe0d91 100644 --- a/src/adapter_p.h +++ b/src/adapter_p.h @@ -1,82 +1,68 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_ADAPTER_P_H #define BLUEZQT_ADAPTER_P_H #include #include #include "types.h" #include "bluezadapter1.h" #include "dbusproperties.h" #include "bluezqt_dbustypes.h" namespace BluezQt { typedef org::bluez::Adapter1 BluezAdapter; typedef org::freedesktop::DBus::Properties DBusProperties; class AdapterPrivate : public QObject { Q_OBJECT public: explicit AdapterPrivate(const QString &path, const QVariantMap &properties); void init(const QVariantMap &properties); void interfacesAdded(const QString &path, const QVariantMapMap &interfaces); void interfacesRemoved(const QString &path, const QStringList &interfaces); void addDevice(const DevicePtr &device); void removeDevice(const DevicePtr &device); QDBusPendingReply<> setDBusProperty(const QString &name, const QVariant &value); void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated); QWeakPointer q; BluezAdapter *m_bluezAdapter; DBusProperties *m_dbusProperties; QString m_address; QString m_name; QString m_alias; quint32 m_adapterClass; bool m_powered; bool m_discoverable; quint32 m_discoverableTimeout; bool m_pairable; quint32 m_pairableTimeout; bool m_discovering; QStringList m_uuids; QList m_devices; QString m_modalias; MediaPtr m_media; GattManagerPtr m_gattManager; LEAdvertisingManagerPtr m_leAdvertisingManager; }; } // namespace BluezQt #endif // BLUEZQT_ADAPTER_P_H diff --git a/src/agent.cpp b/src/agent.cpp index 42d3db4..cad54c0 100644 --- a/src/agent.cpp +++ b/src/agent.cpp @@ -1,96 +1,82 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "agent.h" namespace BluezQt { Agent::Agent(QObject *parent) : QObject(parent) { } Agent::Capability Agent::capability() const { return DisplayYesNo; } void Agent::requestPinCode(DevicePtr device, const Request &request) { Q_UNUSED(device) request.cancel(); } void Agent::displayPinCode(DevicePtr device, const QString &pinCode) { Q_UNUSED(device) Q_UNUSED(pinCode) } void Agent::requestPasskey(DevicePtr device, const Request &request) { Q_UNUSED(device) request.cancel(); } void Agent::displayPasskey(DevicePtr device, const QString &passkey, const QString &entered) { Q_UNUSED(device) Q_UNUSED(passkey) Q_UNUSED(entered) } void Agent::requestConfirmation(DevicePtr device, const QString &passkey, const Request<> &request) { Q_UNUSED(device) Q_UNUSED(passkey) request.cancel(); } void Agent::requestAuthorization(DevicePtr device, const Request<> &request) { Q_UNUSED(device) request.cancel(); } void Agent::authorizeService(DevicePtr device, const QString &uuid, const Request<> &request) { Q_UNUSED(device) Q_UNUSED(uuid) request.cancel(); } void Agent::cancel() { } void Agent::release() { } } // namespace BluezQt diff --git a/src/agent.h b/src/agent.h index 5a92947..457e619 100644 --- a/src/agent.h +++ b/src/agent.h @@ -1,213 +1,199 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_AGENT_H #define BLUEZQT_AGENT_H #include #include "request.h" #include "types.h" #include "bluezqt_export.h" class QDBusObjectPath; namespace BluezQt { class Device; /** * @class BluezQt::Agent agent.h * * Bluetooth agent. * * This class represents a Bluetooth agent. * * The agent is used in pairing process to do various actions. * * @note The return value of requests will be sent asynchronously with Request class. * It is also possible to cancel/reject all requests. */ class BLUEZQT_EXPORT Agent : public QObject { Q_OBJECT Q_PROPERTY(Capability capability READ capability) public: /** * The input/output capabilities of Agent. */ enum Capability { DisplayOnly = 0, DisplayYesNo = 1, KeyboardOnly = 2, NoInputNoOutput = 3 }; Q_ENUM(Capability) /** * Creates a new Agent object. * * @param parent */ explicit Agent(QObject *parent = nullptr); /** * D-Bus object path of the agent. * * The path where the agent will be registered. * * @note You must provide valid object path! * * @return object path of agent */ virtual QDBusObjectPath objectPath() const = 0; /** * Input/output capability of the agent. * * By default, this method returns DisplayYesNo. * * @return capability of agent */ virtual Capability capability() const; /** * Requests a PIN code from the agent. * * This method gets called when the Bluetooth daemon * needs to get the PIN code for an authentication. * * The return value should be a string of 1-16 characters * length. The string can be alphanumeric. * * @param device device that invoked the action * @param request request to be used for sending reply */ virtual void requestPinCode(DevicePtr device, const Request &request); /** * Requests the agent to display a PIN code. * * This method gets called when the Bluetooth daemon * needs to display a pincode for an authentication. * * When the PIN code needs no longer to be displayed, * the cancel() method will be called. * * @param device device that invoked the action * @param pinCode PIN code to be displayed */ virtual void displayPinCode(DevicePtr device, const QString &pinCode); /** * Requests a passkey from the agent. * * This method gets called when the Bluetooth daemon * needs to get the passkey for an authentication. * * The return value should be a numeric value between 0-999999. * * @param device device that invoked the action * @param request request to be used for sending reply */ virtual void requestPasskey(DevicePtr device, const Request &request); /** * Requests the agent to display a passkey. * * This method gets called when the Bluetooth daemon * needs to display a passkey for an authentication. * * When the passkey needs no longer to be displayed, * the cancel() method will be called. * * @param device device that invoked the action * @param passkey passkey to be displayed * @param entered number of already typed keys on the remote side */ virtual void displayPasskey(DevicePtr device, const QString &passkey, const QString &entered); /** * Requests the agent to confirm a passkey. * * This method gets called when the Bluetooth daemon * needs to confirm a passkey for an authentication. * * @param device device that invoked the action * @param passkey passkey to be confirmed * @param request request to be used for sending reply */ virtual void requestConfirmation(DevicePtr device, const QString &passkey, const Request<> &request); /** * Requests the agent to authorize an incoming pairing attempt. * * This method gets called to request the user to authorize * an incoming pairing attempt which would in other circumstances * trigger the just-works model. * * @param device device that invoked the action * @param request request to be used for sending reply */ virtual void requestAuthorization(DevicePtr device, const Request<> &request); /** * Requests the agent to authorize a connection/service request. * * This method gets called when the Bluetooth daemon * needs to authorize a connection/service request. * * @param device device that invoked the action * @param uuid UUID of service * @param request request to be used for sending reply */ virtual void authorizeService(DevicePtr device, const QString &uuid, const Request<> &request); /** * Indicate that the agent request failed before receiving reply. * * This method gets called to indicate that the agent * request failed before a reply was returned. * * It cancels the previous request. */ virtual void cancel(); /** * Indicates that the agent was unregistered. * * This method gets called when the Bluetooth daemon * unregisters the agent. * * An agent can use it to do cleanup tasks. There is no need * to unregister the agent, because when this method gets called * it has already been unregistered. */ virtual void release(); }; } // namespace BluezQt #endif // BLUEZQT_AGENT_H diff --git a/src/agentadaptor.cpp b/src/agentadaptor.cpp index 47478e3..6840ed0 100644 --- a/src/agentadaptor.cpp +++ b/src/agentadaptor.cpp @@ -1,151 +1,137 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "agentadaptor.h" #include "agent.h" #include "manager.h" #include "adapter.h" #include "device.h" #include "request.h" #include #include namespace BluezQt { AgentAdaptor::AgentAdaptor(Agent *parent, Manager *manager) : QDBusAbstractAdaptor(parent) , m_agent(parent) , m_manager(manager) { } QString AgentAdaptor::RequestPinCode(const QDBusObjectPath &device, const QDBusMessage &msg) { msg.setDelayedReply(true); Request req(OrgBluezAgent, msg); DevicePtr dev = m_manager->deviceForUbi(device.path()); if (!dev) { req.cancel(); return QString(); } m_agent->requestPinCode(dev, req); return QString(); } void AgentAdaptor::DisplayPinCode(const QDBusObjectPath &device, const QString &pincode) { DevicePtr dev = m_manager->deviceForUbi(device.path()); if (!dev) { return; } m_agent->displayPinCode(dev, pincode); } quint32 AgentAdaptor::RequestPasskey(const QDBusObjectPath &device, const QDBusMessage &msg) { msg.setDelayedReply(true); Request req(OrgBluezAgent, msg); DevicePtr dev = m_manager->deviceForUbi(device.path()); if (!dev) { req.cancel(); return 0; } m_agent->requestPasskey(dev, req); return 0; } void AgentAdaptor::DisplayPasskey(const QDBusObjectPath &device, quint32 passkey, quint16 entered) { DevicePtr dev = m_manager->deviceForUbi(device.path()); if (!dev) { return; } m_agent->displayPasskey(dev, passkeyToString(passkey), QString::number(entered)); } void AgentAdaptor::RequestConfirmation(const QDBusObjectPath &device, quint32 passkey, const QDBusMessage &msg) { msg.setDelayedReply(true); Request<> req(OrgBluezAgent, msg); DevicePtr dev = m_manager->deviceForUbi(device.path()); if (!dev) { req.cancel(); return; } m_agent->requestConfirmation(dev, passkeyToString(passkey), req); } void AgentAdaptor::RequestAuthorization(const QDBusObjectPath &device, const QDBusMessage &msg) { msg.setDelayedReply(true); Request<> req(OrgBluezAgent, msg); DevicePtr dev = m_manager->deviceForUbi(device.path()); if (!dev) { req.cancel(); return; } m_agent->requestAuthorization(dev, req); } void AgentAdaptor::AuthorizeService(const QDBusObjectPath &device, const QString &uuid, const QDBusMessage &msg) { msg.setDelayedReply(true); Request<> req(OrgBluezAgent, msg); DevicePtr dev = m_manager->deviceForUbi(device.path()); if (!dev) { req.cancel(); return; } m_agent->authorizeService(dev, uuid.toUpper(), req); } void AgentAdaptor::Cancel() { m_agent->cancel(); } void AgentAdaptor::Release() { m_agent->release(); } QString AgentAdaptor::passkeyToString(quint32 passkey) const { // Passkey will always be a 6-digit number, zero-pad it at the start return QStringLiteral("%1").arg(passkey, 6, 10, QLatin1Char('0')); } } // namespace BluezQt diff --git a/src/agentadaptor.h b/src/agentadaptor.h index c615fa5..e36d679 100644 --- a/src/agentadaptor.h +++ b/src/agentadaptor.h @@ -1,67 +1,53 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_AGENTADAPTOR_H #define BLUEZQT_AGENTADAPTOR_H #include class QDBusMessage; class QDBusObjectPath; namespace BluezQt { class Device; class Manager; class Agent; class AgentAdaptor : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.Agent1") public: explicit AgentAdaptor(Agent *parent, Manager *manager); public Q_SLOTS: QString RequestPinCode(const QDBusObjectPath &device, const QDBusMessage &msg); Q_NOREPLY void DisplayPinCode(const QDBusObjectPath &device, const QString &pincode); quint32 RequestPasskey(const QDBusObjectPath &device, const QDBusMessage &msg); Q_NOREPLY void DisplayPasskey(const QDBusObjectPath &device, quint32 passkey, quint16 entered); void RequestConfirmation(const QDBusObjectPath &device, quint32 passkey, const QDBusMessage &msg); void RequestAuthorization(const QDBusObjectPath &device, const QDBusMessage &msg); void AuthorizeService(const QDBusObjectPath &device, const QString &uuid, const QDBusMessage &msg); Q_NOREPLY void Cancel(); Q_NOREPLY void Release(); private: QString passkeyToString(quint32 passkey) const; Agent *m_agent; Manager *m_manager; }; } // namespace BluezQt #endif // BLUEZQT_AGENTADAPTOR_H diff --git a/src/battery.cpp b/src/battery.cpp index de6ed73..3b73246 100644 --- a/src/battery.cpp +++ b/src/battery.cpp @@ -1,80 +1,66 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Kai Uwe Broulik + * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "battery.h" #include "battery_p.h" #include "utils.h" #include "macros.h" #include namespace BluezQt { BatteryPrivate::BatteryPrivate(const QString &path, const QVariantMap &properties) : QObject() , m_path(path) { // Init properties m_percentage = properties.value(QStringLiteral("Percentage")).toInt(); } void BatteryPrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated) { Q_UNUSED(invalidated) if (interface != Strings::orgBluezBattery1()) { return; } QVariantMap::const_iterator i; for (i = changed.constBegin(); i != changed.constEnd(); ++i) { const QVariant &value = i.value(); const QString &property = i.key(); if (property == QLatin1String("Percentage")) { PROPERTY_CHANGED2(m_percentage, value.toInt(), percentageChanged) } } } Battery::Battery(const QString &path, const QVariantMap &properties) : d(new BatteryPrivate(path, properties)) { } Battery::~Battery() { delete d; } BatteryPtr Battery::toSharedPtr() const { return d->q.toStrongRef(); } int Battery::percentage() const { return d->m_percentage; } } // namespace BluezQt diff --git a/src/battery.h b/src/battery.h index 381b7a2..86f4559 100644 --- a/src/battery.h +++ b/src/battery.h @@ -1,83 +1,69 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Kai Uwe Broulik + * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_BATTERY_H #define BLUEZQT_BATTERY_H #include #include "types.h" #include "bluezqt_export.h" namespace BluezQt { /** * @class BluezQt::Battery battery.h * * %Device battery. * * This class represents a battery interface. */ class BLUEZQT_EXPORT Battery : public QObject { Q_OBJECT Q_PROPERTY(int percentage READ percentage NOTIFY percentageChanged) public: /** * Destroys a Battery object. */ ~Battery(); /** * Returns a shared pointer from this. * * @return BatteryPtr */ BatteryPtr toSharedPtr() const; /** * Returns the battery percentage. * * @return battery percentage */ int percentage() const; Q_SIGNALS: /** * Indicates that battery's percentage has changed. */ void percentageChanged(int percentage); private: explicit Battery(const QString &path, const QVariantMap &properties); class BatteryPrivate *const d; friend class BatteryPrivate; friend class DevicePrivate; }; } // namespace BluezQt #endif // BLUEZQT_BATTERY_H diff --git a/src/battery_p.h b/src/battery_p.h index 83fdd0b..f7074f1 100644 --- a/src/battery_p.h +++ b/src/battery_p.h @@ -1,50 +1,36 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Kai Uwe Broulik + * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_BATTERY_P_H #define BLUEZQT_BATTERY_P_H #include #include "battery.h" namespace BluezQt { class BatteryPrivate : public QObject { Q_OBJECT public: explicit BatteryPrivate(const QString &path, const QVariantMap &properties); void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated); QWeakPointer q; QString m_path; int m_percentage = 0; }; } // namespace BluezQt #endif // BLUEZQT_BATTERY_P_H diff --git a/src/bluezqt_dbustypes.h b/src/bluezqt_dbustypes.h index 2dbf6fd..3f83434 100644 --- a/src/bluezqt_dbustypes.h +++ b/src/bluezqt_dbustypes.h @@ -1,39 +1,25 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2013 Daniel Schaal - * 2015 David Rosca + * SPDX-FileCopyrightText: 2013 Daniel Schaal + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_DBUSTYPES_H #define BLUEZQT_DBUSTYPES_H #include #include typedef QList QVariantMapList; Q_DECLARE_METATYPE(QVariantMapList) typedef QMap QVariantMapMap; Q_DECLARE_METATYPE(QVariantMapMap) typedef QMap DBusManagerStruct; Q_DECLARE_METATYPE(DBusManagerStruct) #endif // BLUEZQT_DBUSTYPES_H diff --git a/src/device.cpp b/src/device.cpp index 56d44fa..066fe91 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -1,308 +1,294 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "device.h" #include "device_p.h" #include "pendingcall.h" #include "utils.h" namespace BluezQt { Device::Device(const QString &path, const QVariantMap &properties, AdapterPtr adapter) : QObject() , d(new DevicePrivate(path, properties, adapter)) { } Device::~Device() { delete d; } DevicePtr Device::toSharedPtr() const { return d->q.toStrongRef(); } QString Device::ubi() const { return d->m_bluezDevice->path(); } QString Device::address() const { return d->m_address; } QString Device::name() const { return d->m_alias; } PendingCall *Device::setName(const QString &name) { return new PendingCall(d->setDBusProperty(QStringLiteral("Alias"), name), PendingCall::ReturnVoid, this); } QString Device::friendlyName() const { if (name().isEmpty() || name() == remoteName()) { return name(); } if (remoteName().isEmpty()) { return name(); } return QStringLiteral("%1 (%2)").arg(name(), remoteName()); } QString Device::remoteName() const { return d->m_name; } quint32 Device::deviceClass() const { return d->m_deviceClass; } Device::Type Device::type() const { if (deviceClass() == 0) { return appearanceToType(appearance()); } return classToType(d->m_deviceClass); } quint16 Device::appearance() const { return d->m_appearance; } QString Device::icon() const { switch (type()) { case Headset: return QStringLiteral("audio-headset"); case Headphones: return QStringLiteral("audio-headphones"); default: return d->m_icon.isEmpty() ? QStringLiteral("preferences-system-bluetooth") : d->m_icon; } } bool Device::isPaired() const { return d->m_paired; } bool Device::isTrusted() const { return d->m_trusted; } PendingCall *Device::setTrusted(bool trusted) { return new PendingCall(d->setDBusProperty(QStringLiteral("Trusted"), trusted), PendingCall::ReturnVoid, this); } bool Device::isBlocked() const { return d->m_blocked; } PendingCall *Device::setBlocked(bool blocked) { return new PendingCall(d->setDBusProperty(QStringLiteral("Blocked"), blocked), PendingCall::ReturnVoid, this); } bool Device::hasLegacyPairing() const { return d->m_legacyPairing; } qint16 Device::rssi() const { return d->m_rssi; } bool Device::isConnected() const { return d->m_connected; } QStringList Device::uuids() const { return d->m_uuids; } QString Device::modalias() const { return d->m_modalias; } BatteryPtr Device::battery() const { return d->m_battery; } InputPtr Device::input() const { return d->m_input; } MediaPlayerPtr Device::mediaPlayer() const { return d->m_mediaPlayer; } MediaTransportPtr Device::mediaTransport() const { return d->m_mediaTransport; } AdapterPtr Device::adapter() const { return d->m_adapter; } QString Device::typeToString(Device::Type type) { switch (type) { case Device::Phone: return QStringLiteral("phone"); case Device::Modem: return QStringLiteral("modem"); case Device::Computer: return QStringLiteral("computer"); case Device::Network: return QStringLiteral("network"); case Device::Headset: return QStringLiteral("headset"); case Device::Headphones: return QStringLiteral("headphones"); case Device::AudioVideo: return QStringLiteral("audiovideo"); case Device::Keyboard: return QStringLiteral("keyboard"); case Device::Mouse: return QStringLiteral("mouse"); case Device::Joypad: return QStringLiteral("joypad"); case Device::Tablet: return QStringLiteral("tablet"); case Device::Peripheral: return QStringLiteral("peripheral"); case Device::Camera: return QStringLiteral("camera"); case Device::Printer: return QStringLiteral("printer"); case Device::Imaging: return QStringLiteral("imaging"); case Device::Wearable: return QStringLiteral("wearable"); case Device::Toy: return QStringLiteral("toy"); case Device::Health: return QStringLiteral("health"); default: return QStringLiteral("uncategorized"); } } Device::Type Device::stringToType(const QString &typeString) { if (typeString == QLatin1String("phone")) { return Device::Phone; } else if (typeString == QLatin1String("modem")) { return Device::Modem; } else if (typeString == QLatin1String("computer")) { return Device::Computer; } else if (typeString == QLatin1String("network")) { return Device::Network; } else if (typeString == QLatin1String("headset")) { return Device::Headset; } else if (typeString == QLatin1String("headphones")) { return Device::Headphones; } else if (typeString == QLatin1String("audio")) { return Device::AudioVideo; } else if (typeString == QLatin1String("keyboard")) { return Device::Keyboard; } else if (typeString == QLatin1String("mouse")) { return Device::Mouse; } else if (typeString == QLatin1String("joypad")) { return Device::Joypad; } else if (typeString == QLatin1String("tablet")) { return Device::Tablet; } else if (typeString == QLatin1String("peripheral")) { return Device::Peripheral; } else if (typeString == QLatin1String("camera")) { return Device::Camera; } else if (typeString == QLatin1String("printer")) { return Device::Printer; } else if (typeString == QLatin1String("imaging")) { return Device::Imaging; } else if (typeString == QLatin1String("wearable")) { return Device::Wearable; } else if (typeString == QLatin1String("toy")) { return Device::Toy; } else if (typeString == QLatin1String("health")) { return Device::Health; } return Device::Uncategorized; } PendingCall *Device::connectToDevice() { return new PendingCall(d->m_bluezDevice->Connect(), PendingCall::ReturnVoid, this); } PendingCall *Device::disconnectFromDevice() { return new PendingCall(d->m_bluezDevice->Disconnect(), PendingCall::ReturnVoid, this); } PendingCall *Device::connectProfile(const QString &uuid) { return new PendingCall(d->m_bluezDevice->ConnectProfile(uuid), PendingCall::ReturnVoid, this); } PendingCall *Device::disconnectProfile(const QString &uuid) { return new PendingCall(d->m_bluezDevice->DisconnectProfile(uuid), PendingCall::ReturnVoid, this); } PendingCall *Device::pair() { return new PendingCall(d->m_bluezDevice->Pair(), PendingCall::ReturnVoid, this); } PendingCall *Device::cancelPairing() { return new PendingCall(d->m_bluezDevice->CancelPairing(), PendingCall::ReturnVoid, this); } } // namespace BluezQt diff --git a/src/device.h b/src/device.h index ea4bb27..e51cff4 100644 --- a/src/device.h +++ b/src/device.h @@ -1,553 +1,539 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_DEVICE_H #define BLUEZQT_DEVICE_H #include #include "types.h" #include "bluezqt_export.h" namespace BluezQt { class Adapter; class PendingCall; /** * @class BluezQt::Device device.h * * Bluetooth device. * * This class represents a Bluetooth device. */ class BLUEZQT_EXPORT Device : public QObject { Q_OBJECT Q_PROPERTY(QString ubi READ ubi) Q_PROPERTY(QString address READ address NOTIFY addressChanged) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString friendlyName READ friendlyName NOTIFY friendlyNameChanged) Q_PROPERTY(QString remoteName READ remoteName NOTIFY remoteNameChanged) Q_PROPERTY(quint32 deviceClass READ deviceClass NOTIFY deviceClassChanged) Q_PROPERTY(Type type READ type NOTIFY typeChanged) Q_PROPERTY(quint16 appearance READ appearance NOTIFY appearanceChanged) Q_PROPERTY(QString icon READ icon NOTIFY iconChanged) Q_PROPERTY(bool paired READ isPaired NOTIFY pairedChanged) Q_PROPERTY(bool trusted READ isTrusted WRITE setTrusted NOTIFY trustedChanged) Q_PROPERTY(bool blocked READ isBlocked WRITE setBlocked NOTIFY blockedChanged) Q_PROPERTY(bool legacyPairing READ hasLegacyPairing NOTIFY legacyPairingChanged) Q_PROPERTY(qint16 rssi READ rssi NOTIFY rssiChanged) Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged) Q_PROPERTY(QStringList uuids READ uuids NOTIFY uuidsChanged) Q_PROPERTY(QString modalias READ modalias NOTIFY modaliasChanged) Q_PROPERTY(BatteryPtr battery READ battery NOTIFY batteryChanged) Q_PROPERTY(InputPtr input READ input NOTIFY inputChanged) Q_PROPERTY(MediaPlayerPtr mediaPlayer READ mediaPlayer NOTIFY mediaPlayerChanged) Q_PROPERTY(MediaTransportPtr mediaTransport READ mediaTransport NOTIFY mediaTransportChanged) Q_PROPERTY(AdapterPtr adapter READ adapter) public: /** * %Device types. */ enum Type { /** The device is a phone. */ Phone, /** The device is a modem. */ Modem, /** The device is a computer. */ Computer, /** The device is a network. */ Network, /** The device is a headset. */ Headset, /** The device is a headphones. */ Headphones, /** The device is an uncategorized audio video device. */ AudioVideo, /** The device is a keyboard. */ Keyboard, /** The device is a mouse. */ Mouse, /** The device is a joypad. */ Joypad, /** The device is a graphics tablet (input device). */ Tablet, /** The deivce is an uncategorized peripheral device. */ Peripheral, /** The device is a camera. */ Camera, /** The device is a printer. */ Printer, /** The device is an uncategorized imaging device. */ Imaging, /** The device is a wearable device. */ Wearable, /** The device is a toy. */ Toy, /** The device is a health device. */ Health, /** The device is not of any of the known types. */ Uncategorized }; Q_ENUM(Type) /** * Destroys a Device object. */ ~Device(); /** * Returns a shared pointer from this. * * @return DevicePtr */ DevicePtr toSharedPtr() const; /** * Returns an UBI of the device. * * Example UBI: "/org/bluez/hci0/dev_40_79_6A_0C_39_75" * * @return UBI of device */ QString ubi() const; /** * Returns an address of the device. * * Example address: "40:79:6A:0C:39:75" * * @return address of device */ QString address() const; /** * Returns a name of the device. * * If the name of the device wasn't previously changed, * remoteName is returned. * * @return name of device */ QString name() const; /** * Sets the name of the device. * * @param name name for device * @return void pending call */ PendingCall *setName(const QString &name); /** * Returns a friendly name of the device. * * Friendly name is a string "name (remoteName)". * If the remoteName is same as name, it returns just name. * * @return friendly name of device */ QString friendlyName() const; /** * Returns a remote name of the device. * * @return remote name of device */ QString remoteName() const; /** * Returns a class of the device. * * In case of Bluetooth Low Energy only devices, * device class is invalid (0). * * @see type() const * * @return class of device */ quint32 deviceClass() const; /** * Returns a type of the device. * * Type of device is deduced from its class (for Bluetooth Classic devices) * or its appearance (for Bluetooth Low Energy devices). * * @see deviceClass() const * @see appearance() const * * @return type of device */ Device::Type type() const; /** * Returns an appearance of the device. * * @return appearance of device */ quint16 appearance() const; /** * Returns an icon name of the device. * * In case the icon is empty, "preferences-system-bluetooth" is returned. * * @return icon name of device */ QString icon() const; /** * Returns whether the device is paired. * * @return true if device is paired */ bool isPaired() const; /** * Returns whether the device is trusted. * * @return true if device is trusted */ bool isTrusted() const; /** * Sets the trusted state of the device. * * @param trusted trusted state * @return void pending call */ PendingCall *setTrusted(bool trusted); /** * Returns whether the device is blocked. * * @return true if device is blocked */ bool isBlocked() const; /** * Sets the blocked state of the device. * * @param blocked blocked state * @return void pending call */ PendingCall *setBlocked(bool blocked); /** * Returns whether the device has legacy pairing. * * @return true if device has legacy pairing */ bool hasLegacyPairing() const; /** * Returns Received Signal Strength Indicator of the device. * * The bigger value indicates better signal strength. * * @note RSSI is only updated during discovery. * * @return RSSI of device */ qint16 rssi() const; /** * Returns whether the device is connected. * * @return true if connected */ bool isConnected() const; /** * Returns UUIDs of supported services by the device. * * UUIDs will always be returned in uppercase. * * @return UUIDs of supported services */ QStringList uuids() const; /** * Returns remote device ID in modalias format. * * @return device modalias */ QString modalias() const; /** * Returns the battery interface for the device. * * @return null if device has no battery * @since 5.66 */ BatteryPtr battery() const; /** * Returns the input interface for the device. * * Only input devices will have valid input interface. * * @return null if device have no input */ InputPtr input() const; /** * Returns the media player interface for the device. * * Only devices with connected appropriate profile will * have valid media player interface. * * @return null if device have no media player */ MediaPlayerPtr mediaPlayer() const; /** * Returns the media transport interface for the device. * * Only devices with connected appropriate profile will * have valid media transport interface. * * @return null if device have no media transport */ MediaTransportPtr mediaTransport() const; /** * Returns an adapter that discovered this device. * * @return adapter of device */ AdapterPtr adapter() const; /** * Returns a string for device type. * * @param type device type * @return device type string */ static QString typeToString(Device::Type type); /** * Returns a device type for string. * * @param typeString type string * @return device type */ static Device::Type stringToType(const QString &typeString); public Q_SLOTS: /** * Connects all auto-connectable profiles of the device. * * This method indicates success if at least one profile was connected. * * Possible errors: PendingCall::NotReady, PendingCall::Failed, * PendingCall::InProgress, PendingCall::AlreadyConnected * * @return void pending call */ PendingCall *connectToDevice(); /** * Disconnects all connected profiles of the device. * * This method can be used to cancel not-yet finished connectDevice() call. * * Possible errors: PendingCall::NotConnected * * @return void pending call */ PendingCall *disconnectFromDevice(); /** * Connects a specific profile of the device. * * Possible errors: PendingCall::DoesNotExist, PendingCall::AlreadyConnected, * PendingCall::ConnectFailed * * @param uuid service UUID * @return void pending call */ PendingCall *connectProfile(const QString &uuid); /** * Disconnects a specific profile of the device. * * Possible errors: PendingCall::DoesNotExist, PendingCall::Failed, * PendingCall::NotConnected, PendingCall::NotSupported * * @param uuid service UUID * @return void pending call */ PendingCall *disconnectProfile(const QString &uuid); /** * Initiates a pairing with the device. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed, * PendingCall::AlreadyExists, PendingCall::AuthenticationCanceled, * PendingCall::AuthenticationFailed, PendingCall::AuthenticationRejected, * PendingCall::AuthenticationTimeout, PendingCall::ConnectionAttemptFailed * * @return void pending call */ PendingCall *pair(); /** * Cancels a pairing with the device. * * This method can be used to cancel pairing operation initiated with pair(). * * Possible errors: PendingCall::DoesNotExist, PendingCall::Failed * * @return void pending call */ PendingCall *cancelPairing(); Q_SIGNALS: /** * Indicates that the device was removed. */ void deviceRemoved(DevicePtr device); /** * Indicates that at least one of the device's properties have changed. */ void deviceChanged(DevicePtr device); /** * Indicates that device's name have changed. */ void nameChanged(const QString &name); /** * Indicates that device's address have changed. */ void addressChanged(const QString &address); /** * Indicates that device's friendly name have changed. */ void friendlyNameChanged(const QString &friendlyName); /** * Indicates that device's remote name have changed. */ void remoteNameChanged(const QString &remoteName); /** * Indicates that device's class have changed. */ void deviceClassChanged(quint32 deviceClass); /** * Indicates that device's type have changed. */ void typeChanged(Type type); /** * Indicates that device's appearance have changed. */ void appearanceChanged(quint16 appearance); /** * Indicates that device's icon have changed. */ void iconChanged(const QString &icon); /** * Indicates that device's paired state have changed. */ void pairedChanged(bool paired); /** * Indicates that device's trusted state have changed. */ void trustedChanged(bool trusted); /** * Indicates that device's blocked state have changed. */ void blockedChanged(bool blocked); /** * Indicates that device's legacy pairing state have changed. */ void legacyPairingChanged(bool legacyPairing); /** * Indicates that device's RSSI have changed. */ void rssiChanged(qint16 rssi); /** * Indicates that device's connected state have changed. */ void connectedChanged(bool connected); /** * Indicates that device's UUIDs have changed. */ void uuidsChanged(const QStringList &uuids); /** * Indicates that device's modalias have changed. */ void modaliasChanged(const QString &modalias); /** * Indicates that device's battery has changed. */ void batteryChanged(BatteryPtr battery); /** * Indicates that device's input have changed. */ void inputChanged(InputPtr input); /** * Indicates that device's media player have changed. */ void mediaPlayerChanged(MediaPlayerPtr mediaPlayer); /** * Indicates that device's media transport have changed. */ void mediaTransportChanged(MediaTransportPtr mediaTransport); private: explicit Device(const QString &path, const QVariantMap &properties, AdapterPtr adapter); class DevicePrivate *const d; friend class DevicePrivate; friend class ManagerPrivate; friend class Adapter; }; } // namespace BluezQt #endif // BLUEZQT_DEVICE_H diff --git a/src/device_p.cpp b/src/device_p.cpp index 8935799..71a64a6 100644 --- a/src/device_p.cpp +++ b/src/device_p.cpp @@ -1,258 +1,244 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "device_p.h" #include "device.h" #include "adapter.h" #include "battery.h" #include "battery_p.h" #include "input.h" #include "input_p.h" #include "mediaplayer.h" #include "mediaplayer_p.h" #include "mediatransport.h" #include "mediatransport_p.h" #include "utils.h" #include "macros.h" namespace BluezQt { static const qint16 INVALID_RSSI = -32768; // qint16 minimum DevicePrivate::DevicePrivate(const QString &path, const QVariantMap &properties, const AdapterPtr &adapter) : QObject() , m_dbusProperties(nullptr) , m_deviceClass(0) , m_appearance(0) , m_paired(false) , m_trusted(false) , m_blocked(false) , m_legacyPairing(false) , m_rssi(INVALID_RSSI) , m_connected(false) , m_adapter(adapter) { m_bluezDevice = new BluezDevice(Strings::orgBluez(), path, DBusConnection::orgBluez(), this); init(properties); } void DevicePrivate::init(const QVariantMap &properties) { m_dbusProperties = new DBusProperties(Strings::orgBluez(), m_bluezDevice->path(), DBusConnection::orgBluez(), this); // Init properties m_address = properties.value(QStringLiteral("Address")).toString(); m_name = properties.value(QStringLiteral("Name")).toString(); m_alias = properties.value(QStringLiteral("Alias")).toString(); m_deviceClass = properties.value(QStringLiteral("Class")).toUInt(); m_appearance = properties.value(QStringLiteral("Appearance")).toUInt(); m_icon = properties.value(QStringLiteral("Icon")).toString(); m_paired = properties.value(QStringLiteral("Paired")).toBool(); m_trusted = properties.value(QStringLiteral("Trusted")).toBool(); m_blocked = properties.value(QStringLiteral("Blocked")).toBool(); m_legacyPairing = properties.value(QStringLiteral("LegacyPairing")).toBool(); m_rssi = properties.value(QStringLiteral("RSSI")).toInt(); m_connected = properties.value(QStringLiteral("Connected")).toBool(); m_uuids = stringListToUpper(properties.value(QStringLiteral("UUIDs")).toStringList()); m_modalias = properties.value(QStringLiteral("Modalias")).toString(); if (!m_rssi) { m_rssi = INVALID_RSSI; } } void DevicePrivate::interfacesAdded(const QString &path, const QVariantMapMap &interfaces) { bool changed = false; QVariantMapMap::const_iterator it; for (it = interfaces.constBegin(); it != interfaces.constEnd(); ++it) { if (it.key() == Strings::orgBluezBattery1()) { m_battery = BatteryPtr(new Battery(path, it.value())); m_battery->d->q = m_battery.toWeakRef(); Q_EMIT q.lock()->batteryChanged(m_battery); changed = true; } else if (it.key() == Strings::orgBluezInput1()) { m_input = InputPtr(new Input(path, it.value())); m_input->d->q = m_input.toWeakRef(); Q_EMIT q.lock()->inputChanged(m_input); changed = true; } else if (it.key() == Strings::orgBluezMediaPlayer1()) { m_mediaPlayer = MediaPlayerPtr(new MediaPlayer(path, it.value())); m_mediaPlayer->d->q = m_mediaPlayer.toWeakRef(); Q_EMIT q.lock()->mediaPlayerChanged(m_mediaPlayer); changed = true; } else if (it.key() == Strings::orgBluezMediaTransport1()) { m_mediaTransport = MediaTransportPtr(new MediaTransport(path, it.value())); m_mediaTransport->d->q = m_mediaTransport.toWeakRef(); Q_EMIT q.lock()->mediaTransportChanged(m_mediaTransport); changed = true; } } if (changed) { Q_EMIT q.lock()->deviceChanged(q.toStrongRef()); } } void DevicePrivate::interfacesRemoved(const QString &path, const QStringList &interfaces) { bool changed = false; for (const QString &interface : interfaces) { if (interface == Strings::orgBluezBattery1() && m_battery && m_battery->d->m_path == path) { m_battery.clear(); Q_EMIT q.lock()->batteryChanged(m_battery); changed = true; } else if (interface == Strings::orgBluezInput1() && m_input && m_input->d->m_path == path) { m_input.clear(); Q_EMIT q.lock()->inputChanged(m_input); changed = true; } else if (interface == Strings::orgBluezMediaPlayer1() && m_mediaPlayer && m_mediaPlayer->d->m_path == path) { m_mediaPlayer.clear(); Q_EMIT q.lock()->mediaPlayerChanged(m_mediaPlayer); changed = true; } else if (interface == Strings::orgBluezMediaTransport1() && m_mediaTransport && m_mediaTransport->d->m_path == path) { m_mediaTransport.clear(); Q_EMIT q.lock()->mediaTransportChanged(m_mediaTransport); changed = true; } } if (changed) { Q_EMIT q.lock()->deviceChanged(q.toStrongRef()); } } QDBusPendingReply<> DevicePrivate::setDBusProperty(const QString &name, const QVariant &value) { return m_dbusProperties->Set(Strings::orgBluezDevice1(), name, QDBusVariant(value)); } void DevicePrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated) { if (interface == Strings::orgBluezBattery1() && m_battery) { m_battery->d->propertiesChanged(interface, changed, invalidated); } else if (interface == Strings::orgBluezInput1() && m_input) { m_input->d->propertiesChanged(interface, changed, invalidated); } else if (interface == Strings::orgBluezMediaPlayer1() && m_mediaPlayer) { m_mediaPlayer->d->propertiesChanged(interface, changed, invalidated); } else if (interface != Strings::orgBluezDevice1()) { return; } QVariantMap::const_iterator i; for (i = changed.constBegin(); i != changed.constEnd(); ++i) { const QVariant &value = i.value(); const QString &property = i.key(); if (property == QLatin1String("Name")) { namePropertyChanged(value.toString()); } else if (property == QLatin1String("Address")) { addressPropertyChanged(value.toString()); } else if (property == QLatin1String("Alias")) { aliasPropertyChanged(value.toString()); } else if (property == QLatin1String("Class")) { classPropertyChanged(value.toUInt()); } else if (property == QLatin1String("Appearance")) { PROPERTY_CHANGED(m_appearance, toUInt, appearanceChanged); } else if (property == QLatin1String("Icon")) { PROPERTY_CHANGED(m_icon, toString, iconChanged); } else if (property == QLatin1String("Paired")) { PROPERTY_CHANGED(m_paired, toBool, pairedChanged); } else if (property == QLatin1String("Trusted")) { PROPERTY_CHANGED(m_trusted, toBool, trustedChanged); } else if (property == QLatin1String("Blocked")) { PROPERTY_CHANGED(m_blocked, toBool, blockedChanged); } else if (property == QLatin1String("LegacyPairing")) { PROPERTY_CHANGED(m_legacyPairing, toBool, legacyPairingChanged); } else if (property == QLatin1String("RSSI")) { PROPERTY_CHANGED(m_rssi, toInt, rssiChanged); } else if (property == QLatin1String("Connected")) { PROPERTY_CHANGED(m_connected, toBool, connectedChanged); } else if (property == QLatin1String("Modalias")) { PROPERTY_CHANGED(m_modalias, toString, modaliasChanged); } else if (property == QLatin1String("UUIDs")) { PROPERTY_CHANGED2(m_uuids, stringListToUpper(value.toStringList()), uuidsChanged); } } for (const QString &property : invalidated) { if (property == QLatin1String("Name")) { namePropertyChanged(QString()); } else if (property == QLatin1String("Class")) { classPropertyChanged(0); } else if (property == QLatin1String("Appearance")) { PROPERTY_INVALIDATED(m_appearance, 0, appearanceChanged); } else if (property == QLatin1String("Icon")) { PROPERTY_INVALIDATED(m_icon, QString(), iconChanged); } else if (property == QLatin1String("RSSI")) { PROPERTY_INVALIDATED(m_rssi, INVALID_RSSI, rssiChanged); } else if (property == QLatin1String("Modalias")) { PROPERTY_INVALIDATED(m_modalias, QString(), modaliasChanged); } else if (property == QLatin1String("UUIDs")) { PROPERTY_INVALIDATED(m_uuids, QStringList(), uuidsChanged); } } Q_EMIT q.lock()->deviceChanged(q.toStrongRef()); } void DevicePrivate::namePropertyChanged(const QString &value) { if (m_name != value) { m_name = value; Q_EMIT q.lock()->remoteNameChanged(m_name); Q_EMIT q.lock()->friendlyNameChanged(q.lock()->friendlyName()); } } void DevicePrivate::addressPropertyChanged(const QString &value) { if (m_address != value) { m_address = value; Q_EMIT q.lock()->addressChanged(m_address); } } void DevicePrivate::aliasPropertyChanged(const QString &value) { if (m_alias != value) { m_alias = value; Q_EMIT q.lock()->nameChanged(m_alias); Q_EMIT q.lock()->friendlyNameChanged(q.lock()->friendlyName()); } } void DevicePrivate::classPropertyChanged(quint32 value) { if (m_deviceClass != value) { m_deviceClass = value; Q_EMIT q.lock()->deviceClassChanged(m_deviceClass); Q_EMIT q.lock()->typeChanged(q.lock()->type()); } } } // namespace BluezQt diff --git a/src/device_p.h b/src/device_p.h index 07e940c..0e75e10 100644 --- a/src/device_p.h +++ b/src/device_p.h @@ -1,86 +1,72 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_DEVICE_P_H #define BLUEZQT_DEVICE_P_H #include #include #include "types.h" #include "bluezdevice1.h" #include "dbusproperties.h" #include "bluezqt_dbustypes.h" namespace BluezQt { typedef org::bluez::Device1 BluezDevice; typedef org::freedesktop::DBus::Properties DBusProperties; class DevicePrivate : public QObject { Q_OBJECT public: explicit DevicePrivate(const QString &path, const QVariantMap &properties, const AdapterPtr &adapter); void init(const QVariantMap &properties); void interfacesAdded(const QString &path, const QVariantMapMap &interfaces); void interfacesRemoved(const QString &path, const QStringList &interfaces); QDBusPendingReply<> setDBusProperty(const QString &name, const QVariant &value); void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated); void namePropertyChanged(const QString &value); void aliasPropertyChanged(const QString &value); void addressPropertyChanged(const QString &value); void classPropertyChanged(quint32 value); QWeakPointer q; BluezDevice *m_bluezDevice; DBusProperties *m_dbusProperties; QString m_address; QString m_name; QString m_alias; quint32 m_deviceClass; quint16 m_appearance; QString m_icon; bool m_paired; bool m_trusted; bool m_blocked; bool m_legacyPairing; qint16 m_rssi; bool m_connected; QStringList m_uuids; QString m_modalias; BatteryPtr m_battery; InputPtr m_input; MediaPlayerPtr m_mediaPlayer; MediaTransportPtr m_mediaTransport; AdapterPtr m_adapter; }; } // namespace BluezQt #endif // BLUEZQT_DEVICE_P_H diff --git a/src/devicesmodel.cpp b/src/devicesmodel.cpp index 451d729..084a5e7 100644 --- a/src/devicesmodel.cpp +++ b/src/devicesmodel.cpp @@ -1,231 +1,217 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "devicesmodel.h" #include "manager.h" #include "adapter.h" #include "device.h" namespace BluezQt { class DevicesModelPrivate : public QObject { public: explicit DevicesModelPrivate(DevicesModel *q); void init(); void deviceAdded(DevicePtr device); void deviceRemoved(DevicePtr device); void deviceChanged(DevicePtr device); void adapterChanged(AdapterPtr adapter); DevicesModel *q; Manager *m_manager; QList m_devices; }; DevicesModelPrivate::DevicesModelPrivate(DevicesModel *q) : QObject(q) , q(q) , m_manager(nullptr) { } void DevicesModelPrivate::init() { m_devices = m_manager->devices(); connect(m_manager, &Manager::deviceAdded, this, &DevicesModelPrivate::deviceAdded); connect(m_manager, &Manager::deviceRemoved, this, &DevicesModelPrivate::deviceRemoved); connect(m_manager, &Manager::deviceChanged, this, &DevicesModelPrivate::deviceChanged); connect(m_manager, &Manager::adapterChanged, this, &DevicesModelPrivate::adapterChanged); } void DevicesModelPrivate::deviceAdded(DevicePtr device) { q->beginInsertRows(QModelIndex(), m_devices.size(), m_devices.size()); m_devices.append(device); q->endInsertRows(); } void DevicesModelPrivate::deviceRemoved(DevicePtr device) { int offset = m_devices.indexOf(device); Q_ASSERT(offset >= 0); q->beginRemoveRows(QModelIndex(), offset, offset); m_devices.removeAt(offset); q->endRemoveRows(); } void DevicesModelPrivate::deviceChanged(DevicePtr device) { int offset = m_devices.indexOf(device); Q_ASSERT(offset >= 0); QModelIndex idx = q->createIndex(offset, 0); Q_EMIT q->dataChanged(idx, idx); } void DevicesModelPrivate::adapterChanged(AdapterPtr adapter) { const auto devices = adapter->devices(); for (const DevicePtr &device : devices) { deviceChanged(device); } } DevicesModel::DevicesModel(Manager *manager, QObject *parent) : QAbstractListModel(parent) , d(new DevicesModelPrivate(this)) { d->m_manager = manager; d->init(); } DevicesModel::~DevicesModel() { delete d; } QHash DevicesModel::roleNames() const { QHash roles = QAbstractListModel::roleNames(); roles[UbiRole] = QByteArrayLiteral("Ubi"); roles[AddressRole] = QByteArrayLiteral("Address"); roles[NameRole] = QByteArrayLiteral("Name"); roles[FriendlyNameRole] = QByteArrayLiteral("FriendlyName"); roles[RemoteNameRole] = QByteArrayLiteral("RemoteName"); roles[ClassRole] = QByteArrayLiteral("Class"); roles[TypeRole] = QByteArrayLiteral("Type"); roles[AppearanceRole] = QByteArrayLiteral("Appearance"); roles[IconRole] = QByteArrayLiteral("Icon"); roles[PairedRole] = QByteArrayLiteral("Paired"); roles[TrustedRole] = QByteArrayLiteral("Trusted"); roles[BlockedRole] = QByteArrayLiteral("Blocked"); roles[LegacyPairingRole] = QByteArrayLiteral("LegacyPairing"); roles[RssiRole] = QByteArrayLiteral("Rssi"); roles[ConnectedRole] = QByteArrayLiteral("Connected"); roles[UuidsRole] = QByteArrayLiteral("Uuids"); roles[ModaliasRole] = QByteArrayLiteral("Modalias"); roles[AdapterNameRole] = QByteArrayLiteral("AdapterName"); roles[AdapterAddressRole] = QByteArrayLiteral("AdapterAddress"); roles[AdapterPoweredRole] = QByteArrayLiteral("AdapterPowered"); roles[AdapterDiscoverableRole] = QByteArrayLiteral("AdapterDiscoverable"); roles[AdapterPairableRole] = QByteArrayLiteral("AdapterPairable"); roles[AdapterDiscoveringRole] = QByteArrayLiteral("AdapterDiscovering"); roles[AdapterUuidsRole] = QByteArrayLiteral("AdapterUuids"); return roles; } int DevicesModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) { return 0; } return d->m_devices.size(); } QVariant DevicesModel::data(const QModelIndex &index, int role) const { DevicePtr dev = device(index); if (!dev) { return QVariant(); } switch (role) { case Qt::DisplayRole: return dev->name(); case UbiRole: return dev->ubi(); case AddressRole: return dev->address(); case NameRole: return dev->name(); case FriendlyNameRole: return dev->friendlyName(); case RemoteNameRole: return dev->remoteName(); case ClassRole: return dev->deviceClass(); case TypeRole: return dev->type(); case AppearanceRole: return dev->appearance(); case IconRole: return dev->icon(); case PairedRole: return dev->isPaired(); case TrustedRole: return dev->isTrusted(); case BlockedRole: return dev->isBlocked(); case LegacyPairingRole: return dev->hasLegacyPairing(); case RssiRole: return dev->rssi(); case ConnectedRole: return dev->isConnected(); case UuidsRole: return dev->uuids(); case ModaliasRole: return dev->modalias(); case AdapterNameRole: return dev->adapter()->name(); case AdapterAddressRole: return dev->adapter()->address(); case AdapterPoweredRole: return dev->adapter()->isPowered(); case AdapterDiscoverableRole: return dev->adapter()->isDiscoverable(); case AdapterPairableRole: return dev->adapter()->isPairable(); case AdapterDiscoveringRole: return dev->adapter()->isDiscovering(); case AdapterUuidsRole: return dev->adapter()->uuids(); default: return QVariant(); } } QModelIndex DevicesModel::index(int row, int column, const QModelIndex &parent) const { if (!hasIndex(row, column, parent)) { return QModelIndex(); } return createIndex(row, 0); } DevicePtr DevicesModel::device(const QModelIndex &index) const { if (!index.isValid()) { return DevicePtr(); } return d->m_devices.at(index.row()); } } // namespace BluezQt diff --git a/src/devicesmodel.h b/src/devicesmodel.h index 231a215..a753d2f 100644 --- a/src/devicesmodel.h +++ b/src/devicesmodel.h @@ -1,166 +1,152 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_DEVICESMODEL_H #define BLUEZQT_DEVICESMODEL_H #include #include "types.h" #include "bluezqt_export.h" namespace BluezQt { class Manager; class Device; /** * @class BluezQt::DevicesModel devicesmodel.h * * Model of all devices. * * This class represents a model of all devices. * * Example use in QML code: * @code * import org.kde.bluezqt 1.0 as BluezQt * * ListView { * model: BluezQt.DevicesModel { } * delegate: Text { * text: "%1 (%2)".arg(Name).arg(Address) * } * } * @endcode */ class BLUEZQT_EXPORT DevicesModel : public QAbstractListModel { Q_OBJECT public: /** * Device data roles. */ enum DeviceRoles { /** UBI of the device (QString) */ UbiRole = Qt::UserRole + 100, /** Address of the device (QString) */ AddressRole = Qt::UserRole + 101, /** Name of the device (QString) */ NameRole = Qt::UserRole + 102, /** Friendly name of the device (QString) */ FriendlyNameRole = Qt::UserRole + 103, /** Remote name of the device (QString) */ RemoteNameRole = Qt::UserRole + 104, /** Class of the device (quint32) */ ClassRole = Qt::UserRole + 105, /** Type of the device (Device::Type) */ TypeRole = Qt::UserRole + 106, /** Appearance of the device (quint16) */ AppearanceRole = Qt::UserRole + 107, /** Icon name of the device (QString) */ IconRole = Qt::UserRole + 108, /** Indicates whether the device is paired (bool) */ PairedRole = Qt::UserRole + 109, /** Indicates whether the device is trusted (bool) */ TrustedRole = Qt::UserRole + 110, /** Indicates whether the device is blocked (bool) */ BlockedRole = Qt::UserRole + 111, /** Indicates whether the device has legacy pairing (bool) */ LegacyPairingRole = Qt::UserRole + 112, /** Received Signal Strength Indicator of the device (qint16) */ RssiRole = Qt::UserRole + 113, /** Indicates whether the device is connected (bool) */ ConnectedRole = Qt::UserRole + 114, /** UUIDs of supported services by the device (QStringList) */ UuidsRole = Qt::UserRole + 115, /** Modalias of the device (QString) */ ModaliasRole = Qt::UserRole + 116, /** Name of the associated adapter (QString) */ AdapterNameRole = Qt::UserRole + 117, /** Address of the associated adapter (QString) */ AdapterAddressRole = Qt::UserRole + 118, /** Indicates whether the associated adapter is powered (bool) */ AdapterPoweredRole = Qt::UserRole + 119, /** Indicates whether the associated adapter is discoverable (bool) */ AdapterDiscoverableRole = Qt::UserRole + 120, /** Indicates whether the associated adapter is pairable (bool) */ AdapterPairableRole = Qt::UserRole + 121, /** Indicates whether the associated adapter is discovering (bool) */ AdapterDiscoveringRole = Qt::UserRole + 122, /** UUIDs of supported services by the associated adapter (QStringList) */ AdapterUuidsRole = Qt::UserRole + 123, /** Last role used by DevicesModel */ LastRole = Qt::UserRole + 124 }; /** * Creates a new DevicesModel object. * * @param manager manager to be used * @param parent */ explicit DevicesModel(Manager *manager, QObject *parent = nullptr); /** * Destroys a DevicesModel object. */ ~DevicesModel() override; /** * Reimplemented from QAbstractListModel::roleNames() */ QHash roleNames() const override; /** * Reimplemented from QAbstractListModel::rowCount() */ int rowCount(const QModelIndex &parent = QModelIndex()) const override; /** * Reimplemented from QAbstractListModel::data() */ QVariant data(const QModelIndex &index, int role) const override; /** * Reimplemented from QAbstractListModel::index() */ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; /** * Returns a device for specified index. * * @param index index in model * @return device object */ DevicePtr device(const QModelIndex &index) const; private: class DevicesModelPrivate *const d; friend class DevicesModelPrivate; }; } // namespace BluezQt #endif // BLUEZQT_DEVICESMODEL_H diff --git a/src/gattapplication.cpp b/src/gattapplication.cpp index a17759a..bb1ece5 100644 --- a/src/gattapplication.cpp +++ b/src/gattapplication.cpp @@ -1,96 +1,82 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattapplication.h" #include "gattapplication_p.h" #include "gattcharacteristic.h" #include "gattcharacteristicadaptor.h" #include "gattservice.h" #include "gattserviceadaptor.h" #include #include namespace BluezQt { GattApplication::GattApplication(QObject *parent) : GattApplication(QStringLiteral("/org/kde/bluezqt"), parent) { } GattApplication::GattApplication(const QString &objectPathPrefix, QObject *parent) : QObject(parent) , d(new GattApplicationPrivate(objectPathPrefix, this)) { } GattApplication::~GattApplication() { delete d; } DBusManagerStruct GattApplicationPrivate::getManagedObjects() const { DBusManagerStruct objects; const auto serviceAdaptors = q->findChildren(); const auto charcAdaptors = q->findChildren(); for (const GattServiceAdaptor *serviceAdaptor : serviceAdaptors) { QVariantMap properties; for (int i = serviceAdaptor->metaObject()->propertyOffset(); i < serviceAdaptor->metaObject()->propertyCount(); ++i) { auto propertyName = serviceAdaptor->metaObject()->property(i).name(); properties.insert(QString::fromLatin1(propertyName), serviceAdaptor->property(propertyName)); } GattService *service = qobject_cast(serviceAdaptor->parent()); if (service) { objects[service->objectPath()].insert(QStringLiteral("org.bluez.GattService1"), properties); } } for (const GattCharacteristicAdaptor *charcAdaptor : charcAdaptors) { QVariantMap properties; for (int i = charcAdaptor->metaObject()->propertyOffset(); i < charcAdaptor->metaObject()->propertyCount(); ++i) { auto propertyName = charcAdaptor->metaObject()->property(i).name(); properties.insert(QString::fromLatin1(propertyName), charcAdaptor->property(propertyName)); } GattCharacteristic *charc = qobject_cast(charcAdaptor->parent()); if (charc) { objects[charc->objectPath()].insert(QStringLiteral("org.bluez.GattCharacteristic1"), properties); } } return objects; } QDBusObjectPath GattApplication::objectPath() const { return d->m_objectPath; } } // namespace BluezQt diff --git a/src/gattapplication.h b/src/gattapplication.h index 9ede557..4a5e4fb 100644 --- a/src/gattapplication.h +++ b/src/gattapplication.h @@ -1,97 +1,83 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include #include "bluezqt_export.h" class QDBusObjectPath; namespace BluezQt { /** * @class BluezQt::GattApplication GattApplication.h * * Bluetooth GattApplication. * * This class represents a Bluetooth GattApplication, which is the root node of * a GATT object hierarchy. Its child nodes can be GattServices, * GattCharacteristics and GattDescriptors that belong to that GattApplication. * The object path prefix for GattApplications is freely definable and its * children's paths follow the application path hierarchy automatically, while * all instances are enumerated automatically as well. * * Object path: [variable prefix]/appXX/serviceYY/charZZ * */ class BLUEZQT_EXPORT GattApplication : public QObject { Q_OBJECT public: /** * Creates a new GattApplication object with default object path prefix. * * Object path: /org/kde/bluezqt/appXX/serviceYY/charZZ * * @param parent */ explicit GattApplication(QObject *parent = nullptr); /** * Creates a new GattApplication object with custom object path prefix. * * Object path: [objectPathPrefix]/appXX/serviceYY/charZZ * * @param objectPathPrefix * @param parent */ explicit GattApplication(const QString &objectPathPrefix, QObject *parent = nullptr); /** * Destroys a GattApplication object. */ ~GattApplication(); private: /** * D-Bus object path of the GATT application. * * The path where the GATT application will be registered. * * @note You must provide valid object path! * * @return object path of GATT application */ virtual QDBusObjectPath objectPath() const; class GattApplicationPrivate *const d; friend class GattManager; friend class GattService; friend class ObjectManagerAdaptor; }; } // namespace BluezQt diff --git a/src/gattapplication_p.cpp b/src/gattapplication_p.cpp index 834974b..711de65 100644 --- a/src/gattapplication_p.cpp +++ b/src/gattapplication_p.cpp @@ -1,35 +1,21 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattapplication_p.h" namespace BluezQt { GattApplicationPrivate::GattApplicationPrivate(const QString &objectPathPrefix, GattApplication *q_ptr) : q(q_ptr) { static uint8_t appNumber = 0; m_objectPath.setPath(objectPathPrefix + QStringLiteral("/app") + QString::number(appNumber++)); } } // namespace BluezQt diff --git a/src/gattapplication_p.h b/src/gattapplication_p.h index cad9de0..35e4768 100644 --- a/src/gattapplication_p.h +++ b/src/gattapplication_p.h @@ -1,45 +1,31 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "bluezqt_dbustypes.h" #include namespace BluezQt { class GattApplication; class GattApplicationPrivate { public: GattApplicationPrivate(const QString &objectPathPrefix, GattApplication *q_ptr); DBusManagerStruct getManagedObjects() const; GattApplication *q; QDBusObjectPath m_objectPath; }; } // namespace BluezQt diff --git a/src/gattcharacteristic.cpp b/src/gattcharacteristic.cpp index c4e6d9d..14ad732 100644 --- a/src/gattcharacteristic.cpp +++ b/src/gattcharacteristic.cpp @@ -1,76 +1,62 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattcharacteristic.h" #include "gattcharacteristic_p.h" #include "gattservice.h" namespace BluezQt { GattCharacteristic::GattCharacteristic(const QString &uuid, GattService *service) : QObject(service) , d(new GattCharacterisiticPrivate(uuid, service)) { } GattCharacteristic::~GattCharacteristic() { delete d; } QByteArray GattCharacteristic::readValue() { if (d->m_readCallback) { d->m_value = d->m_readCallback(); } return d->m_value; } void GattCharacteristic::writeValue(const QByteArray &value) { d->m_value = value; emit valueWritten(d->m_value); } QString GattCharacteristic::uuid() const { return d->m_uuid; } const GattService *GattCharacteristic::service() const { return d->m_service; } QDBusObjectPath GattCharacteristic::objectPath() const { return d->m_objectPath; } void GattCharacteristic::setReadCallback(ReadCallback callback) { d->m_readCallback = callback; } } // namespace BluezQt diff --git a/src/gattcharacteristic.h b/src/gattcharacteristic.h index 343a3cb..fdb3079 100644 --- a/src/gattcharacteristic.h +++ b/src/gattcharacteristic.h @@ -1,106 +1,92 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "bluezqt_export.h" #include namespace BluezQt { class GattService; class BLUEZQT_EXPORT GattCharacteristic : public QObject { Q_OBJECT public: /** * Creates a new GattCharacteristic object. * * @param parent */ explicit GattCharacteristic(const QString &uuid, GattService *service); /** * Destroys a GattCharacteristic object. */ ~GattCharacteristic(); /** * Reads the value of the characteristic. */ QByteArray readValue(); /** * Writes the value of the characteristic. */ void writeValue(const QByteArray &value); /** * Provide a read callback to operate in *pull* mode. */ using ReadCallback = std::function; void setReadCallback(ReadCallback callback); /** * 128-bit GATT characteristic UUID. * * @return uuid of characteristic */ QString uuid() const; /** * The GATT service the characteristic belongs to. * * @return service this characteristic belongs to */ const GattService *service() const; Q_SIGNALS: /** * Indicates that a value was written. */ void valueWritten(const QByteArray &value); protected: /** * D-Bus object path of the GattCharacteristic. * * The path where the GattCharacteristic will be registered. * * @note You must provide valid object path! * * @return object path of GattCharacteristic */ virtual QDBusObjectPath objectPath() const; private: class GattCharacterisiticPrivate *const d; friend class GattApplicationPrivate; friend class GattCharacteristicAdaptor; friend class GattManager; }; } // namespace BluezQt diff --git a/src/gattcharacteristic_p.cpp b/src/gattcharacteristic_p.cpp index 013f765..453f10f 100644 --- a/src/gattcharacteristic_p.cpp +++ b/src/gattcharacteristic_p.cpp @@ -1,37 +1,23 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattcharacteristic_p.h" #include "gattservice.h" namespace BluezQt { GattCharacterisiticPrivate::GattCharacterisiticPrivate(const QString &uuid, const GattService *service) : m_uuid(uuid) , m_service(service) { static uint8_t charcNumber = 0; m_objectPath.setPath(m_service->objectPath().path() + QStringLiteral("/char") + QString::number(charcNumber++)); } } // namespace BluezQt diff --git a/src/gattcharacteristic_p.h b/src/gattcharacteristic_p.h index c264f22..124dbee 100644 --- a/src/gattcharacteristic_p.h +++ b/src/gattcharacteristic_p.h @@ -1,43 +1,29 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "gattcharacteristic.h" namespace BluezQt { class GattServicePrivate; class GattCharacterisiticPrivate { public: GattCharacterisiticPrivate(const QString &uuid, const GattService *service); QString m_uuid; const GattService *m_service; QDBusObjectPath m_objectPath; QByteArray m_value; GattCharacteristic::ReadCallback m_readCallback = nullptr; }; } // namespace BluezQt diff --git a/src/gattcharacteristicadaptor.cpp b/src/gattcharacteristicadaptor.cpp index 884f93c..01f9c84 100644 --- a/src/gattcharacteristicadaptor.cpp +++ b/src/gattcharacteristicadaptor.cpp @@ -1,73 +1,59 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattcharacteristicadaptor.h" #include "gattcharacteristic.h" #include "gattservice.h" namespace BluezQt { GattCharacteristicAdaptor::GattCharacteristicAdaptor(GattCharacteristic *parent) : QDBusAbstractAdaptor(parent) , m_gattCharacteristic(parent) { } QString GattCharacteristicAdaptor::uuid() const { return m_gattCharacteristic->uuid(); } QDBusObjectPath GattCharacteristicAdaptor::service() const { return m_gattCharacteristic->service()->objectPath(); } QStringList GattCharacteristicAdaptor::flags() const { // TODO: implement flags return { QStringLiteral("read"), QStringLiteral("write") }; } QByteArray GattCharacteristicAdaptor::ReadValue(const QVariantMap &/*options*/) { return m_gattCharacteristic->readValue(); } void GattCharacteristicAdaptor::WriteValue(const QByteArray &value, const QVariantMap &/*options*/) { m_gattCharacteristic->writeValue(value); } void GattCharacteristicAdaptor::StartNotify() { // TODO: implement } void GattCharacteristicAdaptor::StopNotify() { // TODO: implement } } // namespace BluezQt diff --git a/src/gattcharacteristicadaptor.h b/src/gattcharacteristicadaptor.h index 488fc6c..b8cd975 100644 --- a/src/gattcharacteristicadaptor.h +++ b/src/gattcharacteristicadaptor.h @@ -1,61 +1,47 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include class QDBusObjectPath; namespace BluezQt { class GattCharacteristic; class GattCharacteristicAdaptor : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.GattCharacteristic1") Q_PROPERTY(QString UUID READ uuid) Q_PROPERTY(QDBusObjectPath Service READ service) Q_PROPERTY(QStringList Flags READ flags) public: explicit GattCharacteristicAdaptor(GattCharacteristic *parent); QString uuid() const; QDBusObjectPath service() const; QStringList flags() const; public Q_SLOTS: QByteArray ReadValue(const QVariantMap &options); void WriteValue(const QByteArray &value, const QVariantMap &options); void StartNotify(); void StopNotify(); private: GattCharacteristic *m_gattCharacteristic; }; } // namespace BluezQt diff --git a/src/gattmanager.cpp b/src/gattmanager.cpp index 1335782..f04302c 100644 --- a/src/gattmanager.cpp +++ b/src/gattmanager.cpp @@ -1,104 +1,90 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattmanager.h" #include "gattapplication.h" #include "gattcharacteristic.h" #include "gattcharacteristicadaptor.h" #include "gattmanager_p.h" #include "gattservice.h" #include "gattserviceadaptor.h" #include "objectmanageradaptor.h" #include "pendingcall.h" #include "utils.h" #include "debug.h" #include #include namespace BluezQt { GattManager::GattManager(const QString &path, QObject *parent) : QObject(parent) , d(new GattManagerPrivate(path)) { } GattManager::~GattManager() { delete d; } PendingCall *GattManager::registerApplication(GattApplication *application) { Q_ASSERT(application); const auto services = application->findChildren(); for (auto service : services) { new GattServiceAdaptor(service); const auto charcs = service->findChildren(); for (auto charc : charcs) { new GattCharacteristicAdaptor(charc); if (!DBusConnection::orgBluez().registerObject(charc->objectPath().path(), charc, QDBusConnection::ExportAdaptors)) { qCDebug(BLUEZQT) << "Cannot register object" << charc->objectPath().path(); } } if (!DBusConnection::orgBluez().registerObject(service->objectPath().path(), service, QDBusConnection::ExportAdaptors)) { qCDebug(BLUEZQT) << "Cannot register object" << service->objectPath().path(); } } new ObjectManagerAdaptor(application); if (!DBusConnection::orgBluez().registerObject(application->objectPath().path(), application, QDBusConnection::ExportAdaptors)) { qCDebug(BLUEZQT) << "Cannot register object" << application->objectPath().path(); } QList argumentList; argumentList << QVariant::fromValue(application->objectPath()) << QVariantMap(); return new PendingCall(d->m_dbusInterface->asyncCallWithArgumentList(QStringLiteral("RegisterApplication"), argumentList), PendingCall::ReturnVoid, this); } PendingCall *GattManager::unregisterApplication(GattApplication *application) { Q_ASSERT(application); DBusConnection::orgBluez().unregisterObject(application->objectPath().path()); QList argumentList; argumentList << QVariant::fromValue(application->objectPath()); return new PendingCall(d->m_dbusInterface->asyncCallWithArgumentList(QStringLiteral("UnregisterApplication"), argumentList), PendingCall::ReturnVoid, this); } } // namespace BluezQt diff --git a/src/gattmanager.h b/src/gattmanager.h index 629f0eb..f678de9 100644 --- a/src/gattmanager.h +++ b/src/gattmanager.h @@ -1,108 +1,94 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include #include "bluezqt_export.h" namespace BluezQt { class GattApplication; class PendingCall; /** * @class BluezQt::GattManager GattManager.h * * Bluetooth GattManager. * * GATT Manager allows external applications to register GATT services and * profiles. * * Registering a profile allows applications to subscribe to *remote* services. * These must implement the GattProfile1 interface defined above. * * Registering a service allows applications to publish a *local* GATT service, * which then becomes available to remote devices. A GATT service is represented by * a D-Bus object hierarchy where the root node corresponds to a service and the * child nodes represent characteristics and descriptors that belong to that * service. Each node must implement one of GattService1, GattCharacteristic1, * or GattDescriptor1 interfaces described above, based on the attribute it * represents. Each node must also implement the standard D-Bus Properties * interface to expose their properties. These objects collectively represent a * GATT service definition. * * @see GattApplication */ class BLUEZQT_EXPORT GattManager : public QObject { Q_OBJECT public: /** * Destroys a GattManager object. */ ~GattManager(); /** * Registers a local GATT services hierarchy as described * above (GATT Server) and/or GATT profiles (GATT Client). * * The application object path together with the D-Bus * system bus connection ID define the identification of * the application registering a GATT based * service or profile. * * Possible errors: org.bluez.Error.InvalidArguments * org.bluez.Error.AlreadyExists * * @param application application to be registered * @return void pending call */ PendingCall *registerApplication(GattApplication *application); /** * This unregisters the services that has been * previously registered. The object path parameter * must match the same value that has been used * on registration. * * Possible errors: org.bluez.Error.InvalidArguments * org.bluez.Error.DoesNotExist * * @param application application to be unregistered * @return void pending call */ PendingCall *unregisterApplication(GattApplication *application); private: explicit GattManager(const QString &path, QObject *parent = nullptr); class GattManagerPrivate *const d; friend class AdapterPrivate; }; } // namespace BluezQt diff --git a/src/gattmanager_p.cpp b/src/gattmanager_p.cpp index e3a7476..48b87d3 100644 --- a/src/gattmanager_p.cpp +++ b/src/gattmanager_p.cpp @@ -1,44 +1,30 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattmanager_p.h" #include "utils.h" #include namespace BluezQt { GattManagerPrivate::GattManagerPrivate(const QString &path) { m_dbusInterface = new QDBusInterface(Strings::orgBluez(), path, QStringLiteral("org.bluez.GattManager1"), DBusConnection::orgBluez()); } GattManagerPrivate::~GattManagerPrivate() { delete m_dbusInterface; } } // namespace BluezQt diff --git a/src/gattmanager_p.h b/src/gattmanager_p.h index 0f0d72d..bd56e96 100644 --- a/src/gattmanager_p.h +++ b/src/gattmanager_p.h @@ -1,40 +1,26 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once class QDBusInterface; class QString; namespace BluezQt { class GattManagerPrivate { public: GattManagerPrivate(const QString &path); ~GattManagerPrivate(); QDBusInterface *m_dbusInterface = nullptr; }; } // namespace BluezQt diff --git a/src/gattservice.cpp b/src/gattservice.cpp index 58f6844..e544792 100644 --- a/src/gattservice.cpp +++ b/src/gattservice.cpp @@ -1,56 +1,42 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattservice.h" #include "gattapplication.h" #include "gattservice_p.h" namespace BluezQt { GattService::GattService(const QString &uuid, bool isPrimary, GattApplication *parent) : QObject(parent) , d(new GattServicePrivate(uuid, isPrimary, parent->objectPath().path())) { } GattService::~GattService() { delete d; } QString GattService::uuid() const { return d->m_uuid; } bool GattService::isPrimary() const { return d->m_isPrimary; } QDBusObjectPath GattService::objectPath() const { return d->m_objectPath; } } // namespace BluezQt diff --git a/src/gattservice.h b/src/gattservice.h index 20310b6..d0c3fb4 100644 --- a/src/gattservice.h +++ b/src/gattservice.h @@ -1,93 +1,79 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "bluezqt_export.h" #include "types.h" #include namespace BluezQt { /** * @class BluezQt::GattService GattService.h * * Bluetooth GattService. * * This class represents a Bluetooth GattService. */ class BLUEZQT_EXPORT GattService : public QObject { Q_OBJECT public: /** * Creates a new GattService object. * * @param parent */ explicit GattService(const QString &uuid, bool isPrimary, GattApplication *parent); /** * Destroys a GattService object. */ ~GattService(); /** * 128-bit service UUID. * * @return uuid of gatt service */ QString uuid() const; /** * Indicates whether or not this GATT service is a * primary service. If false, the service is secondary. * * @return true if gatt service is primary */ bool isPrimary() const; protected: /** * D-Bus object path of the GattService. * * The path where the GattService will be registered. * * @note You must provide valid object path! * * @return object path of GattService */ virtual QDBusObjectPath objectPath() const; private: class GattServicePrivate *const d; friend class GattApplicationPrivate; friend class GattCharacterisiticPrivate; friend class GattCharacteristicAdaptor; friend class GattManager; }; } // namespace BluezQt diff --git a/src/gattservice_p.cpp b/src/gattservice_p.cpp index fe29b9f..47cc21e 100644 --- a/src/gattservice_p.cpp +++ b/src/gattservice_p.cpp @@ -1,36 +1,22 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattservice_p.h" namespace BluezQt { GattServicePrivate::GattServicePrivate(const QString &uuid, bool isPrimary, const QString &appPath) : m_uuid(uuid) , m_isPrimary(isPrimary) { static uint8_t serviceNumber = 0; m_objectPath.setPath(appPath + QStringLiteral("/service") + QString::number(serviceNumber++)); } } // namespace BluezQt diff --git a/src/gattservice_p.h b/src/gattservice_p.h index f23ec9a..7c01343 100644 --- a/src/gattservice_p.h +++ b/src/gattservice_p.h @@ -1,40 +1,26 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include namespace BluezQt { class GattServicePrivate { public: GattServicePrivate(const QString &uuid, bool isPrimary, const QString &appPath); QString m_uuid; bool m_isPrimary; QDBusObjectPath m_objectPath; }; } // namespace BluezQt diff --git a/src/gattserviceadaptor.cpp b/src/gattserviceadaptor.cpp index 15943e9..003ba10 100644 --- a/src/gattserviceadaptor.cpp +++ b/src/gattserviceadaptor.cpp @@ -1,49 +1,35 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "gattserviceadaptor.h" #include "gattservice.h" #include "request.h" #include namespace BluezQt { GattServiceAdaptor::GattServiceAdaptor(GattService *parent) : QDBusAbstractAdaptor(parent) , m_gattService(parent) { } QString GattServiceAdaptor::uuid() const { return m_gattService->uuid(); } bool GattServiceAdaptor::primary() const { return m_gattService->isPrimary(); } } // namespace BluezQt diff --git a/src/gattserviceadaptor.h b/src/gattserviceadaptor.h index 5b3bc3b..1949524 100644 --- a/src/gattserviceadaptor.h +++ b/src/gattserviceadaptor.h @@ -1,50 +1,36 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include namespace BluezQt { class GattService; class GattServiceAdaptor : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.GattService1") Q_PROPERTY(QString UUID READ uuid) Q_PROPERTY(bool Primary READ primary) public: explicit GattServiceAdaptor(GattService *parent); QString uuid() const; bool primary() const; private: GattService *m_gattService; }; } // namespace BluezQt diff --git a/src/imports/DevicesModel.qml b/src/imports/DevicesModel.qml index 0760024..cf2293f 100644 --- a/src/imports/DevicesModel.qml +++ b/src/imports/DevicesModel.qml @@ -1,25 +1,11 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ import org.kde.bluezqt 1.0 as BluezQt BluezQt.DevicesModelPrivate { manager: BluezQt.Manager } diff --git a/src/imports/bluezqtextensionplugin.cpp b/src/imports/bluezqtextensionplugin.cpp index 1dca4f1..de3f0f9 100644 --- a/src/imports/bluezqtextensionplugin.cpp +++ b/src/imports/bluezqtextensionplugin.cpp @@ -1,88 +1,74 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "bluezqtextensionplugin.h" #include "declarativemanager.h" #include "declarativeadapter.h" #include "declarativebattery.h" #include "declarativedevice.h" #include "declarativeinput.h" #include "declarativemediaplayer.h" #include "declarativedevicesmodel.h" #include "device.h" #include "pendingcall.h" #include "services.h" #include // krazy:exclude=includes static QObject *manager_singleton(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return new DeclarativeManager; } static QJSValue services_singleton(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) QJSValue object = scriptEngine->newObject(); object.setProperty(QStringLiteral("ServiceDiscoveryServer"), BluezQt::Services::ServiceDiscoveryServer); object.setProperty(QStringLiteral("SerialPort"), BluezQt::Services::SerialPort); object.setProperty(QStringLiteral("DialupNetworking"), BluezQt::Services::DialupNetworking); object.setProperty(QStringLiteral("ObexObjectPush"), BluezQt::Services::ObexObjectPush); object.setProperty(QStringLiteral("ObexFileTransfer"), BluezQt::Services::ObexFileTransfer); object.setProperty(QStringLiteral("Headset"), BluezQt::Services::Headset); object.setProperty(QStringLiteral("AudioSource"), BluezQt::Services::AudioSource); object.setProperty(QStringLiteral("AudioVideoRemoteControlTarget"), BluezQt::Services::AudioVideoRemoteControlTarget); object.setProperty(QStringLiteral("AdvancedAudioDistribution"), BluezQt::Services::AdvancedAudioDistribution); object.setProperty(QStringLiteral("AudioVideoRemoteControl"), BluezQt::Services::AudioVideoRemoteControl); object.setProperty(QStringLiteral("HeadsetAudioGateway"), BluezQt::Services::HeadsetAudioGateway); object.setProperty(QStringLiteral("Panu"), BluezQt::Services::Panu); object.setProperty(QStringLiteral("Nap"), BluezQt::Services::Nap); object.setProperty(QStringLiteral("Handsfree"), BluezQt::Services::Handsfree); object.setProperty(QStringLiteral("HandsfreeAudioGateway"), BluezQt::Services::HandsfreeAudioGateway); object.setProperty(QStringLiteral("HumanInterfaceDevice"), BluezQt::Services::HumanInterfaceDevice); object.setProperty(QStringLiteral("SimAccess"), BluezQt::Services::SimAccess); object.setProperty(QStringLiteral("PhonebookAccessServer"), BluezQt::Services::PhonebookAccessServer); object.setProperty(QStringLiteral("MessageAccessServer"), BluezQt::Services::MessageAccessServer); object.setProperty(QStringLiteral("PnpInformation"), BluezQt::Services::PnpInformation); return object; } void BluezQtExtensionPlugin::registerTypes(const char *uri) { using namespace BluezQt; Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.bluezqt")); qmlRegisterSingletonType(uri, 1, 0, "Manager", manager_singleton); qmlRegisterType(uri, 1, 0, "DevicesModelPrivate"); qmlRegisterUncreatableType(uri, 1, 0, "Adapter", QStringLiteral("Adapter cannot be created")); qmlRegisterUncreatableType(uri, 1, 0, "Battery", QStringLiteral("Battery cannot be created")); qmlRegisterUncreatableType(uri, 1, 0, "Device", QStringLiteral("Device cannot be created")); qmlRegisterUncreatableType(uri, 1, 0, "Input", QStringLiteral("Input cannot be created")); qmlRegisterUncreatableType(uri, 1, 0, "MediaPlayer", QStringLiteral("MediaPlayer cannot be created")); qmlRegisterUncreatableType(uri, 1, 0, "PendingCall", QStringLiteral("PendingCall cannot be created")); qmlRegisterSingletonType(uri, 1, 0, "Services", services_singleton); } diff --git a/src/imports/bluezqtextensionplugin.h b/src/imports/bluezqtextensionplugin.h index 3899571..0a639bb 100644 --- a/src/imports/bluezqtextensionplugin.h +++ b/src/imports/bluezqtextensionplugin.h @@ -1,39 +1,25 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQTEXTENSIONPLUGIN_H #define BLUEZQTEXTENSIONPLUGIN_H #include class BluezQtExtensionPlugin: public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.kde.bluezqt") public: void registerTypes(const char *uri) override; }; #endif // BLUEZQTEXTENSIONPLUGIN_H diff --git a/src/imports/declarativeadapter.cpp b/src/imports/declarativeadapter.cpp index cdb71a2..40080b5 100644 --- a/src/imports/declarativeadapter.cpp +++ b/src/imports/declarativeadapter.cpp @@ -1,212 +1,198 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "declarativeadapter.h" #include "declarativedevice.h" static int devicesCountFunction(QQmlListProperty *property) { Q_ASSERT(qobject_cast(property->object)); DeclarativeAdapter *adapter = static_cast(property->object); return adapter->m_devices.count(); } static DeclarativeDevice *devicesAtFunction(QQmlListProperty *property, int index) { Q_ASSERT(qobject_cast(property->object)); DeclarativeAdapter *adapter = static_cast(property->object); return adapter->m_devices.values().at(index); } DeclarativeAdapter::DeclarativeAdapter(BluezQt::AdapterPtr adapter, QObject *parent) : QObject(parent) , m_adapter(adapter) { connect(m_adapter.data(), &BluezQt::Adapter::nameChanged, this, &DeclarativeAdapter::nameChanged); connect(m_adapter.data(), &BluezQt::Adapter::systemNameChanged, this, &DeclarativeAdapter::systemNameChanged); connect(m_adapter.data(), &BluezQt::Adapter::adapterClassChanged, this, &DeclarativeAdapter::adapterClassChanged); connect(m_adapter.data(), &BluezQt::Adapter::poweredChanged, this, &DeclarativeAdapter::poweredChanged); connect(m_adapter.data(), &BluezQt::Adapter::discoverableChanged, this, &DeclarativeAdapter::discoverableChanged); connect(m_adapter.data(), &BluezQt::Adapter::discoverableTimeoutChanged, this, &DeclarativeAdapter::discoverableTimeoutChanged); connect(m_adapter.data(), &BluezQt::Adapter::pairableChanged, this, &DeclarativeAdapter::pairableChanged); connect(m_adapter.data(), &BluezQt::Adapter::pairableTimeoutChanged, this, &DeclarativeAdapter::pairableTimeoutChanged); connect(m_adapter.data(), &BluezQt::Adapter::discoveringChanged, this, &DeclarativeAdapter::discoveringChanged); connect(m_adapter.data(), &BluezQt::Adapter::uuidsChanged, this, &DeclarativeAdapter::uuidsChanged); connect(m_adapter.data(), &BluezQt::Adapter::modaliasChanged, this, &DeclarativeAdapter::modaliasChanged); connect(m_adapter.data(), &BluezQt::Adapter::deviceAdded, this, &DeclarativeAdapter::slotDeviceAdded); connect(m_adapter.data(), &BluezQt::Adapter::deviceRemoved, this, &DeclarativeAdapter::slotDeviceRemoved); connect(m_adapter.data(), &BluezQt::Adapter::adapterRemoved, this, [this]() { Q_EMIT adapterRemoved(this); }); connect(m_adapter.data(), &BluezQt::Adapter::adapterChanged, this, [this]() { Q_EMIT adapterChanged(this); }); connect(m_adapter.data(), &BluezQt::Adapter::deviceChanged, this, [this](const BluezQt::DevicePtr &device) { Q_EMIT deviceChanged(declarativeDeviceFromPtr(device)); }); } QString DeclarativeAdapter::ubi() const { return m_adapter->ubi(); } QString DeclarativeAdapter::address() const { return m_adapter->address(); } QString DeclarativeAdapter::name() const { return m_adapter->name(); } void DeclarativeAdapter::setName(const QString &name) { m_adapter->setName(name); } QString DeclarativeAdapter::systemName() const { return m_adapter->systemName(); } quint32 DeclarativeAdapter::adapterClass() const { return m_adapter->adapterClass(); } bool DeclarativeAdapter::isPowered() const { return m_adapter->isPowered(); } void DeclarativeAdapter::setPowered(bool powered) { m_adapter->setPowered(powered); } bool DeclarativeAdapter::isDiscoverable() const { return m_adapter->isDiscoverable(); } void DeclarativeAdapter::setDiscoverable(bool discoverable) { m_adapter->setDiscoverable(discoverable); } quint32 DeclarativeAdapter::discoverableTimeout() const { return m_adapter->discoverableTimeout(); } void DeclarativeAdapter::setDiscoverableTimeout(quint32 timeout) { m_adapter->setDiscoverableTimeout(timeout); } bool DeclarativeAdapter::isPairable() const { return m_adapter->isPairable(); } void DeclarativeAdapter::setPairable(bool pairable) { m_adapter->setPairable(pairable); } quint32 DeclarativeAdapter::pairableTimeout() const { return m_adapter->pairableTimeout(); } void DeclarativeAdapter::setPairableTimeout(quint32 timeout) { m_adapter->setPairableTimeout(timeout); } bool DeclarativeAdapter::isDiscovering() { return m_adapter->isDiscovering(); } QStringList DeclarativeAdapter::uuids() const { return m_adapter->uuids(); } QString DeclarativeAdapter::modalias() const { return m_adapter->modalias(); } QQmlListProperty DeclarativeAdapter::devices() { return QQmlListProperty(this, nullptr, devicesCountFunction, devicesAtFunction); } DeclarativeDevice *DeclarativeAdapter::deviceForAddress(const QString &address) const { return declarativeDeviceFromPtr(m_adapter->deviceForAddress(address)); } BluezQt::PendingCall *DeclarativeAdapter::startDiscovery() { return m_adapter->startDiscovery(); } BluezQt::PendingCall *DeclarativeAdapter::stopDiscovery() { return m_adapter->stopDiscovery(); } BluezQt::PendingCall *DeclarativeAdapter::removeDevice(DeclarativeDevice *device) { return m_adapter->removeDevice(m_adapter->deviceForAddress(device->address())); } void DeclarativeAdapter::slotDeviceAdded(BluezQt::DevicePtr device) { Q_EMIT deviceFound(declarativeDeviceFromPtr(device)); Q_EMIT devicesChanged(devices()); } void DeclarativeAdapter::slotDeviceRemoved(BluezQt::DevicePtr device) { Q_EMIT deviceRemoved(declarativeDeviceFromPtr(device)); Q_EMIT devicesChanged(devices()); } DeclarativeDevice *DeclarativeAdapter::declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const { if (!ptr) { return nullptr; } return m_devices.value(ptr->ubi()); } diff --git a/src/imports/declarativeadapter.h b/src/imports/declarativeadapter.h index 315e4bd..33a87c3 100644 --- a/src/imports/declarativeadapter.h +++ b/src/imports/declarativeadapter.h @@ -1,125 +1,111 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DECLARATIVEADAPTER_H #define DECLARATIVEADAPTER_H #include #include "adapter.h" class DeclarativeDevice; class DeclarativeAdapter : public QObject { Q_OBJECT Q_PROPERTY(QString ubi READ ubi CONSTANT) Q_PROPERTY(QString address READ address CONSTANT) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString systemName READ systemName NOTIFY systemNameChanged) Q_PROPERTY(quint32 adapterClass READ adapterClass NOTIFY adapterClassChanged) Q_PROPERTY(bool powered READ isPowered WRITE setPowered NOTIFY poweredChanged) Q_PROPERTY(bool discoverable READ isDiscoverable WRITE setDiscoverable NOTIFY discoverableChanged) Q_PROPERTY(quint32 discoverableTimeout READ discoverableTimeout WRITE setDiscoverableTimeout NOTIFY discoverableTimeoutChanged) Q_PROPERTY(bool pairable READ isPairable WRITE setPairable NOTIFY pairableChanged) Q_PROPERTY(quint32 pairableTimeout READ pairableTimeout WRITE setPairableTimeout NOTIFY pairableTimeoutChanged) Q_PROPERTY(bool discovering READ isDiscovering NOTIFY discoveringChanged) Q_PROPERTY(QStringList uuids READ uuids NOTIFY uuidsChanged) Q_PROPERTY(QString modalias READ modalias NOTIFY modaliasChanged) Q_PROPERTY(QQmlListProperty devices READ devices NOTIFY devicesChanged) public: explicit DeclarativeAdapter(BluezQt::AdapterPtr adapter, QObject *parent = nullptr); QString ubi() const; QString address() const; QString name() const; void setName(const QString &name); QString systemName() const; quint32 adapterClass() const; bool isPowered() const; void setPowered(bool powered); bool isDiscoverable() const; void setDiscoverable(bool discoverable); quint32 discoverableTimeout() const; void setDiscoverableTimeout(quint32 timeout); bool isPairable() const; void setPairable(bool pairable); quint32 pairableTimeout() const; void setPairableTimeout(quint32 timeout); bool isDiscovering(); QStringList uuids() const; QString modalias() const; QQmlListProperty devices(); BluezQt::AdapterPtr m_adapter; QHash m_devices; public Q_SLOTS: DeclarativeDevice *deviceForAddress(const QString &address) const; BluezQt::PendingCall *startDiscovery(); BluezQt::PendingCall *stopDiscovery(); BluezQt::PendingCall *removeDevice(DeclarativeDevice *device); Q_SIGNALS: void adapterRemoved(DeclarativeAdapter *adapter); void adapterChanged(DeclarativeAdapter *adapter); void nameChanged(const QString &name); void systemNameChanged(const QString &name); void adapterClassChanged(quint32 adapterClass); void poweredChanged(bool powered); void discoverableChanged(bool discoverable); void discoverableTimeoutChanged(quint32 timeout); void pairableChanged(bool pairable); void pairableTimeoutChanged(quint32 timeout); void discoveringChanged(bool discovering); void uuidsChanged(const QStringList &uuids); void modaliasChanged(const QString &modalias); void deviceFound(DeclarativeDevice *device); void deviceRemoved(DeclarativeDevice *device); void deviceChanged(DeclarativeDevice *device); void devicesChanged(QQmlListProperty devices); private Q_SLOTS: void slotDeviceAdded(BluezQt::DevicePtr device); void slotDeviceRemoved(BluezQt::DevicePtr device); private: DeclarativeDevice *declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const; }; #endif // DECLARATIVEADAPTER_H diff --git a/src/imports/declarativebattery.cpp b/src/imports/declarativebattery.cpp index d70d4f5..5371522 100644 --- a/src/imports/declarativebattery.cpp +++ b/src/imports/declarativebattery.cpp @@ -1,35 +1,21 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Kai Uwe Broulik + * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "declarativebattery.h" DeclarativeBattery::DeclarativeBattery(const BluezQt::BatteryPtr &battery, QObject *parent) : QObject(parent) , m_battery(battery) { connect(m_battery.data(), &BluezQt::Battery::percentageChanged, this, &DeclarativeBattery::percentageChanged); } int DeclarativeBattery::percentage() const { return m_battery->percentage(); } diff --git a/src/imports/declarativebattery.h b/src/imports/declarativebattery.h index bce6193..88c0e8d 100644 --- a/src/imports/declarativebattery.h +++ b/src/imports/declarativebattery.h @@ -1,45 +1,31 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Kai Uwe Broulik + * SPDX-FileCopyrightText: 2019 Kai Uwe Broulik * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DECLARATIVEBATTERY_H #define DECLARATIVEBATTERY_H #include "battery.h" class DeclarativeBattery : public QObject { Q_OBJECT Q_PROPERTY(int percentage READ percentage NOTIFY percentageChanged) public: explicit DeclarativeBattery(const BluezQt::BatteryPtr &battery, QObject *parent = nullptr); int percentage() const; Q_SIGNALS: void percentageChanged(int percentage); private: BluezQt::BatteryPtr m_battery; }; #endif // DECLARATIVEBATTERY_H diff --git a/src/imports/declarativedevice.cpp b/src/imports/declarativedevice.cpp index 1928350..68a2912 100644 --- a/src/imports/declarativedevice.cpp +++ b/src/imports/declarativedevice.cpp @@ -1,260 +1,246 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "declarativedevice.h" #include "declarativeadapter.h" #include "declarativebattery.h" #include "declarativeinput.h" #include "declarativemediaplayer.h" #include DeclarativeDevice::DeclarativeDevice(BluezQt::DevicePtr device, DeclarativeAdapter *adapter) : QObject(adapter) , m_device(device) , m_adapter(adapter) , m_battery(nullptr) , m_input(nullptr) , m_mediaPlayer(nullptr) { connect(m_device.data(), &BluezQt::Device::nameChanged, this, &DeclarativeDevice::nameChanged); connect(m_device.data(), &BluezQt::Device::friendlyNameChanged, this, &DeclarativeDevice::friendlyNameChanged); connect(m_device.data(), &BluezQt::Device::remoteNameChanged, this, &DeclarativeDevice::remoteNameChanged); connect(m_device.data(), &BluezQt::Device::deviceClassChanged, this, &DeclarativeDevice::deviceClassChanged); connect(m_device.data(), &BluezQt::Device::typeChanged, this, &DeclarativeDevice::typeChanged); connect(m_device.data(), &BluezQt::Device::appearanceChanged, this, &DeclarativeDevice::appearanceChanged); connect(m_device.data(), &BluezQt::Device::iconChanged, this, &DeclarativeDevice::iconChanged); connect(m_device.data(), &BluezQt::Device::pairedChanged, this, &DeclarativeDevice::pairedChanged); connect(m_device.data(), &BluezQt::Device::trustedChanged, this, &DeclarativeDevice::trustedChanged); connect(m_device.data(), &BluezQt::Device::blockedChanged, this, &DeclarativeDevice::blockedChanged); connect(m_device.data(), &BluezQt::Device::legacyPairingChanged, this, &DeclarativeDevice::legacyPairingChanged); connect(m_device.data(), &BluezQt::Device::rssiChanged, this, &DeclarativeDevice::rssiChanged); connect(m_device.data(), &BluezQt::Device::connectedChanged, this, &DeclarativeDevice::connectedChanged); connect(m_device.data(), &BluezQt::Device::uuidsChanged, this, &DeclarativeDevice::uuidsChanged); connect(m_device.data(), &BluezQt::Device::modaliasChanged, this, &DeclarativeDevice::modaliasChanged); connect(m_device.data(), &BluezQt::Device::mediaPlayerChanged, this, &DeclarativeDevice::updateMediaPlayer); connect(m_device.data(), &BluezQt::Device::inputChanged, this, &DeclarativeDevice::updateInput); connect(m_device.data(), &BluezQt::Device::batteryChanged, this, &DeclarativeDevice::updateBattery); connect(m_device.data(), &BluezQt::Device::deviceRemoved, this, [this]() { Q_EMIT deviceRemoved(this); }); connect(m_device.data(), &BluezQt::Device::deviceChanged, this, [this]() { Q_EMIT deviceChanged(this); }); updateInput(); updateMediaPlayer(); } QString DeclarativeDevice::ubi() const { return m_device->ubi(); } QString DeclarativeDevice::address() const { return m_device->address(); } QString DeclarativeDevice::name() const { return m_device->name(); } void DeclarativeDevice::setName(const QString &name) { m_device->setName(name); } QString DeclarativeDevice::friendlyName() const { return m_device->friendlyName(); } QString DeclarativeDevice::remoteName() const { return m_device->remoteName(); } quint32 DeclarativeDevice::deviceClass() const { return m_device->deviceClass(); } BluezQt::Device::Type DeclarativeDevice::type() const { return m_device->type(); } quint16 DeclarativeDevice::appearance() const { return m_device->appearance(); } QString DeclarativeDevice::icon() const { return m_device->icon(); } bool DeclarativeDevice::isPaired() const { return m_device->isPaired(); } bool DeclarativeDevice::isTrusted() const { return m_device->isTrusted(); } void DeclarativeDevice::setTrusted(bool trusted) { m_device->setTrusted(trusted); } bool DeclarativeDevice::isBlocked() const { return m_device->isBlocked(); } void DeclarativeDevice::setBlocked(bool blocked) { m_device->setBlocked(blocked); } bool DeclarativeDevice::hasLegacyPairing() const { return m_device->hasLegacyPairing(); } qint16 DeclarativeDevice::rssi() const { return m_device->rssi(); } bool DeclarativeDevice::isConnected() const { return m_device->isConnected(); } QStringList DeclarativeDevice::uuids() const { return m_device->uuids(); } QString DeclarativeDevice::modalias() const { return m_device->modalias(); } DeclarativeBattery *DeclarativeDevice::battery() const { return m_battery; } DeclarativeInput *DeclarativeDevice::input() const { return m_input; } DeclarativeMediaPlayer *DeclarativeDevice::mediaPlayer() const { return m_mediaPlayer; } DeclarativeAdapter *DeclarativeDevice::adapter() const { return m_adapter; } BluezQt::PendingCall *DeclarativeDevice::connectToDevice() { return m_device->connectToDevice(); } BluezQt::PendingCall *DeclarativeDevice::disconnectFromDevice() { return m_device->disconnectFromDevice(); } BluezQt::PendingCall *DeclarativeDevice::connectProfile(const QString &uuid) { return m_device->connectProfile(uuid); } BluezQt::PendingCall *DeclarativeDevice::disconnectProfile(const QString &uuid) { return m_device->disconnectProfile(uuid); } BluezQt::PendingCall *DeclarativeDevice::pair() { return m_device->pair(); } BluezQt::PendingCall *DeclarativeDevice::cancelPairing() { return m_device->cancelPairing(); } void DeclarativeDevice::updateBattery() { if (m_battery) { m_battery->deleteLater(); m_battery = nullptr; } if (m_device->battery()) { m_battery = new DeclarativeBattery(m_device->battery(), this); } Q_EMIT batteryChanged(m_battery); } void DeclarativeDevice::updateInput() { if (m_input) { m_input->deleteLater(); m_input = nullptr; } if (m_device->input()) { m_input = new DeclarativeInput(m_device->input(), this); } Q_EMIT inputChanged(m_input); } void DeclarativeDevice::updateMediaPlayer() { if (m_mediaPlayer) { m_mediaPlayer->deleteLater(); m_mediaPlayer = nullptr; } if (m_device->mediaPlayer()) { m_mediaPlayer = new DeclarativeMediaPlayer(m_device->mediaPlayer(), this); } Q_EMIT mediaPlayerChanged(m_mediaPlayer); } diff --git a/src/imports/declarativedevice.h b/src/imports/declarativedevice.h index 1f3c7ee..bea7c2e 100644 --- a/src/imports/declarativedevice.h +++ b/src/imports/declarativedevice.h @@ -1,148 +1,134 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DECLARATIVEDEVICE_H #define DECLARATIVEDEVICE_H #include "device.h" class DeclarativeAdapter; class DeclarativeBattery; class DeclarativeInput; class DeclarativeMediaPlayer; class DeclarativeDevice : public QObject { Q_OBJECT Q_PROPERTY(QString ubi READ ubi CONSTANT) Q_PROPERTY(QString address READ address CONSTANT) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString friendlyName READ friendlyName NOTIFY friendlyNameChanged) Q_PROPERTY(QString remoteName READ remoteName NOTIFY remoteNameChanged) Q_PROPERTY(quint32 deviceClass READ deviceClass NOTIFY deviceClassChanged) Q_PROPERTY(BluezQt::Device::Type type READ type NOTIFY typeChanged) Q_PROPERTY(quint16 appearance READ appearance NOTIFY appearanceChanged) Q_PROPERTY(QString icon READ icon NOTIFY iconChanged) Q_PROPERTY(bool paired READ isPaired NOTIFY pairedChanged) Q_PROPERTY(bool trusted READ isTrusted WRITE setTrusted NOTIFY trustedChanged) Q_PROPERTY(bool blocked READ isBlocked WRITE setBlocked NOTIFY blockedChanged) Q_PROPERTY(bool legacyPairing READ hasLegacyPairing NOTIFY legacyPairingChanged) Q_PROPERTY(qint16 rssi READ rssi NOTIFY rssiChanged) Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged) Q_PROPERTY(QStringList uuids READ uuids NOTIFY uuidsChanged) Q_PROPERTY(QString modalias READ modalias NOTIFY modaliasChanged) Q_PROPERTY(DeclarativeInput* input READ input NOTIFY inputChanged) Q_PROPERTY(DeclarativeMediaPlayer* mediaPlayer READ mediaPlayer NOTIFY mediaPlayerChanged) Q_PROPERTY(DeclarativeAdapter* adapter READ adapter CONSTANT) public: explicit DeclarativeDevice(BluezQt::DevicePtr device, DeclarativeAdapter *adapter); QString ubi() const; QString address() const; QString name() const; void setName(const QString &name); QString friendlyName() const; QString remoteName() const; quint32 deviceClass() const; BluezQt::Device::Type type() const; quint16 appearance() const; QString icon() const; bool isPaired() const; bool isTrusted() const; void setTrusted(bool trusted); bool isBlocked() const; void setBlocked(bool blocked); bool hasLegacyPairing() const; qint16 rssi() const; bool isConnected() const; QStringList uuids() const; QString modalias() const; DeclarativeBattery *battery() const; DeclarativeInput *input() const; DeclarativeMediaPlayer *mediaPlayer() const; DeclarativeAdapter *adapter() const; public Q_SLOTS: BluezQt::PendingCall *connectToDevice(); BluezQt::PendingCall *disconnectFromDevice(); BluezQt::PendingCall *connectProfile(const QString &uuid); BluezQt::PendingCall *disconnectProfile(const QString &uuid); BluezQt::PendingCall *pair(); BluezQt::PendingCall *cancelPairing(); Q_SIGNALS: void deviceRemoved(DeclarativeDevice *device); void deviceChanged(DeclarativeDevice *device); void nameChanged(const QString &name); void friendlyNameChanged(const QString &friendlyName); void remoteNameChanged(const QString &remoteName); void deviceClassChanged(quint32 deviceClass); void typeChanged(BluezQt::Device::Type type); void appearanceChanged(quint16 appearance); void iconChanged(const QString &icon); void pairedChanged(bool paired); void trustedChanged(bool trusted); void blockedChanged(bool blocked); void legacyPairingChanged(bool legacyPairing); void rssiChanged(qint16 rssi); void connectedChanged(bool connected); void uuidsChanged(const QStringList &uuids); void modaliasChanged(const QString &modalias); void batteryChanged(DeclarativeBattery *battery); void inputChanged(DeclarativeInput *input); void mediaPlayerChanged(DeclarativeMediaPlayer *mediaPlayer); private: void updateBattery(); void updateInput(); void updateMediaPlayer(); BluezQt::DevicePtr m_device; DeclarativeAdapter *m_adapter; DeclarativeBattery *m_battery; DeclarativeInput *m_input; DeclarativeMediaPlayer *m_mediaPlayer; }; #endif // DECLARATIVEDEVICE_H diff --git a/src/imports/declarativedevicesmodel.cpp b/src/imports/declarativedevicesmodel.cpp index 60eadd5..3553047 100644 --- a/src/imports/declarativedevicesmodel.cpp +++ b/src/imports/declarativedevicesmodel.cpp @@ -1,90 +1,76 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "declarativedevicesmodel.h" #include "declarativemanager.h" #include "declarativeadapter.h" #include "declarativebattery.h" #include "declarativedevice.h" #include "declarativemediaplayer.h" DeclarativeDevicesModel::DeclarativeDevicesModel(QObject *parent) : QSortFilterProxyModel(parent) , m_manager(nullptr) , m_model(nullptr) { } DeclarativeManager *DeclarativeDevicesModel::manager() const { return m_manager; } void DeclarativeDevicesModel::setManager(DeclarativeManager *manager) { m_manager = manager; m_model = new BluezQt::DevicesModel(m_manager, this); setSourceModel(m_model); } QHash DeclarativeDevicesModel::roleNames() const { QHash roles = QSortFilterProxyModel::roleNames(); roles[DeviceRole] = QByteArrayLiteral("Device"); roles[AdapterRole] = QByteArrayLiteral("Adapter"); roles[MediaPlayerRole] = QByteArrayLiteral("MediaPlayer"); roles[BatteryRole] = QByteArrayLiteral("Battery"); return roles; } QVariant DeclarativeDevicesModel::data(const QModelIndex &index, int role) const { if (!m_model) { return QSortFilterProxyModel::data(index, role); } BluezQt::DevicePtr dev = m_model->device(mapToSource(index)); if (!dev) { return QSortFilterProxyModel::data(index, role); } switch (role) { case DeviceRole: return QVariant::fromValue(m_manager->declarativeDeviceFromPtr(dev)); case AdapterRole: return QVariant::fromValue(m_manager->declarativeAdapterFromPtr(dev->adapter())); case MediaPlayerRole: if (DeclarativeDevice *device = m_manager->declarativeDeviceFromPtr(dev)) { return QVariant::fromValue(device->mediaPlayer()); } break; case BatteryRole: if (DeclarativeDevice *device = m_manager->declarativeDeviceFromPtr(dev)) { return QVariant::fromValue(device->battery()); } break; } return QSortFilterProxyModel::data(index, role); } diff --git a/src/imports/declarativedevicesmodel.h b/src/imports/declarativedevicesmodel.h index 8ab5df4..4c63971 100644 --- a/src/imports/declarativedevicesmodel.h +++ b/src/imports/declarativedevicesmodel.h @@ -1,59 +1,45 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DECLARATIVEDEVICESMODEL_H #define DECLARATIVEDEVICESMODEL_H #include #include "devicesmodel.h" class DeclarativeManager; class DeclarativeDevicesModel : public QSortFilterProxyModel { Q_OBJECT Q_PROPERTY(DeclarativeManager* manager READ manager WRITE setManager) public: enum DeclarativeDeviceRoles { DeviceRole = BluezQt::DevicesModel::LastRole + 1, AdapterRole = BluezQt::DevicesModel::LastRole + 2, MediaPlayerRole = BluezQt::DevicesModel::LastRole + 3, BatteryRole = BluezQt::DevicesModel::LastRole + 4 }; explicit DeclarativeDevicesModel(QObject *parent = nullptr); DeclarativeManager *manager() const; void setManager(DeclarativeManager *manager); QHash roleNames() const override; QVariant data(const QModelIndex &index, int role) const override; private: DeclarativeManager *m_manager; BluezQt::DevicesModel *m_model; }; #endif // DECLARATIVEMANAGER_H diff --git a/src/imports/declarativeinput.cpp b/src/imports/declarativeinput.cpp index 6bf3185..4cf67ce 100644 --- a/src/imports/declarativeinput.cpp +++ b/src/imports/declarativeinput.cpp @@ -1,35 +1,21 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "declarativeinput.h" DeclarativeInput::DeclarativeInput(const BluezQt::InputPtr &input, QObject *parent) : QObject(parent) , m_input(input) { connect(m_input.data(), &BluezQt::Input::reconnectModeChanged, this, &DeclarativeInput::reconnectModeChanged); } BluezQt::Input::ReconnectMode DeclarativeInput::reconnectMode() const { return m_input->reconnectMode(); } diff --git a/src/imports/declarativeinput.h b/src/imports/declarativeinput.h index 5a5a177..7473004 100644 --- a/src/imports/declarativeinput.h +++ b/src/imports/declarativeinput.h @@ -1,45 +1,31 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DECLARATIVEINPUT_H #define DECLARATIVEINPUT_H #include "input.h" class DeclarativeInput : public QObject { Q_OBJECT Q_PROPERTY(BluezQt::Input::ReconnectMode reconnectMode READ reconnectMode NOTIFY reconnectModeChanged) public: explicit DeclarativeInput(const BluezQt::InputPtr &input, QObject *parent = nullptr); BluezQt::Input::ReconnectMode reconnectMode() const; Q_SIGNALS: void reconnectModeChanged(BluezQt::Input::ReconnectMode mode); private: BluezQt::InputPtr m_input; }; #endif // DECLARATIVEINPUT_H diff --git a/src/imports/declarativemanager.cpp b/src/imports/declarativemanager.cpp index 528fe61..10344c9 100644 --- a/src/imports/declarativemanager.cpp +++ b/src/imports/declarativemanager.cpp @@ -1,188 +1,174 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "declarativemanager.h" #include "declarativeadapter.h" #include "declarativedevice.h" #include "initmanagerjob.h" #include "adapter.h" #include "device.h" static int adaptersCountFunction(QQmlListProperty *property) { Q_ASSERT(qobject_cast(property->object)); DeclarativeManager *manager = static_cast(property->object); return manager->m_adapters.count(); } static DeclarativeAdapter *adaptersAtFunction(QQmlListProperty *property, int index) { Q_ASSERT(qobject_cast(property->object)); DeclarativeManager *manager = static_cast(property->object); return manager->m_adapters.values().at(index); } static int devicesCountFunction(QQmlListProperty *property) { Q_ASSERT(qobject_cast(property->object)); DeclarativeManager *manager = static_cast(property->object); return manager->m_devices.count(); } static DeclarativeDevice *devicesAtFunction(QQmlListProperty *property, int index) { Q_ASSERT(qobject_cast(property->object)); DeclarativeManager *manager = static_cast(property->object); return manager->m_devices.values().at(index); } DeclarativeManager::DeclarativeManager(QObject *parent) : BluezQt::Manager(parent) { BluezQt::InitManagerJob *job = init(); job->start(); connect(job, &BluezQt::InitManagerJob::result, this, &DeclarativeManager::initJobResult); connect(this, &BluezQt::Manager::adapterAdded, this, &DeclarativeManager::slotAdapterAdded); connect(this, &BluezQt::Manager::adapterRemoved, this, &DeclarativeManager::slotAdapterRemoved); connect(this, &BluezQt::Manager::usableAdapterChanged, this, &DeclarativeManager::slotUsableAdapterChanged); connect(this, &BluezQt::Manager::deviceAdded, this, &DeclarativeManager::slotDeviceAdded); connect(this, &BluezQt::Manager::deviceRemoved, this, &DeclarativeManager::slotDeviceRemoved); connect(this, &BluezQt::Manager::adapterChanged, this, [this](const BluezQt::AdapterPtr &adapter) { Q_EMIT adapterChanged(declarativeAdapterFromPtr(adapter)); }); connect(this, &BluezQt::Manager::deviceChanged, this, [this](const BluezQt::DevicePtr &device) { Q_EMIT deviceChanged(declarativeDeviceFromPtr(device)); }); } DeclarativeAdapter *DeclarativeManager::usableAdapter() const { return declarativeAdapterFromPtr(BluezQt::Manager::usableAdapter()); } QQmlListProperty DeclarativeManager::declarativeAdapters() { return QQmlListProperty(this, nullptr, adaptersCountFunction, adaptersAtFunction); } QQmlListProperty DeclarativeManager::declarativeDevices() { return QQmlListProperty(this, nullptr, devicesCountFunction, devicesAtFunction); } DeclarativeAdapter *DeclarativeManager::declarativeAdapterFromPtr(BluezQt::AdapterPtr ptr) const { if (!ptr) { return nullptr; } return m_adapters.value(ptr->ubi()); } DeclarativeDevice *DeclarativeManager::declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const { if (!ptr) { return nullptr; } return m_devices.value(ptr->ubi()); } DeclarativeAdapter *DeclarativeManager::adapterForAddress(const QString &address) const { return declarativeAdapterFromPtr(BluezQt::Manager::adapterForAddress(address)); } DeclarativeAdapter *DeclarativeManager::adapterForUbi(const QString &ubi) const { return declarativeAdapterFromPtr(BluezQt::Manager::adapterForUbi(ubi)); } DeclarativeDevice *DeclarativeManager::deviceForAddress(const QString &address) const { return declarativeDeviceFromPtr(BluezQt::Manager::deviceForAddress(address)); } DeclarativeDevice *DeclarativeManager::deviceForUbi(const QString &ubi) const { return declarativeDeviceFromPtr(BluezQt::Manager::deviceForUbi(ubi)); } void DeclarativeManager::initJobResult(BluezQt::InitManagerJob *job) { if (job->error()) { Q_EMIT initError(job->errorText()); return; } Q_EMIT initFinished(); } void DeclarativeManager::slotAdapterAdded(BluezQt::AdapterPtr adapter) { DeclarativeAdapter *dAdapter = new DeclarativeAdapter(adapter, this); m_adapters[adapter->ubi()] = dAdapter; Q_EMIT adapterAdded(dAdapter); Q_EMIT adaptersChanged(declarativeAdapters()); } void DeclarativeManager::slotAdapterRemoved(BluezQt::AdapterPtr adapter) { DeclarativeAdapter *dAdapter = m_adapters.take(adapter->ubi()); dAdapter->deleteLater(); Q_EMIT adapterRemoved(dAdapter); Q_EMIT adaptersChanged(declarativeAdapters()); } void DeclarativeManager::slotDeviceAdded(BluezQt::DevicePtr device) { DeclarativeAdapter *dAdapter = declarativeAdapterFromPtr(device->adapter()); DeclarativeDevice *dDevice = new DeclarativeDevice(device, dAdapter); m_devices[device->ubi()] = dDevice; dAdapter->m_devices[device->ubi()] = dDevice; Q_EMIT deviceAdded(dDevice); Q_EMIT devicesChanged(declarativeDevices()); } void DeclarativeManager::slotDeviceRemoved(BluezQt::DevicePtr device) { DeclarativeDevice *dDevice = m_devices.take(device->ubi()); dDevice->adapter()->m_devices.take(device->ubi()); dDevice->deleteLater(); Q_EMIT deviceRemoved(dDevice); Q_EMIT devicesChanged(declarativeDevices()); } void DeclarativeManager::slotUsableAdapterChanged(BluezQt::AdapterPtr adapter) { Q_EMIT usableAdapterChanged(declarativeAdapterFromPtr(adapter)); } diff --git a/src/imports/declarativemanager.h b/src/imports/declarativemanager.h index 5c7c61b..6154007 100644 --- a/src/imports/declarativemanager.h +++ b/src/imports/declarativemanager.h @@ -1,84 +1,70 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DECLARATIVEMANAGER_H #define DECLARATIVEMANAGER_H #include #include #include "manager.h" class DeclarativeDevice; class DeclarativeAdapter; class DeclarativeManager : public BluezQt::Manager { Q_OBJECT Q_PROPERTY(DeclarativeAdapter* usableAdapter READ usableAdapter NOTIFY usableAdapterChanged) Q_PROPERTY(QQmlListProperty adapters READ declarativeAdapters NOTIFY adaptersChanged) Q_PROPERTY(QQmlListProperty devices READ declarativeDevices NOTIFY devicesChanged) public: explicit DeclarativeManager(QObject *parent = nullptr); DeclarativeAdapter *usableAdapter() const; QQmlListProperty declarativeAdapters(); QQmlListProperty declarativeDevices(); DeclarativeAdapter *declarativeAdapterFromPtr(BluezQt::AdapterPtr ptr) const; DeclarativeDevice *declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const; QHash m_adapters; QHash m_devices; public Q_SLOTS: DeclarativeAdapter *adapterForAddress(const QString &address) const; DeclarativeAdapter *adapterForUbi(const QString &ubi) const; DeclarativeDevice *deviceForAddress(const QString &address) const; DeclarativeDevice *deviceForUbi(const QString &ubi) const; Q_SIGNALS: void initFinished(); void initError(const QString &errorText); void adapterAdded(DeclarativeAdapter *adapter); void adapterRemoved(DeclarativeAdapter *adapter); void adapterChanged(DeclarativeAdapter *adapter); void deviceAdded(DeclarativeDevice *device); void deviceRemoved(DeclarativeDevice *device); void deviceChanged(DeclarativeDevice *device); void usableAdapterChanged(DeclarativeAdapter *adapter); void adaptersChanged(QQmlListProperty adapters); void devicesChanged(QQmlListProperty devices); private Q_SLOTS: void initJobResult(BluezQt::InitManagerJob *job); void slotAdapterAdded(BluezQt::AdapterPtr adapter); void slotAdapterRemoved(BluezQt::AdapterPtr adapter); void slotDeviceAdded(BluezQt::DevicePtr device); void slotDeviceRemoved(BluezQt::DevicePtr device); void slotUsableAdapterChanged(BluezQt::AdapterPtr adapter); }; #endif // DECLARATIVEMANAGER_H diff --git a/src/imports/declarativemediaplayer.cpp b/src/imports/declarativemediaplayer.cpp index f4ae308..e75f81e 100644 --- a/src/imports/declarativemediaplayer.cpp +++ b/src/imports/declarativemediaplayer.cpp @@ -1,139 +1,125 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "declarativemediaplayer.h" DeclarativeMediaPlayer::DeclarativeMediaPlayer(BluezQt::MediaPlayerPtr mediaPlayer, QObject *parent) : QObject(parent) , m_mediaPlayer(mediaPlayer) { connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::nameChanged, this, &DeclarativeMediaPlayer::nameChanged); connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::equalizerChanged, this, &DeclarativeMediaPlayer::equalizerChanged); connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::repeatChanged, this, &DeclarativeMediaPlayer::repeatChanged); connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::shuffleChanged, this, &DeclarativeMediaPlayer::shuffleChanged); connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::statusChanged, this, &DeclarativeMediaPlayer::statusChanged); connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::positionChanged, this, &DeclarativeMediaPlayer::positionChanged); connect(m_mediaPlayer.data(), &BluezQt::MediaPlayer::trackChanged, this, [this]() { updateTrack(); Q_EMIT trackChanged(m_track); }); updateTrack(); } QString DeclarativeMediaPlayer::name() const { return m_mediaPlayer->name(); } BluezQt::MediaPlayer::Equalizer DeclarativeMediaPlayer::equalizer() const { return m_mediaPlayer->equalizer(); } void DeclarativeMediaPlayer::setEqualizer(BluezQt::MediaPlayer::Equalizer equalizer) { m_mediaPlayer->setEqualizer(equalizer); } BluezQt::MediaPlayer::Repeat DeclarativeMediaPlayer::repeat() const { return m_mediaPlayer->repeat(); } void DeclarativeMediaPlayer::setRepeat(BluezQt::MediaPlayer::Repeat repeat) { m_mediaPlayer->setRepeat(repeat); } BluezQt::MediaPlayer::Shuffle DeclarativeMediaPlayer::shuffle() const { return m_mediaPlayer->shuffle(); } void DeclarativeMediaPlayer::setShuffle(BluezQt::MediaPlayer::Shuffle shuffle) { m_mediaPlayer->setShuffle(shuffle); } BluezQt::MediaPlayer::Status DeclarativeMediaPlayer::status() const { return m_mediaPlayer->status(); } QJsonObject DeclarativeMediaPlayer::track() const { return m_track; } quint32 DeclarativeMediaPlayer::position() const { return m_mediaPlayer->position(); } BluezQt::PendingCall *DeclarativeMediaPlayer::play() { return m_mediaPlayer->play(); } BluezQt::PendingCall *DeclarativeMediaPlayer::pause() { return m_mediaPlayer->pause(); } BluezQt::PendingCall *DeclarativeMediaPlayer::stop() { return m_mediaPlayer->stop(); } BluezQt::PendingCall *DeclarativeMediaPlayer::next() { return m_mediaPlayer->next(); } BluezQt::PendingCall *DeclarativeMediaPlayer::previous() { return m_mediaPlayer->previous(); } BluezQt::PendingCall *DeclarativeMediaPlayer::fastForward() { return m_mediaPlayer->fastForward(); } BluezQt::PendingCall *DeclarativeMediaPlayer::rewind() { return m_mediaPlayer->rewind(); } void DeclarativeMediaPlayer::updateTrack() { m_track[QStringLiteral("valid")] = m_mediaPlayer->track().isValid(); m_track[QStringLiteral("title")] = m_mediaPlayer->track().title(); m_track[QStringLiteral("artist")] = m_mediaPlayer->track().artist(); m_track[QStringLiteral("album")] = m_mediaPlayer->track().album(); m_track[QStringLiteral("genre")] = m_mediaPlayer->track().genre(); m_track[QStringLiteral("numberOfTracks")] = qint64(m_mediaPlayer->track().numberOfTracks()); m_track[QStringLiteral("trackNumber")] = qint64(m_mediaPlayer->track().trackNumber()); m_track[QStringLiteral("duration")] = qint64(m_mediaPlayer->track().duration()); } diff --git a/src/imports/declarativemediaplayer.h b/src/imports/declarativemediaplayer.h index d4af6b6..4f7fcb0 100644 --- a/src/imports/declarativemediaplayer.h +++ b/src/imports/declarativemediaplayer.h @@ -1,86 +1,72 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DECLARATIVEMEDIAPLAYER_H #define DECLARATIVEMEDIAPLAYER_H #include #include "mediaplayer.h" class DeclarativeMediaPlayer : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(BluezQt::MediaPlayer::Equalizer equalizer READ equalizer WRITE setEqualizer NOTIFY equalizerChanged) Q_PROPERTY(BluezQt::MediaPlayer::Repeat repeat READ repeat WRITE setRepeat NOTIFY repeatChanged) Q_PROPERTY(BluezQt::MediaPlayer::Shuffle shuffle READ shuffle WRITE setShuffle NOTIFY shuffleChanged) Q_PROPERTY(BluezQt::MediaPlayer::Status status READ status NOTIFY statusChanged) Q_PROPERTY(QJsonObject track READ track NOTIFY trackChanged) Q_PROPERTY(quint32 position READ position NOTIFY positionChanged) public: explicit DeclarativeMediaPlayer(BluezQt::MediaPlayerPtr mediaPlayer, QObject *parent = nullptr); QString name() const; BluezQt::MediaPlayer::Equalizer equalizer() const; void setEqualizer(BluezQt::MediaPlayer::Equalizer equalizer); BluezQt::MediaPlayer::Repeat repeat() const; void setRepeat(BluezQt::MediaPlayer::Repeat repeat); BluezQt::MediaPlayer::Shuffle shuffle() const; void setShuffle(BluezQt::MediaPlayer::Shuffle shuffle); BluezQt::MediaPlayer::Status status() const; QJsonObject track() const; quint32 position() const; public Q_SLOTS: BluezQt::PendingCall *play(); BluezQt::PendingCall *pause(); BluezQt::PendingCall *stop(); BluezQt::PendingCall *next(); BluezQt::PendingCall *previous(); BluezQt::PendingCall *fastForward(); BluezQt::PendingCall *rewind(); Q_SIGNALS: void nameChanged(const QString &name); void equalizerChanged(BluezQt::MediaPlayer::Equalizer equalizer); void repeatChanged(BluezQt::MediaPlayer::Repeat repeat); void shuffleChanged(BluezQt::MediaPlayer::Shuffle shuffle); void statusChanged(BluezQt::MediaPlayer::Status status); void trackChanged(const QJsonObject &track); void positionChanged(quint32 position); private: void updateTrack(); BluezQt::MediaPlayerPtr m_mediaPlayer; QJsonObject m_track; }; #endif // DECLARATIVEMEDIAPLAYER_H diff --git a/src/initmanagerjob.cpp b/src/initmanagerjob.cpp index afa2429..aa15296 100644 --- a/src/initmanagerjob.cpp +++ b/src/initmanagerjob.cpp @@ -1,111 +1,97 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "initmanagerjob.h" #include "manager.h" #include "manager_p.h" #include "debug.h" namespace BluezQt { class InitManagerJobPrivate : public QObject { public: explicit InitManagerJobPrivate(InitManagerJob *q, Manager *manager); void doStart(); void initError(const QString &errorText); void initFinished(); InitManagerJob *q; Manager *m_manager; }; InitManagerJobPrivate::InitManagerJobPrivate(InitManagerJob *q, Manager *manager) : QObject(q) , q(q) , m_manager(manager) { } void InitManagerJobPrivate::doStart() { if (m_manager->d->m_initialized) { qCWarning(BLUEZQT) << "InitManagerJob: Manager already initialized!"; q->emitResult(); return; } m_manager->d->init(); connect(m_manager->d, &ManagerPrivate::initError, this, &InitManagerJobPrivate::initError); connect(m_manager->d, &ManagerPrivate::initFinished, this, &InitManagerJobPrivate::initFinished); } void InitManagerJobPrivate::initError(const QString &errorText) { qCWarning(BLUEZQT) << "GetManagerJob Error:" << errorText; q->setError(InitManagerJob::UserDefinedError); q->setErrorText(errorText); q->emitResult(); } void InitManagerJobPrivate::initFinished() { q->emitResult(); } InitManagerJob::InitManagerJob(Manager *manager) : Job(manager) , d(new InitManagerJobPrivate(this, manager)) { } InitManagerJob::~InitManagerJob() { if (isRunning()) { qCWarning(BLUEZQT) << "InitManagerJob Error: Job was deleted before finished!"; setError(UserDefinedError); setErrorText(QStringLiteral("Job was deleted before finished.")); emitResult(); } delete d; } Manager *InitManagerJob::manager() const { return d->m_manager; } void InitManagerJob::doStart() { d->doStart(); } void InitManagerJob::doEmitResult() { Q_EMIT result(this); } } // namespace BluezQt diff --git a/src/initmanagerjob.h b/src/initmanagerjob.h index d19cd65..fc763c1 100644 --- a/src/initmanagerjob.h +++ b/src/initmanagerjob.h @@ -1,80 +1,66 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_INITMANAGERJOB_H #define BLUEZQT_INITMANAGERJOB_H #include "job.h" #include "bluezqt_export.h" namespace BluezQt { class Manager; /** * @class BluezQt::InitManagerJob initmanagerjob.h * * Init manager job. * * This class represents a job that initializes Manager. */ class BLUEZQT_EXPORT InitManagerJob : public Job { Q_OBJECT Q_PROPERTY(Manager* manager READ manager) public: /** * Destroys an InitManagerJob object. */ ~InitManagerJob() override; /** * Returns a manager that is being initialized. * * @return manager */ Manager *manager() const; Q_SIGNALS: /** * Indicates that the job have finished. */ void result(InitManagerJob *job); private: explicit InitManagerJob(Manager *manager); void doStart() override; void doEmitResult() override; class InitManagerJobPrivate *const d; friend class InitManagerJobPrivate; friend class Manager; }; } // namespace BluezQt #endif // BLUEZQT_INITMANAGERJOB_H diff --git a/src/initobexmanagerjob.cpp b/src/initobexmanagerjob.cpp index 92d0c75..fbdbf96 100644 --- a/src/initobexmanagerjob.cpp +++ b/src/initobexmanagerjob.cpp @@ -1,112 +1,98 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "initobexmanagerjob.h" #include "obexmanager.h" #include "obexmanager_p.h" #include "debug.h" namespace BluezQt { class InitObexManagerJobPrivate : public QObject { public: explicit InitObexManagerJobPrivate(InitObexManagerJob *q, ObexManager *manager); void doStart(); void initError(const QString &errorText); void initFinished(); InitObexManagerJob *q; ObexManager *m_manager; }; InitObexManagerJobPrivate::InitObexManagerJobPrivate(InitObexManagerJob *q, ObexManager *manager) : QObject(q) , q(q) , m_manager(manager) { } void InitObexManagerJobPrivate::doStart() { if (m_manager->d->m_initialized) { qCWarning(BLUEZQT) << "InitObexManagerJob: ObexManager already initialized!"; q->emitResult(); return; } connect(m_manager->d, &ObexManagerPrivate::initError, this, &InitObexManagerJobPrivate::initError); connect(m_manager->d, &ObexManagerPrivate::initFinished, this, &InitObexManagerJobPrivate::initFinished); m_manager->d->init(); } void InitObexManagerJobPrivate::initError(const QString &errorText) { qCWarning(BLUEZQT) << "InitObexManagerJob Error:" << errorText; q->setError(InitObexManagerJob::UserDefinedError); q->setErrorText(errorText); q->emitResult(); } void InitObexManagerJobPrivate::initFinished() { q->emitResult(); } InitObexManagerJob::InitObexManagerJob(ObexManager *manager) : Job(manager) , d(new InitObexManagerJobPrivate(this, manager)) { } InitObexManagerJob::~InitObexManagerJob() { if (isRunning()) { qCWarning(BLUEZQT) << "InitObexManagerJob Error: Job was deleted before finished!"; setError(UserDefinedError); setErrorText(QStringLiteral("Job was deleted before finished.")); emitResult(); } delete d; } ObexManager *InitObexManagerJob::manager() const { return d->m_manager; } void InitObexManagerJob::doStart() { d->doStart(); } void InitObexManagerJob::doEmitResult() { Q_EMIT result(this); } } // namespace BluezQt diff --git a/src/initobexmanagerjob.h b/src/initobexmanagerjob.h index c84b726..a372096 100644 --- a/src/initobexmanagerjob.h +++ b/src/initobexmanagerjob.h @@ -1,80 +1,66 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_INITOBEXMANAGERJOB_H #define BLUEZQT_INITOBEXMANAGERJOB_H #include "job.h" #include "bluezqt_export.h" namespace BluezQt { class ObexManager; /** * @class BluezQt::InitObexManagerJob initobexmanagerjob.h * * Init obex manager job. * * This class represents a job that initializes ObexManager. */ class BLUEZQT_EXPORT InitObexManagerJob : public Job { Q_OBJECT Q_PROPERTY(ObexManager* manager READ manager) public: /** * Destroys an InitObexManagerJob object. */ ~InitObexManagerJob() override; /** * Returns a manager that is being initialized. * * @return manager */ ObexManager *manager() const; Q_SIGNALS: /** * Indicates that the job have finished. */ void result(InitObexManagerJob *job); private: explicit InitObexManagerJob(ObexManager *manager); void doStart() override; void doEmitResult() override; class InitObexManagerJobPrivate *const d; friend class InitObexManagerJobPrivate; friend class ObexManager; }; } // namespace BluezQt #endif // BLUEZQT_INITOBEXMANAGERJOB_H diff --git a/src/input.cpp b/src/input.cpp index 1a8843a..67309d4 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1,92 +1,78 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "input.h" #include "input_p.h" #include "utils.h" #include "macros.h" #include namespace BluezQt { static Input::ReconnectMode stringToReconnectMode(const QString &mode) { if (mode == QLatin1String("none")) { return Input::NoReconnect; } else if (mode == QLatin1String("host")) { return Input::HostReconnect; } else if (mode == QLatin1String("device")) { return Input::DeviceReconnect; } return Input::AnyReconnect; } InputPrivate::InputPrivate(const QString &path, const QVariantMap &properties) : QObject() , m_path(path) { // Init properties m_reconnectMode = stringToReconnectMode(properties.value(QStringLiteral("ReconnectMode")).toString()); } void InputPrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated) { Q_UNUSED(invalidated) if (interface != Strings::orgBluezInput1()) { return; } QVariantMap::const_iterator i; for (i = changed.constBegin(); i != changed.constEnd(); ++i) { const QVariant &value = i.value(); const QString &property = i.key(); if (property == QLatin1String("ReconnectMode")) { PROPERTY_CHANGED2(m_reconnectMode, stringToReconnectMode(value.toString()), reconnectModeChanged); } } } Input::Input(const QString &path, const QVariantMap &properties) : d(new InputPrivate(path, properties)) { } Input::~Input() { delete d; } InputPtr Input::toSharedPtr() const { return d->q.toStrongRef(); } Input::ReconnectMode Input::reconnectMode() const { return d->m_reconnectMode; } } // namespace BluezQt diff --git a/src/input.h b/src/input.h index e8b2c64..5cc9e16 100644 --- a/src/input.h +++ b/src/input.h @@ -1,96 +1,82 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_INPUT_H #define BLUEZQT_INPUT_H #include #include "types.h" #include "bluezqt_export.h" namespace BluezQt { /** * @class BluezQt::Input input.h * * %Device input. * * This class represents an input interface. */ class BLUEZQT_EXPORT Input : public QObject { Q_OBJECT Q_PROPERTY(ReconnectMode reconnectMode READ reconnectMode NOTIFY reconnectModeChanged) public: /** Reconnect mode. */ enum ReconnectMode { /** Device and host are not required to automatically restore the connection. */ NoReconnect, /** Host restores the connection. */ HostReconnect, /** Device restores the connection. */ DeviceReconnect, /** Device shall attempt to restore the lost connection, but host may also restore the connection. */ AnyReconnect }; Q_ENUM(ReconnectMode) /** * Destroys an Input object. */ ~Input(); /** * Returns a shared pointer from this. * * @return InputPtr */ InputPtr toSharedPtr() const; /** * Returns the reconnect mode. * * @return reconnect mode */ ReconnectMode reconnectMode() const; Q_SIGNALS: /** * Indicates that input's reconnect mode have changed. */ void reconnectModeChanged(ReconnectMode mode); private: explicit Input(const QString &path, const QVariantMap &properties); class InputPrivate *const d; friend class InputPrivate; friend class DevicePrivate; }; } // namespace BluezQt #endif // BLUEZQT_INPUT_H diff --git a/src/input_p.h b/src/input_p.h index 195d1fd..35da15d 100644 --- a/src/input_p.h +++ b/src/input_p.h @@ -1,50 +1,36 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_INPUT_P_H #define BLUEZQT_INPUT_P_H #include #include "input.h" namespace BluezQt { class InputPrivate : public QObject { Q_OBJECT public: explicit InputPrivate(const QString &path, const QVariantMap &properties); void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated); QWeakPointer q; QString m_path; Input::ReconnectMode m_reconnectMode; }; } // namespace BluezQt #endif // BLUEZQT_INPUT_P_H diff --git a/src/job.cpp b/src/job.cpp index 64f0295..2ac635e 100644 --- a/src/job.cpp +++ b/src/job.cpp @@ -1,135 +1,121 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 Alejandro Fiestas Olivares - * 2014 David Rosca + * SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "job.h" #include "job_p.h" #include namespace BluezQt { JobPrivate::JobPrivate() { eventLoop = nullptr; error = Job::NoError; running = false; finished = false; killed = false; } Job::Job(QObject *parent) : QObject(parent) , d_ptr(new JobPrivate) { d_ptr->q_ptr = this; } Job::~Job() { delete d_ptr; } void Job::start() { d_func()->running = true; QMetaObject::invokeMethod(this, "doStart", Qt::QueuedConnection); } void Job::kill() { Q_D(Job); Q_ASSERT(!d->eventLoop); d->running = false; d->finished = true; d->killed = true; deleteLater(); } void Job::emitResult() { Q_D(Job); if (d->killed) { return; } if (d->eventLoop) { d->eventLoop->quit(); } d->running = false; d->finished = true; doEmitResult(); deleteLater(); } int Job::error() const { return d_func()->error; } QString Job::errorText() const { return d_func()->errorText; } bool Job::isRunning() const { return d_func()->running; } bool Job::isFinished() const { return d_func()->finished; } void Job::setError(int errorCode) { d_func()->error = errorCode; } void Job::setErrorText(const QString &errorText) { d_func()->errorText = errorText; } bool Job::exec() { Q_D(Job); Q_ASSERT(!d->eventLoop); QEventLoop loop(this); d->eventLoop = &loop; start(); d->eventLoop->exec(QEventLoop::ExcludeUserInputEvents); d->running = false; d->finished = true; return d->error == NoError; } } // namespace BluezQt diff --git a/src/job.h b/src/job.h index 018b940..2f34b86 100644 --- a/src/job.h +++ b/src/job.h @@ -1,245 +1,231 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014 Alejandro Fiestas Olivares - * 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_JOB_H #define BLUEZQT_JOB_H #include #include "bluezqt_export.h" namespace BluezQt { class JobPrivate; /** * @class BluezQt::Job job.h * * This class represents an asynchronous job performed by BluezQt, * it is usually not used directly but instead it is inherit by some * other class. * * There are two ways of using this class, one is via exec() which will block * the thread until a result is fetched, the other is via connecting to the * signal result() * * Please, think twice before using exec(), it should be used only in either * unittest or cli apps. * * @note Job and its subclasses are meant to be used in a fire-and-forget way. * Jobs will delete themselves when they finish using deleteLater(). * * @note Even given their asynchronous nature, Jobs are still executed in the * main thread, so any blocking code executed in it will block the app calling it. * * @see InitManagerJob * @see InitObexManagerJob */ class BLUEZQT_EXPORT Job : public QObject { Q_OBJECT Q_PROPERTY(int error READ error) Q_PROPERTY(QString errorText READ errorText) Q_PROPERTY(bool running READ isRunning) Q_PROPERTY(bool finished READ isFinished) public: /** * Creates a new Job object. * * @param parent */ explicit Job(QObject *parent = nullptr); /** * Destroys a Job object. */ ~Job(); /** * Error type * * @see error() const */ enum Error { /** Indicates there is no error */ NoError = 0, /** Subclasses should define error codes starting at this value */ UserDefinedError = 100 }; Q_ENUM(Error) /** * Executes the job synchronously. * * This will start a nested QEventLoop internally. Nested event loop can be dangerous and * can have unintended side effects, you should avoid calling exec() whenever you can and use the * asynchronous interface of Job instead. * * Should you indeed call this method, you need to make sure that all callers are reentrant, * so that events delivered by the inner event loop don't cause non-reentrant functions to be * called, which usually wreaks havoc. * * Note that the event loop started by this method does not process user input events, which means * your user interface will effectively be blocked. Other events like paint or network events are * still being processed. The advantage of not processing user input events is that the chance of * accidental reentrancy is greatly reduced. Still you should avoid calling this function. * * @warning This method blocks until the job finishes! * * @return true if the job has been executed without error, false otherwise */ bool exec(); /** * Returns the error code, if there has been an error. * * Make sure to call this once result() has been emitted * * @return the error code for this job, 0 if no error. */ int error() const; /** * Returns the error text if there has been an error. * * Only call if error is not 0. * * This is usually some extra data associated with the error, * such as a URL. Use errorString() to get a human-readable, * translated message. * * @return a string to help understand the error */ QString errorText() const; /** * Returns whether the job is currently running * * @return true if the job is running */ bool isRunning() const; /** * Returns whether the job have already finished * * @return true if the job already finished */ bool isFinished() const; public Q_SLOTS: /** * Starts the job asynchronously. * * This method will schedule doStart() to be executed in the next * loop. This is done so this method returns as soon as possible. * * When the job is finished, result() is emitted. */ void start(); /** * Kills the job. * * This method will kill the job and then call deleteLater(). * Only jobs started with start() can be killed. * * It will not emit result signal. */ void kill(); protected Q_SLOTS: /** * Implementation for start() that will be executed in next loop * * This slot is always called in the next loop, triggered by start(). * * When implementing this method is important to remember that jobs * are not executed on a different thread (unless done that way), so any * blocking task has to be done in a different thread or process. */ virtual void doStart() = 0; protected: /** * Sets the error code. * * It should be called when an error * is encountered in the job, just before calling emitResult(). * * You should define an enum of error codes, * with values starting at Job::UserDefinedError, and use * those. For example: * @code * enum ExampleErrors{ * InvalidFoo = UserDefinedError, * BarNotFound * }; * @endcode * * @param errorCode the error code * @see emitResult() */ void setError(int errorCode); /** * Sets the error text. * * It should be called when an error * is encountered in the job, just before calling emitResult(). * * Provides extra information about the error that cannot be * determined directly from the error code. For example, a * URL or filename. This string is not normally translatable. * * @param errorText the error text * @see emitResult(), setError() */ void setErrorText(const QString &errorText); /** * Utility function to emit the result signal, and suicide this job. * * @note Deletes this job using deleteLater(). * @see result() const */ void emitResult(); /** * Implementation for emitting the result signal * * This function is needed to be able to emit result() signal * with the job pointer's type being subclass */ virtual void doEmitResult() = 0; private: JobPrivate *const d_ptr; Q_DECLARE_PRIVATE(Job) }; } // namespace BluezQt #endif //BLUEZQT_JOB_H diff --git a/src/job_p.h b/src/job_p.h index e931c05..e034f4e 100644 --- a/src/job_p.h +++ b/src/job_p.h @@ -1,49 +1,35 @@ /* - Copyright 2014 Alejandro Fiestas Olivares - - 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) version 3, or any - later version accepted by the membership of KDE e.V. (or its - successor approved by the membership of KDE e.V.), which shall - act as a proxy defined in Section 6 of version 3 of the license. - - 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, see . + SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares + + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_JOB_PRIVATE #define BLUEZQT_JOB_PRIVATE #include "job.h" class QEventLoop; namespace BluezQt { class JobPrivate { public: JobPrivate(); Job *q_ptr; int error; QString errorText; bool running; bool finished; bool killed; QEventLoop *eventLoop; Q_DECLARE_PUBLIC(Job) }; } // namespace BluezQt #endif // BLUEZQT_JOB_PRIVATE diff --git a/src/leadvertisement.cpp b/src/leadvertisement.cpp index 4d3cc22..926a9ea 100644 --- a/src/leadvertisement.cpp +++ b/src/leadvertisement.cpp @@ -1,54 +1,40 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "leadvertisement.h" #include "leadvertisement_p.h" namespace BluezQt { LEAdvertisement::LEAdvertisement(const QStringList &serviceUuids, QObject *parent) : QObject(parent), d(new LEAdvertisementPrivate(serviceUuids)) { } LEAdvertisement::~LEAdvertisement() { delete d; } QDBusObjectPath LEAdvertisement::objectPath() const { return d->m_objectPath; } QStringList LEAdvertisement::serviceUuids() const { return d->m_serviceUuids; } void LEAdvertisement::release() { } } // namespace BluezQt diff --git a/src/leadvertisement.h b/src/leadvertisement.h index 60d0bff..a505d74 100644 --- a/src/leadvertisement.h +++ b/src/leadvertisement.h @@ -1,96 +1,82 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_LEADVERTISEMENT_H #define BLUEZQT_LEADVERTISEMENT_H #include #include "bluezqt_export.h" class QDBusObjectPath; namespace BluezQt { /** * @class BluezQt::LEAdvertisement leadvertisement.h * * Bluetooth LE advertisement. * * This class represents a Bluetooth LE advertisement. */ class BLUEZQT_EXPORT LEAdvertisement : public QObject { Q_OBJECT public: /** * Creates a new LEAdvertisement object. * * @param parent */ explicit LEAdvertisement(const QStringList &serviceUuids, QObject *parent = nullptr); /** * Destroys a LEAdvertisement object. */ ~LEAdvertisement(); /** * List of UUIDs to include in the "Service UUID" field of the Advertising Data. * * @return UUIDs of the advertisement */ virtual QStringList serviceUuids() const; /** * Indicates that the LEAdvertisement was unregistered. * * This method gets called when the service daemon removes the Advertisement. * A client can use it to do cleanup tasks. There is no need to call * UnregisterAdvertisement because when this method gets called it has * already been unregistered. */ virtual void release(); protected: /** * D-Bus object path of the advertisement. * * The path where the advertisement will be registered. * * @note You must provide valid object path! * * @return object path of advertisement */ virtual QDBusObjectPath objectPath() const; private: class LEAdvertisementPrivate *const d; friend class LEAdvertisingManager; }; } // namespace BluezQt #endif // BLUEZQT_LEADVERTISEMENT_H diff --git a/src/leadvertisement_p.cpp b/src/leadvertisement_p.cpp index 69ad619..1ac3aa3 100644 --- a/src/leadvertisement_p.cpp +++ b/src/leadvertisement_p.cpp @@ -1,36 +1,22 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "leadvertisement_p.h" namespace BluezQt { LEAdvertisementPrivate::LEAdvertisementPrivate(const QStringList &serviceUuids) : m_serviceUuids(serviceUuids) { static uint8_t advNumber = 0; QString objectPath = QLatin1String("/org/bluez/lead") + QString::number(advNumber++); m_objectPath.setPath(objectPath); } } // namespace BluezQt diff --git a/src/leadvertisement_p.h b/src/leadvertisement_p.h index 18f623d..10ab377 100644 --- a/src/leadvertisement_p.h +++ b/src/leadvertisement_p.h @@ -1,41 +1,27 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_LEADVERTISEMENT_P_H #define BLUEZQT_LEADVERTISEMENT_P_H #include namespace BluezQt { class LEAdvertisementPrivate { public: explicit LEAdvertisementPrivate(const QStringList &serviceUuids); QStringList m_serviceUuids; QDBusObjectPath m_objectPath; }; } // namespace BluezQt #endif // BLUEZQT_LEADVERTISEMENT_P_H diff --git a/src/leadvertisementadaptor.cpp b/src/leadvertisementadaptor.cpp index 29be042..a1996cc 100644 --- a/src/leadvertisementadaptor.cpp +++ b/src/leadvertisementadaptor.cpp @@ -1,52 +1,38 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "leadvertisementadaptor.h" #include "leadvertisement.h" #include namespace BluezQt { LEAdvertisementAdaptor::LEAdvertisementAdaptor(LEAdvertisement *parent) : QDBusAbstractAdaptor(parent) , m_advertisement(parent) { } QString LEAdvertisementAdaptor::type() const { return QStringLiteral("peripheral"); } QStringList LEAdvertisementAdaptor::serviceUuids() const { return m_advertisement->serviceUuids(); } void LEAdvertisementAdaptor::Release() { m_advertisement->release(); } } // namespace BluezQt diff --git a/src/leadvertisementadaptor.h b/src/leadvertisementadaptor.h index 7182011..a58c44c 100644 --- a/src/leadvertisementadaptor.h +++ b/src/leadvertisementadaptor.h @@ -1,56 +1,42 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_LEADVERTISEMENTADAPTOR_H #define BLUEZQT_LEADVERTISEMENTADAPTOR_H #include namespace BluezQt { class LEAdvertisement; class LEAdvertisementAdaptor : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.LEAdvertisement1") Q_PROPERTY(QString Type READ type) Q_PROPERTY(QStringList ServiceUUIDs READ serviceUuids) public: explicit LEAdvertisementAdaptor(LEAdvertisement *parent); QString type() const; QStringList serviceUuids() const; public Q_SLOTS: Q_NOREPLY void Release(); private: LEAdvertisement *m_advertisement; }; } // namespace BluezQt #endif // BLUEZQT_LEADVERTISEMENTADAPTOR_H diff --git a/src/leadvertisingmanager.cpp b/src/leadvertisingmanager.cpp index 3bac837..6393225 100644 --- a/src/leadvertisingmanager.cpp +++ b/src/leadvertisingmanager.cpp @@ -1,79 +1,65 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "leadvertisingmanager.h" #include "leadvertisingmanager_p.h" #include "leadvertisement.h" #include "leadvertisementadaptor.h" #include "pendingcall.h" #include "utils.h" #include "debug.h" namespace BluezQt { LEAdvertisingManager::LEAdvertisingManager(const QString &path, QObject *parent) : QObject(parent) , d(new LEAdvertisingManagerPrivate()) { d->m_path = path; d->m_bluezLEAdvertisingManager = new BluezLEAdvertisingManager(Strings::orgBluez(), path, DBusConnection::orgBluez(), this); } LEAdvertisingManager::~LEAdvertisingManager() { delete d; } PendingCall *LEAdvertisingManager::registerAdvertisement(LEAdvertisement *advertisement) { Q_ASSERT(advertisement); if (!d->m_bluezLEAdvertisingManager) { return new PendingCall(PendingCall::InternalError, QStringLiteral("LEAdvertisingManager not operational!")); } new LEAdvertisementAdaptor(advertisement); if (!DBusConnection::orgBluez().registerObject(advertisement->objectPath().path(), advertisement)) { qCDebug(BLUEZQT) << "Cannot register object" << advertisement->objectPath().path(); } return new PendingCall(d->m_bluezLEAdvertisingManager->RegisterAdvertisement(advertisement->objectPath(), QVariantMap()), PendingCall::ReturnVoid, this); } PendingCall *LEAdvertisingManager::unregisterAdvertisement(LEAdvertisement *advertisement) { Q_ASSERT(advertisement); if (!d->m_bluezLEAdvertisingManager) { return new PendingCall(PendingCall::InternalError, QStringLiteral("LEAdvertisingManager not operational!")); } DBusConnection::orgBluez().unregisterObject(advertisement->objectPath().path()); return new PendingCall(d->m_bluezLEAdvertisingManager->UnregisterAdvertisement(advertisement->objectPath()), PendingCall::ReturnVoid, this); } } // namespace BluezQt diff --git a/src/leadvertisingmanager.h b/src/leadvertisingmanager.h index 5d5922e..204367e 100644 --- a/src/leadvertisingmanager.h +++ b/src/leadvertisingmanager.h @@ -1,100 +1,86 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_LEADVERTISINGMANAGER_H #define BLUEZQT_LEADVERTISINGMANAGER_H #include #include "bluezqt_export.h" namespace BluezQt { class LEAdvertisement; class PendingCall; /** * @class BluezQt::LEAdvertisingManager leadvertisingmanager.h * * Bluetooth LE advertising manager. * * The Advertising Manager allows external applications to register Advertisement * Data which should be broadcast to devices. Advertisement Data elements must * follow the API for LE Advertisement Data. * * @see LEAdvertisement */ class BLUEZQT_EXPORT LEAdvertisingManager : public QObject { Q_OBJECT public: /** * Destroys an LEAdvertisingManager object. */ ~LEAdvertisingManager(); /** * Registers advertisement. * * Registers an advertisement object to be sent over the LE Advertising * channel. The service must be exported under interface LEAdvertisement1. * * InvalidArguments error indicates invalid or conflicting properties. * InvalidLength error indicates that provided data results in too long data packet. * The properties of this object are parsed on register, any changes are ignored. * If the same object is registered twice it will result in an AlreadyExists error. * NotPermitted error indicates that the maximum number of advertisements is reached. * * Possible errors: PendingCall::InvalidArguments, PendingCall::AlreadyExists, * PendingCall::InvalidLength, PendingCall::NotPermitted * * @param advertisement advertisement to be registered * @return void pending call */ PendingCall *registerAdvertisement(LEAdvertisement *advertisement); /** * Unregisters advertisement. * * This unregisters an advertisement that has been previously registered. * The object path must match the same value that has been used on registration. * * Possible errors: PendingCall::InvalidArguments, PendingCall::DoesNotExist * * @param advertisement advertisement to be unregistered * @return void pending call */ PendingCall *unregisterAdvertisement(LEAdvertisement *advertisement); private: explicit LEAdvertisingManager(const QString &path, QObject *parent = nullptr); class LEAdvertisingManagerPrivate *const d; friend class AdapterPrivate; }; } // namespace BluezQt #endif // BLUEZQT_LEADVERTISINGMANAGER_H diff --git a/src/leadvertisingmanager_p.h b/src/leadvertisingmanager_p.h index 83a8085..5130f7f 100644 --- a/src/leadvertisingmanager_p.h +++ b/src/leadvertisingmanager_p.h @@ -1,42 +1,28 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_LEADVERTISINGMANAGER_P_H #define BLUEZQT_LEADVERTISINGMANAGER_P_H #include "bluezleadvertisingmanager1.h" namespace BluezQt { typedef org::bluez::LEAdvertisingManager1 BluezLEAdvertisingManager; class LEAdvertisingManagerPrivate { public: QString m_path; BluezLEAdvertisingManager *m_bluezLEAdvertisingManager = nullptr; }; } // namespace BluezQt #endif // BLUEZQT_LEADVERTISINGMANAGER_P_H diff --git a/src/macros.h b/src/macros.h index f175969..5a130a2 100644 --- a/src/macros.h +++ b/src/macros.h @@ -1,47 +1,33 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MACROS_H #define BLUEZQT_MACROS_H // Change property value and emit propertyChanged signal #define PROPERTY_CHANGED(var, type_cast, signal) \ if (var != value.type_cast()) { \ var = value.type_cast(); \ Q_EMIT q.lock()->signal(var); \ } #define PROPERTY_CHANGED2(var, value, signal) \ const auto &val = value; \ if (var != val) { \ var = val; \ Q_EMIT q.lock()->signal(var); \ } // Clears property value and emit propertyChanged signal #define PROPERTY_INVALIDATED(var, empty, signal) \ if (var != empty) { \ var = empty; \ Q_EMIT q.lock()->signal(var); \ } #endif // BLUEZQT_MACROS_H diff --git a/src/manager.cpp b/src/manager.cpp index 3d91ef4..4f65216 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -1,256 +1,242 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "manager.h" #include "manager_p.h" #include "adapter.h" #include "agent.h" #include "agentadaptor.h" #include "profile.h" #include "profile_p.h" #include "profileadaptor.h" #include "pendingcall.h" #include "initmanagerjob.h" #include "utils.h" #include "debug.h" namespace BluezQt { Manager::Manager(QObject *parent) : QObject(parent) , d(new ManagerPrivate(this)) { Instance::setManager(this); } Manager::~Manager() { delete d; } InitManagerJob *Manager::init() { return new InitManagerJob(this); } bool Manager::isInitialized() const { return d->m_initialized; } bool Manager::isOperational() const { return d->m_initialized && d->m_bluezRunning && d->m_loaded; } bool Manager::isBluetoothOperational() const { return !d->m_bluetoothBlocked && d->m_bluezRunning && d->m_loaded && d->m_usableAdapter; } bool Manager::isBluetoothBlocked() const { return d->m_bluetoothBlocked; } bool Manager::setBluetoothBlocked(bool blocked) { if (blocked) { return d->m_rfkill->block(); } else { return d->m_rfkill->unblock(); } } AdapterPtr Manager::usableAdapter() const { return d->m_usableAdapter; } QList Manager::adapters() const { return d->m_adapters.values(); } QList Manager::devices() const { return d->m_devices.values(); } PendingCall *Manager::startService() { QDBusMessage msg = QDBusMessage::createMethodCall(Strings::orgFreedesktopDBus(), QStringLiteral("/org/freedesktop/DBus"), Strings::orgFreedesktopDBus(), QStringLiteral("StartServiceByName")); msg << Strings::orgBluez(); msg << quint32(0); return new PendingCall(DBusConnection::orgBluez().asyncCall(msg), PendingCall::ReturnUint32); } AdapterPtr Manager::adapterForAddress(const QString &address) const { for (AdapterPtr adapter : qAsConst(d->m_adapters)) { if (adapter->address() == address) { return adapter; } } return AdapterPtr(); } AdapterPtr Manager::adapterForUbi(const QString &ubi) const { return d->m_adapters.value(ubi); } DevicePtr Manager::deviceForAddress(const QString &address) const { DevicePtr device; for (AdapterPtr adapter : qAsConst(d->m_adapters)) { DevicePtr d = adapter->deviceForAddress(address); if (!d) { continue; } // Prefer powered adapter if (!device) { device = d; } else if (adapter->isPowered()) { device = d; } } return device; } DevicePtr Manager::deviceForUbi(const QString &ubi) const { return d->m_devices.value(ubi); } PendingCall *Manager::registerAgent(Agent *agent) { Q_ASSERT(agent); if (!d->m_bluezAgentManager) { return new PendingCall(PendingCall::InternalError, QStringLiteral("Manager not operational!")); } QString capability; switch (agent->capability()) { case Agent::DisplayOnly: capability = QStringLiteral("DisplayOnly"); break; case Agent::DisplayYesNo: capability = QStringLiteral("DisplayYesNo"); break; case Agent::KeyboardOnly: capability = QStringLiteral("KeyboardOnly"); break; case Agent::NoInputNoOutput: capability = QStringLiteral("NoInputNoOutput"); break; default: capability = QStringLiteral("DisplayYesNo"); break; } new AgentAdaptor(agent, this); if (!DBusConnection::orgBluez().registerObject(agent->objectPath().path(), agent)) { qCDebug(BLUEZQT) << "Cannot register object" << agent->objectPath().path(); } return new PendingCall(d->m_bluezAgentManager->RegisterAgent(agent->objectPath(), capability), PendingCall::ReturnVoid, this); } PendingCall *Manager::unregisterAgent(Agent *agent) { Q_ASSERT(agent); if (!d->m_bluezAgentManager) { return new PendingCall(PendingCall::InternalError, QStringLiteral("Manager not operational!")); } DBusConnection::orgBluez().unregisterObject(agent->objectPath().path()); return new PendingCall(d->m_bluezAgentManager->UnregisterAgent(agent->objectPath()), PendingCall::ReturnVoid, this); } PendingCall *Manager::requestDefaultAgent(Agent *agent) { Q_ASSERT(agent); if (!d->m_bluezAgentManager) { return new PendingCall(PendingCall::InternalError, QStringLiteral("Manager not operational!")); } return new PendingCall(d->m_bluezAgentManager->RequestDefaultAgent(agent->objectPath()), PendingCall::ReturnVoid, this); } PendingCall *Manager::registerProfile(Profile *profile) { Q_ASSERT(profile); if (!d->m_bluezProfileManager) { return new PendingCall(PendingCall::InternalError, QStringLiteral("Manager not operational!")); } new ProfileAdaptor(profile, this); if (!DBusConnection::orgBluez().registerObject(profile->objectPath().path(), profile)) { qCDebug(BLUEZQT) << "Cannot register object" << profile->objectPath().path(); } return new PendingCall(d->m_bluezProfileManager->RegisterProfile(profile->objectPath(), profile->uuid(), profile->d->options), PendingCall::ReturnVoid, this); } PendingCall *Manager::unregisterProfile(Profile *profile) { Q_ASSERT(profile); if (!d->m_bluezProfileManager) { return new PendingCall(PendingCall::InternalError, QStringLiteral("Manager not operational!")); } DBusConnection::orgBluez().unregisterObject(profile->objectPath().path()); return new PendingCall(d->m_bluezProfileManager->UnregisterProfile(profile->objectPath()), PendingCall::ReturnVoid, this); } #if BLUEZQT_BUILD_DEPRECATED_SINCE(5, 57) MediaPtr Manager::media() const { return usableAdapter() ? usableAdapter()->media() : nullptr; } #endif } // namespace BluezQt diff --git a/src/manager.h b/src/manager.h index 716abb1..76e6885 100644 --- a/src/manager.h +++ b/src/manager.h @@ -1,376 +1,362 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MANAGER_H #define BLUEZQT_MANAGER_H #include #include "types.h" #include "bluezqt_export.h" namespace BluezQt { class Device; class Adapter; class Agent; class Profile; class PendingCall; class InitManagerJob; /** * @class BluezQt::Manager manager.h * * Bluetooth manager. * * The entry point to communicate with system BlueZ daemon. * * The typical usecase is to work with usableAdapter() (any powered adapter), * but it is also possible to use specific adapter. * * You must call init() before other functions can be used. * * The only functions that can be used before initialization are two rfkill-related * functions: isBluetoothBlocked() and setBluetoothBlocked(). * * Example use in C++ code: * @code * BluezQt::Manager *manager = new BluezQt::Manager(); * BluezQt::InitManagerJob *job = manager->init(); * job->start(); * connect(job, &BluezQt::InitManagerJob::result, ...); * @endcode * * In QML, manager is a singleton and initialization is started when first using * the manager. You don't need to track initialized state, just use property binding. * * Example use in QML code: * @code * import QtQuick 2.2 * import org.kde.bluezqt 1.0 as BluezQt * * Item { * property QtObject manager : BluezQt.Manager * property devicesCount : manager.devices.length * property adaptersCount : manager.adapters.length * * Component.onCompleted: { * console.log("Manager operational:", manager.operational) * } * } * @endcode * * @note All communication with BlueZ daemon happens asynchronously. Almost all methods * returns PendingCall to help track the call progress and to check for any errors. * * @note If manager is not operational, all methods that returns a PendingCall will fail * with PendingCall::InternalError. * * @see InitManagerJob */ class BLUEZQT_EXPORT Manager : public QObject { Q_OBJECT Q_PROPERTY(bool initialized READ isInitialized) Q_PROPERTY(bool operational READ isOperational NOTIFY operationalChanged) Q_PROPERTY(bool bluetoothOperational READ isBluetoothOperational NOTIFY bluetoothOperationalChanged) Q_PROPERTY(bool bluetoothBlocked READ isBluetoothBlocked WRITE setBluetoothBlocked NOTIFY bluetoothBlockedChanged) Q_PROPERTY(AdapterPtr usableAdapter READ usableAdapter NOTIFY usableAdapterChanged) Q_PROPERTY(QList adapters READ adapters) Q_PROPERTY(QList devices READ devices) public: /** * Creates a new Manager object. * * @param parent */ explicit Manager(QObject *parent = nullptr); /** * Destroys a Manager object. */ ~Manager(); /** * Creates a new init job. * * @return init manager job */ InitManagerJob *init(); /** * Returns whether the manager is initialized. * * @return true if manager is initialized */ bool isInitialized() const; /** * Returns whether the manager is operational. * * The manager is operational when initialization was successful and * BlueZ system daemon is running. * * @return true if manager is operational */ bool isOperational() const; /** * Returns whether Bluetooth is operational. * * Bluetooth is operational when manager is operational and there is * a valid usable adapter. * * @return true if Bluetooth is operational */ bool isBluetoothOperational() const; /** * Returns whether Bluetooth is blocked. * * Bluetooth is blocked if rfkill state for Bluetooth is either * SOFT_BLOCKED or HARD_BLOCKED. * * @note This requires read access to /dev/rfkill. * * @return true if Bluetooth is blocked */ bool isBluetoothBlocked() const; /** * Sets a Bluetooth blocked state. * * This may fail either due to insufficent permissions or * because rfkill state is HARD_BLOCKED. In that case, * this function returns false. * * @note This requires write access to /dev/rfkill. * * @return true if unblocking rfkill devices succeeded */ bool setBluetoothBlocked(bool blocked); /** * Returns a usable adapter. * * Usable adapter is any adapter that is currently powered on. * * @return usable adapter */ AdapterPtr usableAdapter() const; /** * Returns a list of all adapters. * * @return list of adapters */ QList adapters() const; /** * Returns a list of all devices. * * @return list of devices */ QList devices() const; /** * Attempts to start org.bluez service by D-Bus activation. * * Possible return values are 1 if the service was started, * 2 if the service is already running or error if the service * could not be started. * * @return quint32 pending call */ static PendingCall *startService(); /** * Returns an adapter for specified address. * * @param address address of adapter (eg. "1C:E5:C3:BC:94:7E") * @return null if there is no adapter with specified address */ AdapterPtr adapterForAddress(const QString &address) const; /** * Returns an adapter for specified UBI. * * @param ubi UBI of adapter (eg. "/org/bluez/hci0") * @return null if there is no adapter with specified UBI */ AdapterPtr adapterForUbi(const QString &ubi) const; /** * Returns a device for specified address. * * @note There may be more devices with the same address (same device * in multiple adapters). In this case, the first found device will * be returned while preferring powered adapters in search. * * @param address address of device (eg. "40:79:6A:0C:39:75") * @return null if there is no device with specified address */ DevicePtr deviceForAddress(const QString &address) const; /** * Returns a device for specified UBI. * * @param ubi UBI of device (eg. "/org/bluez/hci0/dev_40_79_6A_0C_39_75") * @return null if there is no device with specified UBI */ DevicePtr deviceForUbi(const QString &ubi) const; /** * Registers agent. * * This agent will be used for for all actions triggered by the application. * Eg. show a PIN code in pairing process. * * Possible errors: PendingCall::InvalidArguments, PendingCall::AlreadyExists * * @param agent agent to be registered * @return void pending call */ PendingCall *registerAgent(Agent *agent); /** * Unregisters agent. * * Possible errors: PendingCall::DoesNotExist * * @param agent agent to be unregistered * @return void pending call */ PendingCall *unregisterAgent(Agent *agent); /** * Requests default agent. * * This requests to make the application agent the default agent. * * Possible errors: PendingCall::DoesNotExist * * @param agent registered agent * @return void pending call */ PendingCall *requestDefaultAgent(Agent *agent); /** * Registers profile. * * Possible errors: PendingCall::InvalidArguments, PendingCall::AlreadyExists * * @param profile profile to be registered * @return void pending call */ PendingCall *registerProfile(Profile *profile); /** * Unregisters profile. * * Possible errors: PendingCall::DoesNotExist * * @param profile profile to be unregistered * @return void pending call */ PendingCall *unregisterProfile(Profile *profile); #if BLUEZQT_ENABLE_DEPRECATED_SINCE(5, 57) /** * Returns the media interface. * * @return media * @deprecated since 5.57, use Adapter::media() instead. */ BLUEZQT_DEPRECATED_VERSION(5, 57, "Use Adapter::media()") MediaPtr media() const; #endif Q_SIGNALS: /** * Indicates that operational state have changed. */ void operationalChanged(bool operational); /** * Indicates that Bluetooth operational state have changed. */ void bluetoothOperationalChanged(bool operational); /** * Indicates that Bluetooth blocked state have changed. */ void bluetoothBlockedChanged(bool blocked); /** * Indicates that adapter was added. */ void adapterAdded(AdapterPtr adapter); /** * Indicates that adapter was removed. */ void adapterRemoved(AdapterPtr adapter); /** * Indicates that at least one of the adapter's properties have changed. */ void adapterChanged(AdapterPtr adapter); /** * Indicates that a new device was added (eg. found by discovery). */ void deviceAdded(DevicePtr device); /** * Indicates that a device was removed. */ void deviceRemoved(DevicePtr device); /** * Indicates that at least one of the device's properties have changed. */ void deviceChanged(DevicePtr device); /** * Indicates that usable adapter have changed. */ void usableAdapterChanged(AdapterPtr adapter); /** * Indicates that all adapters were removed. */ void allAdaptersRemoved(); private: class ManagerPrivate *const d; friend class ManagerPrivate; friend class InitManagerJobPrivate; }; } // namespace BluezQt #endif // BLUEZQT_MANAGER_H diff --git a/src/manager_p.cpp b/src/manager_p.cpp index 39a2e6a..ea38688 100644 --- a/src/manager_p.cpp +++ b/src/manager_p.cpp @@ -1,470 +1,456 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "manager_p.h" #include "manager.h" #include "device.h" #include "device_p.h" #include "adapter.h" #include "adapter_p.h" #include "debug.h" #include "utils.h" #include namespace BluezQt { ManagerPrivate::ManagerPrivate(Manager *parent) : QObject(parent) , q(parent) , m_dbusObjectManager(nullptr) , m_bluezAgentManager(nullptr) , m_bluezProfileManager(nullptr) , m_initialized(false) , m_bluezRunning(false) , m_loaded(false) , m_adaptersLoaded(false) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); m_rfkill = new Rfkill(this); m_bluetoothBlocked = rfkillBlocked(); connect(m_rfkill, &Rfkill::stateChanged, this, &ManagerPrivate::rfkillStateChanged); connect(q, &Manager::adapterRemoved, this, &ManagerPrivate::adapterRemoved); } void ManagerPrivate::init() { // Keep an eye on org.bluez service QDBusServiceWatcher *serviceWatcher = new QDBusServiceWatcher(Strings::orgBluez(), DBusConnection::orgBluez(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this); connect(serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &ManagerPrivate::serviceRegistered); connect(serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &ManagerPrivate::serviceUnregistered); // Update the current state of org.bluez service if (!DBusConnection::orgBluez().isConnected()) { Q_EMIT initError(QStringLiteral("DBus system bus is not connected!")); return; } QDBusMessage call = QDBusMessage::createMethodCall(Strings::orgFreedesktopDBus(), QStringLiteral("/"), Strings::orgFreedesktopDBus(), QStringLiteral("NameHasOwner")); call << Strings::orgBluez(); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(DBusConnection::orgBluez().asyncCall(call)); connect(watcher, &QDBusPendingCallWatcher::finished, this, &ManagerPrivate::nameHasOwnerFinished); DBusConnection::orgBluez().connect(Strings::orgBluez(), QString(), Strings::orgFreedesktopDBusProperties(), QStringLiteral("PropertiesChanged"), this, SLOT(propertiesChanged(QString,QVariantMap,QStringList))); } void ManagerPrivate::nameHasOwnerFinished(QDBusPendingCallWatcher *watcher) { const QDBusPendingReply &reply = *watcher; watcher->deleteLater(); if (reply.isError()) { Q_EMIT initError(reply.error().message()); return; } m_bluezRunning = reply.value(); if (m_bluezRunning) { load(); } else { m_initialized = true; Q_EMIT initFinished(); } } void ManagerPrivate::load() { if (!m_bluezRunning || m_loaded) { return; } // Force QDBus to cache owner of org.bluez - this will be the only blocking call on system connection DBusConnection::orgBluez().connect(Strings::orgBluez(), QStringLiteral("/"), Strings::orgFreedesktopDBus(), QStringLiteral("Dummy"), this, SLOT(dummy())); m_dbusObjectManager = new DBusObjectManager(Strings::orgBluez(), QStringLiteral("/"), DBusConnection::orgBluez(), this); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(m_dbusObjectManager->GetManagedObjects(), this); connect(watcher, &QDBusPendingCallWatcher::finished, this, &ManagerPrivate::getManagedObjectsFinished); } void ManagerPrivate::getManagedObjectsFinished(QDBusPendingCallWatcher *watcher) { const QDBusPendingReply &reply = *watcher; watcher->deleteLater(); if (reply.isError()) { Q_EMIT initError(reply.error().message()); return; } DBusManagerStruct::const_iterator it; const DBusManagerStruct &managedObjects = reply.value(); for (it = managedObjects.constBegin(); it != managedObjects.constEnd(); ++it) { const QString &path = it.key().path(); const QVariantMapMap &interfaces = it.value(); interfacesAdded(it.key(), interfaces); if (interfaces.contains(Strings::orgBluezAgentManager1())) { m_bluezAgentManager = new BluezAgentManager(Strings::orgBluez(), path, DBusConnection::orgBluez(), this); } if (interfaces.contains(Strings::orgBluezProfileManager1())) { m_bluezProfileManager = new BluezProfileManager(Strings::orgBluez(), path, DBusConnection::orgBluez(), this); } } if (!m_bluezAgentManager) { Q_EMIT initError(QStringLiteral("Cannot find org.bluez.AgentManager1 object!")); return; } if (!m_bluezProfileManager) { Q_EMIT initError(QStringLiteral("Cannot find org.bluez.ProfileManager1 object!")); return; } connect(m_dbusObjectManager, &DBusObjectManager::InterfacesAdded, this, &ManagerPrivate::interfacesAdded); connect(m_dbusObjectManager, &DBusObjectManager::InterfacesRemoved, this, &ManagerPrivate::interfacesRemoved); m_loaded = true; m_initialized = true; Q_EMIT q->operationalChanged(true); if (q->isBluetoothOperational()) { Q_EMIT q->bluetoothOperationalChanged(true); } Q_EMIT initFinished(); } void ManagerPrivate::clear() { m_loaded = false; // Delete all devices first while (!m_devices.isEmpty()) { DevicePtr device = m_devices.begin().value(); m_devices.remove(m_devices.begin().key()); device->adapter()->d->removeDevice(device); } // Delete all adapters while (!m_adapters.isEmpty()) { AdapterPtr adapter = m_adapters.begin().value(); m_adapters.remove(m_adapters.begin().key()); Q_EMIT adapter->adapterRemoved(adapter); if (m_adapters.isEmpty()) { Q_EMIT q->allAdaptersRemoved(); } } // Delete all other objects m_usableAdapter.clear(); if (m_dbusObjectManager) { m_dbusObjectManager->deleteLater(); m_dbusObjectManager = nullptr; } if (m_bluezAgentManager) { m_bluezAgentManager->deleteLater(); m_bluezAgentManager = nullptr; } } AdapterPtr ManagerPrivate::findUsableAdapter() const { for (AdapterPtr adapter : qAsConst(m_adapters)) { if (adapter->isPowered()) { return adapter; } } return AdapterPtr(); } void ManagerPrivate::serviceRegistered() { qCDebug(BLUEZQT) << "BlueZ service registered"; m_bluezRunning = true; load(); } void ManagerPrivate::serviceUnregistered() { qCDebug(BLUEZQT) << "BlueZ service unregistered"; bool wasBtOperational = q->isBluetoothOperational(); m_bluezRunning = false; if (wasBtOperational) { Q_EMIT q->bluetoothOperationalChanged(false); } clear(); Q_EMIT q->operationalChanged(false); } void ManagerPrivate::interfacesAdded(const QDBusObjectPath &objectPath, const QVariantMapMap &interfaces) { const QString &path = objectPath.path(); QVariantMapMap::const_iterator it; for (it = interfaces.constBegin(); it != interfaces.constEnd(); ++it) { if (it.key() == Strings::orgBluezAdapter1()) { addAdapter(path, it.value()); } else if (it.key() == Strings::orgBluezDevice1()) { addDevice(path, it.value()); } } for (auto it = m_adapters.cbegin(); it != m_adapters.cend(); ++it) { if (path.startsWith(it.value()->ubi())) { it.value()->d->interfacesAdded(path, interfaces); break; } } for (auto it = m_devices.cbegin(); it != m_devices.cend(); ++it) { if (path.startsWith(it.value()->ubi())) { it.value()->d->interfacesAdded(path, interfaces); break; } } } void ManagerPrivate::interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces) { const QString &path = objectPath.path(); for (const QString &interface : interfaces) { if (interface == Strings::orgBluezAdapter1()) { removeAdapter(path); } else if (interface == Strings::orgBluezDevice1()) { removeDevice(path); } } for (auto it = m_adapters.cbegin(); it != m_adapters.cend(); ++it) { if (path.startsWith(it.value()->ubi())) { it.value()->d->interfacesRemoved(path, interfaces); break; } } for (auto it = m_devices.cbegin(); it != m_devices.cend(); ++it) { if (path.startsWith(it.value()->ubi())) { it.value()->d->interfacesRemoved(path, interfaces); break; } } } void ManagerPrivate::adapterRemoved(const AdapterPtr &adapter) { disconnect(adapter.data(), &Adapter::poweredChanged, this, &ManagerPrivate::adapterPoweredChanged); // Current usable adapter was removed if (adapter == m_usableAdapter) { setUsableAdapter(findUsableAdapter()); } } void ManagerPrivate::adapterPoweredChanged(bool powered) { Q_ASSERT(qobject_cast(sender())); AdapterPtr adapter = static_cast(sender())->toSharedPtr(); // Current usable adapter was powered off if (m_usableAdapter == adapter && !powered) { setUsableAdapter(findUsableAdapter()); } // Adapter was powered on, set it as usable if (!m_usableAdapter && powered) { setUsableAdapter(adapter); } } void ManagerPrivate::rfkillStateChanged(Rfkill::State state) { Q_UNUSED(state) bool blocked = rfkillBlocked(); bool wasBtOperational = q->isBluetoothOperational(); if (m_bluetoothBlocked != blocked) { m_bluetoothBlocked = blocked; Q_EMIT q->bluetoothBlockedChanged(m_bluetoothBlocked); if (wasBtOperational != q->isBluetoothOperational()) { Q_EMIT q->bluetoothOperationalChanged(q->isBluetoothOperational()); } } } void ManagerPrivate::addAdapter(const QString &adapterPath, const QVariantMap &properties) { AdapterPtr adapter = AdapterPtr(new Adapter(adapterPath, properties)); adapter->d->q = adapter.toWeakRef(); m_adapters.insert(adapterPath, adapter); Q_EMIT q->adapterAdded(adapter); // Powered adapter was added, set it as usable if (!m_usableAdapter && adapter->isPowered()) { setUsableAdapter(adapter); } connect(adapter.data(), &Adapter::deviceAdded, q, &Manager::deviceAdded); connect(adapter.data(), &Adapter::adapterRemoved, q, &Manager::adapterRemoved); connect(adapter.data(), &Adapter::adapterChanged, q, &Manager::adapterChanged); connect(adapter.data(), &Adapter::poweredChanged, this, &ManagerPrivate::adapterPoweredChanged); } void ManagerPrivate::addDevice(const QString &devicePath, const QVariantMap &properties) { AdapterPtr adapter = m_adapters.value(properties.value(QStringLiteral("Adapter")).value().path()); if (!adapter) { return; } DevicePtr device = DevicePtr(new Device(devicePath, properties, adapter)); device->d->q = device.toWeakRef(); m_devices.insert(devicePath, device); adapter->d->addDevice(device); connect(device.data(), &Device::deviceRemoved, q, &Manager::deviceRemoved); connect(device.data(), &Device::deviceChanged, q, &Manager::deviceChanged); } void ManagerPrivate::removeAdapter(const QString &adapterPath) { AdapterPtr adapter = m_adapters.value(adapterPath); if (!adapter) { return; } // Make sure we always remove all devices before removing the adapter const auto devices = adapter->devices(); for (const DevicePtr &device : devices) { removeDevice(device->ubi()); } m_adapters.remove(adapterPath); Q_EMIT adapter->adapterRemoved(adapter); if (m_adapters.isEmpty()) { Q_EMIT q->allAdaptersRemoved(); } disconnect(adapter.data(), &Adapter::adapterChanged, q, &Manager::adapterChanged); disconnect(adapter.data(), &Adapter::poweredChanged, this, &ManagerPrivate::adapterPoweredChanged); } void ManagerPrivate::removeDevice(const QString &devicePath) { DevicePtr device = m_devices.take(devicePath); if (!device) { return; } device->adapter()->d->removeDevice(device); disconnect(device.data(), &Device::deviceChanged, q, &Manager::deviceChanged); } bool ManagerPrivate::rfkillBlocked() const { return m_rfkill->state() == Rfkill::SoftBlocked || m_rfkill->state() == Rfkill::HardBlocked; } void ManagerPrivate::setUsableAdapter(const AdapterPtr &adapter) { if (m_usableAdapter == adapter) { return; } qCDebug(BLUEZQT) << "Setting usable adapter" << adapter; bool wasBtOperational = q->isBluetoothOperational(); m_usableAdapter = adapter; Q_EMIT q->usableAdapterChanged(m_usableAdapter); if (wasBtOperational != q->isBluetoothOperational()) { Q_EMIT q->bluetoothOperationalChanged(q->isBluetoothOperational()); } } void ManagerPrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated) { // Cut anything after device path to forward it to Device to handle const QString path = message().path().section(QLatin1Char('/'), 0, 4); QTimer::singleShot(0, this, [=]() { AdapterPtr adapter = m_adapters.value(path); if (adapter) { adapter->d->propertiesChanged(interface, changed, invalidated); return; } DevicePtr device = m_devices.value(path); if (device) { device->d->propertiesChanged(interface, changed, invalidated); return; } qCDebug(BLUEZQT) << "Unhandled property change" << interface << changed << invalidated; }); } void ManagerPrivate::dummy() { } } // namespace BluezQt diff --git a/src/manager_p.h b/src/manager_p.h index cc3276d..84f9bb7 100644 --- a/src/manager_p.h +++ b/src/manager_p.h @@ -1,107 +1,93 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MANAGER_P_H #define BLUEZQT_MANAGER_P_H #include #include #include #include "types.h" #include "rfkill.h" #include "dbusobjectmanager.h" #include "bluezagentmanager1.h" #include "bluezprofilemanager1.h" namespace BluezQt { typedef org::freedesktop::DBus::ObjectManager DBusObjectManager; typedef org::bluez::AgentManager1 BluezAgentManager; typedef org::bluez::ProfileManager1 BluezProfileManager; class Manager; class Adapter; class Device; class AdapterPrivate; class ManagerPrivate : public QObject, protected QDBusContext { Q_OBJECT public: explicit ManagerPrivate(Manager *parent); void init(); void nameHasOwnerFinished(QDBusPendingCallWatcher *watcher); void load(); void getManagedObjectsFinished(QDBusPendingCallWatcher *watcher); void clear(); AdapterPtr findUsableAdapter() const; void serviceRegistered(); void serviceUnregistered(); void interfacesAdded(const QDBusObjectPath &objectPath, const QVariantMapMap &interfaces); void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces); void adapterRemoved(const AdapterPtr &adapter); void adapterPoweredChanged(bool powered); void rfkillStateChanged(Rfkill::State state); void addAdapter(const QString &adapterPath, const QVariantMap &properties); void addDevice(const QString &devicePath, const QVariantMap &properties); void removeAdapter(const QString &adapterPath); void removeDevice(const QString &devicePath); bool rfkillBlocked() const; void setUsableAdapter(const AdapterPtr &adapter); Manager *q; Rfkill *m_rfkill; DBusObjectManager *m_dbusObjectManager; BluezAgentManager *m_bluezAgentManager; BluezProfileManager *m_bluezProfileManager; QHash m_adapters; QHash m_devices; AdapterPtr m_usableAdapter; bool m_initialized; bool m_bluezRunning; bool m_loaded; bool m_adaptersLoaded; bool m_bluetoothBlocked; Q_SIGNALS: void initError(const QString &errorText); void initFinished(); private Q_SLOTS: void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated); void dummy(); }; } // namespace BluezQt #endif // BLUEZQT_MANAGER_P_H diff --git a/src/media.cpp b/src/media.cpp index 9a95bfd..281f5af 100644 --- a/src/media.cpp +++ b/src/media.cpp @@ -1,79 +1,65 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "media.h" #include "media_p.h" #include "mediaendpoint.h" #include "mediaendpointadaptor.h" #include "pendingcall.h" #include "utils.h" #include "debug.h" namespace BluezQt { Media::Media(const QString &path, QObject *parent) : QObject(parent) , d(new MediaPrivate()) { d->m_path = path; d->m_bluezMedia = new BluezMedia(Strings::orgBluez(), path, DBusConnection::orgBluez(), this); } Media::~Media() { delete d; } PendingCall *Media::registerEndpoint(MediaEndpoint *endpoint) { Q_ASSERT(endpoint); if (!d->m_bluezMedia) { return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!")); } new MediaEndpointAdaptor(endpoint); if (!DBusConnection::orgBluez().registerObject(endpoint->objectPath().path(), endpoint)) { qCDebug(BLUEZQT) << "Cannot register object" << endpoint->objectPath().path(); } return new PendingCall(d->m_bluezMedia->RegisterEndpoint(endpoint->objectPath(), endpoint->properties()), PendingCall::ReturnVoid, this); } PendingCall *Media::unregisterEndpoint(MediaEndpoint *endpoint) { Q_ASSERT(endpoint); if (!d->m_bluezMedia) { return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!")); } DBusConnection::orgBluez().unregisterObject(endpoint->objectPath().path()); return new PendingCall(d->m_bluezMedia->UnregisterEndpoint(endpoint->objectPath()), PendingCall::ReturnVoid, this); } } // namespace BluezQt diff --git a/src/media.h b/src/media.h index efdbd4d..ec90c77 100644 --- a/src/media.h +++ b/src/media.h @@ -1,95 +1,81 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MEDIA_H #define BLUEZQT_MEDIA_H #include #include "bluezqt_export.h" namespace BluezQt { class MediaEndpoint; class PendingCall; /** * @class BluezQt::Media Media.h * * Bluetooth Media. * * This allows media endpoints to be established in accordance with the * capabilities of a specific media service profile. * * For example, an A2DP media endpoint could be created allowing data from a * remote device to be streamed to/from the sender. * * Each media endpoint is associated with a service object instance that * implements the required behaviours of the endpoint. The service object * must be created at a given path before it is registered. * * @see MediaEndpoint */ class BLUEZQT_EXPORT Media : public QObject { Q_OBJECT public: /** * Destroys a Media object. */ ~Media(); /** * Registers endpoint. * * Register a local end point to sender, the sender can register as many end points as it likes. * * Note: If the sender disconnects the end points are automatically unregistered. * * Possible errors: PendingCall::InvalidArguments, PendingCall::NotSupported * * @param endpoint endpoint to be registered * @return void pending call */ PendingCall *registerEndpoint(MediaEndpoint *endpoint); /** * Unregisters endpoint. * * @param endpoint endpoint to be unregistered * @return void pending call */ PendingCall *unregisterEndpoint(MediaEndpoint *endpoint); private: explicit Media(const QString &path, QObject *parent = nullptr); class MediaPrivate *const d; friend class AdapterPrivate; }; } // namespace BluezQt #endif // BLUEZQT_MEDIA_H diff --git a/src/media_p.h b/src/media_p.h index d2d8f72..e405c32 100644 --- a/src/media_p.h +++ b/src/media_p.h @@ -1,42 +1,28 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MEDIA_P_H #define BLUEZQT_MEDIA_P_H #include "bluezmedia1.h" namespace BluezQt { typedef org::bluez::Media1 BluezMedia; class MediaPrivate { public: QString m_path; BluezMedia *m_bluezMedia = nullptr; }; } // namespace BluezQt #endif // BLUEZQT_MEDIA_P_H diff --git a/src/mediaendpoint.cpp b/src/mediaendpoint.cpp index c1a4d64..875a7fa 100644 --- a/src/mediaendpoint.cpp +++ b/src/mediaendpoint.cpp @@ -1,150 +1,136 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediaendpoint.h" #include "mediaendpoint_p.h" #include "a2dp-codecs.h" namespace BluezQt { MediaEndpoint::MediaEndpoint(const Configuration &configuration, QObject *parent) : QObject(parent), d(new MediaEndpointPrivate(configuration)) { } MediaEndpoint::~MediaEndpoint() { delete d; } QDBusObjectPath MediaEndpoint::objectPath() const { return d->m_objectPath; } const QVariantMap &MediaEndpoint::properties() const { return d->m_properties; } void MediaEndpoint::setConfiguration(const QString &transportObjectPath, const QVariantMap &properties) { emit configurationSet(transportObjectPath, properties); } void MediaEndpoint::selectConfiguration(const QByteArray &capabilities, const Request &request) { switch (d->m_configuration.codec) { case MediaEndpoint::Codec::Sbc: { if (capabilities.size() != sizeof(a2dp_sbc_t)) { emit configurationSelected(capabilities, QByteArray()); request.reject(); return; } a2dp_sbc_t caps = *reinterpret_cast(capabilities.constData()); if (caps.frequency & SBC_SAMPLING_FREQ_44100) { caps.frequency = SBC_SAMPLING_FREQ_44100; } else if (caps.frequency & SBC_SAMPLING_FREQ_48000) { caps.frequency = SBC_SAMPLING_FREQ_48000; } else { break; } if (caps.channel_mode & SBC_CHANNEL_MODE_STEREO) { caps.channel_mode = SBC_CHANNEL_MODE_STEREO; } else if (caps.channel_mode & SBC_CHANNEL_MODE_JOINT_STEREO) { caps.channel_mode = SBC_CHANNEL_MODE_JOINT_STEREO; } else { break; } if (caps.block_length & SBC_BLOCK_LENGTH_16) { caps.block_length = SBC_BLOCK_LENGTH_16; } else if (caps.block_length & SBC_BLOCK_LENGTH_12) { caps.block_length = SBC_BLOCK_LENGTH_12; } else if (caps.block_length & SBC_BLOCK_LENGTH_8) { caps.block_length = SBC_BLOCK_LENGTH_8; } else if (caps.block_length & SBC_BLOCK_LENGTH_4) { caps.block_length = SBC_BLOCK_LENGTH_4; } else { break; } if (caps.subbands & SBC_SUBBANDS_8) { caps.subbands = SBC_SUBBANDS_8; } else if (caps.subbands & SBC_SUBBANDS_4) { caps.subbands = SBC_SUBBANDS_4; } else { break; } if (caps.allocation_method & SBC_ALLOCATION_LOUDNESS) { caps.allocation_method = SBC_ALLOCATION_LOUDNESS; } else if (caps.allocation_method & SBC_ALLOCATION_SNR) { caps.allocation_method = SBC_ALLOCATION_SNR; } else { break; } caps.min_bitpool = 2; caps.max_bitpool = 53; const QByteArray configuration(reinterpret_cast(&caps), sizeof(caps)); emit configurationSelected(capabilities, configuration); request.accept(configuration); return; break; } case MediaEndpoint::Codec::Aac: if (capabilities.size() != sizeof(a2dp_aac_t)) { emit configurationSelected(capabilities, QByteArray()); request.reject(); return; } // TODO: implement AAC. However selectConfiguration seems not to be used by iOS nor Android. emit configurationSelected(capabilities, QByteArray()); request.reject(); return; break; } emit configurationSelected(capabilities, QByteArray()); request.reject(); } void MediaEndpoint::clearConfiguration(const QString &transportObjectPath) { emit configurationCleared(transportObjectPath); } void MediaEndpoint::release() { } } // namespace BluezQt diff --git a/src/mediaendpoint.h b/src/mediaendpoint.h index e756454..2cc0e35 100644 --- a/src/mediaendpoint.h +++ b/src/mediaendpoint.h @@ -1,155 +1,141 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MEDIAENDPOINT_H #define BLUEZQT_MEDIAENDPOINT_H #include #include "bluezqt_export.h" #include "request.h" class QDBusObjectPath; namespace BluezQt { /** * @class BluezQt::MediaEndpoint MediaEndpoint.h * * Bluetooth MediaEndpoint. * * This class represents a Bluetooth MediaEndpoint. */ class BLUEZQT_EXPORT MediaEndpoint : public QObject { Q_OBJECT public: /** Role which this MediaEndpoint acts as. */ enum class Role { AudioSource, AudioSink }; // KF6 TODO: use types from mediatypes.h /** Codec which this MediaEndpoint supports. */ enum class Codec { Sbc, Aac }; /** Configuration for MediaEndpoint construction. */ struct Configuration { Role role; Codec codec; }; /** * Creates a new MediaEndpoint object. * * @param parent */ explicit MediaEndpoint(const Configuration &configuration, QObject *parent = nullptr); /** * Destroys a MediaEndpoint object. */ ~MediaEndpoint(); /** * D-Bus object path of the MediaEndpoint. * * The path where the MediaEndpoint will be registered. * * @note You must provide valid object path! * * @return object path of MediaEndpoint */ virtual QDBusObjectPath objectPath() const; /** * Properties of the endpoint. * * @return Properties of the endpoint */ virtual const QVariantMap &properties() const; /** * Set configuration for the transport. * * @param transport transport to be configured * @param properties properties to be set for transport */ virtual void setConfiguration(const QString &transportObjectPath, const QVariantMap &properties); /** * Select preferable configuration from the supported capabilities. * * @note There is no need to cache the selected configuration since on success * the configuration is send back as parameter of SetConfiguration. * * @param capabilities supported capabilities * @param request request to be used for sending reply */ virtual void selectConfiguration(const QByteArray &capabilities, const Request &request); /** * Clear transport configuration. */ virtual void clearConfiguration(const QString &transportObjectPath); /** * Indicates that the MediaEndpoint was unregistered. * * This method gets called when the Bluetooth daemon * unregisters the MediaEndpoint. * * An MediaEndpoint can use it to do cleanup tasks. There is no need * to unregister the MediaEndpoint, because when this method gets called * it has already been unregistered. */ virtual void release(); Q_SIGNALS: /** * Indicates that configuration was selected. */ void configurationSelected(const QByteArray &capabilities, const QByteArray &configuration); /** * Indicates that configuration was set for transport. */ void configurationSet(const QString &transportObjectPath, const QVariantMap &properties); /** * Indicates that configuration was cleared for transport. */ void configurationCleared(const QString &transportObjectPath); private: class MediaEndpointPrivate *const d; }; } // namespace BluezQt #endif // BLUEZQT_MEDIAENDPOINT_H diff --git a/src/mediaendpoint_p.cpp b/src/mediaendpoint_p.cpp index eca5508..582bb4c 100644 --- a/src/mediaendpoint_p.cpp +++ b/src/mediaendpoint_p.cpp @@ -1,72 +1,58 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediaendpoint_p.h" #include "a2dp-codecs.h" #include "services.h" namespace BluezQt { MediaEndpointPrivate::MediaEndpointPrivate(const MediaEndpoint::Configuration &configuration) : m_configuration(configuration) { init(configuration); } void MediaEndpointPrivate::init(const MediaEndpoint::Configuration &configuration) { const QString uuid = QStringLiteral("UUID"); const QString codec = QStringLiteral("Codec"); const QString capabilities = QStringLiteral("Capabilities"); QString objectPath = QStringLiteral("/MediaEndpoint"); switch (configuration.role) { case MediaEndpoint::Role::AudioSource: m_properties[uuid] = Services::AudioSource; objectPath += QStringLiteral("/Source"); break; case MediaEndpoint::Role::AudioSink: m_properties[uuid] = Services::AudioSink; objectPath += QStringLiteral("/Sink"); break; } switch (configuration.codec) { case MediaEndpoint::Codec::Sbc: m_properties[codec] = QVariant::fromValue(uchar(A2DP_CODEC_SBC)); m_properties[capabilities] = QByteArray(reinterpret_cast(&sbcCapabilities), sizeof(sbcCapabilities)); objectPath += QStringLiteral("/Sbc"); break; case MediaEndpoint::Codec::Aac: m_properties[codec] = QVariant::fromValue(uchar(A2DP_CODEC_MPEG24)); m_properties[capabilities] = QByteArray(reinterpret_cast(&aacCapabilities), sizeof(aacCapabilities)); objectPath += QStringLiteral("/Aac"); break; } m_objectPath.setPath(objectPath); } } // namespace BluezQt diff --git a/src/mediaendpoint_p.h b/src/mediaendpoint_p.h index 676c8c4..0b8a994 100644 --- a/src/mediaendpoint_p.h +++ b/src/mediaendpoint_p.h @@ -1,48 +1,34 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MEDIAENDPOINT_P_H #define BLUEZQT_MEDIAENDPOINT_P_H #include #include #include "mediaendpoint.h" namespace BluezQt { class MediaEndpointPrivate { public: explicit MediaEndpointPrivate(const MediaEndpoint::Configuration &configuration); void init(const MediaEndpoint::Configuration &configuration); QVariantMap m_properties; MediaEndpoint::Configuration m_configuration; QDBusObjectPath m_objectPath; }; } // namespace BluezQt #endif // BLUEZQT_MEDIAENDPOINT_P_H diff --git a/src/mediaendpointadaptor.cpp b/src/mediaendpointadaptor.cpp index 20ac25e..901fd36 100644 --- a/src/mediaendpointadaptor.cpp +++ b/src/mediaendpointadaptor.cpp @@ -1,63 +1,49 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediaendpointadaptor.h" #include "mediaendpoint.h" #include "request.h" #include #include namespace BluezQt { MediaEndpointAdaptor::MediaEndpointAdaptor(MediaEndpoint *parent) : QDBusAbstractAdaptor(parent) , m_endpoint(parent) { } void MediaEndpointAdaptor::SetConfiguration(const QDBusObjectPath &transport, const QVariantMap &properties) { m_endpoint->setConfiguration(transport.path(), properties); } QByteArray MediaEndpointAdaptor::SelectConfiguration(const QByteArray &capabilities, const QDBusMessage &msg) { msg.setDelayedReply(true); Request req(OrgBluezMediaEndpoint, msg); m_endpoint->selectConfiguration(capabilities, req); return QByteArray(); } void MediaEndpointAdaptor::ClearConfiguration(const QDBusObjectPath &transport) { m_endpoint->clearConfiguration(transport.path()); } void MediaEndpointAdaptor::Release() { m_endpoint->release(); } } // namespace BluezQt diff --git a/src/mediaendpointadaptor.h b/src/mediaendpointadaptor.h index 090f020..38d67e6 100644 --- a/src/mediaendpointadaptor.h +++ b/src/mediaendpointadaptor.h @@ -1,56 +1,42 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MEDIAENDPOINTADAPTOR_H #define BLUEZQT_MEDIAENDPOINTADAPTOR_H #include class QDBusMessage; class QDBusObjectPath; namespace BluezQt { class MediaEndpoint; class MediaEndpointAdaptor : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.MediaEndpoint1") public: explicit MediaEndpointAdaptor(MediaEndpoint *parent); public Q_SLOTS: void SetConfiguration(const QDBusObjectPath &transport, const QVariantMap &properties); QByteArray SelectConfiguration(const QByteArray &capabilities, const QDBusMessage &msg); void ClearConfiguration(const QDBusObjectPath &transport); Q_NOREPLY void Release(); private: MediaEndpoint *m_endpoint; }; } // namespace BluezQt #endif // BLUEZQT_MEDIAENDPOINTADAPTOR_H diff --git a/src/mediaplayer.cpp b/src/mediaplayer.cpp index 8d2c90a..ef742ce 100644 --- a/src/mediaplayer.cpp +++ b/src/mediaplayer.cpp @@ -1,170 +1,156 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediaplayer.h" #include "mediaplayer_p.h" #include "pendingcall.h" namespace BluezQt { static QString equalizerToString(MediaPlayer::Equalizer equalizer) { switch (equalizer) { case MediaPlayer::EqualizerOn: return QStringLiteral("on"); default: return QStringLiteral("off"); } } static QString repeatToString(MediaPlayer::Repeat repeat) { switch (repeat) { case MediaPlayer::RepeatSingleTrack: return QStringLiteral("singletrack"); case MediaPlayer::RepeatAllTracks: return QStringLiteral("alltracks"); case MediaPlayer::RepeatGroup: return QStringLiteral("group"); default: return QStringLiteral("off"); } } static QString shuffleToString(MediaPlayer::Shuffle shuffle) { switch (shuffle) { case MediaPlayer::ShuffleAllTracks: return QStringLiteral("alltracks"); case MediaPlayer::ShuffleGroup: return QStringLiteral("group"); default: return QStringLiteral("off"); } } MediaPlayer::MediaPlayer(const QString &path, const QVariantMap &properties) : QObject() , d(new MediaPlayerPrivate(path, properties)) { } MediaPlayer::~MediaPlayer() { delete d; } MediaPlayerPtr MediaPlayer::toSharedPtr() const { return d->q.toStrongRef(); } QString MediaPlayer::name() const { return d->m_name; } MediaPlayer::Equalizer MediaPlayer::equalizer() const { return d->m_equalizer; } PendingCall *MediaPlayer::setEqualizer(MediaPlayer::Equalizer equalizer) { return new PendingCall(d->setDBusProperty(QStringLiteral("Equalizer"), equalizerToString(equalizer)), PendingCall::ReturnVoid, this); } MediaPlayer::Repeat MediaPlayer::repeat() const { return d->m_repeat; } PendingCall *MediaPlayer::setRepeat(MediaPlayer::Repeat repeat) { return new PendingCall(d->setDBusProperty(QStringLiteral("Repeat"), repeatToString(repeat)), PendingCall::ReturnVoid, this); } MediaPlayer::Shuffle MediaPlayer::shuffle() const { return d->m_shuffle; } PendingCall *MediaPlayer::setShuffle(MediaPlayer::Shuffle shuffle) { return new PendingCall(d->setDBusProperty(QStringLiteral("Shuffle"), shuffleToString(shuffle)), PendingCall::ReturnVoid, this); } MediaPlayer::Status MediaPlayer::status() const { return d->m_status; } MediaPlayerTrack MediaPlayer::track() const { return d->m_track; } quint32 MediaPlayer::position() const { return d->m_position; } PendingCall *MediaPlayer::play() { return new PendingCall(d->m_bluezMediaPlayer->Play(), PendingCall::ReturnVoid, this); } PendingCall *MediaPlayer::pause() { return new PendingCall(d->m_bluezMediaPlayer->Pause(), PendingCall::ReturnVoid, this); } PendingCall *MediaPlayer::stop() { return new PendingCall(d->m_bluezMediaPlayer->Stop(), PendingCall::ReturnVoid, this); } PendingCall *MediaPlayer::next() { return new PendingCall(d->m_bluezMediaPlayer->Next(), PendingCall::ReturnVoid, this); } PendingCall *MediaPlayer::previous() { return new PendingCall(d->m_bluezMediaPlayer->Previous(), PendingCall::ReturnVoid, this); } PendingCall *MediaPlayer::fastForward() { return new PendingCall(d->m_bluezMediaPlayer->FastForward(), PendingCall::ReturnVoid, this); } PendingCall *MediaPlayer::rewind() { return new PendingCall(d->m_bluezMediaPlayer->Rewind(), PendingCall::ReturnVoid, this); } } // namespace BluezQt diff --git a/src/mediaplayer.h b/src/mediaplayer.h index f04c8f8..b5672c7 100644 --- a/src/mediaplayer.h +++ b/src/mediaplayer.h @@ -1,302 +1,288 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MEDIAPLAYER_H #define BLUEZQT_MEDIAPLAYER_H #include #include "types.h" #include "mediaplayertrack.h" #include "bluezqt_export.h" namespace BluezQt { class PendingCall; /** * @class BluezQt::MediaPlayer mediaplayer.h * * Media player. * * This class represents a media player interface. */ class BLUEZQT_EXPORT MediaPlayer : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(Equalizer equalizer READ equalizer WRITE setEqualizer NOTIFY equalizerChanged) Q_PROPERTY(Repeat repeat READ repeat WRITE setRepeat NOTIFY repeatChanged) Q_PROPERTY(Shuffle shuffle READ shuffle WRITE setShuffle NOTIFY shuffleChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(MediaPlayerTrack track READ track NOTIFY trackChanged) Q_PROPERTY(quint32 position READ position NOTIFY positionChanged) public: /** Equalizer state. */ enum Equalizer { /** Equalizer on. */ EqualizerOn, /** Equalizer off. */ EqualizerOff }; Q_ENUM(Equalizer) /** Repeat state. */ enum Repeat { /** Repeat off. */ RepeatOff, /** Repeat single track. */ RepeatSingleTrack, /** Repeat all tracks. */ RepeatAllTracks, /** Repeat group. */ RepeatGroup }; Q_ENUM(Repeat) /** Shuffle state. */ enum Shuffle { /** Shuffle off. */ ShuffleOff, /** Shuffle all tracks. */ ShuffleAllTracks, /** Shuffle group. */ ShuffleGroup }; Q_ENUM(Shuffle) /** Player status. */ enum Status { /** Player is playing. */ Playing, /** Player is stopped. */ Stopped, /** Player is paused. */ Paused, /** Player is forward seeking. */ ForwardSeek, /** Player is reverse seeking. */ ReverseSeek, /** Error */ Error }; Q_ENUM(Status) /** * Destroys a MediaPlayer object. */ ~MediaPlayer(); /** * Returns a shared pointer from this. * * @return MediaPlayerPtr */ MediaPlayerPtr toSharedPtr() const; /** * Returns the name of the player. * * @return name of player */ QString name() const; /** * Returns the equalizer state of the player. * * @return equalizer state of player */ Equalizer equalizer() const; /** * Sets the equalizer state of the player. * * @param equalizer equalizer state * @return void pending call */ PendingCall *setEqualizer(Equalizer equalizer); /** * Returns the repeat state of the player. * * @return repeat state of player */ Repeat repeat() const; /** * Sets the repeat state of the player. * * @param repeat repeat state * @return void pending call */ PendingCall *setRepeat(Repeat repeat); /** * Returns the shuffle state of the player. * * @return shuffle state of player */ Shuffle shuffle() const; /** * Sets the shuffle state of the player. * * @param shuffle shuffle state * @return void pending call */ PendingCall *setShuffle(Shuffle shuffle); /** * Returns the status of the player. * * @return status of player */ Status status() const; /** * Returns the current track. * * @return current track */ MediaPlayerTrack track() const; /** * Returns the playback position in milliseconds. * * @return playback position */ quint32 position() const; public Q_SLOTS: /** * Resumes playback. * * Possible errors: PendingCall::NotSupported, PendingCall::Failed * * @return void pending call */ PendingCall *play(); /** * Pauses playback. * * Possible errors: PendingCall::NotSupported, PendingCall::Failed * * @return void pending call */ PendingCall *pause(); /** * Stops playback. * * Possible errors: PendingCall::NotSupported, PendingCall::Failed * * @return void pending call */ PendingCall *stop(); /** * Switch to next track. * * Possible errors: PendingCall::NotSupported, PendingCall::Failed * * @return void pending call */ PendingCall *next(); /** * Switch to previous track. * * Possible errors: PendingCall::NotSupported, PendingCall::Failed * * @return void pending call */ PendingCall *previous(); /** * Fast forwards playback. * * Possible errors: PendingCall::NotSupported, PendingCall::Failed * * @return void pending call */ PendingCall *fastForward(); /** * Rewinds playback. * * Possible errors: PendingCall::NotSupported, PendingCall::Failed * * @return void pending call */ PendingCall *rewind(); Q_SIGNALS: /** * Indicates that player's name have changed. */ void nameChanged(const QString &name); /** * Indicates that player's equalizer state have changed. */ void equalizerChanged(Equalizer equalizer); /** * Indicates that player's repeat state have changed. */ void repeatChanged(Repeat repeat); /** * Indicates that player's shuffle state have changed. */ void shuffleChanged(Shuffle shuffle); /** * Indicates that player's status have changed. */ void statusChanged(Status status); /** * Indicates that player's current track have changed. */ void trackChanged(MediaPlayerTrack track); /** * Indicates that player's playback position have changed. */ void positionChanged(quint32 position); private: explicit MediaPlayer(const QString &path, const QVariantMap &properties); class MediaPlayerPrivate *const d; friend class MediaPlayerPrivate; friend class DevicePrivate; }; } // namespace BluezQt #endif // BLUEZQT_MEDIAPLAYER_H diff --git a/src/mediaplayer_p.cpp b/src/mediaplayer_p.cpp index aa7e3f5..3175b6e 100644 --- a/src/mediaplayer_p.cpp +++ b/src/mediaplayer_p.cpp @@ -1,166 +1,152 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediaplayer_p.h" #include "utils.h" #include "macros.h" namespace BluezQt { static MediaPlayer::Equalizer stringToEqualizer(const QString &equalizer) { if (equalizer == QLatin1String("on")) { return MediaPlayer::EqualizerOn; } return MediaPlayer::EqualizerOff; } static MediaPlayer::Repeat stringToRepeat(const QString &repeat) { if (repeat == QLatin1String("singletrack")) { return MediaPlayer::RepeatSingleTrack; } else if (repeat == QLatin1String("alltracks")) { return MediaPlayer::RepeatAllTracks; } else if (repeat == QLatin1String("group")) { return MediaPlayer::RepeatGroup; } return MediaPlayer::RepeatOff; } static MediaPlayer::Shuffle stringToShuffle(const QString &shuffle) { if (shuffle == QLatin1String("alltracks")) { return MediaPlayer::ShuffleAllTracks; } else if (shuffle == QLatin1String("group")) { return MediaPlayer::ShuffleGroup; } return MediaPlayer::ShuffleOff; } static MediaPlayer::Status stringToStatus(const QString &status) { if (status == QLatin1String("playing")) { return MediaPlayer::Playing; } else if (status == QLatin1String("stopped")) { return MediaPlayer::Stopped; } else if (status == QLatin1String("paused")) { return MediaPlayer::Paused; } else if (status == QLatin1String("forward-seek")) { return MediaPlayer::ForwardSeek; } else if (status == QLatin1String("reverse-seek")) { return MediaPlayer::ReverseSeek; } return MediaPlayer::Error; } MediaPlayerPrivate::MediaPlayerPrivate(const QString &path, const QVariantMap &properties) : QObject() , m_dbusProperties(nullptr) , m_path(path) , m_equalizer(MediaPlayer::EqualizerOff) , m_repeat(MediaPlayer::RepeatOff) , m_shuffle(MediaPlayer::ShuffleOff) , m_status(MediaPlayer::Error) , m_position(0) { m_bluezMediaPlayer = new BluezMediaPlayer(Strings::orgBluez(), path, DBusConnection::orgBluez(), this); init(properties); } void MediaPlayerPrivate::init(const QVariantMap &properties) { m_dbusProperties = new DBusProperties(Strings::orgBluez(), m_bluezMediaPlayer->path(), DBusConnection::orgBluez(), this); // Init properties m_name = properties.value(QStringLiteral("Name")).toString(); m_equalizer = stringToEqualizer(properties.value(QStringLiteral("Equalizer")).toString()); m_repeat = stringToRepeat(properties.value(QStringLiteral("Repeat")).toString()); m_shuffle = stringToShuffle(properties.value(QStringLiteral("Shuffle")).toString()); m_status = stringToStatus(properties.value(QStringLiteral("Status")).toString()); m_track = variantToTrack(properties.value(QStringLiteral("Track"))); m_position = properties.value(QStringLiteral("Position")).toUInt(); } QDBusPendingReply<> MediaPlayerPrivate::setDBusProperty(const QString &name, const QVariant &value) { return m_dbusProperties->Set(Strings::orgBluezMediaPlayer1(), name, QDBusVariant(value)); } void MediaPlayerPrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated) { if (interface != Strings::orgBluezMediaPlayer1()) { return; } QVariantMap::const_iterator i; for (i = changed.constBegin(); i != changed.constEnd(); ++i) { const QVariant &value = i.value(); const QString &property = i.key(); if (property == QLatin1String("Name")) { PROPERTY_CHANGED(m_name, toString, nameChanged); } else if (property == QLatin1String("Equalizer")) { PROPERTY_CHANGED2(m_equalizer, stringToEqualizer(value.toString()), equalizerChanged); } else if (property == QLatin1String("Repeat")) { PROPERTY_CHANGED2(m_repeat, stringToRepeat(value.toString()), repeatChanged); } else if (property == QLatin1String("Shuffle")) { PROPERTY_CHANGED2(m_shuffle, stringToShuffle(value.toString()), shuffleChanged); } else if (property == QLatin1String("Status")) { PROPERTY_CHANGED2(m_status, stringToStatus(value.toString()), statusChanged); } else if (property == QLatin1String("Position")) { PROPERTY_CHANGED(m_position, toUInt, positionChanged); } else if (property == QLatin1String("Track")) { m_track = variantToTrack(value); Q_EMIT q.lock()->trackChanged(m_track); } } for (const QString &property : invalidated) { if (property == QLatin1String("Name")) { PROPERTY_INVALIDATED(m_name, QString(), nameChanged); } else if (property == QLatin1String("Equalizer")) { PROPERTY_INVALIDATED(m_equalizer, MediaPlayer::EqualizerOff, equalizerChanged); } else if (property == QLatin1String("Repeat")) { PROPERTY_INVALIDATED(m_repeat, MediaPlayer::RepeatOff, repeatChanged); } else if (property == QLatin1String("Shuffle")) { PROPERTY_INVALIDATED(m_shuffle, MediaPlayer::ShuffleOff, shuffleChanged); } else if (property == QLatin1String("Status")) { PROPERTY_INVALIDATED(m_status, MediaPlayer::Error, statusChanged); } else if (property == QLatin1String("Position")) { PROPERTY_INVALIDATED(m_position, 0, positionChanged); } else if (property == QLatin1String("Track")) { m_track = variantToTrack(QVariant()); Q_EMIT q.lock()->trackChanged(m_track); } } } MediaPlayerTrack MediaPlayerPrivate::variantToTrack(const QVariant &variant) const { const QVariantMap &properties = qdbus_cast(variant); return MediaPlayerTrack(properties); } } // namespace BluezQt diff --git a/src/mediaplayer_p.h b/src/mediaplayer_p.h index edd67c2..fe90729 100644 --- a/src/mediaplayer_p.h +++ b/src/mediaplayer_p.h @@ -1,68 +1,54 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MEDIAPLAYER_P_H #define BLUEZQT_MEDIAPLAYER_P_H #include #include "mediaplayer.h" #include "bluezmediaplayer1.h" #include "dbusproperties.h" namespace BluezQt { typedef org::bluez::MediaPlayer1 BluezMediaPlayer; typedef org::freedesktop::DBus::Properties DBusProperties; class MediaPlayerPrivate : public QObject { Q_OBJECT public: explicit MediaPlayerPrivate(const QString &path, const QVariantMap &properties); void init(const QVariantMap &properties); QDBusPendingReply<> setDBusProperty(const QString &name, const QVariant &value); void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated); MediaPlayerTrack variantToTrack(const QVariant &variant) const; QWeakPointer q; BluezMediaPlayer *m_bluezMediaPlayer; DBusProperties *m_dbusProperties; QString m_path; QString m_name; MediaPlayer::Equalizer m_equalizer; MediaPlayer::Repeat m_repeat; MediaPlayer::Shuffle m_shuffle; MediaPlayer::Status m_status; MediaPlayerTrack m_track; quint32 m_position; }; } // namespace BluezQt #endif // BLUEZQT_MEDIAPLAYER_P_H diff --git a/src/mediaplayertrack.cpp b/src/mediaplayertrack.cpp index b9912d9..225fe3d 100644 --- a/src/mediaplayertrack.cpp +++ b/src/mediaplayertrack.cpp @@ -1,122 +1,108 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediaplayertrack.h" #include namespace BluezQt { class MediaPlayerTrackPrivate { public: bool m_valid; QString m_title; QString m_artist; QString m_album; QString m_genre; quint32 m_numberOfTracks; quint32 m_trackNumber; quint32 m_duration; }; MediaPlayerTrack::MediaPlayerTrack() : d(new MediaPlayerTrackPrivate) { d->m_valid = false; d->m_numberOfTracks = 0; d->m_trackNumber = 0; d->m_duration = 0; } MediaPlayerTrack::MediaPlayerTrack(const QVariantMap &properties) : d(new MediaPlayerTrackPrivate) { d->m_valid = !properties.isEmpty(); d->m_title = properties.value(QStringLiteral("Title")).toString(); d->m_artist = properties.value(QStringLiteral("Artist")).toString(); d->m_album = properties.value(QStringLiteral("Album")).toString(); d->m_genre = properties.value(QStringLiteral("Genre")).toString(); d->m_numberOfTracks = properties.value(QStringLiteral("NumberOfTracks")).toUInt(); d->m_trackNumber = properties.value(QStringLiteral("TrackNumber")).toUInt(); d->m_duration = properties.value(QStringLiteral("Duration")).toUInt(); } MediaPlayerTrack::~MediaPlayerTrack() { } MediaPlayerTrack::MediaPlayerTrack(const MediaPlayerTrack &other) : d(other.d) { } MediaPlayerTrack &MediaPlayerTrack::operator=(const MediaPlayerTrack &other) { if (d != other.d) { d = other.d; } return *this; } bool MediaPlayerTrack::isValid() const { return d->m_valid; } QString MediaPlayerTrack::title() const { return d->m_title; } QString MediaPlayerTrack::artist() const { return d->m_artist; } QString MediaPlayerTrack::album() const { return d->m_album; } QString MediaPlayerTrack::genre() const { return d->m_genre; } quint32 MediaPlayerTrack::numberOfTracks() const { return d->m_numberOfTracks; } quint32 MediaPlayerTrack::trackNumber() const { return d->m_trackNumber; } quint32 MediaPlayerTrack::duration() const { return d->m_duration; } } // namespace BluezQt diff --git a/src/mediaplayertrack.h b/src/mediaplayertrack.h index 843cb52..d32181c 100644 --- a/src/mediaplayertrack.h +++ b/src/mediaplayertrack.h @@ -1,136 +1,122 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_MEDIAPLAYERTRACK_H #define BLUEZQT_MEDIAPLAYERTRACK_H #include #include #include "bluezqt_export.h" namespace BluezQt { /** * @class BluezQt::MediaPlayerTrack mediaplayertrack.h * * Media player track. * * This class represents a track in media player. */ class BLUEZQT_EXPORT MediaPlayerTrack { public: /** * Creates a new invalid MediaPlayerTrack object. */ explicit MediaPlayerTrack(); /** * Destroys a MediaPlayerTrack object. */ virtual ~MediaPlayerTrack(); /** * Copy constructor. * * @param other */ MediaPlayerTrack(const MediaPlayerTrack &other); /** * Copy assignment operator. * * @param other */ MediaPlayerTrack &operator=(const MediaPlayerTrack &other); /** * Returns whether the track is valid. * * @return true if track is valid */ bool isValid() const; /** * Returns a title of the track. * * @return track title */ QString title() const; /** * Returns an artist of the track. * * @return track artist */ QString artist() const; /** * Returns an album of the track. * * @return track album */ QString album() const; /** * Returns a genre of the track. * * @return track genre */ QString genre() const; /** * Returns a total number of tracks. * * @return total number of tracks */ quint32 numberOfTracks() const; /** * Returns a track number of the track. * * @return track number */ quint32 trackNumber() const; /** * Returns a duration of the track. * * @return track duration */ quint32 duration() const; private: explicit MediaPlayerTrack(const QVariantMap &properties); QSharedPointer d; friend class MediaPlayerPrivate; }; } // namespace BluezQt Q_DECLARE_METATYPE(BluezQt::MediaPlayerTrack) #endif // BLUEZQT_MEDIAPLAYERTRACK_H diff --git a/src/mediatransport.cpp b/src/mediatransport.cpp index 5115acf..f07609c 100644 --- a/src/mediatransport.cpp +++ b/src/mediatransport.cpp @@ -1,70 +1,56 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediatransport.h" #include "mediatransport_p.h" namespace BluezQt { MediaTransport::MediaTransport(const QString &path, const QVariantMap &properties) : QObject() , d(new MediaTransportPrivate(path, properties)) { } MediaTransport::~MediaTransport() { delete d; } AudioConfiguration MediaTransport::audioConfiguration() const { return d->m_configuration; } MediaTransport::State MediaTransport::state() const { return d->m_state; } quint16 MediaTransport::volume() const { return d->m_volume; } TPendingCall *MediaTransport::acquire() { return new TPendingCall(d->m_dbusInterface->asyncCall(QStringLiteral("Acquire")), this); } TPendingCall *MediaTransport::tryAcquire() { return new TPendingCall(d->m_dbusInterface->asyncCall(QStringLiteral("TryAcquire")), this); } TPendingCall *MediaTransport::release() { return new TPendingCall(d->m_dbusInterface->asyncCall(QStringLiteral("Release")), this); } } // namespace BluezQt diff --git a/src/mediatransport.h b/src/mediatransport.h index b0c32d9..d84a3bb 100644 --- a/src/mediatransport.h +++ b/src/mediatransport.h @@ -1,142 +1,128 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include #include "bluezqt_export.h" #include "mediatypes.h" #include "tpendingcall.h" namespace BluezQt { class PendingCall; /** * @class BluezQt::MediaTransport mediatransport.h * * Media transport. * * This class represents a media transport interface. */ class BLUEZQT_EXPORT MediaTransport : public QObject { Q_OBJECT Q_PROPERTY(State state READ state NOTIFY stateChanged) Q_PROPERTY(quint16 volume READ volume NOTIFY volumeChanged) public: /** Indicates the state of the transport. */ enum class State { Idle, Pending, Active }; Q_ENUM(State) /** * Destroys a MediaTransport object. */ ~MediaTransport(); /** * Returns the (audio) configuration of the transport. * * @return configuration of transport */ AudioConfiguration audioConfiguration() const; /** * Returns the state of the transport. * * @return state of transport */ State state() const; /** * Returns the volume of the transport. * * The volume is a percentage of the maximum. The value 0x00 corresponds to 0%. * The value 0x7F corresponds to 100%. Scaling should be applied to achieve * values between these two. The existence of this scale does not impose any * restriction on the granularity of the volume control scale on the target. * As this command specifies a percentage rather than an absolute dB level * the controller should exercise caution when sending this command. * * @return volume of transport */ quint16 volume() const; public Q_SLOTS: /** * Acquire transport file descriptor and the MTU for read * and write respectively. * * Possible errors: PendingCall::NotAuthorized, PendingCall::Failed * * @return pending call */ TPendingCall *acquire(); /** * Acquire transport file descriptor only if the transport * is in "pending" state at the time the message is * received by BlueZ. Otherwise no request will be sent * to the remote device and the function will just fail * with org.bluez.Error.NotAvailable. * * Possible errors: PendingCall::NotAuthorized, PendingCall::Failed, PendingCall::NotAvailable * * @return pending call */ TPendingCall *tryAcquire(); /** * Releases file descriptor. * * @return void pending call */ TPendingCall *release(); Q_SIGNALS: /** * Indicates that transport's state have changed. */ void stateChanged(State state); /** * Indicates that transport's volume have changed. */ void volumeChanged(quint16 volume); private: explicit MediaTransport(const QString &path, const QVariantMap &properties); class MediaTransportPrivate *const d; friend class MediaTransportPrivate; friend class DevicePrivate; }; } // namespace BluezQt diff --git a/src/mediatransport_p.cpp b/src/mediatransport_p.cpp index a212aed..ee07d84 100644 --- a/src/mediatransport_p.cpp +++ b/src/mediatransport_p.cpp @@ -1,159 +1,145 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediatransport_p.h" #include "utils.h" #include "macros.h" #include "a2dp-codecs.h" namespace BluezQt { static MediaTransport::State stringToState(const QString &state) { if (state == QLatin1String("pending")) { return MediaTransport::State::Pending; } else if (state == QLatin1String("active")) { return MediaTransport::State::Active; } return MediaTransport::State::Idle; } static AudioCodec intToCodec(int value) { switch (value) { case A2DP_CODEC_SBC: return AudioCodec::Sbc; break; case A2DP_CODEC_MPEG24: return AudioCodec::Aac; break; } return AudioCodec::Invalid; } static AudioSampleRate byteArrayToSampleRate(AudioCodec codec, const QByteArray &buffer) { switch (codec) { case AudioCodec::Sbc: { if (buffer.size() != sizeof(a2dp_sbc_t)) { return AudioSampleRate::Invalid; } a2dp_sbc_t sbcConfig = *reinterpret_cast(buffer.constData()); switch (sbcConfig.frequency) { case SBC_SAMPLING_FREQ_44100: return AudioSampleRate::Rate44100; break; case SBC_SAMPLING_FREQ_48000: return AudioSampleRate::Rate48000; break; } break; } case AudioCodec::Aac: { if (buffer.size() != sizeof(a2dp_aac_t)) { return AudioSampleRate::Invalid; } a2dp_aac_t aacConfig = *reinterpret_cast(buffer.constData()); switch (AAC_GET_FREQUENCY(aacConfig)) { case AAC_SAMPLING_FREQ_44100: return AudioSampleRate::Rate44100; break; case AAC_SAMPLING_FREQ_48000: return AudioSampleRate::Rate48000; break; } break; } default: break; } return AudioSampleRate::Invalid; } MediaTransportPrivate::MediaTransportPrivate(const QString &path, const QVariantMap &properties) : QObject() , m_dbusProperties(nullptr) , m_path(path) { m_dbusInterface = new QDBusInterface(Strings::orgBluez(), path, QStringLiteral("org.bluez.MediaTransport1"), DBusConnection::orgBluez(), this); DBusConnection::orgBluez().connect(Strings::orgBluez(), path, Strings::orgFreedesktopDBusProperties(), QStringLiteral("PropertiesChanged"), this, SLOT(onPropertiesChanged(QString,QVariantMap,QStringList))); init(properties); } void MediaTransportPrivate::init(const QVariantMap &properties) { m_dbusProperties = new DBusProperties(Strings::orgBluez(), m_path, DBusConnection::orgBluez(), this); m_volume = properties.value(QStringLiteral("Volume")).toUInt(); m_state = stringToState(properties.value(QStringLiteral("State")).toString()); m_configuration.codec = intToCodec(properties.value(QStringLiteral("Codec")).toInt()); m_configuration.sampleRate = byteArrayToSampleRate(m_configuration.codec, properties.value(QStringLiteral("Configuration")).toByteArray()); } void MediaTransportPrivate::onPropertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated) { if (interface != Strings::orgBluezMediaTransport1()) { return; } for (auto it = changed.constBegin(); it != changed.constEnd(); ++it) { const QString &key = it.key(); const QVariant &value = it.value(); if (key == QLatin1String("Volume")) { m_volume = value.toUInt(); Q_EMIT q.lock()->volumeChanged(m_volume); } else if (key == QLatin1String("State")) { m_state = stringToState(value.toString()); Q_EMIT q.lock()->stateChanged(m_state); } } for (const QString &property : invalidated) { if (property == QLatin1String("Volume")) { m_volume = 0; Q_EMIT q.lock()->volumeChanged(m_volume); } else if (property == QLatin1String("State")) { PROPERTY_INVALIDATED(m_state, MediaTransport::State::Idle, stateChanged); } } } } // namespace BluezQt diff --git a/src/mediatransport_p.h b/src/mediatransport_p.h index 09ddd6f..d2ec3bc 100644 --- a/src/mediatransport_p.h +++ b/src/mediatransport_p.h @@ -1,56 +1,42 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "mediatransport.h" #include "dbusproperties.h" namespace BluezQt { typedef org::freedesktop::DBus::Properties DBusProperties; class MediaTransportPrivate : public QObject { Q_OBJECT public: explicit MediaTransportPrivate(const QString &path, const QVariantMap &properties); void init(const QVariantMap &properties); public Q_SLOTS: void onPropertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated); public: QWeakPointer q; QDBusInterface *m_dbusInterface; DBusProperties *m_dbusProperties; QString m_path; AudioConfiguration m_configuration; MediaTransport::State m_state = MediaTransport::State::Idle; quint16 m_volume = 0; }; } // namespace BluezQt diff --git a/src/mediatypes.h b/src/mediatypes.h index db3a3c9..59ccca5 100644 --- a/src/mediatypes.h +++ b/src/mediatypes.h @@ -1,66 +1,52 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once namespace BluezQt { /** Assigned number of codec that the endpoint/transport supports. Currently limited to most common codecs. Further codecs reserved. */ enum class AudioCodec { Invalid = 0x0000, Sbc = 0x0001, //Mp3 = 0x0002, Aac = 0x0004, //Atrac = 0x0008, //AptX = 0x0010, //AptXLl = 0x0020, //AptXHd = 0x0040, //FastStream = 0x0080, //Ldac = 0x0100, }; /** Assigned number of sample rate that the endpoint/transport supports. Currently limited to most common rates. Further rates reserved. */ enum class AudioSampleRate { Invalid = 0x0000, //Rate8000 = 0x0001, //Rate11025 = 0x0002, //Rate12000 = 0x0004, //Rate16000 = 0x0008, //Rate22050 = 0x0010, //Rate24000 = 0x0020, //Rate32000 = 0x0040, Rate44100 = 0x0080, Rate48000 = 0x0100, //Rate64000 = 0x0200, //Rate88200 = 0x0400, //Rate96000 = 0x0800 }; struct AudioConfiguration { AudioCodec codec = AudioCodec::Invalid; AudioSampleRate sampleRate = AudioSampleRate::Invalid; }; } // namespace BluezQt diff --git a/src/obexagent.cpp b/src/obexagent.cpp index d92260f..0c44091 100644 --- a/src/obexagent.cpp +++ b/src/obexagent.cpp @@ -1,49 +1,35 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexagent.h" #include "debug.h" namespace BluezQt { ObexAgent::ObexAgent(QObject *parent) : QObject(parent) { } void ObexAgent::authorizePush(ObexTransferPtr transfer, ObexSessionPtr session, const Request &request) { Q_UNUSED(transfer) Q_UNUSED(session) Q_UNUSED(request) } void ObexAgent::cancel() { } void ObexAgent::release() { } } // namespace BluezQt diff --git a/src/obexagent.h b/src/obexagent.h index 331a8e6..3d46dfb 100644 --- a/src/obexagent.h +++ b/src/obexagent.h @@ -1,121 +1,107 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXAGENT_H #define BLUEZQT_OBEXAGENT_H #include #include "types.h" #include "request.h" #include "bluezqt_export.h" class QDBusObjectPath; namespace BluezQt { class Device; class ObexTransfer; /** * @class BluezQt::ObexAgent obexagent.h * * Bluetooth OBEX agent. * * This class represents a Bluetooth OBEX agent. * * The agent is used to authorize an incoming object push requests. * * @note The return value of request will be sent asynchronously with Request class. * It is also possible to cancel/reject the request. */ class BLUEZQT_EXPORT ObexAgent : public QObject { Q_OBJECT public: /** * Creates a new ObexAgent object. * * @param parent */ explicit ObexAgent(QObject *parent = nullptr); /** * D-Bus object path of the agent. * * The path where the agent will be registered. * * @note You must provide valid object path! * * @return object path of agent */ virtual QDBusObjectPath objectPath() const = 0; /** * Requests the agent to authorize an incoming object push request. * * This method gets called when the Bluetooth daemon * needs to accept/reject a Bluetooth object push request. * * The return value should be full path where the incoming object * will be saved. * * The ObexTransfer::fileName() contains the default location * and name that can be returned. * * You can use @p session to get device and adapter this transfer * belongs to. * * @param transfer transfer object * @param session transfer session * @param request request to be used for sending reply */ virtual void authorizePush(ObexTransferPtr transfer, ObexSessionPtr session, const Request &request); /** * Indicate that the agent request failed before receiving reply. * * This method gets called to indicate that the agent * request failed before a reply was returned. * * It cancels the previous request. */ virtual void cancel(); /** * Indicates that the agent was unregistered. * * This method gets called when the Bluetooth daemon * unregisters the agent. * * An agent can use it to do cleanup tasks. There is no need * to unregister the agent, because when this method gets called * it has already been unregistered. */ virtual void release(); }; } // namespace BluezQt #endif // BLUEZQT_OBEXAGENT_H diff --git a/src/obexagentadaptor.cpp b/src/obexagentadaptor.cpp index 238c59d..d39721d 100644 --- a/src/obexagentadaptor.cpp +++ b/src/obexagentadaptor.cpp @@ -1,94 +1,80 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexagentadaptor.h" #include "obexagent.h" #include "obexmanager.h" #include "obextransfer.h" #include "obextransfer_p.h" #include "dbusproperties.h" #include "utils.h" #include namespace BluezQt { typedef org::freedesktop::DBus::Properties DBusProperties; ObexAgentAdaptor::ObexAgentAdaptor(ObexAgent *parent, ObexManager *manager) : QDBusAbstractAdaptor(parent) , m_agent(parent) , m_manager(manager) { } QString ObexAgentAdaptor::AuthorizePush(const QDBusObjectPath &transfer, const QDBusMessage &msg) { msg.setDelayedReply(true); m_transferRequest = Request(OrgBluezObexAgent, msg); m_transferPath = transfer.path(); DBusProperties dbusProperties(Strings::orgBluezObex(), m_transferPath, DBusConnection::orgBluezObex(), this); const QDBusPendingReply &call = dbusProperties.GetAll(Strings::orgBluezObexTransfer1()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); connect(watcher, &QDBusPendingCallWatcher::finished, this, &ObexAgentAdaptor::getPropertiesFinished); return QString(); } void ObexAgentAdaptor::Cancel() { m_agent->cancel(); } void ObexAgentAdaptor::Release() { m_agent->release(); } void ObexAgentAdaptor::getPropertiesFinished(QDBusPendingCallWatcher *watcher) { const QDBusPendingReply &reply = *watcher; watcher->deleteLater(); if (reply.isError()) { m_transferRequest.cancel(); return; } ObexTransferPtr transfer = ObexTransferPtr(new ObexTransfer(m_transferPath, reply.value())); transfer->d->q = transfer.toWeakRef(); ObexSessionPtr session = m_manager->sessionForPath(transfer->objectPath()); Q_ASSERT(session); if (!session) { m_transferRequest.cancel(); return; } m_agent->authorizePush(transfer, session, m_transferRequest); } } // namespace BluezQt diff --git a/src/obexagentadaptor.h b/src/obexagentadaptor.h index 3de3b2b..4f07438 100644 --- a/src/obexagentadaptor.h +++ b/src/obexagentadaptor.h @@ -1,66 +1,52 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXAGENTADAPTOR_H #define BLUEZQT_OBEXAGENTADAPTOR_H #include #include "types.h" #include "request.h" class QDBusObjectPath; class QDBusPendingCallWatcher; namespace BluezQt { class ObexAgent; class ObexManager; class ObexAgentAdaptor : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.obex.Agent1") public: explicit ObexAgentAdaptor(ObexAgent *parent, ObexManager *manager); public Q_SLOTS: QString AuthorizePush(const QDBusObjectPath &transfer, const QDBusMessage &msg); Q_NOREPLY void Cancel(); Q_NOREPLY void Release(); private Q_SLOTS: void getPropertiesFinished(QDBusPendingCallWatcher *watcher); private: ObexAgent *m_agent; ObexManager *m_manager; QString m_transferPath; Request m_transferRequest; }; } // namespace BluezQt #endif // BLUEZQT_OBEXAGENTADAPTOR_H diff --git a/src/obexfiletransfer.cpp b/src/obexfiletransfer.cpp index 1dec08e..d5040ce 100644 --- a/src/obexfiletransfer.cpp +++ b/src/obexfiletransfer.cpp @@ -1,108 +1,94 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexfiletransfer.h" #include "pendingcall.h" #include "utils.h" #include "obexfiletransfer1.h" namespace BluezQt { typedef org::bluez::obex::FileTransfer1 BluezFileTransfer; class ObexFileTransferPrivate { public: ObexFileTransfer *q; BluezFileTransfer *m_bluezFileTransfer; }; ObexFileTransfer::ObexFileTransfer(const QDBusObjectPath &path, QObject *parent) : QObject(parent) , d(new ObexFileTransferPrivate) { d->m_bluezFileTransfer = new BluezFileTransfer(Strings::orgBluezObex(), path.path(), DBusConnection::orgBluezObex(), this); } ObexFileTransfer::~ObexFileTransfer() { delete d; } QDBusObjectPath ObexFileTransfer::objectPath() const { return QDBusObjectPath(d->m_bluezFileTransfer->path()); } PendingCall *ObexFileTransfer::changeFolder(const QString &folder) { return new PendingCall(d->m_bluezFileTransfer->ChangeFolder(folder), PendingCall::ReturnVoid, this); } PendingCall *ObexFileTransfer::createFolder(const QString &folder) { return new PendingCall(d->m_bluezFileTransfer->CreateFolder(folder), PendingCall::ReturnVoid, this); } PendingCall *ObexFileTransfer::listFolder() { return new PendingCall(d->m_bluezFileTransfer->ListFolder(), PendingCall::ReturnFileTransferList, this); } PendingCall *ObexFileTransfer::getFile(const QString &targetFileName, const QString &sourceFileName) { return new PendingCall(d->m_bluezFileTransfer->GetFile(targetFileName, sourceFileName), PendingCall::ReturnTransferWithProperties, this); } PendingCall *ObexFileTransfer::putFile(const QString &sourceFileName, const QString &targetFileName) { return new PendingCall(d->m_bluezFileTransfer->PutFile(sourceFileName, targetFileName), PendingCall::ReturnTransferWithProperties, this); } PendingCall *ObexFileTransfer::copyFile(const QString &sourceFileName, const QString &targetFileName) { return new PendingCall(d->m_bluezFileTransfer->CopyFile(sourceFileName, targetFileName), PendingCall::ReturnVoid, this); } PendingCall *ObexFileTransfer::moveFile(const QString &sourceFileName, const QString &targetFileName) { return new PendingCall(d->m_bluezFileTransfer->MoveFile(sourceFileName, targetFileName), PendingCall::ReturnVoid, this); } PendingCall *ObexFileTransfer::deleteFile(const QString &fileName) { return new PendingCall(d->m_bluezFileTransfer->Delete(fileName), PendingCall::ReturnVoid, this); } } // namespace BluezQt diff --git a/src/obexfiletransfer.h b/src/obexfiletransfer.h index 87d6928..40915b4 100644 --- a/src/obexfiletransfer.h +++ b/src/obexfiletransfer.h @@ -1,170 +1,156 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXFILETRANSFER_H #define BLUEZQT_OBEXFILETRANSFER_H #include #include "obexfiletransferentry.h" #include "bluezqt_export.h" class QDBusObjectPath; namespace BluezQt { class PendingCall; /** * @class BluezQt::ObexFileTransfer obexfiletransfer.h * * OBEX file transfer. * * This class represents an OBEX file transfer interface. */ class BLUEZQT_EXPORT ObexFileTransfer : public QObject { Q_OBJECT public: /** * Creates a new ObexFileTransfer object. * * This class will be typically used with a @p path * from result of ObexManager::createSession(). * * @param path path of session * @param parent */ explicit ObexFileTransfer(const QDBusObjectPath &path, QObject *parent = nullptr); /** * Destroys an ObexFileTransfer object. */ ~ObexFileTransfer(); /** * D-Bus object path of the file transfer session. * * @return object path of session */ QDBusObjectPath objectPath() const; /** * Changes the current folder. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param folder folder to be changed * @return void pending call */ PendingCall *changeFolder(const QString &folder); /** * Creates a new folder. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param folder name of new folder * @return void pending call */ PendingCall *createFolder(const QString &folder); /** * Lists a current folder. * * Possible errors: PendingCall::Failed * * @return QList pending call */ PendingCall *listFolder(); /** * Gets the file from the remote device. * * If an empty @p targetFileName is given, a name will be * automatically calculated for the temporary file. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param targetFileName full local path where the file will be saved * @param sourceFileName file within the remote device * @return ObexTransferPtr pending call */ PendingCall *getFile(const QString &targetFileName, const QString &sourceFileName); /** * Puts the file to the remote device. * * If an empty @p targetFileName is given, a name will be * automatically calculated for the temporary file. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param sourceFileName full path of the local file * @param targetFileName file to be saved within the remote device * @return ObexTransferPtr pending call */ PendingCall *putFile(const QString &sourceFileName, const QString &targetFileName); /** * Copies a file within the remote device. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param sourceFileName source within the remote device * @param targetFileName target file within the remote device * @return void pending call */ PendingCall *copyFile(const QString &sourceFileName, const QString &targetFileName); /** * Moves a file within the remote device. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param sourceFileName source file within the remote device * @param targetFileName target file within the remote device * @return void pending call */ PendingCall *moveFile(const QString &sourceFileName, const QString &targetFileName); /** * Deletes a file/folder within the remote device. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param fileName file within the remote device * @return void pending call */ PendingCall *deleteFile(const QString &fileName); private: class ObexFileTransferPrivate *const d; friend class ObexFileTransferPrivate; }; } // namespace BluezQt #endif // BLUEZQT_OBEXFILETRANSFER_H diff --git a/src/obexfiletransferentry.cpp b/src/obexfiletransferentry.cpp index 7c0ba90..4a926dc 100644 --- a/src/obexfiletransferentry.cpp +++ b/src/obexfiletransferentry.cpp @@ -1,132 +1,118 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexfiletransferentry.h" #include #include namespace BluezQt { class ObexFileTransferEntryPrivate { public: QString m_name; QString m_label; ObexFileTransferEntry::Type m_type; quint64 m_size; QString m_permissions; QString m_memoryType; QDateTime m_modified; }; static QDateTime dateTimeFromTransfer(const QString &value) { return QDateTime::fromString(value, QStringLiteral("yyyyMMddThhmmssZ")); } ObexFileTransferEntry::ObexFileTransferEntry() : d(new ObexFileTransferEntryPrivate) { d->m_type = Invalid; d->m_size = 0; } ObexFileTransferEntry::ObexFileTransferEntry(const QVariantMap &properties) : d(new ObexFileTransferEntryPrivate) { d->m_name = properties.value(QStringLiteral("Name")).toString(); d->m_label = properties.value(QStringLiteral("Label")).toString(); d->m_size = properties.value(QStringLiteral("Size")).toUInt(); d->m_permissions = properties.value(QStringLiteral("User-perm")).toString(); d->m_memoryType = properties.value(QStringLiteral("Mem-type")).toString(); d->m_modified = dateTimeFromTransfer(properties.value(QStringLiteral("Modified")).toString()); const QString &type = properties.value(QStringLiteral("Type")).toString(); if (type == QLatin1String("folder")) { d->m_type = ObexFileTransferEntry::Folder; } else if (type == QLatin1String("file")) { d->m_type = ObexFileTransferEntry::File; } else { d->m_type = ObexFileTransferEntry::Invalid; } } ObexFileTransferEntry::~ObexFileTransferEntry() { } ObexFileTransferEntry::ObexFileTransferEntry(const ObexFileTransferEntry &other) : d(other.d) { } ObexFileTransferEntry &ObexFileTransferEntry::operator=(const ObexFileTransferEntry &other) { if (d != other.d) { d = other.d; } return *this; } bool ObexFileTransferEntry::isValid() const { return d->m_type != Invalid; } QString ObexFileTransferEntry::name() const { return d->m_name; } QString ObexFileTransferEntry::label() const { return d->m_label; } ObexFileTransferEntry::Type ObexFileTransferEntry::type() const { return d->m_type; } quint64 ObexFileTransferEntry::size() const { return d->m_size; } QString ObexFileTransferEntry::permissions() const { return d->m_permissions; } QString ObexFileTransferEntry::memoryType() const { return d->m_memoryType; } QDateTime ObexFileTransferEntry::modificationTime() const { return d->m_modified; } } // namespace BluezQt diff --git a/src/obexfiletransferentry.h b/src/obexfiletransferentry.h index 9564eef..ef55b97 100644 --- a/src/obexfiletransferentry.h +++ b/src/obexfiletransferentry.h @@ -1,152 +1,138 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXFILETRANSFERENTRY_H #define BLUEZQT_OBEXFILETRANSFERENTRY_H #include #include #include "bluezqt_export.h" namespace BluezQt { /** * @class BluezQt::ObexFileTransferEntry obexfiletransferentry.h * * OBEX file transfer entry. * * This class represents an entry in remote file system. */ class BLUEZQT_EXPORT ObexFileTransferEntry { public: /** Type of entry. */ enum Type { /** Indicates that the entry is a file. */ File, /** Indicates that the entry is a folder. */ Folder, /** Indicates that the entry is invalid. */ Invalid }; /** * Creates a new invalid ObexFileTransferEntry object. */ explicit ObexFileTransferEntry(); /** * Destroys an ObexFileTransferEntry object. */ virtual ~ObexFileTransferEntry(); /** * Copy constructor. * * @param other */ ObexFileTransferEntry(const ObexFileTransferEntry &other); /** * Copy assignment operator. * * @param other */ ObexFileTransferEntry &operator=(const ObexFileTransferEntry &other); /** * Returns whether the entry is valid. * * This only checks if type() != Invalid. * * @return true if entry is valid */ bool isValid() const; /** * Returns a name of the entry. * * @return name of entry */ QString name() const; /** * Returns a label of the entry. * * @return label of entry */ QString label() const; /** * Returns a type of the entry. * * Entry can be either a file or folder. * * @return type of entry */ Type type() const; /** * Returns a size of the entry. * * Size is a number of items in the folder or file size in bytes. * * @return size of entry */ quint64 size() const; /** * Returns a permissions of the entry. * * @return permissions of entry */ QString permissions() const; /** * Returns a memory type where the entry is stored. * * @return memory type */ QString memoryType() const; /** * Returns a modification time of the entry. * * @return modification time of entry */ QDateTime modificationTime() const; private: explicit ObexFileTransferEntry(const QVariantMap &properties); QSharedPointer d; friend class PendingCallPrivate; }; } // namespace BluezQt Q_DECLARE_METATYPE(BluezQt::ObexFileTransferEntry) #endif // BLUEZQT_OBEXFILETRANSFERENTRY_H diff --git a/src/obexmanager.cpp b/src/obexmanager.cpp index 36e86fa..10f3998 100644 --- a/src/obexmanager.cpp +++ b/src/obexmanager.cpp @@ -1,145 +1,131 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexmanager.h" #include "obexmanager_p.h" #include "initobexmanagerjob.h" #include "debug.h" #include "pendingcall.h" #include "obexagent.h" #include "obexagentadaptor.h" #include "obexsession.h" #include "utils.h" #include namespace BluezQt { ObexManager::ObexManager(QObject *parent) : QObject(parent) , d(new ObexManagerPrivate(this)) { Instance::setObexManager(this); } ObexManager::~ObexManager() { delete d; } InitObexManagerJob *ObexManager::init() { return new InitObexManagerJob(this); } bool ObexManager::isInitialized() const { return d->m_initialized; } bool ObexManager::isOperational() const { return d->m_initialized && d->m_obexRunning && d->m_loaded; } QList ObexManager::sessions() const { return d->m_sessions.values(); } ObexSessionPtr ObexManager::sessionForPath(const QDBusObjectPath &path) const { for (ObexSessionPtr session : qAsConst(d->m_sessions)) { if (path.path().startsWith(session->objectPath().path())) { return session; } } return ObexSessionPtr(); } PendingCall *ObexManager::startService() { QDBusMessage msg = QDBusMessage::createMethodCall(Strings::orgFreedesktopDBus(), QStringLiteral("/org/freedesktop/DBus"), Strings::orgFreedesktopDBus(), QStringLiteral("StartServiceByName")); msg << Strings::orgBluezObex(); msg << quint32(0); return new PendingCall(DBusConnection::orgBluezObex().asyncCall(msg), PendingCall::ReturnUint32); } PendingCall *ObexManager::registerAgent(ObexAgent *agent) { Q_ASSERT(agent); if (!d->m_obexAgentManager) { return new PendingCall(PendingCall::InternalError, QStringLiteral("ObexManager not operational!")); } new ObexAgentAdaptor(agent, this); if (!DBusConnection::orgBluezObex().registerObject(agent->objectPath().path(), agent)) { qCDebug(BLUEZQT) << "Cannot register object" << agent->objectPath().path(); } return new PendingCall(d->m_obexAgentManager->RegisterAgent(agent->objectPath()), PendingCall::ReturnVoid, this); } PendingCall *ObexManager::unregisterAgent(ObexAgent *agent) { Q_ASSERT(agent); if (!d->m_obexAgentManager) { return new PendingCall(PendingCall::InternalError, QStringLiteral("ObexManager not operational!")); } DBusConnection::orgBluezObex().unregisterObject(agent->objectPath().path()); return new PendingCall(d->m_obexAgentManager->UnregisterAgent(agent->objectPath()), PendingCall::ReturnVoid, this); } PendingCall *ObexManager::createSession(const QString &destination, const QVariantMap &args) { if (!d->m_obexClient) { return new PendingCall(PendingCall::InternalError, QStringLiteral("ObexManager not operational!")); } return new PendingCall(d->m_obexClient->CreateSession(destination, args), PendingCall::ReturnObjectPath, this); } PendingCall *ObexManager::removeSession(const QDBusObjectPath &session) { if (!d->m_obexClient) { return new PendingCall(PendingCall::InternalError, QStringLiteral("ObexManager not operational!")); } return new PendingCall(d->m_obexClient->RemoveSession(session), PendingCall::ReturnVoid, this); } } // namespace BluezQt diff --git a/src/obexmanager.h b/src/obexmanager.h index cd96303..bb97e6b 100644 --- a/src/obexmanager.h +++ b/src/obexmanager.h @@ -1,214 +1,200 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXMANAGER_H #define BLUEZQT_OBEXMANAGER_H #include #include "types.h" #include "bluezqt_export.h" class QDBusObjectPath; namespace BluezQt { class ObexAgent; class PendingCall; class InitObexManagerJob; /** * @class BluezQt::ObexManager obexmanager.h * * OBEX manager. * * The entry point to communicate with session BlueZ obex daemon. * * You must call init() before other functions can be used. * * @note If manager is not operational, all methods that returns a PendingCall * will fail with PendingCall::InternalError. */ class BLUEZQT_EXPORT ObexManager : public QObject { Q_OBJECT Q_PROPERTY(bool initialized READ isInitialized) Q_PROPERTY(bool operational READ isOperational NOTIFY operationalChanged) Q_PROPERTY(QList sessions READ sessions) public: /** * Creates a new ObexManager object. * * @param parent */ explicit ObexManager(QObject *parent = nullptr); /** * Destroys an ObexManager object. */ ~ObexManager(); /** * Creates a new init job. * * @return init manager job */ InitObexManagerJob *init(); /** * Returns whether the manager is initialized. * * @return true if manager is initialized */ bool isInitialized() const; /** * Returns whether the manager is operational. * * The manager is operational when initialization was successful * and BlueZ session daemon is running. * * @return true if manager is operational */ bool isOperational() const; /** * Returns a list of all sessions. * * @return list of sessions */ QList sessions() const; /** * Returns a session for specified path. * * The @p path does not need to be equal to ObexSession path, startsWith * test is performed in the search. That means you can use this method * to get ObexSession from path returned by createSession(). * * @param path path of session * @return null if there is no session with specified path */ ObexSessionPtr sessionForPath(const QDBusObjectPath &path) const; /** * Attempts to start org.bluez.obex service by D-Bus activation. * * Possible return values are 1 if the service was started, * 2 if the service is already running or error if the service * could not be started. * * @return quint32 pending call */ static PendingCall *startService(); public Q_SLOTS: /** * Registers agent. * * This agent will be used to authorize an incoming object push requests. * * Possible errors: PendingCall::AlreadyExists * * @param agent agent to be registered * @return void pending call */ PendingCall *registerAgent(ObexAgent *agent); /** * Unregisters agent. * * Possible errors: PendingCall::DoesNotExist * * @param agent agent to be unregistered * @return void pending call */ PendingCall *unregisterAgent(ObexAgent *agent); /** * Creates a new OBEX session. * * The @p args parameter is a dictionary to hold optional or * type-specific parameters. * * Typical parameters: *
    *
  • QString target - type of session to be created
  • *
  • QString source - device address to be used
  • *
* * Supported targets: *
    *
  • ftp - ObexFileTransfer
  • *
  • map
  • *
  • opp - ObexObjectPush
  • *
  • pbap
  • *
  • sync
  • *
* * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param destination address of target device * @param args session parameters * @return QDBusObjectPath pending call */ PendingCall *createSession(const QString &destination, const QVariantMap &args); /** * Removes an existing OBEX session. * * Possible errors: PendingCall::InvalidArguments, PendingCall::NotAuthorized * * @param session session to be removed * @return void pending call */ PendingCall *removeSession(const QDBusObjectPath &session); Q_SIGNALS: /** * Indicates that operational state have changed. */ void operationalChanged(bool operational); /** * Indicates that the session was added. */ void sessionAdded(ObexSessionPtr session); /** * Indicates that the session was removed. */ void sessionRemoved(ObexSessionPtr session); private: class ObexManagerPrivate *const d; friend class ObexManagerPrivate; friend class InitObexManagerJobPrivate; }; } // namespace BluezQt #endif // BLUEZQT_OBEXMANAGER_H diff --git a/src/obexmanager_p.cpp b/src/obexmanager_p.cpp index e90c298..622dc97 100644 --- a/src/obexmanager_p.cpp +++ b/src/obexmanager_p.cpp @@ -1,264 +1,250 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexmanager_p.h" #include "obexmanager.h" #include "obexsession.h" #include "obexsession_p.h" #include "debug.h" #include "utils.h" #include "dbusobjectmanager.h" #include namespace BluezQt { typedef org::freedesktop::DBus::ObjectManager DBusObjectManager; ObexManagerPrivate::ObexManagerPrivate(ObexManager *q) : QObject(q) , q(q) , m_obexClient(nullptr) , m_obexAgentManager(nullptr) , m_dbusObjectManager(nullptr) , m_initialized(false) , m_obexRunning(false) , m_loaded(false) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); m_timer.setSingleShot(true); connect(&m_timer, &QTimer::timeout, this, &ObexManagerPrivate::load); } void ObexManagerPrivate::init() { // Keep an eye on org.bluez.obex service QDBusServiceWatcher *serviceWatcher = new QDBusServiceWatcher(Strings::orgBluezObex(), DBusConnection::orgBluezObex(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this); connect(serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, &ObexManagerPrivate::serviceRegistered); connect(serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &ObexManagerPrivate::serviceUnregistered); // Update the current state of org.bluez.obex service if (!DBusConnection::orgBluezObex().isConnected()) { Q_EMIT initError(QStringLiteral("DBus session bus is not connected!")); return; } QDBusMessage call = QDBusMessage::createMethodCall(Strings::orgFreedesktopDBus(), QStringLiteral("/"), Strings::orgFreedesktopDBus(), QStringLiteral("NameHasOwner")); call << Strings::orgBluezObex(); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(DBusConnection::orgBluezObex().asyncCall(call)); connect(watcher, &QDBusPendingCallWatcher::finished, this, &ObexManagerPrivate::nameHasOwnerFinished); } void ObexManagerPrivate::nameHasOwnerFinished(QDBusPendingCallWatcher *watcher) { const QDBusPendingReply &reply = *watcher; watcher->deleteLater(); if (reply.isError()) { Q_EMIT initError(reply.error().message()); return; } m_obexRunning = reply.value(); if (m_obexRunning) { load(); } else { m_initialized = true; Q_EMIT initFinished(); } } void ObexManagerPrivate::load() { if (!m_obexRunning || m_loaded) { return; } // Force QDBus to cache owner of org.bluez.obex - this will be the only blocking call on session connection DBusConnection::orgBluezObex().connect(Strings::orgBluezObex(), QStringLiteral("/"), Strings::orgFreedesktopDBus(), QStringLiteral("Dummy"), this, SLOT(dummy())); m_dbusObjectManager = new DBusObjectManager(Strings::orgBluezObex(), QStringLiteral("/"), DBusConnection::orgBluezObex(), this); connect(m_dbusObjectManager, &DBusObjectManager::InterfacesAdded, this, &ObexManagerPrivate::interfacesAdded); connect(m_dbusObjectManager, &DBusObjectManager::InterfacesRemoved, this, &ObexManagerPrivate::interfacesRemoved); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(m_dbusObjectManager->GetManagedObjects(), this); connect(watcher, &QDBusPendingCallWatcher::finished, this, &ObexManagerPrivate::getManagedObjectsFinished); } void ObexManagerPrivate::getManagedObjectsFinished(QDBusPendingCallWatcher *watcher) { const QDBusPendingReply &reply = *watcher; watcher->deleteLater(); if (reply.isError()) { Q_EMIT initError(reply.error().message()); return; } DBusManagerStruct::const_iterator it; const DBusManagerStruct &managedObjects = reply.value(); for (it = managedObjects.constBegin(); it != managedObjects.constEnd(); ++it) { const QString &path = it.key().path(); const QVariantMapMap &interfaces = it.value(); if (interfaces.contains(Strings::orgBluezObexSession1())) { addSession(path, interfaces.value(Strings::orgBluezObexSession1())); } else if (interfaces.contains(Strings::orgBluezObexClient1()) && interfaces.contains(Strings::orgBluezObexAgentManager1())) { m_obexClient = new ObexClient(Strings::orgBluezObex(), path, DBusConnection::orgBluezObex(), this); m_obexAgentManager = new ObexAgentManager(Strings::orgBluezObex(), path, DBusConnection::orgBluezObex(), this); } } if (!m_obexClient) { Q_EMIT initError(QStringLiteral("Cannot find org.bluez.obex.Client1 object!")); return; } if (!m_obexAgentManager) { Q_EMIT initError(QStringLiteral("Cannot find org.bluez.obex.AgentManager1 object!")); return; } m_loaded = true; m_initialized = true; Q_EMIT q->operationalChanged(true); Q_EMIT initFinished(); } void ObexManagerPrivate::clear() { m_loaded = false; // Delete all sessions while (!m_sessions.isEmpty()) { ObexSessionPtr session = m_sessions.begin().value(); m_sessions.remove(m_sessions.begin().key()); Q_EMIT q->sessionRemoved(session); } // Delete all other objects if (m_obexClient) { m_obexClient->deleteLater(); m_obexClient = nullptr; } if (m_obexAgentManager) { m_obexAgentManager->deleteLater(); m_obexAgentManager = nullptr; } if (m_dbusObjectManager) { m_dbusObjectManager->deleteLater(); m_dbusObjectManager = nullptr; } } void ObexManagerPrivate::serviceRegistered() { qCDebug(BLUEZQT) << "Obex service registered"; m_obexRunning = true; // Client1 and AgentManager1 objects are not ready by the time org.bluez.obex is registered // nor will the ObjectManager emits interfacesAdded for adding them... // So we delay the call to load() by 0.5s m_timer.start(500); } void ObexManagerPrivate::serviceUnregistered() { qCDebug(BLUEZQT) << "Obex service unregistered"; m_obexRunning = false; clear(); Q_EMIT q->operationalChanged(false); } void ObexManagerPrivate::interfacesAdded(const QDBusObjectPath &objectPath, const QVariantMapMap &interfaces) { const QString &path = objectPath.path(); QVariantMapMap::const_iterator it; for (it = interfaces.constBegin(); it != interfaces.constEnd(); ++it) { if (it.key() == Strings::orgBluezObexSession1()) { addSession(path, it.value()); } } } void ObexManagerPrivate::interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces) { const QString &path = objectPath.path(); for (const QString &interface : interfaces) { if (interface == Strings::orgBluezObexSession1()) { removeSession(path); } } } void ObexManagerPrivate::addSession(const QString &sessionPath, const QVariantMap &properties) { ObexSessionPtr session = ObexSessionPtr(new ObexSession(sessionPath, properties)); session->d->q = session.toWeakRef(); m_sessions.insert(sessionPath, session); Q_EMIT q->sessionAdded(session); } void ObexManagerPrivate::removeSession(const QString &sessionPath) { ObexSessionPtr session = m_sessions.take(sessionPath); if (!session) { return; } Q_EMIT q->sessionRemoved(session); } void ObexManagerPrivate::dummy() { } } // namespace BluezQt diff --git a/src/obexmanager_p.h b/src/obexmanager_p.h index 437d663..8f87d48 100644 --- a/src/obexmanager_p.h +++ b/src/obexmanager_p.h @@ -1,86 +1,72 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXMANAGER_P_H #define BLUEZQT_OBEXMANAGER_P_H #include #include #include "types.h" #include "dbusobjectmanager.h" #include "obexclient1.h" #include "obexagentmanager1.h" namespace BluezQt { typedef org::bluez::obex::Client1 ObexClient; typedef org::bluez::obex::AgentManager1 ObexAgentManager; typedef org::freedesktop::DBus::ObjectManager DBusObjectManager; class ObexManager; class ObexManagerPrivate : public QObject { Q_OBJECT public: explicit ObexManagerPrivate(ObexManager *q); void init(); void nameHasOwnerFinished(QDBusPendingCallWatcher *watcher); void load(); void getManagedObjectsFinished(QDBusPendingCallWatcher *watcher); void clear(); void serviceRegistered(); void serviceUnregistered(); void interfacesAdded(const QDBusObjectPath &objectPath, const QVariantMapMap &interfaces); void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces); void addSession(const QString &sessionPath, const QVariantMap &properties); void removeSession(const QString &sessionPath); ObexManager *q; ObexClient *m_obexClient; ObexAgentManager *m_obexAgentManager; DBusObjectManager *m_dbusObjectManager; QTimer m_timer; QHash m_sessions; bool m_initialized; bool m_obexRunning; bool m_loaded; Q_SIGNALS: void initError(const QString &errorText); void initFinished(); private Q_SLOTS: void dummy(); }; } // namespace BluezQt #endif // BLUEZQT_OBEXMANAGER_P_H diff --git a/src/obexobjectpush.cpp b/src/obexobjectpush.cpp index 07c4549..b7572a2 100644 --- a/src/obexobjectpush.cpp +++ b/src/obexobjectpush.cpp @@ -1,77 +1,63 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexobjectpush.h" #include "pendingcall.h" #include "utils.h" #include "obexobjectpush1.h" namespace BluezQt { typedef org::bluez::obex::ObjectPush1 BluezObjectPush; class ObexObjectPushPrivate { public: ObexObjectPush *q; BluezObjectPush *m_bluezObjectPush; }; ObexObjectPush::ObexObjectPush(const QDBusObjectPath &path, QObject *parent) : QObject(parent) , d(new ObexObjectPushPrivate) { d->m_bluezObjectPush = new BluezObjectPush(Strings::orgBluezObex(), path.path(), DBusConnection::orgBluezObex(), this); } ObexObjectPush::~ObexObjectPush() { delete d; } QDBusObjectPath ObexObjectPush::objectPath() const { return QDBusObjectPath(d->m_bluezObjectPush->path()); } PendingCall *ObexObjectPush::sendFile(const QString &fileName) { return new PendingCall(d->m_bluezObjectPush->SendFile(fileName), PendingCall::ReturnTransferWithProperties, this); } PendingCall *ObexObjectPush::pullBusinessCard(const QString &targetFileName) { return new PendingCall(d->m_bluezObjectPush->PullBusinessCard(targetFileName), PendingCall::ReturnTransferWithProperties, this); } PendingCall *ObexObjectPush::exchangeBusinessCards(const QString &clientFileName, const QString &targetFileName) { return new PendingCall(d->m_bluezObjectPush->ExchangeBusinessCards(clientFileName, targetFileName), PendingCall::ReturnTransferWithProperties, this); } } // namespace BluezQt diff --git a/src/obexobjectpush.h b/src/obexobjectpush.h index 475c226..3cd9a60 100644 --- a/src/obexobjectpush.h +++ b/src/obexobjectpush.h @@ -1,127 +1,113 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXOBJECTPUSH_H #define BLUEZQT_OBEXOBJECTPUSH_H #include #include "bluezqt_export.h" class QDBusObjectPath; namespace BluezQt { class PendingCall; /** * @class BluezQt::ObexObjectPush obexobjectpush.h * * OBEX object push. * * This class represents an OBEX object push interface. */ class BLUEZQT_EXPORT ObexObjectPush : public QObject { Q_OBJECT public: /** * Creates a new ObexObjectPush object. * * This class will be typically used with a @p path * from result of ObexManager::createSession(). * * @param path path of session * @param parent */ explicit ObexObjectPush(const QDBusObjectPath &path, QObject *parent = nullptr); /** * Destroys an ObexObjectPush object. */ ~ObexObjectPush(); /** * D-Bus object path of the object push session. * * @return object path of session */ QDBusObjectPath objectPath() const; /** * Sends one local file to the remote device. * * The returned ObexTransfer can be used to track progress of transfer. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param fileName full path of file to send * @return ObexTransfer * pending call */ PendingCall *sendFile(const QString &fileName); /** * Pulls the business card from a remote device. * * If an empty @p targetFileName is given, a name will be * automatically calculated for the temporary file. * * The returned ObexTransfer can be used to track progress of transfer. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param targetFileName full path where the business card will be saved * @return ObexTransfer * pending call */ PendingCall *pullBusinessCard(const QString &targetFileName); /** * Exchanges the business cards on the remote device. * * This method pushes the local business card to the remote * device and then retrieve the remote business card and store * it in a local file. * * If an empty @p targetFileName is given, a name will be * automatically calculated for the temporary file. * * The returned ObexTransfer can be used to track progress of transfer. * * Possible errors: PendingCall::InvalidArguments, PendingCall::Failed * * @param clientFileName full path to local business card * @param targetFileName full path where the business card will be saved * @return ObexTransfer * pending call */ PendingCall *exchangeBusinessCards(const QString &clientFileName, const QString &targetFileName); private: class ObexObjectPushPrivate *const d; friend class ObexObjectPushPrivate; }; } // namespace BluezQt #endif // BLUEZQT_OBEXOBJECTPUSH_H diff --git a/src/obexsession.cpp b/src/obexsession.cpp index e9f7dfe..e72aefe 100644 --- a/src/obexsession.cpp +++ b/src/obexsession.cpp @@ -1,100 +1,86 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obexsession.h" #include "obexsession_p.h" #include "pendingcall.h" #include "utils.h" namespace BluezQt { ObexSessionPrivate::ObexSessionPrivate(const QString &path, const QVariantMap &properties) : QObject() { m_bluezSession = new BluezSession(Strings::orgBluezObex(), path, DBusConnection::orgBluezObex(), this); init(properties); } void ObexSessionPrivate::init(const QVariantMap &properties) { m_source = properties.value(QStringLiteral("Source")).toString(); m_destination = properties.value(QStringLiteral("Destination")).toString(); m_channel = properties.value(QStringLiteral("Channel")).toUInt(); m_target = properties.value(QStringLiteral("Target")).toString().toUpper(); m_root = properties.value(QStringLiteral("Root")).toString(); } ObexSession::ObexSession(const QString &path, const QVariantMap &properties) : QObject() , d(new ObexSessionPrivate(path, properties)) { } ObexSession::~ObexSession() { delete d; } ObexSessionPtr ObexSession::toSharedPtr() const { return d->q.toStrongRef(); } QDBusObjectPath ObexSession::objectPath() const { return QDBusObjectPath(d->m_bluezSession->path()); } QString ObexSession::source() const { return d->m_source; } QString ObexSession::destination() const { return d->m_destination; } quint8 ObexSession::channel() const { return d->m_channel; } QString ObexSession::target() const { return d->m_target; } QString ObexSession::root() const { return d->m_root; } PendingCall *ObexSession::getCapabilities() { return new PendingCall(d->m_bluezSession->GetCapabilities(), PendingCall::ReturnString, this); } } // namespace BluezQt diff --git a/src/obexsession.h b/src/obexsession.h index fd2756f..6d6c453 100644 --- a/src/obexsession.h +++ b/src/obexsession.h @@ -1,134 +1,120 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXSESSION_H #define BLUEZQT_OBEXSESSION_H #include #include "types.h" #include "bluezqt_export.h" class QDBusObjectPath; namespace BluezQt { class PendingCall; /** * @class BluezQt::ObexSession obexsession.h * * OBEX session. * * This class represents an OBEX session. */ class BLUEZQT_EXPORT ObexSession : public QObject { Q_OBJECT Q_PROPERTY(QString source READ source) Q_PROPERTY(QString destination READ destination) Q_PROPERTY(quint8 channel READ channel) Q_PROPERTY(QString target READ target) Q_PROPERTY(QString root READ root) public: /** * Destroys an ObexSession object. */ ~ObexSession(); /** * Returns a shared pointer from this. * * @return ObexSessionPtr */ ObexSessionPtr toSharedPtr() const; /** * D-Bus object path of the session. * * @return object path of session */ QDBusObjectPath objectPath() const; /** * Returns address of the Bluetooth adapter. * * @see Manager::adapterForAddress() const * * @return address of adapter */ QString source() const; /** * Returns address of the Bluetooth device. * * @see Manager::deviceForAddress() const * * @return address of device */ QString destination() const; /** * Returns the Bluetooth channel. * * @return channel */ quint8 channel() const; /** * Returns the target UUID. * * @return target UUID */ QString target() const; /** * Returns the root path. * * @return root path */ QString root() const; /** * Returns the remote device capabilities. * * Possible errors: PendingCall::NotSupported, PendingCall::Failed * * @return QString pending call */ PendingCall *getCapabilities(); private: explicit ObexSession(const QString &path, const QVariantMap &properties); class ObexSessionPrivate *const d; friend class ObexSessionPrivate; friend class ObexManagerPrivate; }; } // namespace BluezQt #endif // BLUEZQT_OBEXSESSION_H diff --git a/src/obexsession_p.h b/src/obexsession_p.h index f772b51..53bed4c 100644 --- a/src/obexsession_p.h +++ b/src/obexsession_p.h @@ -1,56 +1,42 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXSESSION_P_H #define BLUEZQT_OBEXSESSION_P_H #include "obexsession1.h" namespace BluezQt { class ObexSession; typedef org::bluez::obex::Session1 BluezSession; class ObexSessionPrivate : public QObject { Q_OBJECT public: explicit ObexSessionPrivate(const QString &path, const QVariantMap &properties); void init(const QVariantMap &properties); QWeakPointer q; BluezSession *m_bluezSession; QString m_source; QString m_destination; quint8 m_channel; QString m_target; QString m_root; }; } // namespace BluezQt #endif // BLUEZQT_OBEXSESSION_P_H diff --git a/src/obextransfer.cpp b/src/obextransfer.cpp index d1a66d2..c5b7b85 100644 --- a/src/obextransfer.cpp +++ b/src/obextransfer.cpp @@ -1,198 +1,184 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "obextransfer.h" #include "obextransfer_p.h" #include "pendingcall.h" #include "obexmanager.h" #include "obexsession.h" #include "utils.h" #include "macros.h" namespace BluezQt { static ObexTransfer::Status stringToStatus(const QString &status) { if (status == QLatin1String("queued")) { return ObexTransfer::Queued; } else if (status == QLatin1String("active")) { return ObexTransfer::Active; } else if (status == QLatin1String("suspended")) { return ObexTransfer::Suspended; } else if (status == QLatin1String("complete")) { return ObexTransfer::Complete; } else if (status == QLatin1String("error")) { return ObexTransfer::Error; } return ObexTransfer::Unknown; } ObexTransferPrivate::ObexTransferPrivate(const QString &path, const QVariantMap &properties) : QObject() , m_dbusProperties(nullptr) , m_status(ObexTransfer::Error) , m_time(0) , m_size(0) , m_transferred(0) , m_suspendable(false) { m_bluezTransfer = new BluezTransfer(Strings::orgBluezObex(), path, DBusConnection::orgBluezObex(), this); if (Instance::obexManager()) { connect(Instance::obexManager(), &ObexManager::sessionRemoved, this, &ObexTransferPrivate::sessionRemoved); } init(properties); } void ObexTransferPrivate::init(const QVariantMap &properties) { m_dbusProperties = new DBusProperties(Strings::orgBluezObex(), m_bluezTransfer->path(), DBusConnection::orgBluezObex(), this); connect(m_dbusProperties, &DBusProperties::PropertiesChanged, this, &ObexTransferPrivate::propertiesChanged, Qt::QueuedConnection); // Init properties m_status = stringToStatus(properties.value(QStringLiteral("Status")).toString()); m_name = properties.value(QStringLiteral("Name")).toString(); m_type = properties.value(QStringLiteral("Type")).toString(); m_time = properties.value(QStringLiteral("Time")).toUInt(); m_size = properties.value(QStringLiteral("Size")).toUInt(); m_transferred = properties.value(QStringLiteral("Transferred")).toUInt(); m_fileName = properties.value(QStringLiteral("Filename")).toString(); } void ObexTransferPrivate::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated) { Q_UNUSED(invalidated) if (interface != Strings::orgBluezObexTransfer1()) { return; } QVariantMap::const_iterator i; for (i = changed.constBegin(); i != changed.constEnd(); ++i) { const QVariant &value = i.value(); const QString &property = i.key(); if (property == QLatin1String("Status")) { PROPERTY_CHANGED2(m_status, stringToStatus(value.toString()), statusChanged); } else if (property == QLatin1String("Transferred")) { PROPERTY_CHANGED(m_transferred, toUInt, transferredChanged); } else if (property == QLatin1String("Filename")) { PROPERTY_CHANGED(m_fileName, toString, fileNameChanged); } } } void ObexTransferPrivate::sessionRemoved(const ObexSessionPtr &session) { if (!m_bluezTransfer->path().startsWith(session->objectPath().path())) { return; } // Change status to Error if org.bluez.obex crashes if (m_status != ObexTransfer::Complete && m_status != ObexTransfer::Error) { m_status = ObexTransfer::Error; Q_EMIT q.lock()->statusChanged(m_status); } } ObexTransfer::ObexTransfer(const QString &path, const QVariantMap &properties) : QObject() , d(new ObexTransferPrivate(path, properties)) { } ObexTransfer::~ObexTransfer() { delete d; } ObexTransferPtr ObexTransfer::toSharedPtr() const { return d->q.toStrongRef(); } QDBusObjectPath ObexTransfer::objectPath() const { return QDBusObjectPath(d->m_bluezTransfer->path()); } ObexTransfer::Status ObexTransfer::status() const { return d->m_status; } QString ObexTransfer::name() const { return d->m_name; } QString ObexTransfer::type() const { return d->m_type; } quint64 ObexTransfer::time() const { return d->m_time; } quint64 ObexTransfer::size() const { return d->m_size; } quint64 ObexTransfer::transferred() const { return d->m_transferred; } QString ObexTransfer::fileName() const { return d->m_fileName; } bool ObexTransfer::isSuspendable() const { return d->m_suspendable; } PendingCall *ObexTransfer::cancel() { return new PendingCall(d->m_bluezTransfer->Cancel(), PendingCall::ReturnVoid, this); } PendingCall *ObexTransfer::suspend() { return new PendingCall(d->m_bluezTransfer->Suspend(), PendingCall::ReturnVoid, this); } PendingCall *ObexTransfer::resume() { return new PendingCall(d->m_bluezTransfer->Resume(), PendingCall::ReturnVoid, this); } } // namespace BluezQt diff --git a/src/obextransfer.h b/src/obextransfer.h index 8aa121f..6072024 100644 --- a/src/obextransfer.h +++ b/src/obextransfer.h @@ -1,213 +1,199 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXTRANSFER_H #define BLUEZQT_OBEXTRANSFER_H #include #include "types.h" #include "bluezqt_export.h" class QDBusObjectPath; namespace BluezQt { class PendingCall; /** * @class BluezQt::ObexTransfer obextransfer.h * * OBEX transfer. * * This class represents transfer of one file. */ class BLUEZQT_EXPORT ObexTransfer : public QObject { Q_OBJECT Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_PROPERTY(QString name READ name) Q_PROPERTY(QString type READ type) Q_PROPERTY(quint64 time READ time) Q_PROPERTY(quint64 size READ size) Q_PROPERTY(quint64 transferred READ transferred NOTIFY transferredChanged) Q_PROPERTY(QString fileName READ fileName NOTIFY fileNameChanged) Q_PROPERTY(bool suspendable READ isSuspendable) public: /** * Status of transfer. */ enum Status { /** Indicates that the transfer is queued. */ Queued, /** Indicates that the transfer is active. */ Active, /** Indicates that the transfer is suspended. */ Suspended, /** Indicates that the transfer have completed successfully. */ Complete, /** Indicates that the transfer have failed with error. */ Error, /** Indicates that the transfer status is unknown. */ Unknown }; Q_ENUM(Status) /** * Destroys an ObexTransfer object. */ ~ObexTransfer(); /** * Returns a shared pointer from this. * * @return ObexTransferPtr */ ObexTransferPtr toSharedPtr() const; /** * D-Bus object path of the transfer. * * @return object path of transfer */ QDBusObjectPath objectPath() const; /** * Returns the status of the transfer. * * @return status of transfer */ Status status() const; /** * Returns the name of the transferred object. * * @return name of transferred object */ QString name() const; /** * Returns the type of the transferred object. * * @return type of transferred object */ QString type() const; /** * Returns the time of the transferred object. * * @return time of transferred object */ quint64 time() const; /** * Returns the total size of the transferred object. * * @return size of transferred object */ quint64 size() const; /** * Returns the number of bytes transferred. * * @return number of bytes transferred */ quint64 transferred() const; /** * Returns the full name of the transferred file. * * @return full name of transferred file */ QString fileName() const; /** * Returns whether the transfer is suspendable. * * @return true if transfer is suspendable */ bool isSuspendable() const; /** * Stops the current transfer. * * Possible errors: PendingCall::NotAuthorized, PendingCall::InProgress * PendingCall::Failed * * @return void pending call */ PendingCall *cancel(); /** * Suspends the current transfer. * * Only suspendable transfers can be suspended. * * Possible errors: PendingCall::NotAuthorized, PendingCall::NotInProgress * * @see isSuspendable() const * * @return void pending call */ PendingCall *suspend(); /** * Resumes the current transfer. * * Possible errors: PendingCall::NotAuthorized, PendingCall::NotInProgress * * @return void pending call */ PendingCall *resume(); Q_SIGNALS: /** * Indicates that the status of transfer have changed. */ void statusChanged(Status status); /** * Indicates that the number of transferred bytes have changed. */ void transferredChanged(quint64 transferred); /** * Indicates that the name of transferred file have changed. */ void fileNameChanged(const QString &fileName); private: explicit ObexTransfer(const QString &path, const QVariantMap &properties); class ObexTransferPrivate *const d; friend class ObexTransferPrivate; friend class ObexAgentAdaptor; friend class PendingCallPrivate; }; } // namespace BluezQt #endif // BLUEZQT_OBEXTRANSFER_H diff --git a/src/obextransfer_p.h b/src/obextransfer_p.h index 4dd8078..2bddf2a 100644 --- a/src/obextransfer_p.h +++ b/src/obextransfer_p.h @@ -1,65 +1,51 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_OBEXTRANSFER_P_H #define BLUEZQT_OBEXTRANSFER_P_H #include "obextransfer.h" #include "obextransfer1.h" #include "dbusproperties.h" namespace BluezQt { typedef org::bluez::obex::Transfer1 BluezTransfer; typedef org::freedesktop::DBus::Properties DBusProperties; class ObexTransferPrivate : public QObject { Q_OBJECT public: explicit ObexTransferPrivate(const QString &path, const QVariantMap &properties); void init(const QVariantMap &properties); void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalidated); void sessionRemoved(const ObexSessionPtr &session); QWeakPointer q; BluezTransfer *m_bluezTransfer; DBusProperties *m_dbusProperties; ObexTransfer::Status m_status; QString m_name; QString m_type; quint64 m_time; quint64 m_size; quint64 m_transferred; QString m_fileName; bool m_suspendable; }; } // namespace BluezQt #endif // BLUEZQT_OBEXTRANSFER_P_H diff --git a/src/objectmanageradaptor.cpp b/src/objectmanageradaptor.cpp index 8b86183..bbde1ab 100644 --- a/src/objectmanageradaptor.cpp +++ b/src/objectmanageradaptor.cpp @@ -1,45 +1,31 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "objectmanageradaptor.h" #include "gattapplication.h" #include "gattapplication_p.h" namespace BluezQt { ObjectManagerAdaptor::ObjectManagerAdaptor(QObject *parent) : QDBusAbstractAdaptor(parent) , m_gattApplication(qobject_cast(parent)) { } DBusManagerStruct ObjectManagerAdaptor::GetManagedObjects() { if (m_gattApplication) { return m_gattApplication->d->getManagedObjects(); } return {}; } } // namespace BluezQt diff --git a/src/objectmanageradaptor.h b/src/objectmanageradaptor.h index 9d9bb17..fe8e031 100644 --- a/src/objectmanageradaptor.h +++ b/src/objectmanageradaptor.h @@ -1,52 +1,38 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include #include "bluezqt_dbustypes.h" namespace BluezQt { class GattApplication; class ObjectManagerAdaptor : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.freedesktop.DBus.ObjectManager") public: explicit ObjectManagerAdaptor(QObject *parent); public Q_SLOTS: DBusManagerStruct GetManagedObjects(); Q_SIGNALS: void InterfacesAdded(const QDBusObjectPath &object, const QVariantMapMap &interfaces); void InterfacesRemoved(const QDBusObjectPath &object, const QStringList &interfaces); private: GattApplication *m_gattApplication = nullptr; }; } // namespace BluezQt diff --git a/src/pendingcall.cpp b/src/pendingcall.cpp index a127a00..6f6ef44 100644 --- a/src/pendingcall.cpp +++ b/src/pendingcall.cpp @@ -1,331 +1,317 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "pendingcall.h" #include "obextransfer.h" #include "obextransfer_p.h" #include "obexfiletransferentry.h" #include "bluezqt_dbustypes.h" #include "debug.h" #include #include namespace BluezQt { static PendingCall::Error nameToError(const QString &name) { if (name.startsWith(QLatin1String("org.freedesktop.DBus.Error"))) { return PendingCall::DBusError; } if (!name.startsWith(QLatin1String("org.bluez.Error"))) { return PendingCall::UnknownError; } #define FROM_BLUEZ_ERROR(string, value) \ if (errorName == QLatin1String(string)) { \ return value; \ } const QString &errorName = name.mid(16); FROM_BLUEZ_ERROR("NotReady", PendingCall::NotReady); FROM_BLUEZ_ERROR("Failed", PendingCall::Failed); FROM_BLUEZ_ERROR("Rejected", PendingCall::Rejected); FROM_BLUEZ_ERROR("Canceled", PendingCall::Canceled); FROM_BLUEZ_ERROR("InvalidArguments", PendingCall::InvalidArguments); FROM_BLUEZ_ERROR("AlreadyExists", PendingCall::AlreadyExists); FROM_BLUEZ_ERROR("DoesNotExist", PendingCall::DoesNotExist); FROM_BLUEZ_ERROR("AlreadyConnected", PendingCall::AlreadyConnected); FROM_BLUEZ_ERROR("ConnectFailed", PendingCall::ConnectFailed); FROM_BLUEZ_ERROR("NotConnected", PendingCall::NotConnected); FROM_BLUEZ_ERROR("NotSupported", PendingCall::NotSupported); FROM_BLUEZ_ERROR("NotAuthorized", PendingCall::NotAuthorized); FROM_BLUEZ_ERROR("AuthenticationCanceled", PendingCall::AuthenticationCanceled); FROM_BLUEZ_ERROR("AuthenticationFailed", PendingCall::AuthenticationFailed); FROM_BLUEZ_ERROR("AuthenticationRejected", PendingCall::AuthenticationRejected); FROM_BLUEZ_ERROR("AuthenticationTimeout", PendingCall::AuthenticationTimeout); FROM_BLUEZ_ERROR("ConnectionAttemptFailed", PendingCall::ConnectionAttemptFailed); FROM_BLUEZ_ERROR("InvalidLength", PendingCall::InvalidLength); FROM_BLUEZ_ERROR("NotPermitted", PendingCall::NotPermitted); #undef FROM_BLUEZ_ERROR return PendingCall::UnknownError; } class PendingCallPrivate : public QObject { public: explicit PendingCallPrivate(PendingCall *parent); void processReply(QDBusPendingCallWatcher *call); void processVoidReply(const QDBusPendingReply<> &reply); void processUint32Reply(const QDBusPendingReply &reply); void processStringReply(const QDBusPendingReply &reply); void processObjectPathReply(const QDBusPendingReply &reply); void processFileTransferListReply(const QDBusPendingReply &reply); void processTransferWithPropertiesReply(const QDBusPendingReply &reply); void processError(const QDBusError &m_error); void emitFinished(); void emitDelayedFinished(); void emitInternalError(const QString &errorText); void pendingCallFinished(QDBusPendingCallWatcher *m_watcher); PendingCall *q; int m_error; QString m_errorText; QVariant m_userData; QVariantList m_value; PendingCall::ReturnType m_type; QDBusPendingCallWatcher *m_watcher; }; PendingCallPrivate::PendingCallPrivate(PendingCall *parent) : QObject(parent) , q(parent) , m_error(PendingCall::NoError) , m_type(PendingCall::ReturnVoid) , m_watcher(nullptr) { } void PendingCallPrivate::processReply(QDBusPendingCallWatcher *call) { switch (m_type) { case PendingCall::ReturnVoid: processVoidReply(*call); break; case PendingCall::ReturnUint32: processUint32Reply(*call); break; case PendingCall::ReturnString: processStringReply(*call); break; case PendingCall::ReturnObjectPath: processObjectPathReply(*call); break; case PendingCall::ReturnFileTransferList: processFileTransferListReply(*call); break; case PendingCall::ReturnTransferWithProperties: processTransferWithPropertiesReply(*call); break; default: break; } } void PendingCallPrivate::processVoidReply(const QDBusPendingReply<> &reply) { processError(reply.error()); } void PendingCallPrivate::processUint32Reply(const QDBusPendingReply &reply) { processError(reply.error()); if (!reply.isError()) { m_value.append(reply.value()); } } void PendingCallPrivate::processStringReply(const QDBusPendingReply &reply) { processError(reply.error()); if (!reply.isError()) { m_value.append(reply.value()); } } void PendingCallPrivate::processObjectPathReply(const QDBusPendingReply &reply) { processError(reply.error()); if (!reply.isError()) { m_value.append(QVariant::fromValue(reply.value())); } } void PendingCallPrivate::processFileTransferListReply(const QDBusPendingReply &reply) { processError(reply.error()); if (!reply.isError()) { QList items; items.reserve(reply.value().size()); const auto maps = reply.value(); for (const QVariantMap &map : maps) { items.append(ObexFileTransferEntry(map)); } m_value.append(QVariant::fromValue(items)); } } void PendingCallPrivate::processTransferWithPropertiesReply(const QDBusPendingReply &reply) { processError(reply.error()); if (reply.isError()) { return; } ObexTransferPtr transfer = ObexTransferPtr(new ObexTransfer(reply.argumentAt<0>().path(), reply.argumentAt<1>())); transfer->d->q = transfer.toWeakRef(); transfer->d->m_suspendable = true; m_value.append(QVariant::fromValue(transfer)); } void PendingCallPrivate::processError(const QDBusError &error) { if (error.isValid()) { qCWarning(BLUEZQT) << "PendingCall Error:" << error.message(); m_error = nameToError(error.name()); m_errorText = error.message(); } } void PendingCallPrivate::emitFinished() { m_watcher->deleteLater(); m_watcher = nullptr; Q_EMIT q->finished(q); q->deleteLater(); } void PendingCallPrivate::emitDelayedFinished() { Q_ASSERT(qobject_cast(sender())); Q_EMIT q->finished(q); static_cast(sender())->deleteLater(); } void PendingCallPrivate::emitInternalError(const QString &errorText) { qCWarning(BLUEZQT) << "PendingCall Internal error:" << errorText; m_error = PendingCall::InternalError; m_errorText = errorText; emitFinished(); } void PendingCallPrivate::pendingCallFinished(QDBusPendingCallWatcher *watcher) { processReply(watcher); emitFinished(); } PendingCall::PendingCall(const QDBusPendingCall &call, ReturnType type, QObject *parent) : QObject(parent) , d(new PendingCallPrivate(this)) { qDBusRegisterMetaType(); d->m_type = type; d->m_watcher = new QDBusPendingCallWatcher(call, this); connect(d->m_watcher, &QDBusPendingCallWatcher::finished, d, &PendingCallPrivate::pendingCallFinished); } PendingCall::PendingCall(PendingCall::Error error, const QString &errorText, QObject *parent) : QObject(parent) , d(new PendingCallPrivate(this)) { d->m_error = error; d->m_errorText = errorText; QTimer *timer = new QTimer(this); timer->setSingleShot(true); timer->start(0); connect(timer, &QTimer::timeout, d, &PendingCallPrivate::emitDelayedFinished); } PendingCall::PendingCall(const QDBusPendingCall &call, ExternalProcessor externalProcessor, QObject *parent) : QObject(parent) , d(new PendingCallPrivate(this)) { qDBusRegisterMetaType(); d->m_watcher = new QDBusPendingCallWatcher(call, this); connect(d->m_watcher, &QDBusPendingCallWatcher::finished, [externalProcessor, this](QDBusPendingCallWatcher *watcher) { externalProcessor(watcher, std::bind(&PendingCallPrivate::processError, d, std::placeholders::_1), &d->m_value); d->emitFinished(); }); } PendingCall::~PendingCall() { delete d; } QVariant PendingCall::value() const { if (d->m_value.isEmpty()) { return QVariant(); } return d->m_value.first(); } QVariantList PendingCall::values() const { return d->m_value; } int PendingCall::error() const { return d->m_error; } QString PendingCall::errorText() const { return d->m_errorText; } bool PendingCall::isFinished() const { if (d->m_watcher) { return d->m_watcher->isFinished(); } return true; } void PendingCall::waitForFinished() { if (d->m_watcher) { d->m_watcher->waitForFinished(); } } QVariant PendingCall::userData() const { return d->m_userData; } void PendingCall::setUserData(const QVariant &userData) { d->m_userData = userData; } } // namespace BluezQt diff --git a/src/pendingcall.h b/src/pendingcall.h index 2683771..1531293 100644 --- a/src/pendingcall.h +++ b/src/pendingcall.h @@ -1,221 +1,207 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_PENDINGCALL_H #define BLUEZQT_PENDINGCALL_H #include #include #include "bluezqt_export.h" class QDBusError; class QDBusPendingCall; class QDBusPendingCallWatcher; namespace BluezQt { /** * @class BluezQt::PendingCall pendingcall.h * * Pending method call. * * This class represents a pending method call. It is a convenient wrapper * around QDBusPendingReply and QDBusPendingCallWatcher. */ class BLUEZQT_EXPORT PendingCall : public QObject { Q_OBJECT Q_PROPERTY(QVariant value READ value) Q_PROPERTY(QVariantList values READ values) Q_PROPERTY(int error READ error) Q_PROPERTY(QString errorText READ errorText) Q_PROPERTY(bool isFinished READ isFinished) Q_PROPERTY(QVariant userData READ userData WRITE setUserData) public: /** * Known error types. */ enum Error { /** Indicates there is no error. */ NoError = 0, /** Indicates that the device is not ready. */ NotReady = 1, /** Indicates that the action have failed. */ Failed = 2, /** Indicates that the action was rejected. */ Rejected = 3, /** Indicates that the action was canceled. */ Canceled = 4, /** Indicates that invalid arguments were passed. */ InvalidArguments = 5, /** Indicates that an agent or pairing record already exists. */ AlreadyExists = 6, /** Indicates that an agent, service or pairing operation does not exists. */ DoesNotExist = 7, /** Indicates that the action is already in progress. */ InProgress = 8, /** Indicates that the action is not in progress. */ NotInProgress = 9, /** Indicates that the device is already connected. */ AlreadyConnected = 10, /** Indicates that the connection to the device have failed. */ ConnectFailed = 11, /** Indicates that the device is not connected. */ NotConnected = 12, /** Indicates that the action is not supported. */ NotSupported = 13, /** Indicates that the caller is not authorized to do the action. */ NotAuthorized = 14, /** Indicates that the authentication was canceled. */ AuthenticationCanceled = 15, /** Indicates that the authentication have failed. */ AuthenticationFailed = 16, /** Indicates that the authentication was rejected. */ AuthenticationRejected = 17, /** Indicates that the authentication timed out. */ AuthenticationTimeout = 18, /** Indicates that the connection attempt have failed. */ ConnectionAttemptFailed = 19, /** Indicates that the data provided generates a data packet which is too long. */ InvalidLength = 20, /** Indicates that the action is not permitted (e.g. maximum reached or socket locked). */ NotPermitted = 21, /** Indicates an error with D-Bus. */ DBusError = 98, /** Indicates an internal error. */ InternalError = 99, /** Indicates an unknown error. */ UnknownError = 100 }; Q_ENUM(Error) /** * Destroys a PendingCall object. */ ~PendingCall(); /** * Returns a first return value of the call. * * @return first return value */ QVariant value() const; /** * Returns all values of the call. * * @return all return values */ QVariantList values() const; /** * Returns an error code. * * @return error code * @see Error */ int error() const; /** * Returns an error text. * * @return error text */ QString errorText() const; /** * Returns whether the call is finished. * * @return true if call is finished */ bool isFinished() const; /** * Waits for the call to finish. * * @warning This method blocks until the call finishes! */ void waitForFinished(); /** * Returns the user data of the call. * * @return user data of call */ QVariant userData() const; /** * Sets the user data of the call. * * @param userData user data */ void setUserData(const QVariant &userData); Q_SIGNALS: /** * Indicates that the call have finished. */ void finished(PendingCall *call); private: enum ReturnType { ReturnVoid, ReturnUint32, ReturnString, ReturnObjectPath, ReturnFileTransferList, ReturnTransferWithProperties }; explicit PendingCall(const QDBusPendingCall &call, ReturnType type, QObject *parent = nullptr); explicit PendingCall(Error error, const QString &errorText, QObject *parent = nullptr); using ErrorProcessor = std::function; using ExternalProcessor = std::function; explicit PendingCall(const QDBusPendingCall &call, ExternalProcessor externalProcessor, QObject *parent = nullptr); class PendingCallPrivate *const d; friend class PendingCallPrivate; friend class Manager; friend class Adapter; friend class Device; friend class GattManager; friend class LEAdvertisingManager; friend class Media; friend class MediaPlayer; friend class ObexManager; friend class ObexTransfer; friend class ObexSession; friend class ObexObjectPush; friend class ObexFileTransfer; template friend class TPendingCall; }; } // namespace BluezQt #endif // BLUEZQT_PENDINGCALL_H diff --git a/src/profile.cpp b/src/profile.cpp index 7af84cd..42f09f8 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -1,153 +1,139 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "profile.h" #include "profile_p.h" #include "debug.h" #include #include #include namespace BluezQt { Profile::Profile(QObject *parent) : QObject(parent) , d(new ProfilePrivate) { } Profile::~Profile() { delete d; } void Profile::setName(const QString &name) { d->options[QStringLiteral("Name")] = name; } void Profile::setService(const QString &service) { d->options[QStringLiteral("Service")] = service; } void Profile::setLocalRole(Profile::LocalRole role) { QString str; switch (role) { case ClientRole: str = QStringLiteral("client"); break; case ServerRole: str = QStringLiteral("server"); break; default: break; } if (str.isEmpty()) { qCWarning(BLUEZQT) << "Invalid local role!"; return; } d->options[QStringLiteral("Role")] = str; } void Profile::setChannel(quint16 channel) { if (channel > 31) { qCWarning(BLUEZQT) << "Invalid channel number. Must be 0-31!"; return; } d->options[QStringLiteral("Channel")] = QVariant::fromValue(channel); } void Profile::setPsm(quint16 psm) { d->options[QStringLiteral("PSM")] = QVariant::fromValue(psm); } void Profile::setRequireAuthentication(bool require) { d->options[QStringLiteral("RequireAuthentication")] = require; } void Profile::setRequireAuthorization(bool require) { d->options[QStringLiteral("RequireAuthorization")] = require; } void Profile::setAutoConnect(bool autoConnect) { d->options[QStringLiteral("AutoConnect")] = autoConnect; } void Profile::setServiceRecord(const QString &serviceRecord) { d->options[QStringLiteral("ServiceRecord")] = serviceRecord; } void Profile::setVersion(quint16 version) { d->options[QStringLiteral("Version")] = QVariant::fromValue(version); } void Profile::setFeatures(quint16 features) { d->options[QStringLiteral("Features")] = QVariant::fromValue(features); } QSharedPointer Profile::createSocket(const QDBusUnixFileDescriptor &fd) { int newfd = ::dup(fd.fileDescriptor()); QSharedPointer socket(new QLocalSocket); socket->setSocketDescriptor(newfd); return socket; } void Profile::newConnection(DevicePtr device, const QDBusUnixFileDescriptor &fd, const QVariantMap &properties, const Request<> &request) { Q_UNUSED(device) Q_UNUSED(fd) Q_UNUSED(properties) request.cancel(); } void Profile::requestDisconnection(DevicePtr device, const Request<> &request) { Q_UNUSED(device) request.cancel(); } void Profile::release() { } } // namespace BluezQt diff --git a/src/profile.h b/src/profile.h index f2a60af..6d54e10 100644 --- a/src/profile.h +++ b/src/profile.h @@ -1,271 +1,257 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_PROFILE_H #define BLUEZQT_PROFILE_H #include #include "request.h" #include "types.h" #include "bluezqt_export.h" class QLocalSocket; class QDBusObjectPath; class QDBusUnixFileDescriptor; namespace BluezQt { class Device; /** * @class BluezQt::Profile profile.h * * Bluetooth profile. * * This class represents a Bluetooth profile. * * It is only needed to reimplement pure virtual functions. * You don't need to set any additional properties. * * But you may need to specify at least channel number or PSM in case it couldn't be * determined from UUID. It is also a good idea to provide name for the profile. * * Setting the channel number with setChannel() will make the profile use RFCOMM, while * setting the PSM with setPsm() will make the profile use L2CAP. * * @note The return value of requests will be sent asynchronously with Request class. * It is also possible to cancel/reject all requests. * */ class BLUEZQT_EXPORT Profile : public QObject { Q_OBJECT Q_PROPERTY(QString uuid READ uuid) public: /** Local role to identify sides in asymmetric profiles. */ enum LocalRole { /** Indicates that this is a client. */ ClientRole, /** Indicates that this is a server. */ ServerRole }; /** * Creates a new Profile object. * * @param parent */ explicit Profile(QObject *parent = nullptr); /** * Destroys a Profile object. */ ~Profile(); /** * D-Bus object path of the profile. * * The path where the profile will be registered. * * @note You must provide valid object path! * * @return object path of agent */ virtual QDBusObjectPath objectPath() const = 0; /** * UUID of the profile. * * @return UUID of the profile */ virtual QString uuid() const = 0; /** * Sets the human readable name of the profile. * * @param name name of the profile */ void setName(const QString &name); /** * Sets the primary service class UUID (if different from profile UUID). * * @param service service UUID */ void setService(const QString &service); /** * Sets the local role to identify side. * * For asymmetric profiles that do not have UUIDs available * to uniquely identify each side this parameter allows * specifying the precise local role. * * @param role local role */ void setLocalRole(LocalRole role); /** * Sets the RFCOMM channel number. * * Available channel number range is 0-31. * Setting channel number to 0 will automatically choose * correct channel number for profile UUID. * * @param channel channel number */ void setChannel(quint16 channel); /** * Sets the L2CAP port number. * * PSM (Protocol Service Multiplexer) is a port number * in L2CAP. * * Setting PSM to 0 will automatically choose correct * PSM for profile UUID. * * @param psm PSM */ void setPsm(quint16 psm); /** * Sets whether the pairing is required to connect. * * @param require require to pair */ void setRequireAuthentication(bool require); /** * Sets whether the authorization is required to connect. * * @param require require to authorize */ void setRequireAuthorization(bool require); /** * Sets whether the profile is automatically connected. * * In case of a client UUID this will force connection * of the RFCOMM or L2CAP channels when a remote device * is connected. * * @param autoConnect autoconnect the profile */ void setAutoConnect(bool autoConnect); /** * Sets a SDP record. * * This allows to provide a manual SDP record, otherwise it will * be generated automatically. * * @param serviceRecord SDP record */ void setServiceRecord(const QString &serviceRecord); /** * Sets the profile version. * * @param version version of the profile */ void setVersion(quint16 version); /** * Sets the profile features. * * @param features features of the profile */ void setFeatures(quint16 features); /** * Creates a socket from file descriptor. * * @param fd socket file descriptor * @return socket * * @see newConnection() */ QSharedPointer createSocket(const QDBusUnixFileDescriptor &fd); /** * Requests the new connection. * * Common properties: *
    *
  • quint16 Version - Profile version
  • *
  • quint16 Features - Profile features
  • *
* * To create socket from fd, you can use: * @code * QSharedPointer socket = createSocket(fd); * if (!socket->isValid()) { * delete socket; * request.cancel(); * return; * } * @endcode * * @param device device that requested connection * @param fd socket file descriptor * @param properties additional properties * @param request request to be used for sending reply */ virtual void newConnection(DevicePtr device, const QDBusUnixFileDescriptor &fd, const QVariantMap &properties, const Request<> &request); /** * Requests the disconnection of the profile. * * This method gets called when a profile gets disconnected. * * @param device device to be disconnected * @param request request to be used for sending reply */ virtual void requestDisconnection(DevicePtr device, const Request<> &request); /** * Indicates that the profile was unregistered. * * This method gets called when the Bluetooth daemon * unregisters the profile. * * A profile can use it to do cleanup tasks. There is no need * to unregister the profile, because when this method gets called * it has already been unregistered. * */ virtual void release(); private: class ProfilePrivate *const d; friend class Manager; }; } // namespace BluezQt #endif // BLUEZQT_PROFILE_H diff --git a/src/profile_p.h b/src/profile_p.h index 5af2938..13f7158 100644 --- a/src/profile_p.h +++ b/src/profile_p.h @@ -1,39 +1,25 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_PROFILE_P_H #define BLUEZQT_PROFILE_P_H #include namespace BluezQt { class ProfilePrivate { public: QVariantMap options; }; } // namepsace BluezQt #endif // BLUEZQT_PROFILE_P_H diff --git a/src/profileadaptor.cpp b/src/profileadaptor.cpp index 2e80e0a..57fe793 100644 --- a/src/profileadaptor.cpp +++ b/src/profileadaptor.cpp @@ -1,75 +1,61 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "profileadaptor.h" #include "profile.h" #include "manager.h" #include "device.h" #include #include #include namespace BluezQt { ProfileAdaptor::ProfileAdaptor(Profile *parent, Manager *manager) : QDBusAbstractAdaptor(parent) , m_profile(parent) , m_manager(manager) { } void ProfileAdaptor::NewConnection(const QDBusObjectPath &device, const QDBusUnixFileDescriptor &fd, const QVariantMap &properties, const QDBusMessage &msg) { msg.setDelayedReply(true); Request<> req(OrgBluezProfile, msg); DevicePtr dev = m_manager->deviceForUbi(device.path()); if (!dev) { req.cancel(); return; } m_profile->newConnection(dev, fd, properties, req); } void ProfileAdaptor::RequestDisconnection(const QDBusObjectPath &device, const QDBusMessage &msg) { msg.setDelayedReply(true); Request<> req(OrgBluezProfile, msg); DevicePtr dev = m_manager->deviceForUbi(device.path()); if (!dev) { req.cancel(); return; } m_profile->requestDisconnection(dev, req); } void ProfileAdaptor::Release() { m_profile->release(); } } // namespace BluezQt diff --git a/src/profileadaptor.h b/src/profileadaptor.h index 4ee3ffe..97b8b69 100644 --- a/src/profileadaptor.h +++ b/src/profileadaptor.h @@ -1,59 +1,45 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_PROFILEADAPTOR_H #define BLUEZQT_PROFILEADAPTOR_H #include class QDBusMessage; class QDBusObjectPath; class QDBusUnixFileDescriptor; namespace BluezQt { class Device; class Manager; class Profile; class ProfileAdaptor : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.bluez.Profile1") public: explicit ProfileAdaptor(Profile *parent, Manager *manager); public Q_SLOTS: void NewConnection(const QDBusObjectPath &device, const QDBusUnixFileDescriptor &fd, const QVariantMap &properties, const QDBusMessage &msg); void RequestDisconnection(const QDBusObjectPath &device, const QDBusMessage &msg); Q_NOREPLY void Release(); private: Profile *m_profile; Manager *m_manager; }; } // namespace BluezQt #endif // BLUEZQT_PROFILEADAPTOR_H diff --git a/src/request.cpp b/src/request.cpp index f99a50d..d15a286 100644 --- a/src/request.cpp +++ b/src/request.cpp @@ -1,211 +1,197 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014 David Rosca + * SPDX-FileCopyrightText: 2014 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "request.h" #include "debug.h" #include "utils.h" #include #include namespace BluezQt { class RequestPrivate { public: RequestOriginatingType m_type; QDBusMessage m_message; bool sendMessage(const QDBusMessage &msg); QString interfaceName(); void acceptRequest(const QVariant &val); void rejectRequest(); void cancelRequest(); }; bool RequestPrivate::sendMessage(const QDBusMessage &msg) { switch (m_type) { case OrgBluezAgent: case OrgBluezProfile: return DBusConnection::orgBluez().send(msg); case OrgBluezObexAgent: return DBusConnection::orgBluezObex().send(msg); default: return false; } } QString RequestPrivate::interfaceName() { switch (m_type) { case OrgBluezAgent: return QStringLiteral("org.bluez.Agent1"); case OrgBluezProfile: return QStringLiteral("org.bluez.Profile1"); case OrgBluezObexAgent: return QStringLiteral("org.bluez.obex.Agent1"); default: return QString(); } } void RequestPrivate::acceptRequest(const QVariant &val) { QDBusMessage reply; if (val.isValid()) { reply = m_message.createReply(val); } else { reply = m_message.createReply(); } if (!sendMessage(reply)) { qCWarning(BLUEZQT) << "Request: Failed to put reply on DBus queue"; } } void RequestPrivate::rejectRequest() { const QDBusMessage &reply = m_message.createErrorReply(interfaceName() % QStringLiteral(".Rejected"), QStringLiteral("Rejected")); if (!sendMessage(reply)) { qCWarning(BLUEZQT) << "Request: Failed to put reply on DBus queue"; } } void RequestPrivate::cancelRequest() { const QDBusMessage &reply = m_message.createErrorReply(interfaceName() % QStringLiteral(".Canceled"), QStringLiteral("Canceled")); if (!sendMessage(reply)) { qCWarning(BLUEZQT) << "Request: Failed to put reply on DBus queue"; } } // T template Request::Request() : d(new RequestPrivate) { } template Request::Request(RequestOriginatingType type, const QDBusMessage &message) : d(new RequestPrivate) { d->m_type = type; d->m_message = message; } template Request::~Request() { } template Request::Request(const Request &other) : d(other.d) { } template Request &Request::operator=(const Request &other) { if (d != other.d) { d = other.d; } return *this; } template void Request::accept(T returnValue) const { d->acceptRequest(returnValue); } template void Request::reject() const { d->rejectRequest(); } template void Request::cancel() const { d->cancelRequest(); } // void Request::Request() : d(new RequestPrivate) { } Request::Request(RequestOriginatingType type, const QDBusMessage &message) : d(new RequestPrivate) { d->m_type = type; d->m_message = message; } Request::~Request() { } Request::Request(const Request &other) : d(other.d) { } Request &Request::operator=(const Request &other) { if (d != other.d) { d = other.d; } return *this; } void Request::accept() const { d->acceptRequest(QVariant()); } void Request::reject() const { d->rejectRequest(); } void Request::cancel() const { d->cancelRequest(); } // Generate classes template class Request; template class Request; template class Request; template class Request; } // namespace BluezQt diff --git a/src/request.h b/src/request.h index acf34aa..87b0437 100644 --- a/src/request.h +++ b/src/request.h @@ -1,147 +1,133 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_REQUEST_H #define BLUEZQT_REQUEST_H #include #include "bluezqt_export.h" class QDBusMessage; namespace BluezQt { enum RequestOriginatingType { OrgBluezAgent, OrgBluezProfile, OrgBluezObexAgent, OrgBluezMediaEndpoint }; /** * @class BluezQt::Request request.h * * D-Bus request. * * This class represents a request from a Bluetooth daemon. It is a convenient * wrapper around QDBusMessage and easily allows sending replies and handling errors. * * @see Agent, ObexAgent, Profile */ template class BLUEZQT_EXPORT Request { public: /** * Creates a new Request object. */ explicit Request(); /** * Destroys a Request object. */ virtual ~Request(); /** * Copy constructor. * * @param other */ Request(const Request &other); /** * Copy assignment operator. * * @param other */ Request &operator=(const Request &other); /** * Accepts the request. * * This method should be called to send a reply to indicate * the request was accepted. * * In case the request is of type void, this method does not * take any parameter. * * @param returnValue return value of request */ void accept(T returnValue) const; /** * Rejects the request. * * This method should be called to send an error reply to * indicate the request was rejected. */ void reject() const; /** * Cancels the request. * * This method should be called to send an error reply to * indicate the request was canceled. */ void cancel() const; private: explicit Request(RequestOriginatingType type, const QDBusMessage &message); QSharedPointer d; friend class AgentAdaptor; friend class ObexAgentAdaptor; friend class ProfileAdaptor; friend class MediaEndpointAdaptor; }; // void template<> class BLUEZQT_EXPORT Request { public: explicit Request(); virtual ~Request(); Request(const Request &other); Request &operator=(const Request &other); void accept() const; void reject() const; void cancel() const; private: explicit Request(RequestOriginatingType type, const QDBusMessage &message); QSharedPointer d; friend class AgentAdaptor; friend class ObexAgentAdaptor; friend class ProfileAdaptor; }; } // namespace BluezQt #endif // BLUEZQT_REQUEST_H diff --git a/src/rfkill.cpp b/src/rfkill.cpp index be8f90b..af4baed 100644 --- a/src/rfkill.cpp +++ b/src/rfkill.cpp @@ -1,262 +1,248 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "rfkill.h" #include "debug.h" #ifdef Q_OS_LINUX #include #include #include #include #endif #include namespace BluezQt { #ifdef Q_OS_LINUX enum rfkill_type { RFKILL_TYPE_ALL = 0, RFKILL_TYPE_WLAN, RFKILL_TYPE_BLUETOOTH, RFKILL_TYPE_UWB, RFKILL_TYPE_WIMAX, RFKILL_TYPE_WWAN }; enum rfkill_operation { RFKILL_OP_ADD = 0, RFKILL_OP_DEL, RFKILL_OP_CHANGE, RFKILL_OP_CHANGE_ALL }; struct rfkill_event { quint32 idx; quint8 type; quint8 op; quint8 soft; quint8 hard; }; #endif Rfkill::Rfkill(QObject *parent) : QObject(parent) , m_readFd(-1) , m_writeFd(-1) , m_state(Unknown) { init(); } Rfkill::~Rfkill() { #ifdef Q_OS_LINUX if (m_readFd != -1) { ::close(m_readFd); } if (m_writeFd != -1) { ::close(m_writeFd); } #endif } Rfkill::State Rfkill::state() const { return m_state; } bool Rfkill::block() { if (m_state == SoftBlocked || m_state == HardBlocked) { return true; } if (m_state != Unblocked) { return false; } return setSoftBlock(1); } bool Rfkill::unblock() { if (m_state == Unblocked) { return true; } if (m_state != SoftBlocked) { return false; } return setSoftBlock(0); } void Rfkill::devReadyRead() { State oldState = m_state; updateRfkillDevices(); if (m_state != oldState) { Q_EMIT stateChanged(m_state); } } void Rfkill::init() { #ifdef Q_OS_LINUX m_readFd = ::open("/dev/rfkill", O_RDONLY | O_CLOEXEC); if (m_readFd == -1) { qCWarning(BLUEZQT) << "Cannot open /dev/rfkill for reading!"; return; } if (::fcntl(m_readFd, F_SETFL, O_NONBLOCK) < 0) { ::close(m_readFd); m_readFd = -1; return; } updateRfkillDevices(); QSocketNotifier *notifier = new QSocketNotifier(m_readFd, QSocketNotifier::Read, this); connect(notifier, &QSocketNotifier::activated, this, &Rfkill::devReadyRead); #endif } bool Rfkill::openForWriting() { #ifndef Q_OS_LINUX return false; #else if (m_writeFd != -1) { return true; } m_writeFd = ::open("/dev/rfkill", O_WRONLY | O_CLOEXEC); if (m_writeFd == -1) { qCWarning(BLUEZQT) << "Cannot open /dev/rfkill for writing!"; return false; } if (::fcntl(m_writeFd, F_SETFL, O_NONBLOCK) < 0) { ::close(m_writeFd); m_writeFd = -1; return false; } return true; #endif } #ifdef Q_OS_LINUX static Rfkill::State getState(const rfkill_event &event) { if (event.hard) { return Rfkill::HardBlocked; } else if (event.soft) { return Rfkill::SoftBlocked; } return Rfkill::Unblocked; } #endif void Rfkill::updateRfkillDevices() { #ifdef Q_OS_LINUX if (m_readFd == -1) { return; } rfkill_event event; while (::read(m_readFd, &event, sizeof(event)) == sizeof(event)) { if (event.type != RFKILL_TYPE_BLUETOOTH) { continue; } switch (event.op) { case RFKILL_OP_ADD: case RFKILL_OP_CHANGE: m_devices[event.idx] = getState(event); break; case RFKILL_OP_DEL: m_devices.remove(event.idx); break; case RFKILL_OP_CHANGE_ALL: for (auto it = m_devices.begin(); it != m_devices.end(); ++it) { it.value() = getState(event); } break; default: break; } } // Update global state m_state = Unknown; for (State state : qAsConst(m_devices)) { Q_ASSERT(state != Unknown); if (m_state == Unknown) { m_state = state; } else if (state > m_state) { m_state = state; } } qCDebug(BLUEZQT) << "Rfkill global state changed:" << m_state; #endif } bool Rfkill::setSoftBlock(quint8 soft) { #ifndef Q_OS_LINUX Q_UNUSED(soft) return false; #else if (!openForWriting()) { return false; } rfkill_event event; ::memset(&event, 0, sizeof(event)); event.op = RFKILL_OP_CHANGE_ALL; event.type = RFKILL_TYPE_BLUETOOTH; event.soft = soft; bool ret = ::write(m_writeFd, &event, sizeof(event)) == sizeof(event); qCDebug(BLUEZQT) << "Setting Rfkill soft block succeeded:" << ret; return ret; #endif } } // namespace BluezQt diff --git a/src/rfkill.h b/src/rfkill.h index 176045d..a7976bf 100644 --- a/src/rfkill.h +++ b/src/rfkill.h @@ -1,71 +1,57 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_RFKILL_H #define BLUEZQT_RFKILL_H #include #include namespace BluezQt { class Rfkill : public QObject { Q_OBJECT public: enum State { Unblocked = 0, SoftBlocked = 1, HardBlocked = 2, Unknown = 3 }; explicit Rfkill(QObject *parent = nullptr); ~Rfkill(); State state() const; bool block(); bool unblock(); Q_SIGNALS: void stateChanged(State state); private Q_SLOTS: void devReadyRead(); private: void init(); bool openForWriting(); void updateRfkillDevices(); bool setSoftBlock(quint8 soft); int m_readFd; int m_writeFd; State m_state; QHash m_devices; }; } // namespace BluezQt #endif // BLUEZQT_RFKILL_H diff --git a/src/services.h b/src/services.h index 2a4144c..ecc021f 100644 --- a/src/services.h +++ b/src/services.h @@ -1,69 +1,55 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_SERVICES_H #define BLUEZQT_SERVICES_H #include namespace BluezQt { /** Service UUIDs. */ namespace Services { const QString ServiceDiscoveryServer = QLatin1String("00001000-0000-1000-8000-00805F9B34FB"); const QString SerialPort = QLatin1String("00001101-0000-1000-8000-00805F9B34FB"); const QString DialupNetworking = QLatin1String("00001103-0000-1000-8000-00805F9B34FB"); const QString ObexObjectPush = QLatin1String("00001105-0000-1000-8000-00805F9B34FB"); const QString ObexFileTransfer = QLatin1String("00001106-0000-1000-8000-00805F9B34FB"); const QString Headset = QLatin1String("00001108-0000-1000-8000-00805F9B34FB"); const QString AudioSource = QLatin1String("0000110A-0000-1000-8000-00805F9B34FB"); const QString AudioSink = QLatin1String("0000110B-0000-1000-8000-00805F9B34FB"); const QString AudioVideoRemoteControlTarget = QLatin1String("0000110C-0000-1000-8000-00805F9B34FB"); const QString AdvancedAudioDistribution = QLatin1String("0000110D-0000-1000-8000-00805F9B34FB"); const QString AudioVideoRemoteControl = QLatin1String("0000110E-0000-1000-8000-00805F9B34FB"); const QString HeadsetAudioGateway = QLatin1String("00001112-0000-1000-8000-00805F9B34FB"); const QString Panu = QLatin1String("00001115-0000-1000-8000-00805F9B34FB"); const QString Nap = QLatin1String("00001116-0000-1000-8000-00805F9B34FB"); const QString Handsfree = QLatin1String("0000111E-0000-1000-8000-00805F9B34FB"); const QString HandsfreeAudioGateway = QLatin1String("0000111F-0000-1000-8000-00805F9B34FB"); const QString HumanInterfaceDevice = QLatin1String("00001124-0000-1000-8000-00805F9B34FB"); const QString SimAccess = QLatin1String("0000112D-0000-1000-8000-00805F9B34FB"); const QString PhonebookAccessServer = QLatin1String("0000112F-0000-1000-8000-00805F9B34FB"); const QString MessageAccessServer = QLatin1String("00001132-0000-1000-8000-00805F9B34FB"); const QString PnpInformation = QLatin1String("00001200-0000-1000-8000-00805F9B34FB"); // Bluetooth Low Energy const QString GenericAcces = QLatin1String("00001800-0000-1000-8000-00805f9b34fb"); const QString GenericAttribute = QLatin1String("00001801-0000-1000-8000-00805f9b34fb"); const QString ImmediateAlert = QLatin1String("00001802-0000-1000-8000-00805f9b34fb"); const QString LinkLoss = QLatin1String("00001803-0000-1000-8000-00805f9b34fb"); const QString TxPower = QLatin1String("00001804-0000-1000-8000-00805f9b34fb"); const QString HeartRate = QLatin1String("0000180d-0000-1000-8000-00805f9b34fb"); } } // namespace BluezQt #endif // BLUEZQT_SERVICES_H diff --git a/src/tpendingcall.h b/src/tpendingcall.h index 7baeca5..6c171a1 100644 --- a/src/tpendingcall.h +++ b/src/tpendingcall.h @@ -1,102 +1,88 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include #include "pendingcall.h" namespace BluezQt { using namespace std::placeholders; /** * @class BluezQt::TPendingCall tpendingcall.h * * Pending method call (template version). * * This class represents a pending method call. It is a convenient wrapper * around QDBusPendingReply and QDBusPendingCallWatcher. * The TPendingCall is a template class whose parameters are the types that will * be used to extract the contents of the reply's data. */ // KF6 TODO: convert all PendingCalls to TPendingCall (or convert existing PendingCall class to templated version). template class TPendingCall : public PendingCall { private: template struct Select { using Type = typename Select::Type; }; template struct Select<0, Ty, Ts...> { using Type = Ty; }; public: /** * Returns a return value at given index of the call. * * Returns the return value at position Index (which is a template parameter) cast to type Type. * This function uses template code to determine the proper Type type, according to the type * list used in the construction of this object. * * @return return value at index */ template inline const typename Select::Type valueAt() const { using ResultType = typename Select::Type; return qdbus_cast(m_reply.argumentAt(Index), nullptr); } private: TPendingCall(const QDBusPendingCall &call, QObject *parent = nullptr) : PendingCall(call, std::bind(&TPendingCall::process, this, _1, _2, _3), parent) { } void process(QDBusPendingCallWatcher *watcher, ErrorProcessor errorProcessor, QVariantList *values) { m_reply = *watcher; errorProcessor(m_reply.error()); if (m_reply.isError()) { return; } for (int i = 0; i < m_reply.count(); ++i) { values->append(m_reply.argumentAt(i)); } } QDBusPendingReply m_reply; friend class MediaTransport; }; } // namespace BluezQt diff --git a/src/types.h b/src/types.h index 48bac0f..7aa29c8 100644 --- a/src/types.h +++ b/src/types.h @@ -1,73 +1,59 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_TYPES_H #define BLUEZQT_TYPES_H #include namespace BluezQt { class Manager; class Adapter; class Battery; class Device; class Input; class GattManager; class LEAdvertisingManager; class Media; class MediaPlayer; class MediaPlayerTrack; class MediaTransport; class Agent; class DevicesModel; class InitManagerJob; class Profile; class PendingCall; class ObexManager; class ObexSession; class ObexTransfer; class InitObexManagerJob; class ObexAgent; class ObexFileTransfer; class ObexFileTransferEntry; class ObexObjectPush; class GattApplication; typedef QSharedPointer ManagerPtr; typedef QSharedPointer AdapterPtr; typedef QSharedPointer BatteryPtr; typedef QSharedPointer DevicePtr; typedef QSharedPointer InputPtr; typedef QSharedPointer GattManagerPtr; typedef QSharedPointer LEAdvertisingManagerPtr; typedef QSharedPointer MediaPtr; typedef QSharedPointer MediaPlayerPtr; typedef QSharedPointer MediaTransportPtr; typedef QSharedPointer ObexManagerPtr; typedef QSharedPointer ObexSessionPtr; typedef QSharedPointer ObexTransferPtr; } // namespace BluezQt #endif // BLUEZQT_TYPES_H diff --git a/src/utils.cpp b/src/utils.cpp index 3768324..744f1fc 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,333 +1,319 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "utils.h" #include "manager.h" #include "obexmanager.h" #include "bluezqt_export.h" #include #include #include namespace BluezQt { class GlobalData { public: explicit GlobalData(); bool testRun; QString orgFreedesktopDBus; QString orgFreedesktopDBusProperties; QString orgBluez; QString orgBluezAdapter1; QString orgBluezBattery1; QString orgBluezDevice1; QString orgBluezInput1; QString orgBluezGattManager1; QString orgBluezLEAdvertisingManager1; QString orgBluezMedia1; QString orgBluezMediaPlayer1; QString orgBluezMediaTransport1; QString orgBluezAgentManager1; QString orgBluezProfileManager1; QString orgBluezObex; QString orgBluezObexClient1; QString orgBluezObexAgentManager1; QString orgBluezObexSession1; QString orgBluezObexTransfer1; QPointer manager; QPointer obexManager; }; GlobalData::GlobalData() { testRun = false; orgFreedesktopDBus = QStringLiteral("org.freedesktop.DBus"); orgFreedesktopDBusProperties = QStringLiteral("org.freedesktop.DBus.Properties"); orgBluez = QStringLiteral("org.bluez"); orgBluezAdapter1 = QStringLiteral("org.bluez.Adapter1"); orgBluezBattery1 = QStringLiteral("org.bluez.Battery1"); orgBluezDevice1 = QStringLiteral("org.bluez.Device1"); orgBluezInput1 = QStringLiteral("org.bluez.Input1"); orgBluezGattManager1 = QStringLiteral("org.bluez.GattManager1"); orgBluezLEAdvertisingManager1 = QStringLiteral("org.bluez.LEAdvertisingManager1"); orgBluezMedia1 = QStringLiteral("org.bluez.Media1"); orgBluezMediaPlayer1 = QStringLiteral("org.bluez.MediaPlayer1"); orgBluezMediaTransport1 = QStringLiteral("org.bluez.MediaTransport1"); orgBluezAgentManager1 = QStringLiteral("org.bluez.AgentManager1"); orgBluezProfileManager1 = QStringLiteral("org.bluez.ProfileManager1"); orgBluezObex = QStringLiteral("org.bluez.obex"); orgBluezObexClient1 = QStringLiteral("org.bluez.obex.Client1"); orgBluezObexAgentManager1 = QStringLiteral("org.bluez.obex.AgentManager1"); orgBluezObexSession1 = QStringLiteral("org.bluez.obex.Session1"); orgBluezObexTransfer1 = QStringLiteral("org.bluez.obex.Transfer1"); } Q_GLOBAL_STATIC(GlobalData, globalData) // For fakebluez tests BLUEZQT_EXPORT void bluezqt_initFakeBluezTestRun() { globalData->testRun = true; globalData->orgBluez = QStringLiteral("org.kde.bluezqt.fakebluez"); globalData->orgBluezObex = QStringLiteral("org.kde.bluezqt.fakebluez"); } QString Strings::orgFreedesktopDBus() { return globalData->orgFreedesktopDBus; } QString Strings::orgFreedesktopDBusProperties() { return globalData->orgFreedesktopDBusProperties; } QString Strings::orgBluez() { return globalData->orgBluez; } QString Strings::orgBluezAdapter1() { return globalData->orgBluezAdapter1; } QString Strings::orgBluezBattery1() { return globalData->orgBluezBattery1; } QString Strings::orgBluezDevice1() { return globalData->orgBluezDevice1; } QString Strings::orgBluezInput1() { return globalData->orgBluezInput1; } QString Strings::orgBluezGattManager1() { return globalData->orgBluezGattManager1; } QString Strings::orgBluezLEAdvertisingManager1() { return globalData->orgBluezLEAdvertisingManager1; } QString Strings::orgBluezMedia1() { return globalData->orgBluezMedia1; } QString Strings::orgBluezMediaPlayer1() { return globalData->orgBluezMediaPlayer1; } QString Strings::orgBluezMediaTransport1() { return globalData->orgBluezMediaTransport1; } QString Strings::orgBluezAgentManager1() { return globalData->orgBluezAgentManager1; } QString Strings::orgBluezProfileManager1() { return globalData->orgBluezProfileManager1; } QString Strings::orgBluezObex() { return globalData->orgBluezObex; } QString Strings::orgBluezObexClient1() { return globalData->orgBluezObexClient1; } QString Strings::orgBluezObexAgentManager1() { return globalData->orgBluezObexAgentManager1; } QString Strings::orgBluezObexSession1() { return globalData->orgBluezObexSession1; } QString Strings::orgBluezObexTransfer1() { return globalData->orgBluezObexTransfer1; } QDBusConnection DBusConnection::orgBluez() { if (globalData->testRun) { return QDBusConnection::sessionBus(); } return QDBusConnection::systemBus(); } QDBusConnection DBusConnection::orgBluezObex() { return QDBusConnection::sessionBus(); } Manager *Instance::manager() { return globalData->manager; } void Instance::setManager(Manager *manager) { globalData->manager = manager; } ObexManager *Instance::obexManager() { return globalData->obexManager; } void Instance::setObexManager(ObexManager *obexManager) { globalData->obexManager = obexManager; } QStringList stringListToUpper(const QStringList &list) { QStringList converted; converted.reserve(list.size()); for (const QString &str : list) { converted.append(str.toUpper()); } return converted; } Device::Type classToType(quint32 classNum) { switch ((classNum & 0x1f00) >> 8) { case 0x01: return Device::Computer; case 0x02: switch ((classNum & 0xfc) >> 2) { case 0x04: return Device::Modem; default: return Device::Phone; } case 0x03: return Device::Network; case 0x04: switch ((classNum & 0xfc) >> 2) { case 0x01: case 0x02: return Device::Headset; case 0x06: return Device::Headphones; default: return Device::AudioVideo; } case 0x05: switch ((classNum & 0xc0) >> 6) { case 0x00: switch ((classNum & 0x1e) >> 2) { case 0x01: case 0x02: return Device::Joypad; } break; case 0x01: return Device::Keyboard; case 0x02: switch ((classNum & 0x1e) >> 2) { case 0x05: return Device::Tablet; default: return Device::Mouse; } } return Device::Peripheral; case 0x06: if (classNum & 0x80) { return Device::Printer; } else if (classNum & 0x20) { return Device::Camera; } return Device::Imaging; case 0x07: return Device::Wearable; case 0x08: return Device::Toy; case 0x09: return Device::Health; default: return Device::Uncategorized; } } Device::Type appearanceToType(quint16 appearance) { switch ((appearance & 0xffc0) >> 6) { case 0x00: return Device::Uncategorized; case 0x01: // Generic Phone return Device::Phone; case 0x02: // Generic Computer return Device::Computer; case 0x05: // Generic Display return Device::AudioVideo; case 0x0a: // Generic Media Player return Device::AudioVideo; case 0x0b: // Generic Barcode Scanner return Device::Peripheral; case 0x0f: // Generic HID switch (appearance & 0x3f) { case 0x01: // Keyboard return Device::Keyboard; case 0x02: // Mouse return Device::Mouse; case 0x03: // Joystick case 0x04: // Gamepad return Device::Joypad; case 0x05: // Digitizer Tablet return Device::Tablet; case 0x08: // Barcode Scanner return Device::Peripheral; } // fall-through default: return Device::Uncategorized; } } } // namespace BluezQt diff --git a/src/utils.h b/src/utils.h index 94c1eed..bb7cd5f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,85 +1,71 @@ /* * BluezQt - Asynchronous Bluez wrapper library * - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef BLUEZQT_UTILS_H #define BLUEZQT_UTILS_H #include "device.h" class QString; class QStringList; class QDBusConnection; namespace BluezQt { namespace Strings { QString orgFreedesktopDBus(); QString orgFreedesktopDBusProperties(); QString orgBluez(); QString orgBluezAdapter1(); QString orgBluezBattery1(); QString orgBluezDevice1(); QString orgBluezInput1(); QString orgBluezGattManager1(); QString orgBluezLEAdvertisingManager1(); QString orgBluezMedia1(); QString orgBluezMediaPlayer1(); QString orgBluezMediaTransport1(); QString orgBluezAgentManager1(); QString orgBluezProfileManager1(); QString orgBluezObex(); QString orgBluezObexClient1(); QString orgBluezObexAgentManager1(); QString orgBluezObexSession1(); QString orgBluezObexTransfer1(); } namespace DBusConnection { QDBusConnection orgBluez(); QDBusConnection orgBluezObex(); } namespace Instance { Manager *manager(); void setManager(Manager *manager); ObexManager *obexManager(); void setObexManager(ObexManager *obexManager); } QStringList stringListToUpper(const QStringList &list); Device::Type classToType(quint32 classNum); Device::Type appearanceToType(quint16 appearance); } // namespace BluezQt #endif // BLUEZQT_UTILS_H diff --git a/tests/adaptersreceiver.cpp b/tests/adaptersreceiver.cpp index 40186b5..cb966d2 100644 --- a/tests/adaptersreceiver.cpp +++ b/tests/adaptersreceiver.cpp @@ -1,105 +1,91 @@ /* - * Copyright (C) 2011 Rafael Fernández López - * Copyright (C) 2011 UFO Coders - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2011 Rafael Fernández López + * SPDX-FileCopyrightText: 2011 UFO Coders + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "adaptersreceiver.h" #include #include #include "adapter.h" #include "initmanagerjob.h" using namespace BluezQt; AdaptersReceiver::AdaptersReceiver(Manager *manager, QObject *parent) : QObject(parent) , m_manager(manager) { connect(manager, &Manager::adapterAdded, this, &AdaptersReceiver::adapterAdded); connect(manager, &Manager::adapterRemoved, this, &AdaptersReceiver::adapterRemoved); connect(manager, &Manager::usableAdapterChanged, this, &AdaptersReceiver::usableAdapterChanged); connect(manager, &Manager::allAdaptersRemoved, this, &AdaptersReceiver::allAdaptersRemoved); connect(manager, &Manager::bluetoothOperationalChanged, this, &AdaptersReceiver::bluetoothOperationalChanged); connect(manager, &Manager::bluetoothBlockedChanged, this, &AdaptersReceiver::bluetoothBlockedChanged); } void AdaptersReceiver::adapterAdded(const BluezQt::AdapterPtr &adapter) { qDebug() << "Adapter added: " << adapter->name(); printStatus(); } void AdaptersReceiver::adapterRemoved(const BluezQt::AdapterPtr &adapter) { qDebug() << "Adapter removed: " << adapter->name(); printStatus(); } void AdaptersReceiver::usableAdapterChanged(const BluezQt::AdapterPtr &adapter) { qDebug() << "Usable adapter changed: " << adapter; printStatus(); } void AdaptersReceiver::allAdaptersRemoved() { qDebug() << "All adapters have been removed"; printStatus(); } void AdaptersReceiver::bluetoothOperationalChanged(bool operational) { qDebug() << "Bluetooth operational changed: " << operational; printStatus(); } void AdaptersReceiver::bluetoothBlockedChanged(bool blocked) { qDebug() << "Bluetooth blocked changed: " << blocked; printStatus(); } void AdaptersReceiver::printStatus() { qDebug() << "\tBluetooth Blocked: " << m_manager->isBluetoothBlocked(); qDebug() << "\tBluetooth Operational: " << m_manager->isBluetoothOperational(); qDebug() << "\tUsable Adapter: " << m_manager->usableAdapter(); qDebug() << ""; } int main(int argc, char **argv) { QCoreApplication app(argc, argv); qDebug() << "Looping until stopped"; Manager *manager = new Manager(); InitManagerJob *initJob = manager->init(); initJob->exec(); if (initJob->error()) { qWarning() << "Error initializing manager:" << initJob->errorText(); return 1; } new AdaptersReceiver(manager); return app.exec(); } diff --git a/tests/adaptersreceiver.h b/tests/adaptersreceiver.h index a1a540f..474db70 100644 --- a/tests/adaptersreceiver.h +++ b/tests/adaptersreceiver.h @@ -1,50 +1,36 @@ /* - * Copyright (C) 2011 Rafael Fernández López - * Copyright (C) 2011 UFO Coders - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2011 Rafael Fernández López + * SPDX-FileCopyrightText: 2011 UFO Coders + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef ADAPTERSRECEIVER_H #define ADAPTERSRECEIVER_H #include #include "manager.h" class AdaptersReceiver : public QObject { Q_OBJECT public: explicit AdaptersReceiver(BluezQt::Manager *manager, QObject *parent = nullptr); public Q_SLOTS: void adapterAdded(const BluezQt::AdapterPtr &adapter); void adapterRemoved(const BluezQt::AdapterPtr &adapter); void usableAdapterChanged(const BluezQt::AdapterPtr &adapter); void allAdaptersRemoved(); void bluetoothOperationalChanged(bool operational); void bluetoothBlockedChanged(bool blocked); void printStatus(); private: BluezQt::Manager *m_manager; }; #endif // ADAPTERSRECEIVER_H diff --git a/tests/chatprofile.cpp b/tests/chatprofile.cpp index a20bd8b..bd29719 100644 --- a/tests/chatprofile.cpp +++ b/tests/chatprofile.cpp @@ -1,127 +1,113 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "chatprofile.h" #include "manager.h" #include "initmanagerjob.h" #include "pendingcall.h" #include #include #include #include #include #include // This is a server for BluetoothChat application from Android samples. // // On successful connection, it sends "test-data" message to the client // and then writes all messages from client to the standard output. // // https://developer.android.com/samples/BluetoothChat/index.html ChatProfile::ChatProfile(QObject *parent) : BluezQt::Profile(parent) { setName(QStringLiteral("BluetoothChatSecure")); setChannel(0); } QDBusObjectPath ChatProfile::objectPath() const { return QDBusObjectPath(QStringLiteral("/ChatProfile")); } QString ChatProfile::uuid() const { return QStringLiteral("fa87c0d0-afac-11de-8a39-0800200c9a66"); } void ChatProfile::newConnection(BluezQt::DevicePtr device, const QDBusUnixFileDescriptor &fd, const QVariantMap &properties, const BluezQt::Request<> &request) { qDebug() << "Connect" << device->name() << properties; m_socket = createSocket(fd); if (!m_socket->isValid()) { request.cancel(); return; } connect(m_socket.data(), &QLocalSocket::readyRead, this, &ChatProfile::socketReadyRead); connect(m_socket.data(), &QLocalSocket::disconnected, this, &ChatProfile::socketDisconnected); QTimer::singleShot(1000, this, SLOT(writeToSocket())); request.accept(); } void ChatProfile::requestDisconnection(BluezQt::DevicePtr device, const BluezQt::Request<> &request) { qDebug() << "Disconnect" << device->name(); request.accept(); } void ChatProfile::release() { qDebug() << "Release"; } void ChatProfile::socketReadyRead() { qDebug() << "Read:" << m_socket->socketDescriptor() << m_socket->readAll(); } void ChatProfile::socketDisconnected() { qDebug() << "Socket disconnected"; m_socket.clear(); } void ChatProfile::writeToSocket() { qDebug() << "Writing" << m_socket->socketDescriptor(); m_socket->write(QByteArrayLiteral("test-data")); } int main(int argc, char **argv) { QCoreApplication app(argc, argv); BluezQt::Manager *manager = new BluezQt::Manager(); BluezQt::InitManagerJob *initJob = manager->init(); initJob->exec(); if (initJob->error()) { qWarning() << "Error initializing manager:" << initJob->errorText(); return 1; } BluezQt::PendingCall *call = manager->registerProfile(new ChatProfile(&app)); call->waitForFinished(); if (call->error()) { qWarning() << "Error registering profile" << call->errorText(); return 1; } qDebug() << "Profile registered"; return app.exec(); } diff --git a/tests/chatprofile.h b/tests/chatprofile.h index 978a096..e2274bc 100644 --- a/tests/chatprofile.h +++ b/tests/chatprofile.h @@ -1,52 +1,38 @@ /* - * Copyright (C) 2015 David Rosca + * SPDX-FileCopyrightText: 2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef CHATPROFILE_H #define CHATPROFILE_H #include "profile.h" #include "device.h" class QLocalSocket; class ChatProfile : public BluezQt::Profile { Q_OBJECT public: explicit ChatProfile(QObject *parent); QDBusObjectPath objectPath() const override; QString uuid() const override; void newConnection(BluezQt::DevicePtr device, const QDBusUnixFileDescriptor &fd, const QVariantMap &properties, const BluezQt::Request<> &request) override; void requestDisconnection(BluezQt::DevicePtr device, const BluezQt::Request<> &request) override; void release() override; private Q_SLOTS: void socketReadyRead(); void socketDisconnected(); void writeToSocket(); private: QSharedPointer m_socket; }; #endif // CHATPROFILE_H diff --git a/tests/devicereceiver.cpp b/tests/devicereceiver.cpp index 66aff0a..3b28cb7 100644 --- a/tests/devicereceiver.cpp +++ b/tests/devicereceiver.cpp @@ -1,121 +1,107 @@ /* - * Copyright (C) 2010 Rafael Fernández López - * Copyright (C) 2010 UFO Coders - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2010 Rafael Fernández López + * SPDX-FileCopyrightText: 2010 UFO Coders + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "devicereceiver.h" #include #include #include "adapter.h" #include "device.h" #include "pendingcall.h" #include "initmanagerjob.h" using namespace BluezQt; Manager *g_manager = nullptr; DeviceReceiver::DeviceReceiver(QObject *parent) : QObject(parent) { } void DeviceReceiver::scanDevices() { AdapterPtr usableAdapter = g_manager->usableAdapter(); if (!usableAdapter && g_manager->adapters().isEmpty()) { qDebug() << "!!! No bluetooth adapters were found. Waiting for bluetooth adapters. Ctrl + C to cancel..."; connect(g_manager, &Manager::adapterAdded, this, &DeviceReceiver::adapterAdded); return; } else if (!usableAdapter) { usableAdapter = g_manager->adapters().at(0); PendingCall *powerOnCall = usableAdapter->setPowered(true); powerOnCall->waitForFinished(); } qDebug() << "*** Will scan devices until stopped..."; qDebug(); connect(usableAdapter.data(), &Adapter::deviceAdded, this, &DeviceReceiver::deviceFound); connect(usableAdapter.data(), &Adapter::deviceChanged, this, &DeviceReceiver::devicePropertyChanged); usableAdapter->startDiscovery(); } void DeviceReceiver::deviceFound(const BluezQt::DevicePtr &device) { qDebug() << "*** Remote device found:" << device->name() << "(" << device->address() << ")"; qDebug(); } void DeviceReceiver::devicePropertyChanged(const BluezQt::DevicePtr &device) { qDebug() << "*** Device with address" << device->address() << "changed some property"; qDebug() << "\tAddress:\t" << device->address(); qDebug() << "\tClass:\t\t" << device->deviceClass(); qDebug() << "\tIcon:\t\t" << device->icon(); qDebug() << "\tLegacy Pairing:\t" << (device->hasLegacyPairing() ? "yes" : "no"); qDebug() << "\tName:\t\t" << device->name(); qDebug() << "\tPaired:\t\t" << (device->isPaired() ? "yes" : "no"); qDebug() << "\tTrusted:\t" << (device->isTrusted() ? "yes" : "no"); qDebug() << "\tServices:\n" << device->uuids(); qDebug(); } void DeviceReceiver::adapterAdded(const BluezQt::AdapterPtr &adapter) { Q_UNUSED(adapter) qDebug() << "*** An adapter has been connected."; qDebug(); scanDevices(); } static void stopDiscovering() { if (g_manager) { for (const AdapterPtr &adapter : g_manager->adapters()) { adapter->stopDiscovery(); } } } int main(int argc, char **argv) { QCoreApplication app(argc, argv); qAddPostRoutine(stopDiscovering); g_manager = new Manager(); InitManagerJob *initJob = g_manager->init(); initJob->exec(); if (initJob->error()) { qWarning() << "Error initializing manager:" << initJob->errorText(); return 1; } DeviceReceiver *deviceReceiver = new DeviceReceiver(); deviceReceiver->scanDevices(); return app.exec(); } diff --git a/tests/devicereceiver.h b/tests/devicereceiver.h index 8b7ec8f..9f061e8 100644 --- a/tests/devicereceiver.h +++ b/tests/devicereceiver.h @@ -1,46 +1,32 @@ /* - * Copyright (C) 2010 Rafael Fernández López - * Copyright (C) 2010 UFO Coders - * Copyright (C) 2014-2015 David Rosca + * SPDX-FileCopyrightText: 2010 Rafael Fernández López + * SPDX-FileCopyrightText: 2010 UFO Coders + * SPDX-FileCopyrightText: 2014-2015 David Rosca * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef DEVICERECEIVERTEST_H #define DEVICERECEIVERTEST_H #include #include "manager.h" class DeviceReceiver : public QObject { Q_OBJECT public: explicit DeviceReceiver(QObject *parent = nullptr); void scanDevices(); public Q_SLOTS: void deviceFound(const BluezQt::DevicePtr &device); void devicePropertyChanged(const BluezQt::DevicePtr &device); void adapterAdded(const BluezQt::AdapterPtr &adapter); }; #endif // DEVICERECEIVERTEST_H diff --git a/tests/leserver.cpp b/tests/leserver.cpp index 987af3b..7c09422 100644 --- a/tests/leserver.cpp +++ b/tests/leserver.cpp @@ -1,93 +1,79 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "leserver.h" #include #include #include "adapter.h" #include "device.h" #include "gattapplication.h" #include "gattcharacteristic.h" #include "gattmanager.h" #include "gattservice.h" #include "initmanagerjob.h" #include "leadvertisement.h" #include "leadvertisingmanager.h" #include "manager.h" #include "pendingcall.h" using namespace BluezQt; LeServer::LeServer(Manager *manager, QObject *parent) : QObject(parent), m_manager(manager) { auto advertisement = new LEAdvertisement({QStringLiteral("ad100000-d901-11e8-9f8b-f2801f1b9fd1")}, this); auto call = m_manager->usableAdapter()->leAdvertisingManager()->registerAdvertisement(advertisement); connect(call, &PendingCall::finished, this, &LeServer::onCallFinished); auto application = new GattApplication(QStringLiteral("/org/kde/bluezqt"), this); auto service = new GattService(QStringLiteral("ad100000-d901-11e8-9f8b-f2801f1b9fd1"), true, application); new GattCharacteristic(QStringLiteral("ad10e100-d901-11e8-9f8b-f2801f1b9fd1"), service); auto call2 = m_manager->usableAdapter()->gattManager()->registerApplication(application); connect(call2, &PendingCall::finished, this, &LeServer::onCallFinished); } void LeServer::onCallFinished(BluezQt::PendingCall *call) { if (call->error()) { qWarning() << "Error: " << call->errorText(); return; } } int main(int argc, char **argv) { QCoreApplication app(argc, argv); qDebug() << "Advertising LE services. Ctrl + C to cancel..."; Manager *manager = new Manager(); InitManagerJob *initJob = manager->init(); initJob->exec(); if (initJob->error()) { qWarning() << "Error initializing manager:" << initJob->errorText(); return 1; } if (!manager->usableAdapter()) { qWarning() << "No usable adapter"; return 2; } if (!manager->usableAdapter()->leAdvertisingManager()) { qWarning() << "No LE advertising manager"; return 2; } if (!manager->usableAdapter()->gattManager()) { qWarning() << "No GATT manager"; return 2; } new LeServer(manager); return app.exec(); } diff --git a/tests/leserver.h b/tests/leserver.h index 88c08d0..c5e434b 100644 --- a/tests/leserver.h +++ b/tests/leserver.h @@ -1,43 +1,29 @@ /* - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include #include "types.h" namespace BluezQt { class PendingCall; } class LeServer : public QObject { Q_OBJECT public: explicit LeServer(BluezQt::Manager *manager, QObject *parent = nullptr); private: void onCallFinished(BluezQt::PendingCall *call); BluezQt::Manager *m_manager; }; diff --git a/tests/mediaendpointconnector.cpp b/tests/mediaendpointconnector.cpp index fc110d4..9095c4d 100644 --- a/tests/mediaendpointconnector.cpp +++ b/tests/mediaendpointconnector.cpp @@ -1,172 +1,158 @@ /* - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "mediaendpointconnector.h" #include #include #include #include #include "device.h" #include "initmanagerjob.h" #include "media.h" #include "mediaendpoint.h" #include "mediatransport.h" #include "tpendingcall.h" #include "services.h" #include "adapter.h" using namespace BluezQt; class NoInputNoOutputAgentPrivate { public: QStringList allowedUuids; }; NoInputNoOutputAgent::NoInputNoOutputAgent(const QStringList &uuids, QObject *parent) : Agent(parent) , d(new NoInputNoOutputAgentPrivate) { d->allowedUuids = uuids; } NoInputNoOutputAgent::~NoInputNoOutputAgent() { delete d; } QDBusObjectPath NoInputNoOutputAgent::objectPath() const { return QDBusObjectPath("/Agent/NoInputNoOutput"); } Agent::Capability NoInputNoOutputAgent::capability() const { return Agent::NoInputNoOutput; } void NoInputNoOutputAgent::authorizeService(DevicePtr device, const QString &uuid, const Request<> &request) { Q_UNUSED(device) d->allowedUuids.contains(uuid) ? request.accept() : request.reject(); emit serviceAuthorized(device, uuid, d->allowedUuids.contains(uuid)); } MediaEndpointConnector::MediaEndpointConnector(Manager *manager, QObject *parent) : QObject(parent) , m_manager(manager) { connect(manager, &Manager::deviceChanged, [this](DevicePtr device) { connect(device.data(), &Device::mediaTransportChanged, this, &MediaEndpointConnector::onTransportChanged); }); NoInputNoOutputAgent *agent = new NoInputNoOutputAgent({Services::AdvancedAudioDistribution, Services::AudioVideoRemoteControl}); connect(agent, &NoInputNoOutputAgent::serviceAuthorized, this, &MediaEndpointConnector::onServiceAuthorized); manager->registerAgent(agent); manager->requestDefaultAgent(agent); MediaEndpoint *sbcSink = new MediaEndpoint({MediaEndpoint::Role::AudioSink, MediaEndpoint::Codec::Sbc}, manager); MediaEndpoint *aacSink = new MediaEndpoint({MediaEndpoint::Role::AudioSink, MediaEndpoint::Codec::Aac}, manager); connect(sbcSink, &MediaEndpoint::configurationSelected, this, &MediaEndpointConnector::onConfigurationSelected); connect(aacSink, &MediaEndpoint::configurationSelected, this, &MediaEndpointConnector::onConfigurationSelected); connect(sbcSink, &MediaEndpoint::configurationSet, this, &MediaEndpointConnector::onConfigurationSet); connect(aacSink, &MediaEndpoint::configurationSet, this, &MediaEndpointConnector::onConfigurationSet); connect(sbcSink, &MediaEndpoint::configurationCleared, this, &MediaEndpointConnector::onConfigurationCleared); connect(aacSink, &MediaEndpoint::configurationCleared, this, &MediaEndpointConnector::onConfigurationCleared); manager->usableAdapter()->media()->registerEndpoint(sbcSink); manager->usableAdapter()->media()->registerEndpoint(aacSink); } void MediaEndpointConnector::onTransportChanged(MediaTransportPtr transport) { if (!transport) { return; } connect(transport.data(), &MediaTransport::stateChanged, [transport](MediaTransport::State state){ qDebug() << "Transport state:" << state; if (state == MediaTransport::State::Pending) { TPendingCall *fd = transport->tryAcquire(); connect(fd, &PendingCall::finished, [fd]() { qDebug() << "fd: " << fd->valueAt<0>().fileDescriptor() << "mtu read:" << fd->valueAt<1>() << "mtu write:" << fd->valueAt<2>(); }); } }); connect(transport.data(), &MediaTransport::volumeChanged, [](quint16 volume){ qDebug() << "Transport volume:" << volume; }); } void MediaEndpointConnector::onServiceAuthorized(BluezQt::DevicePtr device, const QString &uuid, bool allowed) { qDebug() << (allowed ? "Accepted" : "Rejected") << "service:" << uuid << "from" << device->friendlyName(); } void MediaEndpointConnector::onConfigurationSelected(const QByteArray &capabilities, const QByteArray &configuration) { if (configuration.isEmpty()) { qDebug() << "No usable configuration found for capabilities:" << capabilities; } else { qDebug() << "Selected configuration:" << configuration << "for capabilities:" << capabilities; } } void MediaEndpointConnector::onConfigurationSet(const QString &transportObjectPath, const QVariantMap &properties) { qDebug() << "Set configuration for transport:" << transportObjectPath << "to:" << properties; } void MediaEndpointConnector::onConfigurationCleared(const QString &transportObjectPath) { qDebug() << "Cleared configuration for transport:" << transportObjectPath; } int main(int argc, char **argv) { QCoreApplication app(argc, argv); qDebug() << "Waiting for bluetooth audio source to connect. Ctrl + C to cancel..."; Manager *manager = new Manager(); InitManagerJob *initJob = manager->init(); initJob->exec(); if (initJob->error()) { qWarning() << "Error initializing manager:" << initJob->errorText(); return 1; } if (!manager->usableAdapter()) { qWarning() << "No usable adapter"; return 2; } if (!manager->usableAdapter()->media()) { qWarning() << "No media interface"; return 2; } new MediaEndpointConnector(manager); return app.exec(); } diff --git a/tests/mediaendpointconnector.h b/tests/mediaendpointconnector.h index b0b02ea..151a85f 100644 --- a/tests/mediaendpointconnector.h +++ b/tests/mediaendpointconnector.h @@ -1,78 +1,64 @@ /* - * Copyright (C) 2018 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2018 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef MEDIAENDPOINTCONNECTOR_H #define MEDIAENDPOINTCONNECTOR_H #include #include "agent.h" #include "manager.h" #include "types.h" class NoInputNoOutputAgent : public BluezQt::Agent { Q_OBJECT public: /** * Creates a new NoInputNoOutputAgent object. * * @param parent */ explicit NoInputNoOutputAgent(const QStringList &uuids, QObject *parent = nullptr); /** * Destroys a NoInputNoOutputAgent object. */ ~NoInputNoOutputAgent() override; Q_SIGNALS: /** * Indicates that a service was authorized. */ void serviceAuthorized(BluezQt::DevicePtr device, const QString &uuid, bool allowed); private: QDBusObjectPath objectPath() const override; Capability capability() const override; void authorizeService(BluezQt::DevicePtr device, const QString &uuid, const BluezQt::Request<> &request) override; class NoInputNoOutputAgentPrivate *const d; }; class MediaEndpointConnector : public QObject { Q_OBJECT public: explicit MediaEndpointConnector(BluezQt::Manager *manager, QObject *parent = nullptr); private: void onTransportChanged(BluezQt::MediaTransportPtr transport); void onServiceAuthorized(BluezQt::DevicePtr device, const QString &uuid, bool allowed); void onConfigurationSelected(const QByteArray &capabilities, const QByteArray &configuration); void onConfigurationSet(const QString &transportObjectPath, const QVariantMap &properties); void onConfigurationCleared(const QString &transportObjectPath); BluezQt::Manager *m_manager; }; #endif // MEDIAENDPOINTCONNECTOR_H diff --git a/tools/bluezapi2qt/BluezApiParser.cpp b/tools/bluezapi2qt/BluezApiParser.cpp index 9474c25..d5ba4fe 100644 --- a/tools/bluezapi2qt/BluezApiParser.cpp +++ b/tools/bluezapi2qt/BluezApiParser.cpp @@ -1,67 +1,53 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "BluezApiParser.h" BluezApiParser::BluezApiParser() { } bool BluezApiParser::parse(QTextStream &stream) { while (!stream.atEnd()) { // Get next line auto line = stream.readLine(); // Just look for section markers if (line.startsWith(L'=')) { m_interfaces.emplace_back(Interface()); m_currentInterface = &m_interfaces.back(); } else if (m_currentInterface) { if (!m_currentInterface->parse(line)) { m_currentInterface = nullptr; } } } return true; } bool BluezApiParser::finalize() { bool success = true; m_interfaces.erase(std::remove_if(m_interfaces.begin(), m_interfaces.end(), [](const Interface &interface) { return interface.methods().methods().empty() && interface.properties().properties().empty(); }), m_interfaces.end()); for (auto &interface : m_interfaces) { success &= interface.finalize(); } return success; } std::list BluezApiParser::interfaces() const { return m_interfaces; } diff --git a/tools/bluezapi2qt/BluezApiParser.h b/tools/bluezapi2qt/BluezApiParser.h index 4f51102..7916fea 100644 --- a/tools/bluezapi2qt/BluezApiParser.h +++ b/tools/bluezapi2qt/BluezApiParser.h @@ -1,45 +1,31 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef PARSER_H #define PARSER_H #include #include "Interface.h" class BluezApiParser { public: BluezApiParser(); bool parse(QTextStream &stream); bool finalize(); std::list interfaces() const; private: std::list m_interfaces; Interface *m_currentInterface = nullptr; }; #endif // PARSER_H diff --git a/tools/bluezapi2qt/Comment.cpp b/tools/bluezapi2qt/Comment.cpp index 9d0eee5..5bf7c25 100644 --- a/tools/bluezapi2qt/Comment.cpp +++ b/tools/bluezapi2qt/Comment.cpp @@ -1,52 +1,38 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "Comment.h" bool Comment::finalize() { // Delete last empty lines from comment while (last().isEmpty()) { removeLast(); } // Find indents int indents = 255; for (const auto &line : *this) { if (line.isEmpty()) { continue; } indents = std::min(indents, line.count(QStringLiteral("\t"))); } // Remove indents for (auto &line : *this) { line.remove(0, indents); } // Replace indents for (auto &line : *this) { line.replace(QStringLiteral("\t"), QStringLiteral(" ")); } return true; } diff --git a/tools/bluezapi2qt/Comment.h b/tools/bluezapi2qt/Comment.h index 3841ec3..982de13 100644 --- a/tools/bluezapi2qt/Comment.h +++ b/tools/bluezapi2qt/Comment.h @@ -1,36 +1,22 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef COMMENT_H #define COMMENT_H #include class Comment : public QStringList { public: using QStringList::QStringList; bool finalize(); }; #endif // COMMENT_H diff --git a/tools/bluezapi2qt/CppGenerator.cpp b/tools/bluezapi2qt/CppGenerator.cpp index 96dd89c..3228592 100644 --- a/tools/bluezapi2qt/CppGenerator.cpp +++ b/tools/bluezapi2qt/CppGenerator.cpp @@ -1,259 +1,245 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include #include #include #include "CppGenerator.h" #include "BluezApiParser.h" #include "TypeAnnotation.h" CppGenerator::CppGenerator(const Config &config) : m_config(config) { } bool CppGenerator::generate(const BluezApiParser &parser) { writeAdaptorHeader(parser); writeAdaptorSource(parser); return true; } void CppGenerator::writeAdaptorHeader(const BluezApiParser &parser) { // Iterate interfaces for (const auto &interface : parser.interfaces()) { auto className = interfaceToClassName(interface.name()); // Create file QFile file(className.toLower() + QStringLiteral("adaptor.h")); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qWarning() << "Error opening file for writing:" << file.fileName(); return; } // Write content QTextStream stream(&file); writeCopyrightHeader(stream); stream << "#pragma once\n\n"; stream << "#include \n\n"; stream << "class QDBusObjectPath;\n\n"; stream << "namespace BluezQt\n{\n\n"; stream << "class " << className << ";\n\n"; stream << "class " << className << "Adaptor : public QDBusAbstractAdaptor\n{\n"; stream << " Q_OBJECT \n"; stream << " Q_CLASSINFO(\"D-Bus Interface\", \"" << interface.name() << "\")\n"; // Write properties for (const auto &property : interface.properties().properties()) { // Respect config if ((property.tags().isOptional && !m_config.useOptional) || (property.tags().isExperimental && !m_config.useExperimental)) { continue; } stream << " Q_PROPERTY(" << bluezToQt(property.type()) << " " << property.name() << " READ " << lowerFirstChars(property.name()); if (!property.tags().isReadOnly) { stream << " WRITE set" << property.name(); } stream << ")\n"; } stream << "\npublic:\n"; stream << " explicit " << className << "Adaptor(" << className << "* parent);\n\n"; // Write property accessors for (const auto &property : interface.properties().properties()) { // Respect config if ((property.tags().isOptional && !m_config.useOptional) || (property.tags().isExperimental && !m_config.useExperimental)) { continue; } stream << " " << bluezToQt(property.type()) << " " << lowerFirstChars(property.name()) << "() const;\n"; if (!property.tags().isReadOnly) { stream << " void set" << property.name() << "(const " << bluezToQt(property.type()) << " &" << lowerFirstChars(property.name()) << ");\n"; } stream << "\n"; } stream << "public Q_SLOTS:\n"; // write Methods for (const auto &method : interface.methods().methods()) { // Respect config if ((method.tags().isOptional && !m_config.useOptional) || (method.tags().isExperimental && !m_config.useExperimental)) { continue; } stream << " " << bluezToQt(method.outParameter().type()) << " " << method.name() << "("; for (auto it = method.inParameters().begin(); it != method.inParameters().end(); ++it) { stream << "const " << bluezToQt(it->type()) << " &" << it->name(); if (it != std::prev(method.inParameters().end())) { stream << ", "; } } stream << ");\n"; } // write private members stream << "\nprivate:\n"; stream << " " << className << " *m_" << lowerFirstChars(className) << ";\n"; stream << "};\n\n} // namespace BluezQt\n"; file.close(); } } void CppGenerator::writeAdaptorSource(const BluezApiParser &parser) { // Iterate interfaces for (const auto &interface : parser.interfaces()) { auto className = interfaceToClassName(interface.name()); // Create file QFile file(className.toLower() + QStringLiteral("adaptor.cpp")); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qWarning() << "Error opening file for writing:" << file.fileName(); return; } // Write content QTextStream stream(&file); writeCopyrightHeader(stream); stream << "#include \"" << className << "Adaptor.h\"\n\n"; stream << "#include \"" << className << ".h\"\n\n"; stream << "namespace BluezQt\n{\n\n"; stream << className << "Adaptor::" << className << "Adaptor(" << className << " *parent)\n"; stream << " : QDBusAbstractAdaptor(parent)\n"; stream << " , m_" << lowerFirstChars(className) << "(parent)\n"; stream << "{\n}\n\n"; // Write property accessors for (const auto &property : interface.properties().properties()) { // Respect config if ((property.tags().isOptional && !m_config.useOptional) || (property.tags().isExperimental && !m_config.useExperimental)) { continue; } stream << bluezToQt(property.type()) << " " << className << "Adaptor::" << lowerFirstChars(property.name()) << "() const\n"; stream << "{\n"; stream << " return m_" << lowerFirstChars(className) << "->" << lowerFirstChars(property.name()) << "();\n"; stream << "}\n\n"; if (!property.tags().isReadOnly) { stream << "void " << className << "Adaptor::set" << property.name() << "(const " << bluezToQt(property.type()) << " &" << lowerFirstChars(property.name()) << ");\n"; stream << "{\n"; stream << " m_" << lowerFirstChars(className) << "->set" << property.name() << "(" << lowerFirstChars(property.name()) << ");\n"; stream << "}\n\n"; } } // write Methods for (const auto &method : interface.methods().methods()) { // Respect config if ((method.tags().isOptional && !m_config.useOptional) || (method.tags().isExperimental && !m_config.useExperimental)) { continue; } stream << bluezToQt(method.outParameter().type()) << " " << className << "Adaptor::" << method.name() << "("; for (auto it = method.inParameters().begin(); it != method.inParameters().end(); ++it) { stream << "const " << bluezToQt(it->type()) << " &" << it->name(); if (it != std::prev(method.inParameters().end())) { stream << ", "; } } stream << ")\n{\n"; stream << " return m_" << lowerFirstChars(className) << "->" << lowerFirstChars(method.name()) << "("; for (auto it = method.inParameters().begin(); it != method.inParameters().end(); ++it) { stream << it->name(); if (it != std::prev(method.inParameters().end())) { stream << ", "; } } stream << ");\n}\n\n"; } stream << "} // namespace BluezQt\n"; file.close(); } } QString CppGenerator::interfaceToClassName(const QString &interface) { const int index = interface.lastIndexOf(QRegularExpression(QStringLiteral("\\.[A-Z]\\w+"))) + 1; auto className = interface.mid(index); while (className.back() > L'0' && className.back() <= L'9') { className.remove(className.size()-1, 1); } return className; } QString CppGenerator::lowerFirstChars(const QString &string) { QString str(string); //str.replace(0, 1, string.at(0).toLower()); const QRegularExpression rx(QStringLiteral("^([A-Z]+)")); QRegularExpressionMatch match = rx.match(string); if (match.hasMatch()) { QString matchedStr = match.captured(); for (int i = 0; i < matchedStr.size() - 1; ++i) { str.replace(i, 1, str.at(i).toLower()); } } str.replace(0, 1, string.at(0).toLower()); str.replace(string.size()-1, 1, string.at(string.size()-1).toLower()); return str; } void CppGenerator::writeCopyrightHeader(QTextStream &stream) { stream << "/*\n"; stream << " * BluezQt - Asynchronous Bluez wrapper library\n"; stream << " *\n"; stream << " * Copyright (C) " << m_config.year << " " << m_config.author << "\n"; stream << " *\n"; stream << " * This library is free software; you can redistribute it and/or\n"; stream << " * modify it under the terms of the GNU Lesser General Public\n"; stream << " * License as published by the Free Software Foundation; either\n"; stream << " * version 2.1 of the License, or (at your option) version 3, or any\n"; stream << " * later version accepted by the membership of KDE e.V. (or its\n"; stream << " * successor approved by the membership of KDE e.V.), which shall\n"; stream << " * act as a proxy defined in Section 6 of version 3 of the license.\n"; stream << " *\n"; stream << " * This library is distributed in the hope that it will be useful,\n"; stream << " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"; stream << " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"; stream << " * Lesser General Public License for more details.\n"; stream << " *\n"; stream << " * You should have received a copy of the GNU Lesser General Public\n"; stream << " * License along with this library. If not, see .\n"; stream << " */\n\n"; } diff --git a/tools/bluezapi2qt/CppGenerator.h b/tools/bluezapi2qt/CppGenerator.h index 3b1a82c..746303b 100644 --- a/tools/bluezapi2qt/CppGenerator.h +++ b/tools/bluezapi2qt/CppGenerator.h @@ -1,65 +1,51 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef CPPGENERATOR_H #define CPPGENERATOR_H #include class BluezApiParser; class Method; class CppGenerator { public: struct Config { bool useOptional = false; bool useDeprecated = false; bool useExperimental = false; bool useLowercaseFileNames = false; QString author = QStringLiteral("John Doe "); QString year = QStringLiteral("2019"); }; CppGenerator(const Config &config); bool generate(const BluezApiParser &parser); protected: void writeAdaptorHeader(const BluezApiParser &parser); void writeAdaptorSource(const BluezApiParser &parser); static QString interfaceToClassName(const QString &interface); static QString lowerFirstChars(const QString &string); static void writeFooter(QTextStream &stream); static void writeInterface(QTextStream &stream, const QString &name); static void closeInterface(QTextStream &stream); static bool writeMethod(QTextStream &stream, const Method &method); static bool writeArg(QTextStream &stream, const QString ¶m, const QString &dir); static void writeAnnotation(QTextStream &stream, const QString ¶m, const QString &dir, int i); void writeCopyrightHeader(QTextStream &stream); private: Config m_config; }; #endif // CPPGENERATOR_H diff --git a/tools/bluezapi2qt/Interface.cpp b/tools/bluezapi2qt/Interface.cpp index c8d0168..ccac7d9 100644 --- a/tools/bluezapi2qt/Interface.cpp +++ b/tools/bluezapi2qt/Interface.cpp @@ -1,152 +1,138 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "Interface.h" #include Interface::Interface() { } bool Interface::parse(const QString &line) { if (line.startsWith(QLatin1String("Service\t"))) { m_state = State::Service; } else if (line.startsWith(QLatin1String("Interface\t"))) { m_state = State::Interface; } else if (line.startsWith(QLatin1String("Object path\t"))) { m_state = State::ObjectPath; } else if (line.startsWith(QLatin1String("Methods\t")) || Methods::isMethod(line)) { // Argh! AgentManager is missing the Methods keyword m_state = State::Methods; } else if (line.startsWith(QLatin1String("Properties\t"))) { m_state = State::Properties; } else if (m_state != State::Comment && !line.isEmpty() && !line.startsWith(QLatin1String("\t"))) { // If we do not parse comment, but line starts with characters, we are done. return false; } switch (m_state) { case State::Comment: parseComment(line); break; case State::Service: parseService(line); break; case State::Interface: parseInterface(line); break; case State::ObjectPath: parseObjectPath(line); break; case State::Methods: m_methods.parse(line); break; case State::Properties: m_properties.parse(line); break; } return true; } bool Interface::finalize() { bool success = true; success &= m_methods.finalize(); success &= m_properties.finalize(); return success; } QStringList Interface::comment() const { return m_comment; } QString Interface::service() const { return m_service; } QString Interface::name() const { return m_name; } QString Interface::objectPath() const { return m_objectPath; } Methods Interface::methods() const { return m_methods; } Properties Interface::properties() const { return m_properties; } void Interface::parseComment(const QString &line) { if (line.isEmpty()) { m_comment.append(QString()); return; } else if (line.startsWith(QLatin1Char(' ')) || line.startsWith(QStringLiteral("\t"))) { m_comment.append(QString()); } if (!m_comment.last().isEmpty()) { m_comment.last() += QLatin1Char(' '); } m_comment.last() += line; } void Interface::parseService(const QString &line) { const QRegularExpression rx(QStringLiteral("Service\\t+(.+)")); QRegularExpressionMatch match = rx.match(line); if (match.hasMatch()) { m_service = match.captured(); } } void Interface::parseInterface(const QString &line) { const QRegularExpression rx(QStringLiteral("Interface\\t+(.+)")); QRegularExpressionMatch match = rx.match(line); if (match.hasMatch()) { m_name = match.captured(); } } void Interface::parseObjectPath(const QString &line) { const QRegularExpression rx(QStringLiteral("Object path\\t+(.+)")); QRegularExpressionMatch match = rx.match(line); if (match.hasMatch()) { m_objectPath = match.captured(); } } diff --git a/tools/bluezapi2qt/Interface.h b/tools/bluezapi2qt/Interface.h index e4acfb9..9b3f0f5 100644 --- a/tools/bluezapi2qt/Interface.h +++ b/tools/bluezapi2qt/Interface.h @@ -1,69 +1,55 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef INTERFACE_H #define INTERFACE_H #include "Methods.h" #include "Properties.h" class Interface { public: Interface(); bool parse(const QString &line); bool finalize(); QStringList comment() const; QString service() const; QString name() const; QString objectPath() const; Methods methods() const; Properties properties() const; private: enum class State { Comment, Service, Interface, ObjectPath, Methods, Properties }; void parseComment(const QString &line); void parseService(const QString &line); void parseInterface(const QString &line); void parseObjectPath(const QString &line); State m_state = State::Comment; QStringList m_comment; QString m_service; QString m_name; QString m_objectPath; Methods m_methods; Properties m_properties; }; #endif // INTERFACE_H diff --git a/tools/bluezapi2qt/Method.cpp b/tools/bluezapi2qt/Method.cpp index 55784e2..cefeea2 100644 --- a/tools/bluezapi2qt/Method.cpp +++ b/tools/bluezapi2qt/Method.cpp @@ -1,113 +1,99 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include #include "Method.h" Method::Method() { } bool Method::finalize() { for (const auto &tag : m_stringTags) { m_tags.isOptional |= tag.contains(QLatin1String("optional"), Qt::CaseInsensitive); m_tags.isDeprecated |= tag.contains(QLatin1String("deprecated"), Qt::CaseInsensitive); m_tags.isExperimental |= tag.contains(QLatin1String("experimental"), Qt::CaseInsensitive); } bool success = true; success &= m_comment.finalize(); for (const auto &inParam : m_inParameterStrings) { m_inParameters.push_back(Parameter::fromString(inParam)); } m_outParameterStrings.removeOne(QStringLiteral("void")); if (m_outParameterStrings.isEmpty()) { m_outParameter = Parameter::fromString(QStringLiteral("void unnamend")); return true; } // Guess out parameter name from method name QString paramName = guessOutParameterName(); if (!paramName.isEmpty()) { m_outParameterStrings.front() += QLatin1Char(' ') + paramName; m_outParameter = Parameter::fromString(m_outParameterStrings.front()); } else { for (int i = 0; i < m_outParameterStrings.size(); ++i) { m_outParameterStrings[i] += QLatin1String(" value") + QString::number(i); } } for (const auto &outParam : m_outParameterStrings) { m_outParameters.push_back(Parameter::fromString(outParam)); } return success; } QString Method::name() const { return m_name; } QList Method::inParameters() const { return m_inParameters; } QList Method::outParameters() const { return m_outParameters; } Parameter Method::outParameter() const { return m_outParameter; } Method::Tags Method::tags() const { return m_tags; } QStringList Method::comment() const { return m_comment; } QString Method::guessOutParameterName() const { if (m_outParameterStrings.size() != 1) { return QString(); } const QRegularExpression rx(QStringLiteral("([A-Z][a-z0-9]+)+")); QRegularExpressionMatch match = rx.match(m_name, 1); if (!match.hasMatch()) { return QStringLiteral("value"); } return match.captured().toLower(); } diff --git a/tools/bluezapi2qt/Method.h b/tools/bluezapi2qt/Method.h index 4a20afc..1197fba 100644 --- a/tools/bluezapi2qt/Method.h +++ b/tools/bluezapi2qt/Method.h @@ -1,68 +1,54 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef METHOD_H #define METHOD_H #include "Comment.h" #include "Parameter.h" class Method { public: struct Tags { bool isOptional = false; bool isDeprecated = false; bool isExperimental = false; }; Method(); bool finalize(); QString name() const; QList inParameters() const; QList outParameters() const; Parameter outParameter() const; Tags tags() const; QStringList comment() const; private: QString guessOutParameterName() const; QString m_name; QStringList m_inParameterStrings; QStringList m_outParameterStrings; Parameter m_outParameter; QStringList m_stringTags; QString m_limitation; Comment m_comment; // finalized members Tags m_tags; QList m_inParameters; QList m_outParameters; friend class Methods; }; #endif // METHOD_H diff --git a/tools/bluezapi2qt/Methods.cpp b/tools/bluezapi2qt/Methods.cpp index de146f8..462dfaa 100644 --- a/tools/bluezapi2qt/Methods.cpp +++ b/tools/bluezapi2qt/Methods.cpp @@ -1,83 +1,69 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "Methods.h" #include #include static const QRegularExpression rx(QStringLiteral( "\\t+" // preceding tabs "(?:(.+) )?" // return types - Argh! LE Advertising Manager does not specify return type "([A-Z]\\w+)" // method name "\\(([^\\)]*)\\)" // parameters "(?: \\[(.*)\\])?" // tags "(?: \\((.*)\\))?" // limitations ), QRegularExpression::CaseInsensitiveOption); Methods::Methods() { } bool Methods::isMethod(const QString &line) { // Check if we match a method return (rx.match(line).hasMatch()); } void Methods::parse(const QString &line) { // Check if we match a method QRegularExpressionMatch match = rx.match(line); if (match.hasMatch()) { m_methods.emplace_back(Method()); m_currentMethod = &m_methods.back(); m_currentMethod->m_outParameterStrings = match.captured(1).toLower().split(QStringLiteral(", "), QString::SkipEmptyParts); m_currentMethod->m_name = match.captured(2); m_currentMethod->m_inParameterStrings = match.captured(3).split(QStringLiteral(", "), QString::SkipEmptyParts); m_currentMethod->m_stringTags = match.captured(4).toLower().split(QStringLiteral(", "), QString::SkipEmptyParts); m_currentMethod->m_limitation = match.captured(5).toLower(); } else if (m_currentMethod) { // Skip first empty line if (line.isEmpty() && m_currentMethod->m_comment.isEmpty()) { return; } m_currentMethod->m_comment.append(line); } } bool Methods::finalize() { bool success = true; for (auto &method : m_methods) { success &= method.finalize(); } return success; } std::list Methods::methods() const { return m_methods; } diff --git a/tools/bluezapi2qt/Methods.h b/tools/bluezapi2qt/Methods.h index 971b2f7..bb25db3 100644 --- a/tools/bluezapi2qt/Methods.h +++ b/tools/bluezapi2qt/Methods.h @@ -1,45 +1,31 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef METHODS_H #define METHODS_H #include "Method.h" class Methods { public: Methods(); static bool isMethod(const QString &line); void parse(const QString &line); bool finalize(); std::list methods() const; private: std::list m_methods; Method *m_currentMethod = nullptr; }; #endif // METHODS_H diff --git a/tools/bluezapi2qt/Parameter.cpp b/tools/bluezapi2qt/Parameter.cpp index 3e1a944..6bcffd8 100644 --- a/tools/bluezapi2qt/Parameter.cpp +++ b/tools/bluezapi2qt/Parameter.cpp @@ -1,48 +1,34 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "Parameter.h" #include Parameter Parameter::fromString(const QString &string) { Parameter param; QStringList arg = string.split(QLatin1Char(' ')); if (arg.size() != 2) { return param; } param.m_type = arg.first(); param.m_name = arg.last(); return param; } QString Parameter::type() const { return m_type; } QString Parameter::name() const { return m_name; } diff --git a/tools/bluezapi2qt/Parameter.h b/tools/bluezapi2qt/Parameter.h index 40a7c89..005f406 100644 --- a/tools/bluezapi2qt/Parameter.h +++ b/tools/bluezapi2qt/Parameter.h @@ -1,38 +1,24 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include class Parameter { public: static Parameter fromString(const QString &string); QString type() const; QString name() const; private: QString m_type; QString m_name; }; diff --git a/tools/bluezapi2qt/Properties.cpp b/tools/bluezapi2qt/Properties.cpp index 783766b..291578b 100644 --- a/tools/bluezapi2qt/Properties.cpp +++ b/tools/bluezapi2qt/Properties.cpp @@ -1,77 +1,63 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "Properties.h" #include #include Properties::Properties() { } void Properties::parse(const QString &line) { const QRegularExpression rx(QStringLiteral( "(?:Properties|^)" // Properties keyword or start of line "\\t{1,2}" // preceding tabs (max 2) "([a-z1-6{}_]+)" // type name " " // space "([A-Z]\\w+)" // method name "(?: \\[(.*)\\])?" // tags "(?: \\((.*)\\))?" // limitations ), QRegularExpression::CaseInsensitiveOption); QRegularExpressionMatch match = rx.match(line); // Check if we match a property if (match.hasMatch()) { m_properties.emplace_back(Property()); m_currentProperty = &m_properties.back(); m_currentProperty->m_type = match.captured(1).toLower(); m_currentProperty->m_name = match.captured(2); m_currentProperty->m_stringTags = match.captured(3).toLower().split(QStringLiteral(", "), QString::SkipEmptyParts); m_currentProperty->m_limitation = match.captured(4).toLower(); } else if (m_currentProperty) { // Skip first empty line if (line.isEmpty() && m_currentProperty->m_comment.isEmpty()) { return; } m_currentProperty->m_comment.append(line); } } bool Properties::finalize() { bool success = true; for (auto &property : m_properties) { success &= property.finalize(); } return success; } std::list Properties::properties() const { return m_properties; } diff --git a/tools/bluezapi2qt/Properties.h b/tools/bluezapi2qt/Properties.h index bec6346..7f780b6 100644 --- a/tools/bluezapi2qt/Properties.h +++ b/tools/bluezapi2qt/Properties.h @@ -1,43 +1,29 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef PROPERTIES_H #define PROPERTIES_H #include "Property.h" class Properties { public: Properties(); void parse(const QString &line); bool finalize(); std::list properties() const; private: std::list m_properties; Property *m_currentProperty = nullptr; }; #endif // PROPERTIES_H diff --git a/tools/bluezapi2qt/Property.cpp b/tools/bluezapi2qt/Property.cpp index 05f356b..bb7e151 100644 --- a/tools/bluezapi2qt/Property.cpp +++ b/tools/bluezapi2qt/Property.cpp @@ -1,63 +1,49 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "Property.h" Property::Property() { } bool Property::finalize() { for (auto tag : m_stringTags) { m_tags.isOptional |= tag.contains(QLatin1String("optional"), Qt::CaseInsensitive); m_tags.isExperimental |= tag.contains(QLatin1String("experimental"), Qt::CaseInsensitive); m_tags.isReadOnly |= tag.contains(QLatin1String("read-only"), Qt::CaseInsensitive); } m_tags.isServerOnly = m_limitation.contains(QLatin1String("server only"), Qt::CaseInsensitive); bool success = true; success &= m_comment.finalize(); return success; } QString Property::name() const { return m_name; } QString Property::type() const { return m_type; } Property::Tags Property::tags() const { return m_tags; } QStringList Property::comment() const { return m_comment; } diff --git a/tools/bluezapi2qt/Property.h b/tools/bluezapi2qt/Property.h index d33aa7e..8b7251a 100644 --- a/tools/bluezapi2qt/Property.h +++ b/tools/bluezapi2qt/Property.h @@ -1,57 +1,43 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #pragma once #include "Comment.h" class Property { public: struct Tags { bool isOptional = false; bool isExperimental = false; bool isReadOnly = false; bool isServerOnly = false; }; Property(); bool finalize(); QString name() const; QString type() const; Tags tags() const; QStringList comment() const; private: QString m_name; QString m_type; QStringList m_stringTags; QString m_limitation; Comment m_comment; // finalized members Tags m_tags; friend class Properties; }; diff --git a/tools/bluezapi2qt/TypeAnnotation.cpp b/tools/bluezapi2qt/TypeAnnotation.cpp index 215d15a..657aa5d 100644 --- a/tools/bluezapi2qt/TypeAnnotation.cpp +++ b/tools/bluezapi2qt/TypeAnnotation.cpp @@ -1,71 +1,57 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "TypeAnnotation.h" #include QString annotateType(AnnotationType from, AnnotationType to, const QString &type) { static const std::vector> table = { {"boolean", "b", ""}, //{{"fd"}, "", ""}, {"object", "o", ""}, {"string", "s", ""}, //{{"uint16"}, "", ""}, //{{"uint32"}, "", ""}, {"dict", "a{sv}", "QVariantMap"}, {"array{byte}", "ay", ""}, {"array{dict}", "aa{sv}", "QVariantMapList"}, {"array{string}", "as", ""}, }; for (const auto &entry : table) { if (entry.at(static_cast(from)) == type.toStdString()) { return QString::fromStdString(entry.at(static_cast(to))); } } return QString(); } QString bluezToQt(const QString &type) { static const std::vector> table = { {"boolean", "bool"}, //{{"fd"}, ""}, {"object", "QDBusObjectPath"}, {"string", "QString"}, {"dict", "QVariantMap"}, {"array{byte}", "QByteArray"}, {"array{dict}", "QVariantMapList"}, {"array{string}", "QStringList"}, }; for (const auto &entry : table) { if (entry.front() == type.toStdString()) { return QString::fromStdString(entry.back()); } } return type; } diff --git a/tools/bluezapi2qt/TypeAnnotation.h b/tools/bluezapi2qt/TypeAnnotation.h index c5dc038..065101a 100644 --- a/tools/bluezapi2qt/TypeAnnotation.h +++ b/tools/bluezapi2qt/TypeAnnotation.h @@ -1,37 +1,23 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef TYPEANNOTATION_H #define TYPEANNOTATION_H #include enum class AnnotationType { Bluez = 0, Dbus = 1, Qt = 2 }; QString annotateType(AnnotationType from, AnnotationType to, const QString &type); QString bluezToQt(const QString &type); #endif // TYPEANNOTATION_H diff --git a/tools/bluezapi2qt/XmlGenerator.cpp b/tools/bluezapi2qt/XmlGenerator.cpp index 014fd5b..0c96ae8 100644 --- a/tools/bluezapi2qt/XmlGenerator.cpp +++ b/tools/bluezapi2qt/XmlGenerator.cpp @@ -1,155 +1,141 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "XmlGenerator.h" #include #include #include "BluezApiParser.h" #include "TypeAnnotation.h" XmlGenerator::XmlGenerator(const Config &config) : m_config(config) { } bool XmlGenerator::generate(const BluezApiParser &parser) { // Iterate interfaces for (const auto &interface : parser.interfaces()) { // Only consider interfaces with methods if (interface.methods().methods().empty()) { continue; } // Create file QFile file(interface.name() + QStringLiteral(".xml")); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qWarning() << "Error opening file for writing:" << file.fileName(); return false; } // Write content QTextStream stream(&file); writeHeader(stream); writeInterface(stream, interface.name()); // Iterate methods for (const auto &method : interface.methods().methods()) { // Respect config if ((method.tags().isDeprecated && !m_config.useDeprecated) || (method.tags().isOptional && !m_config.useOptional) || (method.tags().isExperimental && !m_config.useExperimental)) { continue; } writeMethod(stream, method); } closeInterface(stream); writeFooter(stream); file.close(); } return true; } void XmlGenerator::writeHeader(QTextStream &stream) { stream << "\n"; stream << "\n"; stream << "\n"; } void XmlGenerator::writeFooter(QTextStream &stream) { stream << "\n"; } void XmlGenerator::writeInterface(QTextStream &stream, const QString &name) { stream << " \n"; } void XmlGenerator::closeInterface(QTextStream &stream) { stream << " \n"; } bool XmlGenerator::writeMethod(QTextStream &stream, const Method &method) { stream << " \n"; return true; } stream << ">\n"; for (const auto ¶m : method.inParameters()) { if (!writeArg(stream, param, QStringLiteral("in"))) { return false; } } for (const auto ¶m : method.outParameters()) { if (!writeArg(stream, param, QStringLiteral("out"))) { return false; } } for (int i = 0; i < method.inParameters().size(); ++i) { writeAnnotation(stream, method.inParameters().at(i), QStringLiteral("In"), i); } for (int i = 0; i < method.outParameters().size(); ++i) { writeAnnotation(stream, method.outParameters().at(i), QStringLiteral("Out"), i); } stream << " \n"; return true; } bool XmlGenerator::writeArg(QTextStream &stream, const Parameter ¶m, const QString &dir) { auto dbusType = annotateType(AnnotationType::Bluez, AnnotationType::Dbus, param.type()); if (dbusType.isEmpty()) { return false; } stream << " \n"; return true; } void XmlGenerator::writeAnnotation(QTextStream &stream, const Parameter ¶m, const QString &dir, int i) { auto qtType = annotateType(AnnotationType::Bluez, AnnotationType::Qt, param.type()); if (qtType.isEmpty()) { return; } stream << " \n"; return; } diff --git a/tools/bluezapi2qt/XmlGenerator.h b/tools/bluezapi2qt/XmlGenerator.h index a2d97a2..52439e9 100644 --- a/tools/bluezapi2qt/XmlGenerator.h +++ b/tools/bluezapi2qt/XmlGenerator.h @@ -1,57 +1,43 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef XMLGENERATOR_H #define XMLGENERATOR_H class BluezApiParser; class Method; class Parameter; class QString; class QStringList; class QTextStream; class XmlGenerator { public: struct Config { bool useOptional = false; bool useDeprecated = false; bool useExperimental = false; }; XmlGenerator(const Config &config); bool generate(const BluezApiParser &parser); private: static void writeHeader(QTextStream &stream); static void writeFooter(QTextStream &stream); static void writeInterface(QTextStream &stream, const QString &name); static void closeInterface(QTextStream &stream); static bool writeMethod(QTextStream &stream, const Method &method); static bool writeArg(QTextStream &stream, const Parameter ¶m, const QString &dir); static void writeAnnotation(QTextStream &stream, const Parameter ¶m, const QString &dir, int i); Config m_config; }; #endif // XMLGENERATOR_H diff --git a/tools/bluezapi2qt/main.cpp b/tools/bluezapi2qt/main.cpp index e279569..9efc919 100644 --- a/tools/bluezapi2qt/main.cpp +++ b/tools/bluezapi2qt/main.cpp @@ -1,128 +1,114 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * - * Copyright (C) 2019 Manuel Weichselbaumer + * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer * - * 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) version 3, or any - * later version accepted by the membership of KDE e.V. (or its - * successor approved by the membership of KDE e.V.), which shall - * act as a proxy defined in Section 6 of version 3 of the license. - * - * 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, see . + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include #include #include #include #include #include #include "BluezApiParser.h" #include "CppGenerator.h" #include "XmlGenerator.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QCoreApplication::setApplicationName(QStringLiteral("bluezapi2qt")); QCoreApplication::setApplicationVersion(QStringLiteral("0.1")); // Add command line parsing QCommandLineParser parser; parser.setApplicationDescription(QStringLiteral("Generates D-BUS object introspection XML files out of BlueZ D-Bus API\n" "description files (*-api.txt).")); parser.addHelpOption(); parser.addVersionOption(); parser.addPositionalArgument(QStringLiteral("-api.txt"), QStringLiteral("BlueZ D-Bus API description file to use.")); QCommandLineOption deprecatedOption(QStringList() << QStringLiteral("d") << QStringLiteral("deprecated"), QStringLiteral("Generate deprecated methods/properties")); parser.addOption(deprecatedOption); QCommandLineOption experimentalOption(QStringList() << QStringLiteral("e") << QStringLiteral("experimental"), QStringLiteral("Generate experimental methods/properties")); parser.addOption(experimentalOption); QCommandLineOption optionalOption(QStringList() << QStringLiteral("o") << QStringLiteral("optional"), QStringLiteral("Generate optional methods/properties")); parser.addOption(optionalOption); QCommandLineOption xmlOption(QStringList() << QStringLiteral("x") << QStringLiteral("xml"), QStringLiteral("Generate D-Bus object introspection XML files")); parser.addOption(xmlOption); QCommandLineOption cppOption(QStringList() << QStringLiteral("c") << QStringLiteral("cpp"), QStringLiteral("Generate D-Bus interface adaptor C++ files")); parser.addOption(cppOption); QCommandLineOption authorOption(QStringList() << QStringLiteral("a") << QStringLiteral("author"), QStringLiteral("Author for copyright header in C++ files"), QStringLiteral("author")); parser.addOption(authorOption); QCommandLineOption yearOption(QStringList() << QStringLiteral("y") << QStringLiteral("year"), QStringLiteral("Year for copyright header in C++ files"), QStringLiteral("year")); parser.addOption(yearOption); parser.process(a); // Open file auto positionalArgs = parser.positionalArguments(); if (positionalArgs.isEmpty()) { fputs(qPrintable(parser.helpText()), stderr); return 1; } auto fileName = positionalArgs.takeFirst(); QFileInfo inputInfo(fileName); if (!inputInfo.exists() || !inputInfo.isFile() || !inputInfo.isReadable()) { qCritical() << "Cannot open file" << fileName; return 1; } QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qCritical() << "Cannot open file" << file.fileName(); return 1; } QTextStream stream(&file); // Parse file BluezApiParser bluezParser; if (!bluezParser.parse(stream)) { qCritical() << "Error parsing file" << file.fileName(); return 1; } if (!bluezParser.finalize()) { qCritical() << "Error parsing file" << file.fileName(); return 1; } if (parser.isSet(xmlOption)) { XmlGenerator::Config xmlConfig; xmlConfig.useOptional = parser.isSet(optionalOption);; xmlConfig.useDeprecated = parser.isSet(deprecatedOption);; xmlConfig.useExperimental = parser.isSet(experimentalOption);; XmlGenerator xmlGenerator(xmlConfig); if (!xmlGenerator.generate(bluezParser)) { qCritical() << "Error generating xml"; return 1; } } if (parser.isSet(cppOption)) { CppGenerator::Config cppConfig; cppConfig.author = parser.value(authorOption); cppConfig.year = parser.value(yearOption); CppGenerator cppGenerator(cppConfig); if (!cppGenerator.generate(bluezParser)) { qCritical() << "Error generating C++ files"; return 1; } } return 0; }