[alsa-devel] [RFC][PATCH 00/13] alsa-tools: libhinawa for control applications of FireWire devices
This is RFC for a new library into alsa-tools.
ALSA in Linux 3.16 or later extends a support for FireWire sound devices. Currently ALSA drivers supports streaming functionality only, while most of these devices require software implementation to control its internal DSP. The way to achieve this is to transfer byte sequence to the unit and wait byte sequence which the unit transfers if required.
This library, libhinawa, just support these operations, nothing others. The supported types of transactions are: - IEEE 1394 read transaction - IEEE 1394 write transaction - IEEE 1394 lock transaction - IEC 61883-1 FCP transaction - Echo Fireworks transaction (with a help of snd-fireworks kernel driver) - Dice notification (with a help of snd-dice kernel driver)
To help new developers, this library supports GObject Introspection for language bindings. The main logic of applications can be written with preferred languages such as Python, Ruby, Perl and so on. In the end of this patchset, some Python scripts with Gtk+, Qt4 and Qt5 are committed as samples.
This is my first development with GNU Autotools, GLib/GObject and GObject Introspection. Furthermore, I'm a beginner of FireWire subsystem programming. I'm happy to receive your comments, especially: - the way to write Linux version dependency in configure.ac - the way of libtool versioning - the value of poll timeout in fw_unit/snd_unit - the value of thread condition timeout in fw_fcp/snd_dice/snd_efw - improvements of 'unit_query' object - any programming mistakes (threading and so on...)
Regards
Takashi Sakamoto (13): libhinawa: add build definitions libhinawa: add hinawa context libhinawa: support GTK-Doc to generate references libhinawa: add 'fw_unit' object as a listener for FireWire unit libhinawa: support GObject Introspection for language bindings libhinawa: add 'fw_resp' object as a responder for FireWire transaction libhinawa: add 'fw_req' object as requester for FireWire transaction libhinawa: add 'fw_fcp' object as a helper of FCP transaction libhinawa: add 'snd_unit' object as a listener for ALSA FireWire devices libhinawa: add 'snd_dice' object as a helper for Dice notification libhinawa: add 'snd_efw' object as a helper for EFW transaction libhinawa: add 'unit_query' as a query for ALSA FireWire devices libhinawa: add sample scripts
Makefile | 2 +- libhinawa/AUTHORS | 1 + libhinawa/COPYING | 504 ++++++++++++++++++++++++++++ libhinawa/ChangeLog | 5 + libhinawa/Makefile.am | 6 + libhinawa/NEWS | 0 libhinawa/README | 30 ++ libhinawa/autogen.sh | 11 + libhinawa/configure.ac | 68 ++++ libhinawa/doc/Makefile.am | 2 + libhinawa/doc/reference/Makefile.am | 46 +++ libhinawa/doc/reference/hinawa-docs.sgml | 47 +++ libhinawa/doc/reference/version.xml.in | 1 + libhinawa/samples/gtk3.py | 190 +++++++++++ libhinawa/samples/qt4.py | 206 ++++++++++++ libhinawa/samples/qt5.py | 192 +++++++++++ libhinawa/samples/run.sh | 15 + libhinawa/src/Makefile.am | 97 ++++++ libhinawa/src/backport.h | 41 +++ libhinawa/src/fw_fcp.c | 282 ++++++++++++++++ libhinawa/src/fw_fcp.h | 58 ++++ libhinawa/src/fw_req.c | 265 +++++++++++++++ libhinawa/src/fw_req.h | 56 ++++ libhinawa/src/fw_resp.c | 232 +++++++++++++ libhinawa/src/fw_resp.h | 51 +++ libhinawa/src/fw_unit.c | 343 +++++++++++++++++++ libhinawa/src/fw_unit.h | 52 +++ libhinawa/src/hinawa_context.c | 60 ++++ libhinawa/src/hinawa_context.h | 10 + libhinawa/src/internal.h | 31 ++ libhinawa/src/snd_dice.c | 195 +++++++++++ libhinawa/src/snd_dice.h | 53 +++ libhinawa/src/snd_efw.c | 315 ++++++++++++++++++ libhinawa/src/snd_efw.h | 54 +++ libhinawa/src/snd_unit.c | 548 +++++++++++++++++++++++++++++++ libhinawa/src/snd_unit.h | 69 ++++ libhinawa/src/unit_query.c | 116 +++++++ libhinawa/src/unit_query.h | 48 +++ 38 files changed, 4301 insertions(+), 1 deletion(-) create mode 100644 libhinawa/AUTHORS create mode 100644 libhinawa/COPYING create mode 100644 libhinawa/ChangeLog create mode 100644 libhinawa/Makefile.am create mode 100644 libhinawa/NEWS create mode 100644 libhinawa/README create mode 100755 libhinawa/autogen.sh create mode 100644 libhinawa/configure.ac create mode 100644 libhinawa/doc/Makefile.am create mode 100644 libhinawa/doc/reference/Makefile.am create mode 100644 libhinawa/doc/reference/hinawa-docs.sgml create mode 100644 libhinawa/doc/reference/version.xml.in create mode 100755 libhinawa/samples/gtk3.py create mode 100755 libhinawa/samples/qt4.py create mode 100755 libhinawa/samples/qt5.py create mode 100755 libhinawa/samples/run.sh create mode 100644 libhinawa/src/Makefile.am create mode 100644 libhinawa/src/backport.h create mode 100644 libhinawa/src/fw_fcp.c create mode 100644 libhinawa/src/fw_fcp.h create mode 100644 libhinawa/src/fw_req.c create mode 100644 libhinawa/src/fw_req.h create mode 100644 libhinawa/src/fw_resp.c create mode 100644 libhinawa/src/fw_resp.h create mode 100644 libhinawa/src/fw_unit.c create mode 100644 libhinawa/src/fw_unit.h create mode 100644 libhinawa/src/hinawa_context.c create mode 100644 libhinawa/src/hinawa_context.h create mode 100644 libhinawa/src/internal.h create mode 100644 libhinawa/src/snd_dice.c create mode 100644 libhinawa/src/snd_dice.h create mode 100644 libhinawa/src/snd_efw.c create mode 100644 libhinawa/src/snd_efw.h create mode 100644 libhinawa/src/snd_unit.c create mode 100644 libhinawa/src/snd_unit.h create mode 100644 libhinawa/src/unit_query.c create mode 100644 libhinawa/src/unit_query.h
The purpose of this library is to help applications to transact to FireWire unit, mainly for sound devices.
This library is build with GNU Autotools. This commit add some definitions for them, therefore this library depends on: - GNU Autoconf 2.62 or later - GNU Automake 1.10.1 or later - GNU libtool 2.26 or later
This library is released under GNU Lesser General Public License Version 2.1.
Current version of this library is 0.4.0 (major.minor.micro). For libtool interface versioning, this library applies this formula: - current = minor * 10 + micro - revision = major - age = the current
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- Makefile | 2 +- libhinawa/AUTHORS | 1 + libhinawa/COPYING | 504 +++++++++++++++++++++++++++++++++++++++++++++++++ libhinawa/ChangeLog | 5 + libhinawa/Makefile.am | 2 + libhinawa/NEWS | 0 libhinawa/README | 10 + libhinawa/autogen.sh | 10 + libhinawa/configure.ac | 48 +++++ 9 files changed, 581 insertions(+), 1 deletion(-) create mode 100644 libhinawa/AUTHORS create mode 100644 libhinawa/COPYING create mode 100644 libhinawa/ChangeLog create mode 100644 libhinawa/Makefile.am create mode 100644 libhinawa/NEWS create mode 100644 libhinawa/README create mode 100755 libhinawa/autogen.sh create mode 100644 libhinawa/configure.ac
diff --git a/Makefile b/Makefile index b2da046..39ffa2f 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ TOP = . SUBDIRS = as10k1 envy24control hdsploader hdspconf hdspmixer \ mixartloader pcxhrloader rmedigicontrol sb16_csp seq sscape_ctl \ us428control usx2yloader vxloader echomixer ld10k1 qlo10k1 \ - hwmixvolume hdajackretask hda-verb + hwmixvolume hdajackretask hda-verb libhinawa
all: @for i in $(SUBDIRS); do \ diff --git a/libhinawa/AUTHORS b/libhinawa/AUTHORS new file mode 100644 index 0000000..51e9e93 --- /dev/null +++ b/libhinawa/AUTHORS @@ -0,0 +1 @@ +Takashi Sakamoto o-takashi@sakamocchi.jp diff --git a/libhinawa/COPYING b/libhinawa/COPYING new file mode 100644 index 0000000..b1e3f5a --- /dev/null +++ b/libhinawa/COPYING @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + <one line to give the library's name and a brief 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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/libhinawa/ChangeLog b/libhinawa/ChangeLog new file mode 100644 index 0000000..53adf2d --- /dev/null +++ b/libhinawa/ChangeLog @@ -0,0 +1,5 @@ +2015-01-24 Takashi Sakamoto o-takashi@sakamocchi.jp + version 0.4.0 release + +2015-01-18 Takashi Sakamoto o-takashi@sakamocchi.jp + version 0.3.0 release diff --git a/libhinawa/Makefile.am b/libhinawa/Makefile.am new file mode 100644 index 0000000..e39f07b --- /dev/null +++ b/libhinawa/Makefile.am @@ -0,0 +1,2 @@ +# Include m4 macros +ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} diff --git a/libhinawa/NEWS b/libhinawa/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/libhinawa/README b/libhinawa/README new file mode 100644 index 0000000..234ed91 --- /dev/null +++ b/libhinawa/README @@ -0,0 +1,10 @@ +Requirements +- GNU Autoconf 2.62 or later +- GNU Automake 1.10.1 or later +- GNU libtool 2.2.6 or later + +How to build + $ ./autogen.sh + $ ./configure + $ make + $ make install diff --git a/libhinawa/autogen.sh b/libhinawa/autogen.sh new file mode 100755 index 0000000..54ecfa2 --- /dev/null +++ b/libhinawa/autogen.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +set -u +set -e + +if [ ! -e m4 ] ; then + mkdir -p m4 +fi + +autoreconf --install diff --git a/libhinawa/configure.ac b/libhinawa/configure.ac new file mode 100644 index 0000000..2eeef0d --- /dev/null +++ b/libhinawa/configure.ac @@ -0,0 +1,48 @@ +# my versioning +m4_define([my_major], [0]) +m4_define([my_minor], [4]) +m4_define([my_micro], [0]) +m4_define([my_version], [my_major.my_minor.my_revision]) + +# Use -version option for libtool +m4_define([my_current], [m4_eval(my_minor * 10 + my_micro)]) +m4_define([my_revision],[my_major]) +m4_define([my_age], [my_current]) +m4_define([my_iface], [my_current:my_revision:my_age]) + +# Autoconf 2.62 is bootstrapped with Automake 1.10.1. +# https://lists.gnu.org/archive/html/autotools-announce/2008-04/msg00002.html +AC_PREREQ(2.62) +# Initialize Autoconf +AC_INIT([hinawa], [my_version], [o-takashi@sakamocchi.jp]) +# The directory for helper scripts +AC_CONFIG_AUX_DIR([config]) +# The directory for M4 macros +AC_CONFIG_MACRO_DIR([m4]) +# The header for variables with AC_DEFINE +AC_CONFIG_HEADERS([config.h]) + +# Automake 1.13 or later +AM_INIT_AUTOMAKE([1.10.1]) +# Don't output command lines +AM_SILENT_RULES([yes]) + +# GNU libtool 2.2.6 is bootstrapped with Automake 1.10.1 and Autoconf 2.62. +# https://lists.gnu.org/archive/html/autotools-announce/2008-09/msg00000.html +LT_PREREQ(2.2.6) +# Initialize GNU libtool +LT_INIT +# Define library version +LT_IFACE="my_iface" +AC_SUBST(LT_IFACE) + +# Detect C language compiler +AC_PROG_CC + +# The files generated from *.in +AC_CONFIG_FILES([ + Makefile +]) + +# Generate scripts and launch +AC_OUTPUT
In this library, 'transaction' consists of a pair of a request and a response. To achieve the transaction, a requester should wait for a response from the receiver.
Typically, to achieve the transaction, applications which transfer requests are blocked with read(2) or poll(2) to wait responses. But this operation is not good for GUI applications because these blocking API stops a thread of event loop.
To avoid this situation, this commit adds own 'context'. The context is running on own thread and execute poll(2). This context can be written directly with pthreads(7) and select(2)/poll(2)/epoll(7), but in this time I apply GMainContext/GThread in glib to save my time.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/Makefile.am | 3 +++ libhinawa/README | 1 + libhinawa/configure.ac | 7 +++++ libhinawa/src/Makefile.am | 24 +++++++++++++++++ libhinawa/src/hinawa_context.c | 60 ++++++++++++++++++++++++++++++++++++++++++ libhinawa/src/hinawa_context.h | 10 +++++++ 6 files changed, 105 insertions(+) create mode 100644 libhinawa/src/Makefile.am create mode 100644 libhinawa/src/hinawa_context.c create mode 100644 libhinawa/src/hinawa_context.h
diff --git a/libhinawa/Makefile.am b/libhinawa/Makefile.am index e39f07b..05f5d58 100644 --- a/libhinawa/Makefile.am +++ b/libhinawa/Makefile.am @@ -1,2 +1,5 @@ # Include m4 macros ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} + +SUBDIRS = \ + src diff --git a/libhinawa/README b/libhinawa/README index 234ed91..db9b82a 100644 --- a/libhinawa/README +++ b/libhinawa/README @@ -2,6 +2,7 @@ Requirements - GNU Autoconf 2.62 or later - GNU Automake 1.10.1 or later - GNU libtool 2.2.6 or later +- Glib 2.32.4 or later
How to build $ ./autogen.sh diff --git a/libhinawa/configure.ac b/libhinawa/configure.ac index 2eeef0d..5ecb7ec 100644 --- a/libhinawa/configure.ac +++ b/libhinawa/configure.ac @@ -19,6 +19,9 @@ AC_INIT([hinawa], [my_version], [o-takashi@sakamocchi.jp]) AC_CONFIG_AUX_DIR([config]) # The directory for M4 macros AC_CONFIG_MACRO_DIR([m4]) + +# The directory for sources +AC_CONFIG_SRCDIR([src]) # The header for variables with AC_DEFINE AC_CONFIG_HEADERS([config.h])
@@ -39,9 +42,13 @@ AC_SUBST(LT_IFACE) # Detect C language compiler AC_PROG_CC
+# Glib 2.32 or later +AM_PATH_GLIB_2_0([2.32.4], [], [], [gobject]) + # The files generated from *.in AC_CONFIG_FILES([ Makefile + src/Makefile ])
# Generate scripts and launch diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am new file mode 100644 index 0000000..5673255 --- /dev/null +++ b/libhinawa/src/Makefile.am @@ -0,0 +1,24 @@ +# Remove auto-generated files when cleaning +CLEANFILES = + +AM_CPPFLAGS = \ + -I$(top_builddir) \ + -I$(top_srcdir) + +AM_CFLAGS = \ + $(GLIB_CFLAGS) \ + -Wall + +lib_LTLIBRARIES = \ + libhinawa.la + +libhinawa_la_LDFLAGS = \ + -version-info $(LT_IFACE) + +libhinawa_la_LIBADD = \ + $(GLIB_LIBS) + +libhinawa_la_SOURCES = \ + hinawa_context.c + +pkginclude_HEADERS = diff --git a/libhinawa/src/hinawa_context.c b/libhinawa/src/hinawa_context.c new file mode 100644 index 0000000..dd20d21 --- /dev/null +++ b/libhinawa/src/hinawa_context.c @@ -0,0 +1,60 @@ +#include "hinawa_context.h" + +static GMainContext *ctx; +static GThread *thread; + +static gboolean running; +static gint counter; + +static gpointer run_main_loop(gpointer data) +{ + while (running) + g_main_context_iteration(ctx, TRUE); + + g_thread_exit(NULL); + + return NULL; +} + +static GMainContext *get_my_context(GError **exception) +{ + if (ctx == NULL) + ctx = g_main_context_new(); + + if (thread == NULL) { + thread = g_thread_try_new("gmain", run_main_loop, NULL, + exception); + if (*exception != NULL) { + g_main_context_unref(ctx); + ctx = NULL; + } + } + + return ctx; +} + +gpointer hinawa_context_add_src(GSource *src, gint fd, GIOCondition event, + GError **exception) +{ + GMainContext *ctx; + + ctx = get_my_context(exception); + if (*exception != NULL) + return NULL; + running = TRUE; + + /* NOTE: The returned ID is never used. */ + g_source_attach(src, ctx); + + return g_source_add_unix_fd(src, fd, event); +} + +void hinawa_context_remove_src(GSource *src) +{ + g_source_destroy(src); + if (g_atomic_int_dec_and_test(&counter)) { + running = FALSE; + g_thread_join(thread); + thread = NULL; + } +} diff --git a/libhinawa/src/hinawa_context.h b/libhinawa/src/hinawa_context.h new file mode 100644 index 0000000..97666c6 --- /dev/null +++ b/libhinawa/src/hinawa_context.h @@ -0,0 +1,10 @@ +#ifndef __ALSA_TOOLS_HINAWA_CONTEXT_H__ +#define __ALSA_TOOLS_HINAWA_CONTEXT_H__ + +#include <glib.h> +#include <glib-object.h> + +gpointer hinawa_context_add_src(GSource *src, gint fd, GIOCondition event, + GError **exception); + +#endif
On 2015年01月25日 20:34, Takashi Sakamoto wrote:
In this library, 'transaction' consists of a pair of a request and a response. To achieve the transaction, a requester should wait for a response from the receiver.
Typically, to achieve the transaction, applications which transfer requests are blocked with read(2) or poll(2) to wait responses. But this operation is not good for GUI applications because these blocking API stops a thread of event loop.
To avoid this situation, this commit adds own 'context'. The context is running on own thread and execute poll(2). This context can be written directly with pthreads(7) and select(2)/poll(2)/epoll(7), but in this time I apply GMainContext/GThread in glib to save my time.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp
I realize this comment is bad. The strange circuit turned on in my brain when creating this patch...
This library needs to handle any asynchronous events such as bus-reset (from FireWire subsystem) or lock/unlock events (from ALSA), thus should do poll regardless of transactions. In this reason, own thread is required.
libhinawa/Makefile.am | 3 +++ libhinawa/README | 1 + libhinawa/configure.ac | 7 +++++ libhinawa/src/Makefile.am | 24 +++++++++++++++++ libhinawa/src/hinawa_context.c | 60 ++++++++++++++++++++++++++++++++++++++++++ libhinawa/src/hinawa_context.h | 10 +++++++ 6 files changed, 105 insertions(+) create mode 100644 libhinawa/src/Makefile.am create mode 100644 libhinawa/src/hinawa_context.c create mode 100644 libhinawa/src/hinawa_context.h
diff --git a/libhinawa/Makefile.am b/libhinawa/Makefile.am index e39f07b..05f5d58 100644 --- a/libhinawa/Makefile.am +++ b/libhinawa/Makefile.am @@ -1,2 +1,5 @@ # Include m4 macros ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
+SUBDIRS = \
- src
diff --git a/libhinawa/README b/libhinawa/README index 234ed91..db9b82a 100644 --- a/libhinawa/README +++ b/libhinawa/README @@ -2,6 +2,7 @@ Requirements
- GNU Autoconf 2.62 or later
- GNU Automake 1.10.1 or later
- GNU libtool 2.2.6 or later
+- Glib 2.32.4 or later
How to build $ ./autogen.sh diff --git a/libhinawa/configure.ac b/libhinawa/configure.ac index 2eeef0d..5ecb7ec 100644 --- a/libhinawa/configure.ac +++ b/libhinawa/configure.ac @@ -19,6 +19,9 @@ AC_INIT([hinawa], [my_version], [o-takashi@sakamocchi.jp]) AC_CONFIG_AUX_DIR([config]) # The directory for M4 macros AC_CONFIG_MACRO_DIR([m4])
+# The directory for sources +AC_CONFIG_SRCDIR([src]) # The header for variables with AC_DEFINE AC_CONFIG_HEADERS([config.h])
@@ -39,9 +42,13 @@ AC_SUBST(LT_IFACE) # Detect C language compiler AC_PROG_CC
+# Glib 2.32 or later +AM_PATH_GLIB_2_0([2.32.4], [], [], [gobject])
# The files generated from *.in AC_CONFIG_FILES([ Makefile
- src/Makefile
])
# Generate scripts and launch diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am new file mode 100644 index 0000000..5673255 --- /dev/null +++ b/libhinawa/src/Makefile.am @@ -0,0 +1,24 @@ +# Remove auto-generated files when cleaning +CLEANFILES =
+AM_CPPFLAGS = \
-I$(top_builddir) \
-I$(top_srcdir)
+AM_CFLAGS = \
- $(GLIB_CFLAGS) \
- -Wall
+lib_LTLIBRARIES = \
- libhinawa.la
+libhinawa_la_LDFLAGS = \
- -version-info $(LT_IFACE)
+libhinawa_la_LIBADD = \
- $(GLIB_LIBS)
+libhinawa_la_SOURCES = \
- hinawa_context.c
+pkginclude_HEADERS = diff --git a/libhinawa/src/hinawa_context.c b/libhinawa/src/hinawa_context.c new file mode 100644 index 0000000..dd20d21 --- /dev/null +++ b/libhinawa/src/hinawa_context.c @@ -0,0 +1,60 @@ +#include "hinawa_context.h"
+static GMainContext *ctx; +static GThread *thread;
+static gboolean running; +static gint counter;
+static gpointer run_main_loop(gpointer data) +{
- while (running)
g_main_context_iteration(ctx, TRUE);
- g_thread_exit(NULL);
- return NULL;
+}
+static GMainContext *get_my_context(GError **exception) +{
- if (ctx == NULL)
ctx = g_main_context_new();
- if (thread == NULL) {
thread = g_thread_try_new("gmain", run_main_loop, NULL,
exception);
if (*exception != NULL) {
g_main_context_unref(ctx);
ctx = NULL;
}
- }
- return ctx;
+}
+gpointer hinawa_context_add_src(GSource *src, gint fd, GIOCondition event,
GError **exception)
+{
- GMainContext *ctx;
- ctx = get_my_context(exception);
- if (*exception != NULL)
return NULL;
- running = TRUE;
- /* NOTE: The returned ID is never used. */
- g_source_attach(src, ctx);
- return g_source_add_unix_fd(src, fd, event);
+}
+void hinawa_context_remove_src(GSource *src) +{
- g_source_destroy(src);
- if (g_atomic_int_dec_and_test(&counter)) {
running = FALSE;
g_thread_join(thread);
thread = NULL;
- }
+} diff --git a/libhinawa/src/hinawa_context.h b/libhinawa/src/hinawa_context.h new file mode 100644 index 0000000..97666c6 --- /dev/null +++ b/libhinawa/src/hinawa_context.h @@ -0,0 +1,10 @@ +#ifndef __ALSA_TOOLS_HINAWA_CONTEXT_H__ +#define __ALSA_TOOLS_HINAWA_CONTEXT_H__
+#include <glib.h> +#include <glib-object.h>
+gpointer hinawa_context_add_src(GSource *src, gint fd, GIOCondition event,
GError **exception);
+#endif
The GTK-Doc project gives a way to generate API documentation from C source code, mainly from comments. This library uses this mechanism to give references.
This commit adds a dependency with: - GTK-Doc 1.18-2 or later
The reference is available to give '--enable-gtk-doc' option for ./configure script.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/Makefile.am | 3 ++- libhinawa/README | 7 +++++ libhinawa/autogen.sh | 1 + libhinawa/configure.ac | 6 +++++ libhinawa/doc/Makefile.am | 2 ++ libhinawa/doc/reference/Makefile.am | 46 ++++++++++++++++++++++++++++++++ libhinawa/doc/reference/hinawa-docs.sgml | 39 +++++++++++++++++++++++++++ libhinawa/doc/reference/version.xml.in | 1 + 8 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 libhinawa/doc/Makefile.am create mode 100644 libhinawa/doc/reference/Makefile.am create mode 100644 libhinawa/doc/reference/hinawa-docs.sgml create mode 100644 libhinawa/doc/reference/version.xml.in
diff --git a/libhinawa/Makefile.am b/libhinawa/Makefile.am index 05f5d58..3fd84c5 100644 --- a/libhinawa/Makefile.am +++ b/libhinawa/Makefile.am @@ -2,4 +2,5 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
SUBDIRS = \ - src + src \ + doc diff --git a/libhinawa/README b/libhinawa/README index db9b82a..f6a0650 100644 --- a/libhinawa/README +++ b/libhinawa/README @@ -3,9 +3,16 @@ Requirements - GNU Automake 1.10.1 or later - GNU libtool 2.2.6 or later - Glib 2.32.4 or later +- GTK-Doc 1.18-2
How to build $ ./autogen.sh $ ./configure $ make $ make install + +How to refer document + $ ./autogen.sh + $ ./configure --enable-gtk-doc + $ make + $ make install diff --git a/libhinawa/autogen.sh b/libhinawa/autogen.sh index 54ecfa2..98f6dbf 100755 --- a/libhinawa/autogen.sh +++ b/libhinawa/autogen.sh @@ -7,4 +7,5 @@ if [ ! -e m4 ] ; then mkdir -p m4 fi
+gtkdocize --copy --docdir doc/reference autoreconf --install diff --git a/libhinawa/configure.ac b/libhinawa/configure.ac index 5ecb7ec..28ca374 100644 --- a/libhinawa/configure.ac +++ b/libhinawa/configure.ac @@ -45,10 +45,16 @@ AC_PROG_CC # Glib 2.32 or later AM_PATH_GLIB_2_0([2.32.4], [], [], [gobject])
+# GTK-Doc 1.18-2 or later +GTK_DOC_CHECK([1.18-2]) + # The files generated from *.in AC_CONFIG_FILES([ Makefile src/Makefile + doc/Makefile + doc/reference/Makefile + doc/reference/version.xml ])
# Generate scripts and launch diff --git a/libhinawa/doc/Makefile.am b/libhinawa/doc/Makefile.am new file mode 100644 index 0000000..66af18f --- /dev/null +++ b/libhinawa/doc/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = \ + reference diff --git a/libhinawa/doc/reference/Makefile.am b/libhinawa/doc/reference/Makefile.am new file mode 100644 index 0000000..b7e28d2 --- /dev/null +++ b/libhinawa/doc/reference/Makefile.am @@ -0,0 +1,46 @@ +# The name of this module +DOC_MODULE = hinawa + +# THe entry point +DOC_MAIN_SGML_FILE = hinawa-docs.sgml + +# The directory with sources +DOC_SOURCE_DIR = \ + $(top_srcdir)/src + +# The tag for deprecates +SCAN_OPTIONS = + +# The prefix +MKDB_OPTIONS = \ + --name-space=hinawa + +# The patterns for headers +HFILE_GLOB = \ + $(top_srcdir)/src/*.h + +# The patterns for sources +CFILE_GLOB = \ + $(top_srcdir)/src/*.c + +# The options for C Pre-Processor +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -I$(top_srcdir)/src + +# The options for C compiler +AM_CFLAGS = \ + $(GLIB_CFLAGS) \ + -Wall + +# The options to link +GTKDOC_LIBS = \ + $(top_builddir)/src/libhinawa.la \ + $(GLIB_LIBS) + +# Include Makefile generated by GTK-Doc +include $(top_srcdir)/doc/reference/gtk-doc.make + +CLEANFILES += \ + $(DOC_MODULE)-sections.txt \ + $(DOC_MODULE).types diff --git a/libhinawa/doc/reference/hinawa-docs.sgml b/libhinawa/doc/reference/hinawa-docs.sgml new file mode 100644 index 0000000..43c5c4e --- /dev/null +++ b/libhinawa/doc/reference/hinawa-docs.sgml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [ +<!ENTITY version SYSTEM "version.xml"> +]> +<book xmlns:xi="http://www.w3.org/2003/XInclude" id="index" lang="en"> + <bookinfo> + <title>Hinawa Reference Manual</title> + <releaseinfo>This document is for the Hinawa library, version &version;. + </releaseinfo> + </bookinfo> + + <part id="reference"> + <title>Reference</title> + + <chapter id="introduction"> + <title>Introduction</title> + <para> + Hinawa is an gobject introspection library for devices connected to + IEEE 1394 bus. This library supports any types of transactions + over IEEE 1394 bus. + This library also supports some functionality which ALSA firewire + stack produces. + </para> + </chapter> + + <chapter id="libhinawa"> + <title>libhinawa</title> + <para> + This library gives 7 objects, 3 objects are abstraction of the + functionality in ALSA firewire stack, the others are abstractions + of the transaction functionality in Linux firewire stack. + </para> + </chapter> + </part> + + <index id="index-all"> + <title>Index of all symbols</title> + </index> +</book> diff --git a/libhinawa/doc/reference/version.xml.in b/libhinawa/doc/reference/version.xml.in new file mode 100644 index 0000000..d78bda9 --- /dev/null +++ b/libhinawa/doc/reference/version.xml.in @@ -0,0 +1 @@ +@VERSION@
Linux FireWire subsystem gives a way to listen to any units on IEEE 1394 bus. This subsystem adds FireWire character devices and applications can get any events by reading the devices.
This commit adds HINAWA_TYPE_FW_UNIT object to perform this. This object is written with GObject way.
When constructing this object, applications gets file descriptor by open() with a path of FireWire character devices. When calling listen(), the object starts listening. Then the 'generation' property of this object is valid and 'bus-update' signal is generated at IEEE 1394 bus-reset event. When destructing the object, the file descriptor is released.
I note that src/hinawa_sigs_marshal.* are newly generated by glib tools to detect the signature of GObject signal handler. These files should be regenerated when new signals are added or existed signals are changes, thus don't forget to 'make clean' when applying following patches.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/doc/reference/hinawa-docs.sgml | 1 + libhinawa/src/Makefile.am | 27 ++- libhinawa/src/fw_unit.c | 335 +++++++++++++++++++++++++++++++ libhinawa/src/fw_unit.h | 52 +++++ libhinawa/src/internal.h | 13 ++ 5 files changed, 425 insertions(+), 3 deletions(-) create mode 100644 libhinawa/src/fw_unit.c create mode 100644 libhinawa/src/fw_unit.h create mode 100644 libhinawa/src/internal.h
diff --git a/libhinawa/doc/reference/hinawa-docs.sgml b/libhinawa/doc/reference/hinawa-docs.sgml index 43c5c4e..662d8c5 100644 --- a/libhinawa/doc/reference/hinawa-docs.sgml +++ b/libhinawa/doc/reference/hinawa-docs.sgml @@ -30,6 +30,7 @@ functionality in ALSA firewire stack, the others are abstractions of the transaction functionality in Linux firewire stack. </para> + <xi:include href="xml/fw_unit.xml"/> </chapter> </part>
diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am index 5673255..9eda8f4 100644 --- a/libhinawa/src/Makefile.am +++ b/libhinawa/src/Makefile.am @@ -1,5 +1,7 @@ # Remove auto-generated files when cleaning -CLEANFILES = +CLEANFILES = \ + hinawa_sigs_marshal.* +
AM_CPPFLAGS = \ -I$(top_builddir) \ @@ -19,6 +21,25 @@ libhinawa_la_LIBADD = \ $(GLIB_LIBS)
libhinawa_la_SOURCES = \ - hinawa_context.c + hinawa_context.c \ + hinawa_sigs_marshal.h \ + hinawa_sigs_marshal.c \ + fw_unit.h \ + fw_unit.c + +pkginclude_HEADERS = \ + hinawa_sigs_marshal.h \ + fw_unit.h + +hinawa_sigs_marshal.list: + $(AM_V_GEN)( find | grep .c$$ | xargs cat | \ + sed -n -e 's/.*hinawa_sigs_marshal_([A-Z]*__[A-Z_]*).*/\1/p' |\ + sed -e 's/__/:/' -e 'y/_/,/' ) | sort -u > $@ + +hinawa_sigs_marshal.h: hinawa_sigs_marshal.list + $(AM_V_GEN)( glib-genmarshal --header \ + --prefix=hinawa_sigs_marshal $< ) > $@
-pkginclude_HEADERS = +hinawa_sigs_marshal.c: hinawa_sigs_marshal.list hinawa_sigs_marshal.h + $(AM_V_GEN)(echo '#include "hinawa_sigs_marshal.h"'; \ + glib-genmarshal --body --prefix=hinawa_sigs_marshal $< ) > $@ diff --git a/libhinawa/src/fw_unit.c b/libhinawa/src/fw_unit.c new file mode 100644 index 0000000..b948ef8 --- /dev/null +++ b/libhinawa/src/fw_unit.c @@ -0,0 +1,335 @@ +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#include "hinawa_context.h" +#include "fw_unit.h" +#include "internal.h" + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/** + * SECTION:fw_unit + * @Title: HinawaFwUnit + * @Short_description: An event listener for FireWire unit + * + * A #HinawaFwUnit is an event listener for a certain FireWire unit. + * This class is an application of Linux FireWire subsystem. + * All of operations utilize ioctl(2) with subsystem specific request commands. + */ +typedef struct { + GSource src; + HinawaFwUnit *unit; + gpointer tag; +} FwUnitSource; + +struct _HinawaFwUnitPrivate { + int fd; + guint64 generation; + + unsigned int len; + void *buf; + FwUnitSource *src; +}; +G_DEFINE_TYPE_WITH_PRIVATE(HinawaFwUnit, hinawa_fw_unit, G_TYPE_OBJECT) +#define FW_UNIT_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ + HINAWA_TYPE_FW_UNIT, HinawaFwUnitPrivate)) + +/* This object has properties. */ +enum fw_unit_prop_type { + FW_UNIT_PROP_TYPE_GENERATION = 1, + FW_UNIT_PROP_TYPE_COUNT, +}; +static GParamSpec *fw_unit_props[FW_UNIT_PROP_TYPE_COUNT] = { NULL, }; + +/* This object has one signal. */ +enum fw_unit_sig_type { + FW_UNIT_SIG_TYPE_BUS_UPDATE = 0, + FW_UNIT_SIG_TYPE_COUNT, +}; +static guint fw_unit_sigs[FW_UNIT_SIG_TYPE_COUNT] = { 0 }; + +static void fw_unit_get_property(GObject *obj, guint id, + GValue *val, GParamSpec *spec) +{ + HinawaFwUnit *self = HINAWA_FW_UNIT(obj); + HinawaFwUnitPrivate *priv = FW_UNIT_GET_PRIVATE(self); + + switch (id) { + case FW_UNIT_PROP_TYPE_GENERATION: + g_value_set_uint64(val, priv->generation); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); + break; + } +} + +static void fw_unit_set_property(GObject *obj, guint id, + const GValue *val, GParamSpec *spec) +{ + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); +} + +static void fw_unit_dispose(GObject *obj) +{ + HinawaFwUnit *self = HINAWA_FW_UNIT(obj); + HinawaFwUnitPrivate *priv = FW_UNIT_GET_PRIVATE(self); + + hinawa_fw_unit_unlisten(self); + + close(priv->fd); + + G_OBJECT_CLASS(hinawa_fw_unit_parent_class)->dispose(obj); +} + +static void fw_unit_finalize(GObject *gobject) +{ + G_OBJECT_CLASS(hinawa_fw_unit_parent_class)->finalize(gobject); +} + +static void hinawa_fw_unit_class_init(HinawaFwUnitClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->get_property = fw_unit_get_property; + gobject_class->set_property = fw_unit_set_property; + gobject_class->dispose = fw_unit_dispose; + gobject_class->finalize = fw_unit_finalize; + + fw_unit_props[FW_UNIT_PROP_TYPE_GENERATION] = + g_param_spec_uint64("generation", "generation", + "current level of generation on this bus.", + 0, ULONG_MAX, 0, + G_PARAM_READABLE); + + g_object_class_install_properties(gobject_class, + FW_UNIT_PROP_TYPE_COUNT, + fw_unit_props); + + /** + * HinawaFwUnit::bus-update: + * @self: A #HinawaFwUnit + * + * When IEEE 1394 bus is updated, the ::bus-update signal is generated. + * Handlers can read current generation in the bus via 'generation' + * property. + */ + fw_unit_sigs[FW_UNIT_SIG_TYPE_BUS_UPDATE] = + g_signal_new("bus-update", + G_OBJECT_CLASS_TYPE(klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0, G_TYPE_NONE); +} + +static void hinawa_fw_unit_init(HinawaFwUnit *self) +{ + self->priv = hinawa_fw_unit_get_instance_private(self); +} + +/** + * hinawa_fw_unit_open: + * @self: A #HinawaFwUnit + * @path: A path to Linux FireWire character device + * @exception: A #GError + */ +void hinawa_fw_unit_open(HinawaFwUnit *self, gchar *path, GError **exception) +{ + HinawaFwUnitPrivate *priv; + int fd; + struct fw_cdev_get_info info = {0}; + struct fw_cdev_event_bus_reset br = {0}; + + g_return_if_fail(HINAWA_IS_FW_UNIT(self)); + priv = FW_UNIT_GET_PRIVATE(self); + + fd = open(path, O_RDONLY); + if (fd < 0) { + g_set_error(exception, g_quark_from_static_string(__func__), + errno, "%s", strerror(errno)); + return; + } + + info.version = 4; + info.bus_reset = (guint64)&br; + info.bus_reset_closure = (guint64)self; + if (ioctl(fd, FW_CDEV_IOC_GET_INFO, &info) < 0) { + g_set_error(exception, g_quark_from_static_string(__func__), + errno, "%s", strerror(errno)); + close(fd); + return; + } + + priv->fd = fd; + priv->generation = br.generation; +} + +/* Internal use only. */ +void hinawa_fw_unit_ioctl(HinawaFwUnit *self, int req, void *args, int *err) +{ + HinawaFwUnitPrivate *priv; + + g_return_if_fail(HINAWA_IS_FW_UNIT(self)); + priv = FW_UNIT_GET_PRIVATE(self); + + *err = 0; + if (ioctl(priv->fd, req, args) < 0) + *err = errno; +} + +static void handle_update(HinawaFwUnit *self, + struct fw_cdev_event_bus_reset *event) +{ + HinawaFwUnitPrivate *priv; + + g_return_if_fail(HINAWA_IS_FW_UNIT(self)); + priv = FW_UNIT_GET_PRIVATE(self); + + priv->generation = event->generation; + + g_signal_emit(self, fw_unit_sigs[FW_UNIT_SIG_TYPE_BUS_UPDATE], 0, + NULL); +} + +static gboolean prepare_src(GSource *src, gint *timeout) +{ + /* Set 2msec for poll(2) timeout. */ + *timeout = 2; + + /* This source is not ready, let's poll(2) */ + return FALSE; +} + +static gboolean check_src(GSource *gsrc) +{ + FwUnitSource *src = (FwUnitSource *)gsrc; + HinawaFwUnit *unit = src->unit; + HinawaFwUnitPrivate *priv = FW_UNIT_GET_PRIVATE(unit); + struct fw_cdev_event_common *common; + int len; + GIOCondition condition; + + if (unit == NULL) + goto end; + + /* Let's process this source if any inputs are available. */ + condition = g_source_query_unix_fd((GSource *)src, src->tag); + if (!(condition & G_IO_IN)) + goto end; + + len = read(priv->fd, priv->buf, priv->len); + if (len <= 0) + goto end; + + common = (struct fw_cdev_event_common *)priv->buf; + + if (HINAWA_IS_FW_UNIT(common->closure) && + common->type == FW_CDEV_EVENT_BUS_RESET) + handle_update(HINAWA_FW_UNIT(common->closure), + (struct fw_cdev_event_bus_reset *)common); +end: + /* Don't go to dispatch, then continue to process this source. */ + return FALSE; +} + +static gboolean dispatch_src(GSource *src, GSourceFunc callback, + gpointer user_data) +{ + /* Just be sure to continue to process this source. */ + return TRUE; +} + +/** + * hinawa_fw_unit_listen: + * @self: A #HinawaFwUnit + * @exception: A #GError + * + * Start to listen to any events from the unit. + */ +void hinawa_fw_unit_listen(HinawaFwUnit *self, GError **exception) +{ + static GSourceFuncs funcs = { + .prepare = prepare_src, + .check = check_src, + .dispatch = dispatch_src, + .finalize = NULL, + }; + HinawaFwUnitPrivate *priv; + void *buf; + GSource *src; + + g_return_if_fail(HINAWA_IS_FW_UNIT(self)); + priv = FW_UNIT_GET_PRIVATE(self); + + /* + * MEMO: allocate one page because we cannot assume the size of + * transaction frame. + */ + buf = g_malloc0(getpagesize()); + if (buf == NULL) { + g_set_error(exception, g_quark_from_static_string(__func__), + ENOMEM, "%s", strerror(ENOMEM)); + return; + } + + src = g_source_new(&funcs, sizeof(FwUnitSource)); + if (src == NULL) { + g_set_error(exception, g_quark_from_static_string(__func__), + ENOMEM, "%s", strerror(ENOMEM)); + g_free(buf); + return; + } + + g_source_set_name(src, "HinawaFwUnit"); + g_source_set_priority(src, G_PRIORITY_HIGH_IDLE); + g_source_set_can_recurse(src, TRUE); + + ((FwUnitSource *)src)->unit = self; + priv->src = (FwUnitSource *)src; + priv->buf = buf; + priv->len = getpagesize(); + + ((FwUnitSource *)src)->tag = + hinawa_context_add_src(src, priv->fd, G_IO_IN, exception); + if (*exception != NULL) { + g_free(buf); + g_source_destroy(src); + priv->buf = NULL; + priv->len = 0; + priv->src = NULL; + return; + } +} + +/** + * hinawa_fw_unit_unlisten: + * @self: A #HinawaFwUnit + * + * Stop to listen to any events from the unit. + */ +void hinawa_fw_unit_unlisten(HinawaFwUnit *self) +{ + HinawaFwUnitPrivate *priv; + + g_return_if_fail(HINAWA_IS_FW_UNIT(self)); + priv = FW_UNIT_GET_PRIVATE(self); + + if (priv->src == NULL) + return; + + g_source_destroy((GSource *)priv->src); + g_free(priv->src); + priv->src = NULL; + + g_free(priv->buf); + priv->buf = NULL; + priv->len = 0; +} diff --git a/libhinawa/src/fw_unit.h b/libhinawa/src/fw_unit.h new file mode 100644 index 0000000..f8f38a4 --- /dev/null +++ b/libhinawa/src/fw_unit.h @@ -0,0 +1,52 @@ +#ifndef __ALSA_TOOLS_HINAWA_FW_UNIT_H__ +#define __ALSA_TOOLS_HINAWA_FW_UNIT_H__ + +#include <glib.h> +#include <glib-object.h> + +G_BEGIN_DECLS + +#define HINAWA_TYPE_FW_UNIT (hinawa_fw_unit_get_type()) + +#define HINAWA_FW_UNIT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + HINAWA_TYPE_FW_UNIT, \ + HinawaFwUnit)) +#define HINAWA_IS_FW_UNIT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + HINAWA_TYPE_FW_UNIT)) + +#define HINAWA_FW_UNIT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + HINAWA_TYPE_FW_UNIT, \ + HinawaFwUnitClass)) +#define HINAWA_IS_FW_UNIT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + HINAWA_TYPE_FW_UNIT)) +#define HINAWA_FW_UNIT_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + HINAWA_TYPE_FW_UNIT, \ + HinawaFwUnitClass)) + +typedef struct _HinawaFwUnit HinawaFwUnit; +typedef struct _HinawaFwUnitClass HinawaFwUnitClass; +typedef struct _HinawaFwUnitPrivate HinawaFwUnitPrivate; + +struct _HinawaFwUnit { + GObject parent_instance; + + HinawaFwUnitPrivate *priv; +}; + +struct _HinawaFwUnitClass { + GObjectClass parent_class; +}; + +GType hinawa_fw_unit_get_type(void) G_GNUC_CONST; + +void hinawa_fw_unit_open(HinawaFwUnit *self, gchar *path, GError **exception); + +void hinawa_fw_unit_listen(HinawaFwUnit *self, GError **exception); +void hinawa_fw_unit_unlisten(HinawaFwUnit *self); + +#endif diff --git a/libhinawa/src/internal.h b/libhinawa/src/internal.h new file mode 100644 index 0000000..83f920b --- /dev/null +++ b/libhinawa/src/internal.h @@ -0,0 +1,13 @@ +#ifndef __ALSA_TOOLS_HINAWA_INTERNAL_H__ +#define __ALSA_TOOLS_HINAWA_INTERNAL_H__ + +#include <errno.h> +#include <string.h> + +#include <linux/firewire-cdev.h> +#include <linux/firewire-constants.h> + +#include "fw_unit.h" + +void hinawa_fw_unit_ioctl(HinawaFwUnit *self, int req, void *args, int *err); +#endif
GObject Introspection is a mechanism to give a metadata of library to each language bindings. The library should be written by GObject way.
This commit applies this mechanism to this library to produce language bindings, thus adds a dependency with: - GObject Introspaction 1.32.1 or later
The comments in each methods and signals are important for GObject Introspection scanner because of a hint to create better metadata.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/README | 1 + libhinawa/configure.ac | 6 +++++- libhinawa/src/Makefile.am | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/libhinawa/README b/libhinawa/README index f6a0650..1bd0d52 100644 --- a/libhinawa/README +++ b/libhinawa/README @@ -4,6 +4,7 @@ Requirements - GNU libtool 2.2.6 or later - Glib 2.32.4 or later - GTK-Doc 1.18-2 +- GObject Introspection 1.32.1 or later
How to build $ ./autogen.sh diff --git a/libhinawa/configure.ac b/libhinawa/configure.ac index 28ca374..b0d9517 100644 --- a/libhinawa/configure.ac +++ b/libhinawa/configure.ac @@ -26,7 +26,8 @@ AC_CONFIG_SRCDIR([src]) AC_CONFIG_HEADERS([config.h])
# Automake 1.13 or later -AM_INIT_AUTOMAKE([1.10.1]) +# GObject Introspection uses GNU Make-specific functionality. +AM_INIT_AUTOMAKE([1.10.1 -Wno-portability]) # Don't output command lines AM_SILENT_RULES([yes])
@@ -48,6 +49,9 @@ AM_PATH_GLIB_2_0([2.32.4], [], [], [gobject]) # GTK-Doc 1.18-2 or later GTK_DOC_CHECK([1.18-2])
+# GObject introspection 1.32.1 or later +GOBJECT_INTROSPECTION_REQUIRE([1.32.1]) + # The files generated from *.in AC_CONFIG_FILES([ Makefile diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am index 9eda8f4..d9519ab 100644 --- a/libhinawa/src/Makefile.am +++ b/libhinawa/src/Makefile.am @@ -43,3 +43,32 @@ hinawa_sigs_marshal.h: hinawa_sigs_marshal.list hinawa_sigs_marshal.c: hinawa_sigs_marshal.list hinawa_sigs_marshal.h $(AM_V_GEN)(echo '#include "hinawa_sigs_marshal.h"'; \ glib-genmarshal --body --prefix=hinawa_sigs_marshal $< ) > $@ + +-include $(INTROSPECTION_MAKEFILE) +INTROSPECTION_GIRS = +INTROSPECTION_SCANNER_ARGS = --warn-all +INTROSPECTION_COMPILER_ARGS = + +if HAVE_INTROSPECTION +Hinawa-1.0.gir: libhinawa.la +Hinawa_1_0_gir_PACKAGES = +Hinawa_1_0_gir_EXPORT_PACKAGES = hinawa +Hinawa_1_0_gir_INCLUDES = GObject-2.0 +Hinawa_1_0_gir_CFLAGS = +Hinawa_1_0_gir_LIBS = libhinawa.la +Hinawa_1_0_gir_FILES = $(libhinawa_la_SOURCES) +Hinawa_1_0_gir_SCANNERFLAGS = \ + --identifier-prefix=Hinawa \ + --symbol-prefix=hinawa +INTROSPECTION_GIRS += Hinawa-1.0.gir + +girdir = $(datadir)/gir-1.0 +gir_DATA = $(INTROSPECTION_GIRS) + +typelibdir = $(libdir)/girepository-1.0 +typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) + +CLEANFILES += \ + $(gir_DATA) \ + $(typelib_DATA) +endif
The units on IEEE 1394 bus transfers any requests to a certain address on receiver. To receive the request, the receiver should listen to the address and respond it.
Linux FireWire subsystem gives a way to perform this. Applications reserve a range of address on IEEE 1394 host controller by ioctl(2). When the host controller receives any requests, the subsystem generates readable events for applications. When reading the events, the application should transfer a response by ioctl(2). The range of address is an exclusive resource on the host controller, thus the other applications cannot reserve it.
This commit adds HINAWA_TYPE_FW_RESP object to perform this. When constructing the instance, applications can reserve the range of address by register() method. When the host controller receives a request inner the range, the instance generates 'requested' signal. If the application want to transfer some data in the response frame, the handler should return 32bit array. Else return NULL.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/doc/reference/hinawa-docs.sgml | 1 + libhinawa/src/Makefile.am | 7 +- libhinawa/src/fw_resp.c | 232 +++++++++++++++++++++++++++++++ libhinawa/src/fw_resp.h | 51 +++++++ libhinawa/src/fw_unit.c | 4 + libhinawa/src/internal.h | 3 + 6 files changed, 296 insertions(+), 2 deletions(-) create mode 100644 libhinawa/src/fw_resp.c create mode 100644 libhinawa/src/fw_resp.h
diff --git a/libhinawa/doc/reference/hinawa-docs.sgml b/libhinawa/doc/reference/hinawa-docs.sgml index 662d8c5..419e431 100644 --- a/libhinawa/doc/reference/hinawa-docs.sgml +++ b/libhinawa/doc/reference/hinawa-docs.sgml @@ -31,6 +31,7 @@ of the transaction functionality in Linux firewire stack. </para> <xi:include href="xml/fw_unit.xml"/> + <xi:include href="xml/fw_resp.xml"/> </chapter> </part>
diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am index d9519ab..7c09088 100644 --- a/libhinawa/src/Makefile.am +++ b/libhinawa/src/Makefile.am @@ -25,11 +25,14 @@ libhinawa_la_SOURCES = \ hinawa_sigs_marshal.h \ hinawa_sigs_marshal.c \ fw_unit.h \ - fw_unit.c + fw_unit.c \ + fw_resp.h \ + fw_resp.c
pkginclude_HEADERS = \ hinawa_sigs_marshal.h \ - fw_unit.h + fw_unit.h \ + fw_resp.h
hinawa_sigs_marshal.list: $(AM_V_GEN)( find | grep .c$$ | xargs cat | \ diff --git a/libhinawa/src/fw_resp.c b/libhinawa/src/fw_resp.c new file mode 100644 index 0000000..2ee559b --- /dev/null +++ b/libhinawa/src/fw_resp.c @@ -0,0 +1,232 @@ +#include <sys/ioctl.h> +#include "fw_resp.h" +#include "internal.h" +#include "hinawa_sigs_marshal.h" + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/** + * SECTION:fw_resp + * @Title: HinawaFwResp + * @Short_description: A transaction responder for a FireWire unit + * + * A HinawaFwResp responds requests from any units. + * + * Any of transaction frames should be aligned to 32bit (quadlet). + * This class is an application of Linux FireWire subsystem. All of operations + * utilize ioctl(2) with subsystem specific request commands. + */ +struct _HinawaFwRespPrivate { + HinawaFwUnit *unit; + + guchar *buf; + guint width; + guint64 addr_handle; + + GArray *req_frame; +}; +G_DEFINE_TYPE_WITH_PRIVATE(HinawaFwResp, hinawa_fw_resp, G_TYPE_OBJECT) +#define FW_RESP_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ + HINAWA_TYPE_FW_RESP, HinawaFwRespPrivate)) + +/* This object has one signal. */ +enum fw_resp_sig_type { + FW_RESP_SIG_TYPE_REQ = 0, + FW_RESP_SIG_TYPE_COUNT, +}; +static guint fw_resp_sigs[FW_RESP_SIG_TYPE_COUNT] = { 0 }; + +static void fw_resp_dispose(GObject *gobject) +{ + HinawaFwResp *self = HINAWA_FW_RESP(gobject); + + hinawa_fw_resp_unregister(self); + + G_OBJECT_CLASS(hinawa_fw_resp_parent_class)->dispose(gobject); +} + +static void fw_resp_finalize(GObject *gobject) +{ + G_OBJECT_CLASS(hinawa_fw_resp_parent_class)->finalize(gobject); +} + +static void hinawa_fw_resp_class_init(HinawaFwRespClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->get_property = NULL; + gobject_class->set_property = NULL; + gobject_class->dispose = fw_resp_dispose; + gobject_class->finalize = fw_resp_finalize; + + /** + * HinawaFwResp::requested: + * @self: A #HinawaFwResp + * @tcode: Transaction code + * @req_frame: (element-type guint32) (array) (transfer none): + * The frame in request + * + * When any units transfer requests to the range of address to which + * this object listening. The ::requested signal handler can set + * data frame to 'resp_frame' if needed. + * + * Returns: (element-type guint32) (array) (nullable) (transfer full): + * A data frame for response. + */ + fw_resp_sigs[FW_RESP_SIG_TYPE_REQ] = + g_signal_new("requested", + G_OBJECT_CLASS_TYPE(klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + hinawa_sigs_marshal_BOXED__INT_BOXED, + G_TYPE_ARRAY, 2, G_TYPE_INT, G_TYPE_ARRAY); +} + +static void hinawa_fw_resp_init(HinawaFwResp *self) +{ + self->priv = hinawa_fw_resp_get_instance_private(self); +} + +/** + * hinawa_fw_resp_register: + * @self: A #HinawaFwResp + * @unit: A #HinawaFwUnit + * @addr: A start address to listen to in host controller + * @width: The byte width of address to listen to host controller + * @exception: A #GError + * + * Start to listen to a range of address in host controller + */ +void hinawa_fw_resp_register(HinawaFwResp *self, HinawaFwUnit *unit, + guint64 addr, guint width, GError **exception) +{ + HinawaFwRespPrivate *priv; + struct fw_cdev_allocate allocate = {0}; + int err; + + g_return_if_fail(HINAWA_IS_FW_RESP(self)); + priv = FW_RESP_GET_PRIVATE(self); + + if (priv->unit != NULL) { + g_set_error(exception, g_quark_from_static_string(__func__), + EINVAL, "%s", strerror(EINVAL)); + return; + } + priv->unit = g_object_ref(unit); + + allocate.offset = addr; + allocate.closure = (guint64)self; + allocate.length = width; + allocate.region_end = addr + width; + + hinawa_fw_unit_ioctl(priv->unit, FW_CDEV_IOC_ALLOCATE, &allocate, &err); + if (err != 0) { + g_set_error(exception, g_quark_from_static_string(__func__), + err, "%s", strerror(err)); + g_object_unref(priv->unit); + priv->unit = NULL; + return; + } + + priv->buf = g_malloc0(allocate.length); + if (priv->buf == NULL) { + g_set_error(exception, g_quark_from_static_string(__func__), + ENOMEM, "%s", strerror(ENOMEM)); + hinawa_fw_resp_unregister(self); + return; + } + + priv->req_frame = g_array_new(FALSE, TRUE, sizeof(guint32)); + if (priv->req_frame == NULL) { + g_set_error(exception, g_quark_from_static_string(__func__), + ENOMEM, "%s", strerror(ENOMEM)); + hinawa_fw_resp_unregister(self); + return; + } + + priv->width = allocate.length; +} + +/** + * hinawa_fw_resp_unregister: + * @self: A HinawaFwResp + * + * stop to listen to a range of address in host controller + */ +void hinawa_fw_resp_unregister(HinawaFwResp *self) +{ + HinawaFwRespPrivate *priv; + struct fw_cdev_deallocate deallocate = {0}; + int err; + + g_return_if_fail(HINAWA_IS_FW_RESP(self)); + priv = FW_RESP_GET_PRIVATE(self); + + if (priv->unit == NULL) + return; + + deallocate.handle = priv->addr_handle; + hinawa_fw_unit_ioctl(priv->unit, FW_CDEV_IOC_DEALLOCATE, &deallocate, + &err); + g_object_unref(priv->unit); + priv->unit = NULL; + + if (priv->req_frame != NULL) + g_array_free(priv->req_frame, TRUE); + priv->req_frame = NULL; +} + +/* NOTE: For HinawaFwUnit, internal. */ +void hinawa_fw_resp_handle_request(HinawaFwResp *self, + struct fw_cdev_event_request2 *event) +{ + HinawaFwRespPrivate *priv; + struct fw_cdev_send_response resp = {0}; + guint i, quads; + guint32 *buf; + GArray *resp_frame; + int err; + + g_return_if_fail(HINAWA_IS_FW_RESP(self)); + priv = FW_RESP_GET_PRIVATE(self); + + if (event->length > priv->width) { + resp.rcode = RCODE_CONFLICT_ERROR; + goto respond; + } + + /* Store requested frame. */ + quads = event->length / 4; + g_array_set_size(priv->req_frame, quads); + memcpy(priv->req_frame->data, event->data, event->length); + + /* For endiannness. */ + buf = (guint32 *)priv->req_frame->data; + for (i = 0; i < quads; i++) + buf[i] = be32toh(buf[i]); + + /* Emit signal to handlers. */ + g_signal_emit(self, fw_resp_sigs[FW_RESP_SIG_TYPE_REQ], 0, + event->tcode, priv->req_frame, &resp_frame); + + resp.rcode = RCODE_COMPLETE; + if (resp_frame == NULL || resp_frame->len == 0) + goto respond; + + /* For endianness. */ + buf = (guint32 *)resp_frame->data; + for (i = 0; i < resp_frame->len; i++) + buf[i] = htobe32(buf[i]); + + resp.length = resp_frame->len; + resp.data = (guint64)resp_frame->data; +respond: + resp.handle = event->handle; + + hinawa_fw_unit_ioctl(priv->unit, FW_CDEV_IOC_SEND_RESPONSE, &resp, + &err); +} diff --git a/libhinawa/src/fw_resp.h b/libhinawa/src/fw_resp.h new file mode 100644 index 0000000..0e3bb52 --- /dev/null +++ b/libhinawa/src/fw_resp.h @@ -0,0 +1,51 @@ +#ifndef __ALSA_TOOLS_HINAWA_FW_RESP_H__ +#define __ALSA_TOOLS_HINAWA_FW_RESP_H__ + +#include <glib.h> +#include <glib-object.h> +#include "fw_unit.h" + +G_BEGIN_DECLS + +#define HINAWA_TYPE_FW_RESP (hinawa_fw_resp_get_type()) + +#define HINAWA_FW_RESP(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + HINAWA_TYPE_FW_RESP, \ + HinawaFwResp)) +#define HINAWA_IS_FW_RESP(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + HINAWA_TYPE_FW_RESP)) + +#define HINAWA_FW_RESP_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + HINAWA_TYPE_FW_RESP, \ + HinawaFwResp)) +#define HINAWA_IS_FW_RESP_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + HINAWA_TYPE_Seq)) +#define HINAWA_FW_RESP_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + HINAWA_TYPE_FW_RESP, \ + HinawaFwResp)) + +typedef struct _HinawaFwResp HinawaFwResp; +typedef struct _HinawaFwRespClass HinawaFwRespClass; +typedef struct _HinawaFwRespPrivate HinawaFwRespPrivate; + +struct _HinawaFwResp { + GObject parent_instance; + + HinawaFwRespPrivate *priv; +}; + +struct _HinawaFwRespClass { + GObjectClass parent_class; +}; + +GType hinawa_fw_resp_get_type(void) G_GNUC_CONST; + +void hinawa_fw_resp_register(HinawaFwResp *self, HinawaFwUnit *unit, + guint64 addr, guint width, GError **exception); +void hinawa_fw_resp_unregister(HinawaFwResp *self); +#endif diff --git a/libhinawa/src/fw_unit.c b/libhinawa/src/fw_unit.c index b948ef8..019105d 100644 --- a/libhinawa/src/fw_unit.c +++ b/libhinawa/src/fw_unit.c @@ -235,6 +235,10 @@ static gboolean check_src(GSource *gsrc) common->type == FW_CDEV_EVENT_BUS_RESET) handle_update(HINAWA_FW_UNIT(common->closure), (struct fw_cdev_event_bus_reset *)common); + else if (HINAWA_IS_FW_RESP(common->closure) && + common->type == FW_CDEV_EVENT_REQUEST2) + hinawa_fw_resp_handle_request(HINAWA_FW_RESP(common->closure), + (struct fw_cdev_event_request2 *)common); end: /* Don't go to dispatch, then continue to process this source. */ return FALSE; diff --git a/libhinawa/src/internal.h b/libhinawa/src/internal.h index 83f920b..1ee88ec 100644 --- a/libhinawa/src/internal.h +++ b/libhinawa/src/internal.h @@ -8,6 +8,9 @@ #include <linux/firewire-constants.h>
#include "fw_unit.h" +#include "fw_resp.h"
void hinawa_fw_unit_ioctl(HinawaFwUnit *self, int req, void *args, int *err); +void hinawa_fw_resp_handle_request(HinawaFwResp *self, + struct fw_cdev_event_request2 *event); #endif
Each applications are allows to transfer requests to units on IEEE 1394 bus to control the units. The request transaction is defined in IEEE 1212. There are three types of the transaction; read, write and lock.
Linux FireWire subsystem gives a way to perform this. Applications can start the three types of transaction by ioctl(2), then receive the result by read(2).
This commit adds HINAWA_TYPE_FW_REQ object for this purpose. When constructing the instance, applications can transact by read()/write()/lock() method. These methods are programmed with threading. When the instance cannot read the result within timeout, these methods sets ETIMEDOUT to GError and returns. Currently, the timeout is 10 milli-seconds.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/doc/reference/hinawa-docs.sgml | 1 + libhinawa/src/Makefile.am | 7 +- libhinawa/src/fw_req.c | 265 +++++++++++++++++++++++++++++++ libhinawa/src/fw_req.h | 56 +++++++ libhinawa/src/fw_unit.c | 4 + libhinawa/src/internal.h | 3 + 6 files changed, 334 insertions(+), 2 deletions(-) create mode 100644 libhinawa/src/fw_req.c create mode 100644 libhinawa/src/fw_req.h
diff --git a/libhinawa/doc/reference/hinawa-docs.sgml b/libhinawa/doc/reference/hinawa-docs.sgml index 419e431..ff00ecc 100644 --- a/libhinawa/doc/reference/hinawa-docs.sgml +++ b/libhinawa/doc/reference/hinawa-docs.sgml @@ -32,6 +32,7 @@ </para> <xi:include href="xml/fw_unit.xml"/> <xi:include href="xml/fw_resp.xml"/> + <xi:include href="xml/fw_req.xml"/> </chapter> </part>
diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am index 7c09088..91726b8 100644 --- a/libhinawa/src/Makefile.am +++ b/libhinawa/src/Makefile.am @@ -27,12 +27,15 @@ libhinawa_la_SOURCES = \ fw_unit.h \ fw_unit.c \ fw_resp.h \ - fw_resp.c + fw_resp.c \ + fw_req.h \ + fw_req.c
pkginclude_HEADERS = \ hinawa_sigs_marshal.h \ fw_unit.h \ - fw_resp.h + fw_resp.h \ + fw_req.h
hinawa_sigs_marshal.list: $(AM_V_GEN)( find | grep .c$$ | xargs cat | \ diff --git a/libhinawa/src/fw_req.c b/libhinawa/src/fw_req.c new file mode 100644 index 0000000..49f78cc --- /dev/null +++ b/libhinawa/src/fw_req.c @@ -0,0 +1,265 @@ +#include <sys/ioctl.h> +#include "fw_req.h" +#include "internal.h" + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/** + * SECTION:fw_req + * @Title: HinawaFwReq + * @Short_description: A transaction executor to a FireWire unit + * + * A HinawaFwReq supports three types of transactions in IEEE 1212: + * - read + * - write + * - lock + * + * Any of transaction frames should be aligned to 32bit (quadlet). + * This class is an application of Linux FireWire subsystem. All of operations + * utilize ioctl(2) with subsystem specific request commands. + */ + +enum fw_req_type { + FW_REQ_TYPE_WRITE = 0, + FW_REQ_TYPE_READ, + FW_REQ_TYPE_COMPARE_SWAP, +}; + +/* NOTE: This object has no properties and no signals. */ +struct _HinawaFwReqPrivate { + GArray *frame; + + GCond cond; +}; +G_DEFINE_TYPE_WITH_PRIVATE(HinawaFwReq, hinawa_fw_req, G_TYPE_OBJECT) +#define FW_REQ_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ + HINAWA_TYPE_FW_REQ, HinawaFwReqPrivate)) + +static void fw_req_dispose(GObject *gobject) +{ + G_OBJECT_CLASS(hinawa_fw_req_parent_class)->dispose(gobject); +} + +static void fw_req_finalize(GObject *gobject) +{ + G_OBJECT_CLASS(hinawa_fw_req_parent_class)->finalize(gobject); +} + +static void hinawa_fw_req_class_init(HinawaFwReqClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->get_property = NULL; + gobject_class->set_property = NULL; + gobject_class->dispose = fw_req_dispose; + gobject_class->finalize = fw_req_finalize; +} + +static void hinawa_fw_req_init(HinawaFwReq *self) +{ + self->priv = hinawa_fw_req_get_instance_private(self); +} + +static void fw_req_transact(HinawaFwReq *self, HinawaFwUnit *unit, + enum fw_req_type type, guint64 addr, GArray *frame, + gint *err) +{ + struct fw_cdev_send_request req = {0}; + HinawaFwReqPrivate *priv = FW_REQ_GET_PRIVATE(self); + int tcode; + + guint64 generation; + + guint64 expiration; + GMutex lock; + + guint32 *buf; + int i; + + /* From host order to be32. */ + if (frame != NULL) { + buf = (guint32 *)frame->data; + for (i = 0; i < frame->len; i++) + buf[i] = htobe32(buf[i]); + } + + /* Setup a private structure. */ + if (type == FW_REQ_TYPE_READ) { + priv->frame = frame; + req.data = (guint64)NULL; + if (frame->len == 1) + tcode = TCODE_READ_QUADLET_REQUEST; + else + tcode = TCODE_READ_BLOCK_REQUEST; + } else if (type == FW_REQ_TYPE_WRITE) { + priv->frame = NULL; + req.data = (guint64)frame->data; + if (frame->len == 1) + tcode = TCODE_WRITE_QUADLET_REQUEST; + else + tcode = TCODE_WRITE_BLOCK_REQUEST; + } else if ((type == FW_REQ_TYPE_COMPARE_SWAP) && + ((frame->len == 2) || (frame->len == 4))) { + priv->frame = NULL; + req.data = (guint64)frame->data; + tcode = TCODE_LOCK_COMPARE_SWAP; + } else { + *err = EINVAL; + return; + } + + /* Get unit properties. */ + g_object_get(G_OBJECT(unit), "generation", &generation, NULL); + + /* Setup a transaction structure. */ + req.tcode = tcode; + req.length = frame->len * sizeof(guint32); + req.offset = addr; + req.closure = (guint64)self; + req.generation = generation; + + /* NOTE: Timeout is 10 milli-seconds. */ + expiration = g_get_monotonic_time() + 10 * G_TIME_SPAN_MILLISECOND; + g_cond_init(&priv->cond); + g_mutex_init(&lock); + + /* Send this transaction. */ + hinawa_fw_unit_ioctl(unit, FW_CDEV_IOC_SEND_REQUEST, &req, err); + /* Wait for a response with timeout, waken by a response handler. */ + if (*err == 0) { + g_mutex_lock(&lock); + if (!g_cond_wait_until(&priv->cond, &lock, expiration)) + *err = ETIMEDOUT; + else + *err = 0; + g_mutex_unlock(&lock); + } + + /* From be32 to host order. */ + if (frame != NULL) { + buf = (guint32 *)frame->data; + for (i = 0; i < frame->len; i++) + buf[i] = be32toh(buf[i]); + } + + g_mutex_clear(&lock); + g_cond_clear(&priv->cond); +} + +/** + * hinawa_fw_req_write: + * @self: A #HinawaFwReq + * @unit: A #HinawaFwUnit + * @addr: A destination address of target device + * @frame: (element-type guint32) (array) (in): a 32bit array + * @exception: A #GError + * + * Execute write transactions to the given unit. + */ +void hinawa_fw_req_write(HinawaFwReq *self, HinawaFwUnit *unit, guint64 addr, + GArray *frame, GError **exception) +{ + int err; + + g_return_if_fail(HINAWA_IS_FW_REQ(self)); + + if (frame == NULL || g_array_get_element_size(frame) != 4) { + err = EINVAL; + } else { + g_object_ref(unit); + fw_req_transact(self, unit, + FW_REQ_TYPE_WRITE, addr, frame, &err); + g_object_unref(unit); + } + + if (err != 0) + g_set_error(exception, g_quark_from_static_string(__func__), + err, "%s", strerror(err)); +} + +/** + * hinawa_fw_req_read: + * @self: A #HinawaFwReq + * @unit: A #HinawaFwUnit + * @addr: A destination address of target device + * @frame: (element-type guint32) (array) (out caller-allocates): a 32bit array + * @len: the bytes to read + * @exception: A #GError + * + * Execute read transaction to the given unit. + */ +void hinawa_fw_req_read(HinawaFwReq *self, HinawaFwUnit *unit, guint64 addr, + GArray *frame, guint len, GError **exception) +{ + int err; + + g_return_if_fail(HINAWA_IS_FW_REQ(self)); + + if (frame == NULL || g_array_get_element_size(frame) != 4) { + err = EINVAL; + } else { + g_object_ref(unit); + g_array_set_size(frame, len); + fw_req_transact(self, unit, + FW_REQ_TYPE_READ, addr, frame, &err); + g_object_unref(unit); + } + + if (err != 0) + g_set_error(exception, g_quark_from_static_string(__func__), + err, "%s", strerror(err)); +} + +/** + * hinawa_fw_req_lock: + * @self: A #HinawaFwReq + * @unit: A #HinawaFwUnit + * @addr: A destination address of target device + * @frame: (element-type guint32) (array) (inout): a 32bit array + * @exception: A #GError + * + * Execute lock transaction to the given unit. + */ +void hinawa_fw_req_lock(HinawaFwReq *self, HinawaFwUnit *unit, + guint64 addr, GArray *frame, GError **exception) +{ + int err; + + g_return_if_fail(HINAWA_IS_FW_REQ(self)); + + if (frame == NULL || g_array_get_element_size(frame) != 4) { + err = EINVAL; + } else { + g_object_ref(unit); + fw_req_transact(self, unit, + FW_REQ_TYPE_COMPARE_SWAP, addr, frame, &err); + g_object_unref(unit); + } + + if (err != 0) + g_set_error(exception, g_quark_from_static_string(__func__), + err, "%s", strerror(err)); +} + +/* NOTE: For HinawaFwUnit, internal. */ +void hinawa_fw_req_handle_response(HinawaFwReq *self, + struct fw_cdev_event_response *event) +{ + HinawaFwReqPrivate *priv; + + g_return_if_fail(HINAWA_IS_FW_REQ(self)); + priv = FW_REQ_GET_PRIVATE(self); + + /* Copy transaction frame. */ + if (priv->frame != NULL) { + priv->frame->len = 0; + g_array_append_vals(priv->frame, event->data, + event->length / g_array_get_element_size(priv->frame)); + } + + /* Waken a thread of an user application. */ + g_cond_signal(&priv->cond); +} diff --git a/libhinawa/src/fw_req.h b/libhinawa/src/fw_req.h new file mode 100644 index 0000000..057a3d5 --- /dev/null +++ b/libhinawa/src/fw_req.h @@ -0,0 +1,56 @@ +#ifndef __ALSA_TOOLS_HINAWA_FW_REQ_H__ +#define __ALSA_TOOLS_HINAWA_FW_REQ_H__ + +#include <glib.h> +#include <glib-object.h> +#include "fw_unit.h" + +G_BEGIN_DECLS + +#define HINAWA_TYPE_FW_REQ (hinawa_fw_req_get_type()) + +#define HINAWA_FW_REQ(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + HINAWA_TYPE_FW_REQ, \ + HinawaFwReq)) +#define HINAWA_IS_FW_REQ(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + HINAWA_TYPE_FW_REQ)) + +#define HINAWA_FW_REQ_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + HINAWA_TYPE_FW_REQ, \ + HinawaFwReq)) +#define HINAWA_IS_FW_REQ_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + HINAWA_TYPE_Seq)) +#define HINAWA_FW_REQ_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + HINAWA_TYPE_FW_REQ, \ + HinawaFwReq)) + +typedef struct _HinawaFwReq HinawaFwReq; +typedef struct _HinawaFwReqClass HinawaFwReqClass; +typedef struct _HinawaFwReqPrivate HinawaFwReqPrivate; + +struct _HinawaFwReq { + GObject parent_instance; + + HinawaFwReqPrivate *priv; +}; + +struct _HinawaFwReqClass { + GObjectClass parent_class; +}; + +GType hinawa_fw_req_get_type(void) G_GNUC_CONST; + +void hinawa_fw_req_write(HinawaFwReq *self, HinawaFwUnit *unit, guint64 addr, + GArray *frame, GError **exception); + +void hinawa_fw_req_read(HinawaFwReq *self, HinawaFwUnit *unit, guint64 addr, + GArray *frame, guint len, GError **exception); + +void hinawa_fw_req_lock(HinawaFwReq *self, HinawaFwUnit *unit, + guint64 addr, GArray *frame, GError **exception); +#endif diff --git a/libhinawa/src/fw_unit.c b/libhinawa/src/fw_unit.c index 019105d..65f37cd 100644 --- a/libhinawa/src/fw_unit.c +++ b/libhinawa/src/fw_unit.c @@ -239,6 +239,10 @@ static gboolean check_src(GSource *gsrc) common->type == FW_CDEV_EVENT_REQUEST2) hinawa_fw_resp_handle_request(HINAWA_FW_RESP(common->closure), (struct fw_cdev_event_request2 *)common); + else if (HINAWA_IS_FW_REQ(common->closure) && + common->type == FW_CDEV_EVENT_RESPONSE) + hinawa_fw_req_handle_response(HINAWA_FW_REQ(common->closure), + (struct fw_cdev_event_response *)common); end: /* Don't go to dispatch, then continue to process this source. */ return FALSE; diff --git a/libhinawa/src/internal.h b/libhinawa/src/internal.h index 1ee88ec..7ac672c 100644 --- a/libhinawa/src/internal.h +++ b/libhinawa/src/internal.h @@ -9,8 +9,11 @@
#include "fw_unit.h" #include "fw_resp.h" +#include "fw_req.h"
void hinawa_fw_unit_ioctl(HinawaFwUnit *self, int req, void *args, int *err); void hinawa_fw_resp_handle_request(HinawaFwResp *self, struct fw_cdev_event_request2 *event); +void hinawa_fw_req_handle_response(HinawaFwReq *self, + struct fw_cdev_event_response *event); #endif
There are a standard way to transport function control data to units; Function Control Protocol (FCP) in IEC 61883-1. This way uses a pair of request transaction and response transaction. All of AV/C commands which 1394TA defines is an application of FCP.
This commit adds HINAWA_TYPE_FW_FCP object for this purpose. This object uses 'fw_resp' object and 'fw_req' object to support FCP.
I note that 'AV/C Digital Interface Command Set General Specification Version 4.2' (September 1, 2004 1394TA) defines 'deferred transactions' in its clause 6.1.2. This type of AV/C command requres FCP backend to wait 'unspecified interval' for next response when receiving INTERIM type of response. To perform it, this object uses 200 mili-seconds to wait again.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/doc/reference/hinawa-docs.sgml | 1 + libhinawa/src/Makefile.am | 7 +- libhinawa/src/fw_fcp.c | 282 +++++++++++++++++++++++++++++++ libhinawa/src/fw_fcp.h | 58 +++++++ 4 files changed, 346 insertions(+), 2 deletions(-) create mode 100644 libhinawa/src/fw_fcp.c create mode 100644 libhinawa/src/fw_fcp.h
diff --git a/libhinawa/doc/reference/hinawa-docs.sgml b/libhinawa/doc/reference/hinawa-docs.sgml index ff00ecc..d5773a5 100644 --- a/libhinawa/doc/reference/hinawa-docs.sgml +++ b/libhinawa/doc/reference/hinawa-docs.sgml @@ -33,6 +33,7 @@ <xi:include href="xml/fw_unit.xml"/> <xi:include href="xml/fw_resp.xml"/> <xi:include href="xml/fw_req.xml"/> + <xi:include href="xml/fw_fcp.xml"/> </chapter> </part>
diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am index 91726b8..0a64658 100644 --- a/libhinawa/src/Makefile.am +++ b/libhinawa/src/Makefile.am @@ -29,13 +29,16 @@ libhinawa_la_SOURCES = \ fw_resp.h \ fw_resp.c \ fw_req.h \ - fw_req.c + fw_req.c \ + fw_fcp.h \ + fw_fcp.c
pkginclude_HEADERS = \ hinawa_sigs_marshal.h \ fw_unit.h \ fw_resp.h \ - fw_req.h + fw_req.h \ + fw_fcp.h
hinawa_sigs_marshal.list: $(AM_V_GEN)( find | grep .c$$ | xargs cat | \ diff --git a/libhinawa/src/fw_fcp.c b/libhinawa/src/fw_fcp.c new file mode 100644 index 0000000..44c6d3b --- /dev/null +++ b/libhinawa/src/fw_fcp.c @@ -0,0 +1,282 @@ +#include "fw_fcp.h" +#include "fw_resp.h" +#include "fw_req.h" + +/** + * SECTION:fw_fcp + * @Title: HinawaFwFcp + * @Short_description: A FCP transaction executor to a FireWire unit + * + * A HinawaFwFcp supports Function Control Protocol (FCP) in IEC 61883-1. + * Some types of transaction in 'AV/C Digital Interface Command Set General + * Specification Version 4.2' (Sep 1 2004, 1394TA) requires low layer support, + * thus this class has a code for them. + * + * Any of transaction frames should be aligned to 8bit (byte). + * This class is an application of #HinawaFwReq / #HinawaFwResp. + */ + +#define FCP_MAXIMUM_FRAME_BYTES 0x200U +#define FCP_REQUEST_ADDR 0xfffff0000b00 +#define FCP_RESPOND_ADDR 0xfffff0000d00 + +/* For your information. */ +enum avc_type { + AVC_TYPE_CONTROL = 0x00, + AVC_TYPE_STATUS = 0x01, + AVC_TYPE_SPECIFIC_INQUIRY = 0x02, + AVC_TYPE_NOTIFY = 0x03, + AVC_TYPE_GENERAL_INQUIRY = 0x04, + /* 0x05-0x07 are reserved. */ +}; +/* continue */ +enum avc_status { + AVC_STATUS_NOT_IMPLEMENTED = 0x08, + AVC_STATUS_ACCEPTED = 0x09, + AVC_STATUS_REJECTED = 0x0a, + AVC_STATUS_IN_TRANSITION = 0x0b, + AVC_STATUS_IMPLEMENTED_STABLE = 0x0c, + AVC_STATUS_CHANGED = 0x0d, + /* reserved */ + AVC_STATUS_INTERIM = 0x0f, +}; + +struct fcp_transaction { + GArray *req_frame; /* Request frame */ + GArray *resp_frame; /* Response frame */ + GCond cond; +}; + +struct _HinawaFwFcpPrivate { + HinawaFwUnit *unit; + HinawaFwResp *resp; + + GList *transactions; + GMutex lock; +}; +G_DEFINE_TYPE_WITH_PRIVATE(HinawaFwFcp, hinawa_fw_fcp, G_TYPE_OBJECT) +#define FW_FCP_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ + HINAWA_TYPE_FW_FCP, HinawaFwFcpPrivate)) + +static void hinawa_fw_fcp_dispose(GObject *obj) +{ + HinawaFwFcp *self = HINAWA_FW_FCP(obj); + + hinawa_fw_fcp_unlisten(self); + + G_OBJECT_CLASS(hinawa_fw_fcp_parent_class)->dispose(obj); +} + +static void hinawa_fw_fcp_finalize(GObject *gobject) +{ + G_OBJECT_CLASS(hinawa_fw_fcp_parent_class)->finalize(gobject); +} + +static void hinawa_fw_fcp_class_init(HinawaFwFcpClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->dispose = hinawa_fw_fcp_dispose; + gobject_class->finalize = hinawa_fw_fcp_finalize; +} + +static void hinawa_fw_fcp_init(HinawaFwFcp *self) +{ + self->priv = hinawa_fw_fcp_get_instance_private(self); +} + +/** + * hinawa_fw_fcp_transact: + * @self: A #HinawaFwFcp + * @req_frame: (element-type guint8) (array) (in): a byte frame for request + * @resp_frame: (element-type guint8) (array) (out caller-allocates): a byte + * frame for response + * @exception: A #GError + */ +void hinawa_fw_fcp_transact(HinawaFwFcp *self, + GArray *req_frame, GArray *resp_frame, + GError **exception) +{ + HinawaFwFcpPrivate *priv; + HinawaFwReq *req; + struct fcp_transaction trans = {0}; + GMutex local_lock; + gint64 expiration; + guint32 *buf; + guint i, quads, bytes; + + g_return_if_fail(HINAWA_IS_FW_FCP(self)); + priv = FW_FCP_GET_PRIVATE(self); + + if (req_frame == NULL || g_array_get_element_size(req_frame) != 1 || + resp_frame == NULL || g_array_get_element_size(resp_frame) != 1 || + req_frame->len > FCP_MAXIMUM_FRAME_BYTES) { + g_set_error(exception, g_quark_from_static_string(__func__), + EINVAL, "%s", strerror(EINVAL)); + return; + } + + req = g_object_new(HINAWA_TYPE_FW_REQ, NULL); + + /* Copy guint8 array to guint32 array. */ + quads = (req_frame->len + sizeof(guint32) - 1) / sizeof(guint32); + trans.req_frame = g_array_sized_new(FALSE, TRUE, + sizeof(guint32), quads); + g_array_set_size(trans.req_frame, quads); + memcpy(trans.req_frame->data, req_frame->data, req_frame->len); + buf = (guint32 *)trans.req_frame->data; + for (i = 0; i < trans.req_frame->len; i++) + buf[i] = htobe32(buf[i]); + + /* Prepare response buffer. */ + trans.resp_frame = g_array_sized_new(FALSE, TRUE, + sizeof(guint32), quads); + + /* Insert this entry. */ + g_mutex_lock(&priv->lock); + priv->transactions = g_list_prepend(priv->transactions, &trans); + g_mutex_unlock(&priv->lock); + + /* NOTE: Timeout is 200 milli-seconds. */ + expiration = g_get_monotonic_time() + 200 * G_TIME_SPAN_MILLISECOND; + g_cond_init(&trans.cond); + g_mutex_init(&local_lock); + + /* Send this request frame. */ + hinawa_fw_req_write(req, priv->unit, FCP_REQUEST_ADDR, trans.req_frame, + exception); + if (*exception != NULL) + goto end; +deferred: + /* + * Wait corresponding response till timeout. + * NOTE: Timeout at bus-reset, illegally. + */ + g_mutex_lock(&local_lock); + if (!g_cond_wait_until(&trans.cond, &local_lock, expiration)) + g_set_error(exception, g_quark_from_static_string(__func__), + ETIMEDOUT, "%s", strerror(ETIMEDOUT)); + g_mutex_unlock(&local_lock); + + /* Error happened. */ + if (*exception != NULL) + goto end; + + /* It's a deffered transaction, wait 200 milli-seconds again. */ + if (trans.resp_frame->data[0] >> 24 == AVC_STATUS_INTERIM) { + expiration = g_get_monotonic_time() + + 200 * G_TIME_SPAN_MILLISECOND; + goto deferred; + } + + /* Convert guint32 array to guint8 array. */ + buf = (guint32 *)trans.resp_frame->data; + for (i = 0; i < trans.resp_frame->len; i++) + buf[i] = htobe32(buf[i]); + bytes = trans.resp_frame->len * sizeof(guint32); + g_array_set_size(resp_frame, bytes); + memcpy(resp_frame->data, trans.resp_frame->data, bytes); +end: + /* Remove this entry. */ + g_mutex_lock(&priv->lock); + priv->transactions = + g_list_remove(priv->transactions, (gpointer *)&trans); + g_mutex_unlock(&priv->lock); + + g_array_free(trans.req_frame, TRUE); + g_mutex_clear(&local_lock); + g_clear_object(&req); +} + +static GArray *handle_response(HinawaFwResp *self, gint tcode, + GArray *req_frame, gpointer user_data) +{ + HinawaFwFcp *fcp = (HinawaFwFcp *)user_data; + HinawaFwFcpPrivate *priv = FW_FCP_GET_PRIVATE(fcp); + struct fcp_transaction *trans; + GList *entry; + + g_mutex_lock(&priv->lock); + + /* Seek correcponding request. */ + for (entry = priv->transactions; entry != NULL; entry = entry->next) { + trans = (struct fcp_transaction *)entry->data; + + if ((trans->req_frame->data[1] == req_frame->data[1]) && + (trans->req_frame->data[2] == req_frame->data[2])) + break; + } + + /* No requests corresponding to this response. */ + if (entry == NULL) + goto end; + + g_array_insert_vals(trans->resp_frame, 0, + req_frame->data, req_frame->len); + g_cond_signal(&trans->cond); +end: + g_mutex_unlock(&priv->lock); + + /* Transfer no data in the response frame. */ + return NULL; +} + +/** + * hinawa_fw_fcp_listen: + * @self: A #HinawaFwFcp + * @unit: A #HinawaFwUnit + * @exception: A #GError + * + * Start to listen to FCP responses. + */ +void hinawa_fw_fcp_listen(HinawaFwFcp *self, HinawaFwUnit *unit, + GError **exception) +{ + HinawaFwFcpPrivate *priv; + + g_return_if_fail(HINAWA_IS_FW_FCP(self)); + priv = FW_FCP_GET_PRIVATE(self); + + priv->resp = g_object_new(HINAWA_TYPE_FW_RESP, NULL); + priv->unit = g_object_ref(unit); + + hinawa_fw_resp_register(priv->resp, priv->unit, + FCP_RESPOND_ADDR, FCP_MAXIMUM_FRAME_BYTES, + exception); + if (*exception != NULL) { + g_clear_object(&priv->resp); + priv->resp = NULL; + g_object_unref(priv->unit); + priv->unit = NULL; + return; + } + + g_signal_connect(priv->resp, "requested", + G_CALLBACK(handle_response), self); + + g_mutex_init(&priv->lock); + priv->transactions = NULL; +} + +/** + * hinawa_fw_fcp_unlisten: + * @self: A #HinawaFwFcp + * + * Stop to listen to FCP responses. + */ +void hinawa_fw_fcp_unlisten(HinawaFwFcp *self) +{ + HinawaFwFcpPrivate *priv; + + g_return_if_fail(HINAWA_IS_FW_FCP(self)); + priv = FW_FCP_GET_PRIVATE(self); + + if (priv->resp == NULL) + return; + + hinawa_fw_resp_unregister(priv->resp); + priv->resp = NULL; + g_object_unref(priv->unit); + priv->unit = NULL; +} diff --git a/libhinawa/src/fw_fcp.h b/libhinawa/src/fw_fcp.h new file mode 100644 index 0000000..206ebee --- /dev/null +++ b/libhinawa/src/fw_fcp.h @@ -0,0 +1,58 @@ +#ifndef __ALSA_TOOLS_HINAWA_FW_FCP_H__ +#define __ALSA_TOOLS_HINAWA_FW_FCP_H__ + +#include <glib.h> +#include <glib-object.h> +#include "internal.h" +#include "fw_unit.h" + +G_BEGIN_DECLS + +#define HINAWA_TYPE_FW_FCP (hinawa_fw_fcp_get_type()) + +#define HINAWA_FW_FCP(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + HINAWA_TYPE_FW_FCP, \ + HinawaFwFcp)) +#define HINAWA_IS_FW_FCP(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + HINAWA_TYPE_FW_FCP)) + +#define HINAWA_FW_FCP_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + HINAWA_TYPE_FW_FCP, \ + HinawaFwFcpClass)) +#define HINAWA_IS_FW_FCP_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + HINAWA_TYPE_FW_FCP)) +#define HINAWA_FW_FCP_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + HINAWA_TYPE_FW_FCP, \ + HinawaFwFcpClass)) + +typedef struct _HinawaFwFcp HinawaFwFcp; +typedef struct _HinawaFwFcpClass HinawaFwFcpClass; +typedef struct _HinawaFwFcpPrivate HinawaFwFcpPrivate; + +struct _HinawaFwFcp { + GObject parent_instance; + + HinawaFwFcpPrivate *priv; +}; + +struct _HinawaFwFcpClass { + GObjectClass parent_class; +}; + +GType hinawa_fw_fcp_get_type(void) G_GNUC_CONST; + +HinawaFwFcp *hinawa_fw_fcp_new(GError **exception); + +void hinawa_fw_fcp_listen(HinawaFwFcp *self, HinawaFwUnit *unit, + GError **exception); +void hinawa_fw_fcp_transact(HinawaFwFcp *self, + GArray *req_frame, GArray *resp_frame, + GError **exception); +void hinawa_fw_fcp_unlisten(HinawaFwFcp *self); + +#endif
ALSA in Linux 3.16 or later extended its support for FireWire sound devices. Some of ALSA FireWire sound drivers handle any events from units on IEEE 1394 bus to control AMDTP streams. These drivers gives a way for applications to read these events via ALSA hwdep interface.
This commit adds HINAWA_TYPE_SND_UNIT object to listen to the events. This object uses ALSA hwdep interface to communicate with ALSA FireWire drivers, therefore depends on: - alsa-lib 2.0.28 or later
When constructing an instance of this object and calling open() method with the name of ALSA hwdep node, then these properties are available: - type: the value of SNDRV_FIREWIRE_TYPE_XXX in <sound/firewire.h> - card: the numerical ID of this sound card - device: the name of FireWire character device for this sound card - guid: the GUID of unit for this sound card - streaming: whether ALSA FireWire driver starts streaming or not - generation: the bus generation (inherited from fw_unit)
This object is an inheritance of HINAWA_TYPE_FW_UNIT, thus some properties and signals are also available. Additionally, this object gives methods for read/write/lock/fcp transactions.
These methods are also available: - listen(): start listening to events - unlisten(): stop listening to events - lock(): lock streaming functionality of ALSA FireWire driver - unlock(): unlock streaming functionality of ALSA FireWire driver - read_transact(): do IEEE 1394 read transaction - write_transact(): do IEEE 1394 write transaction - lock_transact(): do IEEE 1394 lock transaction - fcp_transact(): do IEC 61883-1 FCP transaction
When calling listen() method, 'streaming' property is valid. Additionally, the instance generates 'lock-status' signal when ALSA FireWire driver starts or stops AMDTP streams, so as 'bus-update' signal.
These signals are also available: - lock-status: at changing the status of streaming functionality - bus-update: IEEE 1394 bus reset (inherited from fw_unit)
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/README | 1 + libhinawa/configure.ac | 3 + libhinawa/doc/reference/hinawa-docs.sgml | 1 + libhinawa/src/Makefile.am | 13 +- libhinawa/src/backport.h | 41 +++ libhinawa/src/internal.h | 6 + libhinawa/src/snd_unit.c | 538 +++++++++++++++++++++++++++++++ libhinawa/src/snd_unit.h | 69 ++++ 8 files changed, 668 insertions(+), 4 deletions(-) create mode 100644 libhinawa/src/backport.h create mode 100644 libhinawa/src/snd_unit.c create mode 100644 libhinawa/src/snd_unit.h
diff --git a/libhinawa/README b/libhinawa/README index 1bd0d52..42d31f5 100644 --- a/libhinawa/README +++ b/libhinawa/README @@ -5,6 +5,7 @@ Requirements - Glib 2.32.4 or later - GTK-Doc 1.18-2 - GObject Introspection 1.32.1 or later +- alsa-lib 1.0.28 or later
How to build $ ./autogen.sh diff --git a/libhinawa/configure.ac b/libhinawa/configure.ac index b0d9517..d18b08c 100644 --- a/libhinawa/configure.ac +++ b/libhinawa/configure.ac @@ -52,6 +52,9 @@ GTK_DOC_CHECK([1.18-2]) # GObject introspection 1.32.1 or later GOBJECT_INTROSPECTION_REQUIRE([1.32.1])
+# alsa-lib 1.0.28 or later +AM_PATH_ALSA(1.0.28) + # The files generated from *.in AC_CONFIG_FILES([ Makefile diff --git a/libhinawa/doc/reference/hinawa-docs.sgml b/libhinawa/doc/reference/hinawa-docs.sgml index d5773a5..8d4483e 100644 --- a/libhinawa/doc/reference/hinawa-docs.sgml +++ b/libhinawa/doc/reference/hinawa-docs.sgml @@ -34,6 +34,7 @@ <xi:include href="xml/fw_resp.xml"/> <xi:include href="xml/fw_req.xml"/> <xi:include href="xml/fw_fcp.xml"/> + <xi:include href="xml/snd_unit.xml"/> </chapter> </part>
diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am index 0a64658..b717e4e 100644 --- a/libhinawa/src/Makefile.am +++ b/libhinawa/src/Makefile.am @@ -18,7 +18,8 @@ libhinawa_la_LDFLAGS = \ -version-info $(LT_IFACE)
libhinawa_la_LIBADD = \ - $(GLIB_LIBS) + $(GLIB_LIBS) \ + -lasound
libhinawa_la_SOURCES = \ hinawa_context.c \ @@ -31,14 +32,17 @@ libhinawa_la_SOURCES = \ fw_req.h \ fw_req.c \ fw_fcp.h \ - fw_fcp.c + fw_fcp.c \ + snd_unit.h \ + snd_unit.c
pkginclude_HEADERS = \ hinawa_sigs_marshal.h \ fw_unit.h \ fw_resp.h \ fw_req.h \ - fw_fcp.h + fw_fcp.h \ + snd_unit.h
hinawa_sigs_marshal.list: $(AM_V_GEN)( find | grep .c$$ | xargs cat | \ @@ -68,7 +72,8 @@ Hinawa_1_0_gir_LIBS = libhinawa.la Hinawa_1_0_gir_FILES = $(libhinawa_la_SOURCES) Hinawa_1_0_gir_SCANNERFLAGS = \ --identifier-prefix=Hinawa \ - --symbol-prefix=hinawa + --symbol-prefix=hinawa \ + -lasound INTROSPECTION_GIRS += Hinawa-1.0.gir
girdir = $(datadir)/gir-1.0 diff --git a/libhinawa/src/backport.h b/libhinawa/src/backport.h new file mode 100644 index 0000000..816954f --- /dev/null +++ b/libhinawa/src/backport.h @@ -0,0 +1,41 @@ +/* backporting from 3.16 */ + +/* alsa-lib 1.0.28 is a lack of some Hwdep interfaces */ +#ifndef SND_HWDEP_IFACE_FW_DICE +#define SND_HWDEP_IFACE_FW_DICE (SND_HWDEP_IFACE_SB_RC + 3) +#define SND_HWDEP_IFACE_FW_FIREWORKS (SND_HWDEP_IFACE_SB_RC + 4) +#define SND_HWDEP_IFACE_FW_BEBOB (SND_HWDEP_IFACE_SB_RC + 5) +#define SND_HWDEP_IFACE_FW_OXFW (SND_HWDEP_IFACE_SB_RC + 6) +#endif + + + +#ifndef SND_EFW_TRANSACTION_USER_SEQNUM_MAX + +#include <linux/types.h> + +#define SND_EFW_TRANSACTION_USER_SEQNUM_MAX ((__u32)((__u16)~0) - 1) + +/* each field should be in big endian */ +struct snd_efw_transaction { + __be32 length; + __be32 version; + __be32 seqnum; + __be32 category; + __be32 command; + __be32 status; + __be32 params[0]; +}; +struct snd_firewire_event_efw_response { + unsigned int type; + __be32 response[0]; /* some responses */ +}; + +#define SNDRV_FIREWIRE_EVENT_EFW_RESPONSE 0x4e617475 + +#define SNDRV_FIREWIRE_TYPE_FIREWORKS 2 +#define SNDRV_FIREWIRE_TYPE_BEBOB 3 +#define SNDRV_FIREWIRE_TYPE_OXFW 4 + +#endif + diff --git a/libhinawa/src/internal.h b/libhinawa/src/internal.h index 7ac672c..717cda3 100644 --- a/libhinawa/src/internal.h +++ b/libhinawa/src/internal.h @@ -7,13 +7,19 @@ #include <linux/firewire-cdev.h> #include <linux/firewire-constants.h>
+#include "backport.h" #include "fw_unit.h" #include "fw_resp.h" #include "fw_req.h" +#include "snd_unit.h"
void hinawa_fw_unit_ioctl(HinawaFwUnit *self, int req, void *args, int *err); void hinawa_fw_resp_handle_request(HinawaFwResp *self, struct fw_cdev_event_request2 *event); void hinawa_fw_req_handle_response(HinawaFwReq *self, struct fw_cdev_event_response *event); + +void hinawa_snd_unit_write(HinawaSndUnit *unit, + const void *buf, unsigned int length, + GError **exception); #endif diff --git a/libhinawa/src/snd_unit.c b/libhinawa/src/snd_unit.c new file mode 100644 index 0000000..859cab2 --- /dev/null +++ b/libhinawa/src/snd_unit.c @@ -0,0 +1,538 @@ +#include <unistd.h> +#include <alsa/asoundlib.h> +#include <sound/firewire.h> + +#include "hinawa_context.h" +#include "snd_unit.h" +#include "fw_req.h" +#include "fw_fcp.h" +#include "internal.h" + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/** + * SECTION:snd_unit + * @Title: HinawaSndUnit + * @Short_description: An event listener for ALSA FireWire sound devices + * + * This class is an application of ALSA FireWire stack. Any functionality which + * ALSA drivers in the stack can be available. + */ + +typedef struct { + GSource src; + HinawaSndUnit *unit; + gpointer tag; +} SndUnitSource; + +struct _HinawaSndUnitPrivate { + snd_hwdep_t *hwdep; + struct snd_firewire_get_info info; + + gboolean streaming; + + void *buf; + unsigned int len; + SndUnitSource *src; + + HinawaFwReq *req; + HinawaFwFcp *fcp; +}; +G_DEFINE_TYPE_WITH_PRIVATE(HinawaSndUnit, hinawa_snd_unit, HINAWA_TYPE_FW_UNIT) +#define SND_UNIT_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ + HINAWA_TYPE_SND_UNIT, HinawaSndUnitPrivate)) + +enum snd_unit_prop_type { + SND_UNIT_PROP_TYPE_FW_TYPE = 1, + SND_UNIT_PROP_TYPE_CARD, + SND_UNIT_PROP_TYPE_DEVICE, + SND_UNIT_PROP_TYPE_GUID, + SND_UNIT_PROP_TYPE_STREAMING, + SND_UNIT_PROP_TYPE_COUNT, +}; +static GParamSpec *snd_unit_props[SND_UNIT_PROP_TYPE_COUNT] = { NULL, }; + +/* This object has one signal. */ +enum snd_unit_sig_type { + SND_UNIT_SIG_TYPE_LOCK_STATUS = 0, + SND_UNIT_SIG_TYPE_COUNT, +}; +static guint snd_unit_sigs[SND_UNIT_SIG_TYPE_COUNT] = { 0 }; + +static void snd_unit_get_property(GObject *obj, guint id, + GValue *val, GParamSpec *spec) +{ + HinawaSndUnit *self = HINAWA_SND_UNIT(obj); + HinawaSndUnitPrivate *priv = SND_UNIT_GET_PRIVATE(self); + + switch (id) { + case SND_UNIT_PROP_TYPE_FW_TYPE: + g_value_set_int(val, priv->info.type); + break; + case SND_UNIT_PROP_TYPE_CARD: + g_value_set_int(val, priv->info.card); + break; + case SND_UNIT_PROP_TYPE_DEVICE: + g_value_set_string(val, (const gchar *)priv->info.device_name); + break; + case SND_UNIT_PROP_TYPE_GUID: + g_value_set_uint64(val, + GUINT64_FROM_BE(*((guint64 *)priv->info.guid))); + break; + case SND_UNIT_PROP_TYPE_STREAMING: + g_value_set_boolean(val, priv->streaming); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); + break; + } +} + +static void snd_unit_set_property(GObject *obj, guint id, + const GValue *val, GParamSpec *spec) +{ + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); +} + +static void snd_unit_dispose(GObject *obj) +{ + HinawaSndUnit *self = HINAWA_SND_UNIT(obj); + HinawaSndUnitPrivate *priv = SND_UNIT_GET_PRIVATE(self); + + if (priv->src != NULL) + hinawa_snd_unit_unlisten(self); + + snd_hwdep_close(priv->hwdep); + g_clear_object(&priv->req); + g_clear_object(&priv->fcp); + + G_OBJECT_CLASS(hinawa_snd_unit_parent_class)->dispose(obj); +} + +static void snd_unit_finalize(GObject *gobject) +{ + G_OBJECT_CLASS(hinawa_snd_unit_parent_class)->finalize(gobject); +} + +static void hinawa_snd_unit_class_init(HinawaSndUnitClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->get_property = snd_unit_get_property; + gobject_class->set_property = snd_unit_set_property; + gobject_class->dispose = snd_unit_dispose; + gobject_class->finalize = snd_unit_finalize; + + snd_unit_props[SND_UNIT_PROP_TYPE_FW_TYPE] = + g_param_spec_int("type", "type", + "The value of SNDRV_FIREWIRE_TYPE_XXX", + 0, INT_MAX, + 0, + G_PARAM_READABLE); + snd_unit_props[SND_UNIT_PROP_TYPE_CARD] = + g_param_spec_int("card", "card", + "A numerical ID for ALSA sound card", + 0, INT_MAX, + 0, + G_PARAM_READABLE); + snd_unit_props[SND_UNIT_PROP_TYPE_DEVICE] = + g_param_spec_string("device", "device", + "A name of special file as FireWire unit.", + NULL, + G_PARAM_READABLE); + snd_unit_props[SND_UNIT_PROP_TYPE_STREAMING] = + g_param_spec_boolean("streaming", "streaming", + "Whether this device is streaming or not", + FALSE, + G_PARAM_READABLE); + snd_unit_props[SND_UNIT_PROP_TYPE_GUID] = + g_param_spec_uint64("guid", "guid", + "Global unique ID for this firewire unit.", + 0, ULONG_MAX, 0, + G_PARAM_READABLE); + + g_object_class_install_properties(gobject_class, + SND_UNIT_PROP_TYPE_COUNT, + snd_unit_props); + + /** + * HinawaSndUnit::lock-status: + * @self: A #HinawaSndUnit + * @state: %TRUE when locked, %FALSE when unlocked. + * + * When ALSA kernel-streaming status is changed, this ::lock-status + * signal is generated. + */ + snd_unit_sigs[SND_UNIT_SIG_TYPE_LOCK_STATUS] = + g_signal_new("lock-status", + G_OBJECT_CLASS_TYPE(klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); +} + +static void hinawa_snd_unit_init(HinawaSndUnit *self) +{ + self->priv = hinawa_snd_unit_get_instance_private(self); +} + +/* For internal use. */ +void hinawa_snd_unit_open(HinawaSndUnit *self, gchar *path, GError **exception) +{ + HinawaSndUnitPrivate *priv; + snd_hwdep_t *hwdep = NULL; + char fw_cdev[32]; + int err; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + priv = SND_UNIT_GET_PRIVATE(self); + + err = snd_hwdep_open(&hwdep, path, SND_HWDEP_OPEN_DUPLEX); + if (err < 0) + goto end; + + /* Get FireWire sound device information. */ + err = snd_hwdep_ioctl(hwdep, SNDRV_FIREWIRE_IOCTL_GET_INFO, + &priv->info); + if (err < 0) + goto end; + + snprintf(fw_cdev, sizeof(fw_cdev), "/dev/%s", priv->info.device_name); + hinawa_fw_unit_open(&self->parent_instance, fw_cdev, exception); + if (*exception != NULL) + goto end; + + priv->hwdep = hwdep; + priv->req = g_object_new(HINAWA_TYPE_FW_REQ, NULL); + priv->fcp = g_object_new(HINAWA_TYPE_FW_FCP, NULL); +end: + if (err < 0) + g_set_error(exception, g_quark_from_static_string(__func__), + -err, "%s", snd_strerror(err)); + if (*exception != NULL) + snd_hwdep_close(hwdep); +} + +/** + * hinawa_snd_unit_lock: + * @self: A #HinawaSndUnit + * @exception: A #GError + * + * Disallow ALSA to start kernel-streaming. + */ +void hinawa_snd_unit_lock(HinawaSndUnit *self, GError **exception) +{ + int err; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + + err = snd_hwdep_ioctl(self->priv->hwdep, SNDRV_FIREWIRE_IOCTL_LOCK, + NULL); + if (err < 0) + g_set_error(exception, g_quark_from_static_string(__func__), + -err, "%s", snd_strerror(err)); +} + +/** + * hinawa_snd_unit_unlock: + * @self: A #HinawaSndUnit + * @exception: A #GError + * + * Allow ALSA to start kernel-streaming. + */ +void hinawa_snd_unit_unlock(HinawaSndUnit *self, GError **exception) +{ + int err; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + + err = snd_hwdep_ioctl(self->priv->hwdep, SNDRV_FIREWIRE_IOCTL_UNLOCK, + NULL); + if (err < 0) + g_set_error(exception, g_quark_from_static_string(__func__), + -err, "%s", snd_strerror(err)); +} + +/** + * hinawa_snd_unit_read_transact: + * @self: A #HinawaSndUnit + * @addr: A destination address of target device + * @frame: (element-type guint32) (array) (out caller-allocates): a 32bit array + * @len: the bytes to read + * @exception: A #GError + * + * Execute read transaction to the given unit. + */ +void hinawa_snd_unit_read_transact(HinawaSndUnit *self, + guint64 addr, GArray *frame, guint len, + GError **exception) +{ + HinawaSndUnitPrivate *priv; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + priv = SND_UNIT_GET_PRIVATE(self); + + hinawa_fw_req_read(priv->req, &self->parent_instance, addr, frame, len, + exception); +} + +/** + * hinawa_snd_unit_write_transact: + * @self: A #HinawaSndUnit + * @addr: A destination address of target device + * @frame: (element-type guint32) (array) (in): a 32bit array + * @exception: A #GError + * + * Execute write transactions to the given unit. + */ +void hinawa_snd_unit_write_transact(HinawaSndUnit *self, + guint64 addr, GArray *frame, + GError **exception) +{ + HinawaSndUnitPrivate *priv; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + priv = SND_UNIT_GET_PRIVATE(self); + + hinawa_fw_req_write(priv->req, &self->parent_instance, addr, frame, + exception); +} + +/** + * hinawa_snd_unit_lock_transact: + * @self: A #HinawaSndUnit + * @addr: A destination address of target device + * @frame: (element-type guint32) (array) (inout): a 32bit array + * @exception: A #GError + * + * Execute lock transaction to the given unit. + */ +void hinawa_snd_unit_lock_transact(HinawaSndUnit *self, + guint64 addr, GArray *frame, + GError **exception) +{ + HinawaSndUnitPrivate *priv; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + priv = SND_UNIT_GET_PRIVATE(self); + + hinawa_fw_req_lock(priv->req, &self->parent_instance, addr, frame, + exception); +} + +/** + * hinawa_snd_unit_fcp_transact: + * @self: A #HinawaSndUnit + * @req_frame: (element-type guint8) (array) (in): a byte frame for request + * @resp_frame: (element-type guint8) (array) (out caller-allocates): a byte + * frame for response + * @exception: A #GError + */ +void hinawa_snd_unit_fcp_transact(HinawaSndUnit *self, + GArray *req_frame, GArray *resp_frame, + GError **exception) +{ + HinawaSndUnitPrivate *priv; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + priv = SND_UNIT_GET_PRIVATE(self); + + hinawa_fw_fcp_transact(priv->fcp, req_frame, resp_frame, exception); +} + +/* For internal use. */ +void hinawa_snd_unit_write(HinawaSndUnit *self, + const void *buf, unsigned int length, + GError **exception) +{ + int err; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + + err = snd_hwdep_write(self->priv->hwdep, buf, length); + if (err < 0) + g_set_error(exception, g_quark_from_static_string(__func__), + -err, "%s", snd_strerror(err)); +} + +static void handle_lock_event(HinawaSndUnit *self, + void *buf, unsigned int length) +{ + struct snd_firewire_event_lock_status *event = + (struct snd_firewire_event_lock_status *)buf; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + + g_signal_emit(self, snd_unit_sigs[SND_UNIT_SIG_TYPE_LOCK_STATUS], 0, + event->status); +} + +static gboolean prepare_src(GSource *src, gint *timeout) +{ + /* Set 2msec for poll(2) timeout. */ + *timeout = 2; + + /* This source is not ready, let's poll(2) */ + return FALSE; +} + +static gboolean check_src(GSource *gsrc) +{ + SndUnitSource *src = (SndUnitSource *)gsrc; + HinawaSndUnit *unit = src->unit; + HinawaSndUnitPrivate *priv = SND_UNIT_GET_PRIVATE(unit); + GIOCondition condition; + + struct snd_firewire_event_common *common; + int len; + + if (unit == NULL) + goto end; + + /* Let's process this source if any inputs are available. */ + condition = g_source_query_unix_fd((GSource *)src, src->tag); + if (!(condition & G_IO_IN)) + goto end; + + len = snd_hwdep_read(priv->hwdep, priv->buf, priv->len); + if (len < 0) + goto end; + + common = (struct snd_firewire_event_common *)priv->buf; + + if (common->type == SNDRV_FIREWIRE_EVENT_LOCK_STATUS) + handle_lock_event(unit, priv->buf, len); +end: + /* Don't go to dispatch, then continue to process this source. */ + return FALSE; +} + +static gboolean dispatch_src(GSource *src, GSourceFunc callback, + gpointer user_data) +{ + /* Just be sure to continue to process this source. */ + return TRUE; +} + +/** + * hinawa_snd_unit_listen: + * @self: A #HinawaSndUnit + * @exception: A #GError + * + * Start listening to events. + */ +void hinawa_snd_unit_listen(HinawaSndUnit *self, GError **exception) +{ + static GSourceFuncs funcs = { + .prepare = prepare_src, + .check = check_src, + .dispatch = dispatch_src, + .finalize = NULL, + }; + HinawaSndUnitPrivate *priv; + void *buf; + struct pollfd pfds; + GSource *src; + int err; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + priv = SND_UNIT_GET_PRIVATE(self); + + /* + * MEMO: allocate one page because we cannot assume the size of + * transaction frame. + */ + buf = g_malloc(getpagesize()); + if (buf == NULL) { + g_set_error(exception, g_quark_from_static_string(__func__), + ENOMEM, "%s", strerror(ENOMEM)); + return; + } + + if (snd_hwdep_poll_descriptors(priv->hwdep, &pfds, 1) != 1) { + g_set_error(exception, g_quark_from_static_string(__func__), + EINVAL, "%s", strerror(EINVAL)); + return; + } + + src = g_source_new(&funcs, sizeof(SndUnitSource)); + if (src == NULL) { + g_set_error(exception, g_quark_from_static_string(__func__), + ENOMEM, "%s", strerror(ENOMEM)); + g_free(buf); + return; + } + + g_source_set_name(src, "HinawaSndUnit"); + g_source_set_priority(src, G_PRIORITY_HIGH_IDLE); + g_source_set_can_recurse(src, TRUE); + + ((SndUnitSource *)src)->unit = self; + priv->src = (SndUnitSource *)src; + priv->buf = buf; + priv->len = getpagesize(); + + ((SndUnitSource *)src)->tag = + hinawa_context_add_src(src, pfds.fd, G_IO_IN, exception); + if (*exception != NULL) { + g_free(buf); + g_source_destroy(src); + priv->buf = NULL; + priv->len = 0; + priv->src = NULL; + return; + } + + hinawa_fw_unit_listen(&self->parent_instance, exception); + if (*exception != NULL) { + hinawa_snd_unit_unlisten(self); + return; + } + + hinawa_fw_fcp_listen(priv->fcp, &self->parent_instance, exception); + if (*exception != NULL) { + hinawa_snd_unit_unlisten(self); + hinawa_fw_unit_unlisten(&self->parent_instance); + } + + /* Check locked or not. */ + err = snd_hwdep_ioctl(priv->hwdep, SNDRV_FIREWIRE_IOCTL_LOCK, + NULL); + priv->streaming = (err == -EBUSY); + if (err == -EBUSY) + return; + snd_hwdep_ioctl(priv->hwdep, SNDRV_FIREWIRE_IOCTL_UNLOCK, NULL); +} + +/** + * hinawa_snd_unit_unlisten: + * @self: A #HinawaSndUnit + * + * Stop listening to events. + */ +void hinawa_snd_unit_unlisten(HinawaSndUnit *self) +{ + HinawaSndUnitPrivate *priv; + + g_return_if_fail(HINAWA_IS_SND_UNIT(self)); + priv = SND_UNIT_GET_PRIVATE(self); + + if (priv->streaming) + snd_hwdep_ioctl(priv->hwdep, SNDRV_FIREWIRE_IOCTL_UNLOCK, NULL); + + g_source_destroy((GSource *)priv->src); + g_free(priv->src); + priv->src = NULL; + + g_free(priv->buf); + priv->buf = NULL; + priv->len = 0; + + hinawa_fw_fcp_unlisten(priv->fcp); + hinawa_fw_unit_unlisten(&self->parent_instance); +} diff --git a/libhinawa/src/snd_unit.h b/libhinawa/src/snd_unit.h new file mode 100644 index 0000000..01fcdab --- /dev/null +++ b/libhinawa/src/snd_unit.h @@ -0,0 +1,69 @@ +#ifndef __ALSA_TOOLS_HINAWA_SND_UNIT_H__ +#define __ALSA_TOOLS_HINAWA_SND_UNIT_H__ + +#include <glib.h> +#include <glib-object.h> +#include "fw_unit.h" + +G_BEGIN_DECLS + +#define HINAWA_TYPE_SND_UNIT (hinawa_snd_unit_get_type()) + +#define HINAWA_SND_UNIT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + HINAWA_TYPE_SND_UNIT, \ + HinawaSndUnit)) +#define HINAWA_IS_SND_UNIT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + HINAWA_TYPE_SND_UNIT)) + +#define HINAWA_SND_UNIT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + HINAWA_TYPE_SND_UNIT, \ + HinawaSndUnitClass)) +#define HINAWA_IS_SND_UNIT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + HINAWA_TYPE_SND_UNIT)) +#define HINAWA_SND_UNIT_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + HINAWA_TYPE_SND_UNIT, \ + HinawaSndUnitClass)) + +typedef struct _HinawaSndUnit HinawaSndUnit; +typedef struct _HinawaSndUnitClass HinawaSndUnitClass; +typedef struct _HinawaSndUnitPrivate HinawaSndUnitPrivate; + +struct _HinawaSndUnit { + HinawaFwUnit parent_instance; + + HinawaSndUnitPrivate *priv; +}; + +struct _HinawaSndUnitClass { + HinawaFwUnitClass parent_class; +}; + +GType hinawa_snd_unit_get_type(void) G_GNUC_CONST; + +void hinawa_snd_unit_open(HinawaSndUnit *self, gchar *path, GError **exception); + +void hinawa_snd_unit_lock(HinawaSndUnit *self, GError **exception); +void hinawa_snd_unit_unlock(HinawaSndUnit *self, GError **exception); + +void hinawa_snd_unit_read_transact(HinawaSndUnit *self, + guint64 addr, GArray *frame, guint len, + GError **exception); +void hinawa_snd_unit_write_transact(HinawaSndUnit *self, + guint64 addr, GArray *frame, + GError **exception); +void hinawa_snd_unit_lock_transact(HinawaSndUnit *self, + guint64 addr, GArray *frame, + GError **exception); +void hinawa_snd_unit_fcp_transact(HinawaSndUnit *self, + GArray *req_frame, GArray *resp_frame, + GError **exception); + +void hinawa_snd_unit_listen(HinawaSndUnit *self, GError **exception); +void hinawa_snd_unit_unlisten(HinawaSndUnit *self); + +#endif
Dice is 'Digital Interface Communications Engine' which TC Applied Technologies produced. Several chipset are produced under a name of Dice. For Dice chipset, well-known FCP or AV/C commands are not used to control devices. It's performed by read/write transactions into specific addresses.
Dice has a specific mechanism called as 'notification'. When device status is changed, Dice devices tells the event by sending transaction. This notification is sent to an address to which ALSA Dice driver listens. Then the driver allows applications to read it via ALSA hwdep interface.
This commit adds HINAWA_TYPE_SND_DICE object to handle the notification. When applications calls listen() method, the instance generates 'notified' signal when the Dice unit transfer notification. This object also have transact() method. An application can change unit status and wait the notification with given bit flag.
This object is an inheritance of HINAWA_TYPE_SND_UNIT, thus any signals and properties, methods are also available.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/doc/reference/hinawa-docs.sgml | 1 + libhinawa/src/Makefile.am | 7 +- libhinawa/src/internal.h | 3 + libhinawa/src/snd_dice.c | 195 +++++++++++++++++++++++++++++++ libhinawa/src/snd_dice.h | 53 +++++++++ libhinawa/src/snd_unit.c | 5 + 6 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 libhinawa/src/snd_dice.c create mode 100644 libhinawa/src/snd_dice.h
diff --git a/libhinawa/doc/reference/hinawa-docs.sgml b/libhinawa/doc/reference/hinawa-docs.sgml index 8d4483e..58c862a 100644 --- a/libhinawa/doc/reference/hinawa-docs.sgml +++ b/libhinawa/doc/reference/hinawa-docs.sgml @@ -35,6 +35,7 @@ <xi:include href="xml/fw_req.xml"/> <xi:include href="xml/fw_fcp.xml"/> <xi:include href="xml/snd_unit.xml"/> + <xi:include href="xml/snd_dice.xml"/> </chapter> </part>
diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am index b717e4e..696e567 100644 --- a/libhinawa/src/Makefile.am +++ b/libhinawa/src/Makefile.am @@ -34,7 +34,9 @@ libhinawa_la_SOURCES = \ fw_fcp.h \ fw_fcp.c \ snd_unit.h \ - snd_unit.c + snd_unit.c \ + snd_dice.h \ + snd_dice.c
pkginclude_HEADERS = \ hinawa_sigs_marshal.h \ @@ -42,7 +44,8 @@ pkginclude_HEADERS = \ fw_resp.h \ fw_req.h \ fw_fcp.h \ - snd_unit.h + snd_unit.h \ + snd_dice.h
hinawa_sigs_marshal.list: $(AM_V_GEN)( find | grep .c$$ | xargs cat | \ diff --git a/libhinawa/src/internal.h b/libhinawa/src/internal.h index 717cda3..ddbb298 100644 --- a/libhinawa/src/internal.h +++ b/libhinawa/src/internal.h @@ -12,6 +12,7 @@ #include "fw_resp.h" #include "fw_req.h" #include "snd_unit.h" +#include "snd_dice.h"
void hinawa_fw_unit_ioctl(HinawaFwUnit *self, int req, void *args, int *err); void hinawa_fw_resp_handle_request(HinawaFwResp *self, @@ -22,4 +23,6 @@ void hinawa_fw_req_handle_response(HinawaFwReq *self, void hinawa_snd_unit_write(HinawaSndUnit *unit, const void *buf, unsigned int length, GError **exception); +void hinawa_snd_dice_handle_notification(HinawaSndDice *self, + const void *buf, unsigned int len); #endif diff --git a/libhinawa/src/snd_dice.c b/libhinawa/src/snd_dice.c new file mode 100644 index 0000000..a3b839e --- /dev/null +++ b/libhinawa/src/snd_dice.c @@ -0,0 +1,195 @@ +#include <linux/types.h> +#include <sound/firewire.h> +#include <alsa/asoundlib.h> +#include "snd_dice.h" +#include "internal.h" + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/** + * SECTION:snd_dice + * @Title: HinawaSndDice + * @Short_description: A notification listener for Dice models + * + * A #HinawaSndDice listen to Dice notification and generates signal when + * received. This inherits #HinawaSndUnit. + */ + +struct notification_waiter { + guint32 bit_flag; + GCond cond; +}; + +struct _HinawaSndDicePrivate { + GList *waiters; + GMutex lock; +}; +G_DEFINE_TYPE_WITH_PRIVATE(HinawaSndDice, hinawa_snd_dice, HINAWA_TYPE_SND_UNIT) +#define SND_DICE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ + HINAWA_TYPE_SND_DICE, \ + HinawaSndDicePrivate)) + +/* This object has one signal. */ +enum dice_sig_type { + DICE_SIG_TYPE_NOTIFIED, + DICE_SIG_TYPE_COUNT, +}; +static guint dice_sigs[DICE_SIG_TYPE_COUNT] = { 0 }; + +static void snd_dice_dispose(GObject *obj) +{ + G_OBJECT_CLASS(hinawa_snd_dice_parent_class)->dispose(obj); +} + +static void snd_dice_finalize(GObject *gobject) +{ + G_OBJECT_CLASS(hinawa_snd_dice_parent_class)->finalize(gobject); +} + +static void hinawa_snd_dice_class_init(HinawaSndDiceClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->dispose = snd_dice_dispose; + gobject_class->finalize = snd_dice_finalize; + + /** + * HinawaSndDice::notified: + * @self: A #HinawaSndDice + * @message: A notification message + * + * When Dice models transfer notification, the ::notified signal is + * generated. + */ + dice_sigs[DICE_SIG_TYPE_NOTIFIED] = + g_signal_new("notified", + G_OBJECT_CLASS_TYPE(klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__ULONG, + G_TYPE_NONE, 1, G_TYPE_ULONG); +} + +static void hinawa_snd_dice_init(HinawaSndDice *self) +{ + self->priv = hinawa_snd_dice_get_instance_private(self); +} + +/** + * hinawa_snd_dice_new: + * @path: A path to ALSA hwdep device for Dice models (i.e. hw:0) + * @exception: A #GError + * + * Returns: An instance of #HinawaSndDice + */ +void hinawa_snd_dice_open(HinawaSndDice *self, gchar *path, GError **exception) +{ + HinawaSndDicePrivate *priv; + int type; + + g_return_if_fail(HINAWA_IS_SND_DICE(self)); + + hinawa_snd_unit_open(&self->parent_instance, path, exception); + if (*exception != NULL) { + g_clear_object(&self); + return; + } + + g_object_get(G_OBJECT(self), "type", &type, NULL); + if (type != SNDRV_FIREWIRE_TYPE_DICE) { + g_set_error(exception, g_quark_from_static_string(__func__), + EINVAL, "%s", strerror(EINVAL)); + g_clear_object(&self); + } + priv = SND_DICE_GET_PRIVATE(self); + + priv->waiters = NULL; + g_mutex_init(&priv->lock); +} + +/** + * hinawa_snd_dice_transact: + * @self: A #HinawaSndDice + * @addr: A destination address of target device + * @frame: (element-type guint32) (array) (in): a 32bit array + * @bit_flag: bit flag to wait + * @exception: A #GError + * + * Execute write transactions to the given address, then wait and check + * notification. + */ +void hinawa_snd_dice_transact(HinawaSndDice *self, guint64 addr, + GArray *frame, guint32 bit_flag, + GError **exception) +{ + HinawaSndDicePrivate *priv; + struct notification_waiter waiter = {0}; + gint64 expiration; + + g_return_if_fail(HINAWA_IS_SND_DICE(self)); + priv = SND_DICE_GET_PRIVATE(self); + + /* Insert this entry to list and enter critical section. */ + g_mutex_lock(&priv->lock); + priv->waiters = g_list_append(priv->waiters, &waiter); + + /* NOTE: Timeout is 200 milli-seconds. */ + expiration = g_get_monotonic_time() + 200 * G_TIME_SPAN_MILLISECOND; + g_cond_init(&waiter.cond); + + waiter.bit_flag = bit_flag; + hinawa_snd_unit_write_transact(&self->parent_instance, addr, frame, + exception); + if (*exception != NULL) + goto end; + + /* + * Wait notification till timeout and temporarily leave the critical + * section. + */ + if (!g_cond_wait_until(&waiter.cond, &priv->lock, expiration)) + g_set_error(exception, g_quark_from_static_string(__func__), + ETIMEDOUT, "%s", strerror(ETIMEDOUT)); +end: + priv->waiters = g_list_remove(priv->waiters, (gpointer *)&waiter); + + g_mutex_unlock(&priv->lock); +} + +void hinawa_snd_dice_handle_notification(HinawaSndDice *self, + const void *buf, unsigned int len) +{ + HinawaSndDicePrivate *priv; + + GList *entry; + struct notification_waiter *waiter; + + struct snd_firewire_event_dice_notification *event = + (struct snd_firewire_event_dice_notification *)buf; + + g_return_if_fail(HINAWA_IS_SND_DICE(self)); + priv = SND_DICE_GET_PRIVATE(self); + + g_signal_emit(self, dice_sigs[DICE_SIG_TYPE_NOTIFIED], + 0, event->notification); + + g_mutex_lock(&priv->lock); + + for (entry = priv->waiters; entry != NULL; entry = entry->next) { + waiter = (struct notification_waiter *)entry->data; + + if (waiter->bit_flag & event->notification) + break; + } + + g_mutex_unlock(&priv->lock); + + if (entry == NULL) + return; + + g_cond_signal(&waiter->cond); +} diff --git a/libhinawa/src/snd_dice.h b/libhinawa/src/snd_dice.h new file mode 100644 index 0000000..f33835a --- /dev/null +++ b/libhinawa/src/snd_dice.h @@ -0,0 +1,53 @@ +#ifndef __ALSA_TOOLS_HINAWA_SND_DICE_H__ +#define __ALSA_TOOLS_HINAWA_SND_DICE_H__ + +#include <glib.h> +#include <glib-object.h> +#include "snd_unit.h" + +G_BEGIN_DECLS + +#define HINAWA_TYPE_SND_DICE (hinawa_snd_dice_get_type()) + +#define HINAWA_SND_DICE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + HINAWA_TYPE_SND_DICE, \ + HinawaSndDice)) +#define HINAWA_IS_SND_DICE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + HINAWA_TYPE_SND_DICE)) + +#define HINAWA_SND_DICE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + HINAWA_TYPE_SND_DICE, \ + HinawaSndDiceClass)) +#define HINAWA_IS_SND_DICE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + HINAWA_TYPE_SND_DICE)) +#define HINAWA_SND_DICE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + HINAWA_TYPE_SND_DICE, \ + HinawaSndDiceClass)) + +typedef struct _HinawaSndDice HinawaSndDice; +typedef struct _HinawaSndDiceClass HinawaSndDiceClass; +typedef struct _HinawaSndDicePrivate HinawaSndDicePrivate; + +struct _HinawaSndDice { + HinawaSndUnit parent_instance; + + HinawaSndDicePrivate *priv; +}; + +struct _HinawaSndDiceClass { + HinawaSndUnitClass parent_class; +}; + +GType hinawa_snd_dice_get_type(void) G_GNUC_CONST; + +void hinawa_snd_dice_open(HinawaSndDice *self, gchar *path, GError **exception); + +void hinawa_snd_dice_transact(HinawaSndDice *self, guint64 addr, + GArray *frame, guint32 bit_flag, + GError **exception); +#endif diff --git a/libhinawa/src/snd_unit.c b/libhinawa/src/snd_unit.c index 859cab2..b7537a3 100644 --- a/libhinawa/src/snd_unit.c +++ b/libhinawa/src/snd_unit.c @@ -6,6 +6,7 @@ #include "snd_unit.h" #include "fw_req.h" #include "fw_fcp.h" +#include "snd_dice.h" #include "internal.h"
#ifdef HAVE_CONFIG_H @@ -407,6 +408,10 @@ static gboolean check_src(GSource *gsrc)
if (common->type == SNDRV_FIREWIRE_EVENT_LOCK_STATUS) handle_lock_event(unit, priv->buf, len); + else if (HINAWA_IS_SND_DICE(unit) && + common->type == SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION) + hinawa_snd_dice_handle_notification(HINAWA_SND_DICE(unit), + priv->buf, len); end: /* Don't go to dispatch, then continue to process this source. */ return FALSE;
Fireworks is a board module which Echo Audio produces. This module can be controlled by Echo Fireworks Transaction (a.k.a. EFW transaction). The transaction has categories, commands and arguments.
The transaction is transferred by two ways; one is vendor-dependent AV/C command and another is a pair of request/response transaction to certain addresses.
ALSA Fireworks driver already supports the latter way because the former way is not avaibale in some Fireworks based devices. The driver gives a way for applications to execute this transaction via ALSA hwdep interface.
This commit adds HINAWA_TYPE_SND_EFW object for this purpose. An application can transfer requests and wait responses by calling transact() method after calling listen() method.
This object is an inheritance of HINAWA_TYPE_SND_UNIT, therefore some signals and properties, methods are also available.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/doc/reference/hinawa-docs.sgml | 1 + libhinawa/src/Makefile.am | 7 +- libhinawa/src/internal.h | 3 + libhinawa/src/snd_efw.c | 315 +++++++++++++++++++++++++++++++ libhinawa/src/snd_efw.h | 54 ++++++ libhinawa/src/snd_unit.c | 5 + 6 files changed, 383 insertions(+), 2 deletions(-) create mode 100644 libhinawa/src/snd_efw.c create mode 100644 libhinawa/src/snd_efw.h
diff --git a/libhinawa/doc/reference/hinawa-docs.sgml b/libhinawa/doc/reference/hinawa-docs.sgml index 58c862a..731ae15 100644 --- a/libhinawa/doc/reference/hinawa-docs.sgml +++ b/libhinawa/doc/reference/hinawa-docs.sgml @@ -36,6 +36,7 @@ <xi:include href="xml/fw_fcp.xml"/> <xi:include href="xml/snd_unit.xml"/> <xi:include href="xml/snd_dice.xml"/> + <xi:include href="xml/snd_efw.xml"/> </chapter> </part>
diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am index 696e567..b746bf1 100644 --- a/libhinawa/src/Makefile.am +++ b/libhinawa/src/Makefile.am @@ -36,7 +36,9 @@ libhinawa_la_SOURCES = \ snd_unit.h \ snd_unit.c \ snd_dice.h \ - snd_dice.c + snd_dice.c \ + snd_efw.h \ + snd_efw.c
pkginclude_HEADERS = \ hinawa_sigs_marshal.h \ @@ -45,7 +47,8 @@ pkginclude_HEADERS = \ fw_req.h \ fw_fcp.h \ snd_unit.h \ - snd_dice.h + snd_dice.h \ + snd_efw.h
hinawa_sigs_marshal.list: $(AM_V_GEN)( find | grep .c$$ | xargs cat | \ diff --git a/libhinawa/src/internal.h b/libhinawa/src/internal.h index ddbb298..9ff8fe4 100644 --- a/libhinawa/src/internal.h +++ b/libhinawa/src/internal.h @@ -13,6 +13,7 @@ #include "fw_req.h" #include "snd_unit.h" #include "snd_dice.h" +#include "snd_efw.h"
void hinawa_fw_unit_ioctl(HinawaFwUnit *self, int req, void *args, int *err); void hinawa_fw_resp_handle_request(HinawaFwResp *self, @@ -25,4 +26,6 @@ void hinawa_snd_unit_write(HinawaSndUnit *unit, GError **exception); void hinawa_snd_dice_handle_notification(HinawaSndDice *self, const void *buf, unsigned int len); +void hinawa_snd_efw_handle_response(HinawaSndEfw *self, + const void *buf, unsigned int len); #endif diff --git a/libhinawa/src/snd_efw.c b/libhinawa/src/snd_efw.c new file mode 100644 index 0000000..6e1882b --- /dev/null +++ b/libhinawa/src/snd_efw.c @@ -0,0 +1,315 @@ +#include <linux/types.h> +#include <sound/firewire.h> +#include <alsa/asoundlib.h> +#include "snd_efw.h" +#include "internal.h" + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +/** + * SECTION:snd_efw + * @Title: HinawaSndEfw + * @Short_description: A transaction executor for Fireworks models + * + * A #HinawaSndEfw is an application of Echo Fireworks Transaction (EFT). + * This inherits #HinawaSndUnit. + */ +#define MINIMUM_SUPPORTED_VERSION 1 +#define MAXIMUM_FRAME_BYTES 0x200U + +enum efw_status { + EFT_STATUS_OK = 0, + EFT_STATUS_BAD = 1, + EFT_STATUS_BAD_COMMAND = 2, + EFT_STATUS_COMM_ERR = 3, + EFT_STATUS_BAD_QUAD_COUNT = 4, + EFT_STATUS_UNSUPPORTED = 5, + EFT_STATUS_1394_TIMEOUT = 6, + EFT_STATUS_DSP_TIMEOUT = 7, + EFT_STATUS_BAD_RATE = 8, + EFT_STATUS_BAD_CLOCK = 9, + EFT_STATUS_BAD_CHANNEL = 10, + EFT_STATUS_BAD_PAN = 11, + EFT_STATUS_FLASH_BUSY = 12, + EFT_STATUS_BAD_MIRROR = 13, + EFT_STATUS_BAD_LED = 14, + EFT_STATUS_BAD_PARAMETER = 15, +}; +static const char *const efw_status_names[] = { + [EFT_STATUS_OK] = "OK", + [EFT_STATUS_BAD] = "bad", + [EFT_STATUS_BAD_COMMAND] = "bad command", + [EFT_STATUS_COMM_ERR] = "comm err", + [EFT_STATUS_BAD_QUAD_COUNT] = "bad quad count", + [EFT_STATUS_UNSUPPORTED] = "unsupported", + [EFT_STATUS_1394_TIMEOUT] = "1394 timeout", + [EFT_STATUS_DSP_TIMEOUT] = "DSP timeout", + [EFT_STATUS_BAD_RATE] = "bad rate", + [EFT_STATUS_BAD_CLOCK] = "bad clock", + [EFT_STATUS_BAD_CHANNEL] = "bad channel", + [EFT_STATUS_BAD_PAN] = "bad pan", + [EFT_STATUS_FLASH_BUSY] = "flash busy", + [EFT_STATUS_BAD_MIRROR] = "bad mirror", + [EFT_STATUS_BAD_LED] = "bad LED", + [EFT_STATUS_BAD_PARAMETER] = "bad parameter", +}; + +struct efw_transaction { + guint seqnum; + + struct snd_efw_transaction *frame; + + GCond cond; +}; + +struct _HinawaSndEfwPrivate { + guint seqnum; + + GList *transactions; + GMutex lock; +}; +G_DEFINE_TYPE_WITH_PRIVATE(HinawaSndEfw, hinawa_snd_efw, HINAWA_TYPE_SND_UNIT) +#define SND_EFW_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), \ + HINAWA_TYPE_SND_EFW, HinawaSndEfwPrivate)) + +static void snd_efw_dispose(GObject *obj) +{ + G_OBJECT_CLASS(hinawa_snd_efw_parent_class)->dispose(obj); +} + +static void snd_efw_finalize(GObject *gobject) +{ + G_OBJECT_CLASS(hinawa_snd_efw_parent_class)->finalize(gobject); +} + +static void hinawa_snd_efw_class_init(HinawaSndEfwClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->dispose = snd_efw_dispose; + gobject_class->finalize = snd_efw_finalize; +} + +static void hinawa_snd_efw_init(HinawaSndEfw *self) +{ + self->priv = hinawa_snd_efw_get_instance_private(self); +} + +/** + * hinawa_snd_efw_new: + * @path: A path to ALSA hwdep device for Fireworks models (i.e. hw:0) + * @exception: A #GError + * + * Returns: A #HinawaSndEfw + */ +void hinawa_snd_efw_open(HinawaSndEfw *self, gchar *path, GError **exception) +{ + HinawaSndEfwPrivate *priv; + int type; + + g_return_if_fail(HINAWA_IS_SND_EFW(self)); + priv = SND_EFW_GET_PRIVATE(self); + + hinawa_snd_unit_open(&self->parent_instance, path, exception); + if (*exception != NULL) { + g_clear_object(&self); + return; + } + + g_object_get(G_OBJECT(self), "type", &type, NULL); + if (type != SNDRV_FIREWIRE_TYPE_FIREWORKS) { + g_set_error(exception, g_quark_from_static_string(__func__), + EINVAL, "%s", strerror(EINVAL)); + g_clear_object(&self); + return; + } + + priv = SND_EFW_GET_PRIVATE(self); + priv->seqnum = 0; + priv->transactions = NULL; + g_mutex_init(&priv->lock); +} + +/** + * hinawa_snd_efw_transact: + * @self: A #HinawaSndEfw + * @category: one of category for the transact + * @command: one of commands for the transact + * @args: (nullable) (element-type guint32) (array) (in): arguments for the + * transaction + * @params: (element-type guint32) (array) (out caller-allocates): return params + * @exception: A #GError + */ +void hinawa_snd_efw_transact(HinawaSndEfw *self, guint category, guint command, + GArray *args, GArray *params, GError **exception) +{ + HinawaSndEfwPrivate *priv; + int type; + + struct efw_transaction trans; + __le32 *items; + + unsigned int quads; + unsigned int count; + unsigned int i; + + gint64 expiration; + + g_return_if_fail(HINAWA_IS_SND_EFW(self)); + priv = SND_EFW_GET_PRIVATE(self); + + /* Check unit type and function arguments . */ + g_object_get(G_OBJECT(self), "type", &type, NULL); + if ((type != SNDRV_FIREWIRE_TYPE_FIREWORKS) || + (args && g_array_get_element_size(args) != sizeof(guint32)) || + (params && g_array_get_element_size(params) != sizeof(guint32))) { + g_set_error(exception, g_quark_from_static_string(__func__), + EINVAL, "%s", strerror(EINVAL)); + return; + } + + trans.frame = g_malloc0(MAXIMUM_FRAME_BYTES); + if (trans.frame == NULL) { + g_set_error(exception, g_quark_from_static_string(__func__), + ENOMEM, "%s", strerror(ENOMEM)); + return; + } + + /* Increment the sequence number for next transaction. */ + trans.frame->seqnum = priv->seqnum; + priv->seqnum += 2; + if (priv->seqnum > SND_EFW_TRANSACTION_USER_SEQNUM_MAX) + priv->seqnum = 0; + + /* Fill transaction frame. */ + quads = sizeof(struct snd_efw_transaction) / 4; + if (args) + quads += args->len; + trans.frame->length = quads; + trans.frame->version = MINIMUM_SUPPORTED_VERSION; + trans.frame->category = category; + trans.frame->command = command; + trans.frame->status = 0xff; + if (args) + memcpy(trans.frame->params, + args->data, args->len * sizeof(guint32)); + + /* The transactions are aligned to big-endian. */ + items = (__le32 *)trans.frame; + for (i = 0; i < quads; i++) + items[i] = htobe32(items[i]); + + /* Insert this entry to list and enter critical section. */ + g_mutex_lock(&priv->lock); + priv->transactions = g_list_append(priv->transactions, &trans); + + /* NOTE: Timeout is 200 milli-seconds. */ + expiration = g_get_monotonic_time() + 200 * G_TIME_SPAN_MILLISECOND; + g_cond_init(&trans.cond); + + /* Send this request frame. */ + hinawa_snd_unit_write(&self->parent_instance, trans.frame, quads * 4, + exception); + if (*exception != NULL) + goto end; + + /* + * Wait corresponding response till timeout and temporarily leave the + * critical section. + */ + if (!g_cond_wait_until(&trans.cond, &priv->lock, expiration)) { + g_set_error(exception, g_quark_from_static_string(__func__), + ETIMEDOUT, "%s", strerror(ETIMEDOUT)); + goto end; + } + + quads = be32toh(trans.frame->length); + + /* The transactions are aligned to big-endian. */ + items = (__le32 *)trans.frame; + for (i = 0; i < quads; i++) + items[i] = be32toh(items[i]); + + /* Check transaction status. */ + if (trans.frame->status != EFT_STATUS_OK) { + g_set_error(exception, g_quark_from_static_string(__func__), + EPROTO, "%s", + efw_status_names[trans.frame->status]); + goto end; + } + + /* Check transaction headers. */ + if ((trans.frame->version < MINIMUM_SUPPORTED_VERSION) || + (trans.frame->category != category) || + (trans.frame->command != command)) { + g_set_error(exception, g_quark_from_static_string(__func__), + EIO, "%s", strerror(EIO)); + goto end; + } + + /* Check returned parameters. */ + count = quads - sizeof(struct snd_efw_transaction) / 4; + if (count > 0 && params == NULL) { + g_set_error(exception, g_quark_from_static_string(__func__), + EINVAL, "%s", strerror(EINVAL)); + goto end; + } + + /* Copy parameters. */ + g_array_insert_vals(params, 0, trans.frame->params, count); +end: + /* Remove thie entry from list and leave the critical section. */ + priv->transactions = + g_list_remove(priv->transactions, (gpointer *)&trans); + g_mutex_unlock(&priv->lock); + + g_free(trans.frame); +} + +void hinawa_snd_efw_handle_response(HinawaSndEfw *self, + const void *buf, unsigned int len) +{ + HinawaSndEfwPrivate *priv; + struct snd_firewire_event_efw_response *event = + (struct snd_firewire_event_efw_response *)buf; + guint *responses = event->response; + + struct snd_efw_transaction *resp_frame; + struct efw_transaction *trans; + + unsigned int quadlets; + GList *entry; + + g_return_if_fail(HINAWA_IS_SND_EFW(self)); + priv = SND_EFW_GET_PRIVATE(self); + + while (len > 0) { + resp_frame = (struct snd_efw_transaction *)responses; + + g_mutex_lock(&priv->lock); + + trans = NULL; + for (entry = priv->transactions; + entry != NULL; entry = entry->next) { + trans = (struct efw_transaction *)entry->data; + + if (be32toh(resp_frame->seqnum) == trans->seqnum) + break; + } + + g_mutex_unlock(&priv->lock); + + if (trans == NULL) + continue; + + quadlets = be32toh(resp_frame->length); + memcpy(trans->frame, resp_frame, quadlets * 4); + g_cond_signal(&trans->cond); + + responses += quadlets; + len -= quadlets * sizeof(guint); + } +} diff --git a/libhinawa/src/snd_efw.h b/libhinawa/src/snd_efw.h new file mode 100644 index 0000000..cdc514b --- /dev/null +++ b/libhinawa/src/snd_efw.h @@ -0,0 +1,54 @@ +#ifndef __ALSA_TOOLS_HINAWA_SND_EFW_H__ +#define __ALSA_TOOLS_HINAWA_SND_EFW_H__ + +#include <glib.h> +#include <glib-object.h> +#include "snd_unit.h" + +G_BEGIN_DECLS + +#define HINAWA_TYPE_SND_EFW (hinawa_snd_efw_get_type()) + +#define HINAWA_SND_EFW(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + HINAWA_TYPE_SND_EFW, \ + HinawaSndEfw)) +#define HINAWA_IS_SND_EFW(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + HINAWA_TYPE_SND_EFW)) + +#define HINAWA_SND_EFW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + HINAWA_TYPE_SND_EFW, \ + HinawaSndEfwClass)) +#define HINAWA_IS_SND_EFW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + HINAWA_TYPE_SND_EFW)) +#define HINAWA_SND_EFW_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + HINAWA_TYPE_SND_EFW, \ + HinawaSndEfwClass)) + +typedef struct _HinawaSndEfw HinawaSndEfw; +typedef struct _HinawaSndEfwClass HinawaSndEfwClass; +typedef struct _HinawaSndEfwPrivate HinawaSndEfwPrivate; + +struct _HinawaSndEfw { + HinawaSndUnit parent_instance; + + HinawaSndEfwPrivate *priv; +}; + +struct _HinawaSndEfwClass { + HinawaSndUnitClass parent_class; +}; + +GType hinawa_snd_efw_get_type(void) G_GNUC_CONST; + +void hinawa_snd_efw_open(HinawaSndEfw *self, gchar *path, GError **exception); + +void hinawa_snd_efw_transact(HinawaSndEfw *self, guint category, guint command, + GArray *args, GArray *params, + GError **exception); + +#endif diff --git a/libhinawa/src/snd_unit.c b/libhinawa/src/snd_unit.c index b7537a3..eea6bbe 100644 --- a/libhinawa/src/snd_unit.c +++ b/libhinawa/src/snd_unit.c @@ -7,6 +7,7 @@ #include "fw_req.h" #include "fw_fcp.h" #include "snd_dice.h" +#include "snd_efw.h" #include "internal.h"
#ifdef HAVE_CONFIG_H @@ -412,6 +413,10 @@ static gboolean check_src(GSource *gsrc) common->type == SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION) hinawa_snd_dice_handle_notification(HINAWA_SND_DICE(unit), priv->buf, len); + else if (HINAWA_IS_SND_EFW(unit) && + common->type == SNDRV_FIREWIRE_EVENT_EFW_RESPONSE) + hinawa_snd_efw_handle_response(HINAWA_SND_EFW(unit), + priv->buf, len); end: /* Don't go to dispatch, then continue to process this source. */ return FALSE;
To construct an instance of snd_unit/snd_dice/snd_efw, applications need to know which hwdep device is corresponding to the target unit.
This commit adds HINAWA_TYPE_UNIT_QUERY object to query hwdep devices for FireWire unit. This object has no constructor, therefore applications can get sibling hwdep device or the type of given hwdep device without any instances.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/doc/reference/hinawa-docs.sgml | 1 + libhinawa/src/Makefile.am | 7 +- libhinawa/src/unit_query.c | 116 +++++++++++++++++++++++++++++++ libhinawa/src/unit_query.h | 48 +++++++++++++ 4 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 libhinawa/src/unit_query.c create mode 100644 libhinawa/src/unit_query.h
diff --git a/libhinawa/doc/reference/hinawa-docs.sgml b/libhinawa/doc/reference/hinawa-docs.sgml index 731ae15..dbfa0f2 100644 --- a/libhinawa/doc/reference/hinawa-docs.sgml +++ b/libhinawa/doc/reference/hinawa-docs.sgml @@ -37,6 +37,7 @@ <xi:include href="xml/snd_unit.xml"/> <xi:include href="xml/snd_dice.xml"/> <xi:include href="xml/snd_efw.xml"/> + <xi:include href="xml/unit_query.xml"/> </chapter> </part>
diff --git a/libhinawa/src/Makefile.am b/libhinawa/src/Makefile.am index b746bf1..4fbbdd3 100644 --- a/libhinawa/src/Makefile.am +++ b/libhinawa/src/Makefile.am @@ -38,7 +38,9 @@ libhinawa_la_SOURCES = \ snd_dice.h \ snd_dice.c \ snd_efw.h \ - snd_efw.c + snd_efw.c \ + unit_query.h \ + unit_query.c
pkginclude_HEADERS = \ hinawa_sigs_marshal.h \ @@ -48,7 +50,8 @@ pkginclude_HEADERS = \ fw_fcp.h \ snd_unit.h \ snd_dice.h \ - snd_efw.h + snd_efw.h \ + unit_query.h
hinawa_sigs_marshal.list: $(AM_V_GEN)( find | grep .c$$ | xargs cat | \ diff --git a/libhinawa/src/unit_query.c b/libhinawa/src/unit_query.c new file mode 100644 index 0000000..669513d --- /dev/null +++ b/libhinawa/src/unit_query.c @@ -0,0 +1,116 @@ +#include <unistd.h> +#include <alsa/asoundlib.h> +#include <sound/firewire.h> + +#include "unit_query.h" + +/** + * SECTION:unit_query + * @Title: HinawaUnitQuery + * @Short_description: An query to seek ALSA FireWire devices + * + */ +G_DEFINE_TYPE(HinawaUnitQuery, hinawa_unit_query, G_TYPE_OBJECT) + +static void unit_query_dispose(GObject *obj) +{ + G_OBJECT_CLASS(hinawa_unit_query_parent_class)->dispose(obj); +} + +static void unit_query_finalize(GObject *gobject) +{ + G_OBJECT_CLASS(hinawa_unit_query_parent_class)->finalize(gobject); +} + +static void hinawa_unit_query_class_init(HinawaUnitQueryClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->dispose = unit_query_dispose; + gobject_class->finalize = unit_query_finalize; +} + +static void hinawa_unit_query_init(HinawaUnitQuery *self) +{ + return; +} + +/** + * hinawa_unit_query_get_sibling: + * @id: The ID of sibling. + * @exception: A #GError + * + * Returns: the ID of sibling. + */ +gint hinawa_unit_query_get_sibling(gint id, GError **exception) +{ + snd_ctl_t *handle = NULL; + int err; + + /* NOTE: at least one sound device is expected to be detected. */ + err = snd_ctl_open(&handle, "hw:0", 0); + if (err < 0) + goto end; + + err = snd_ctl_hwdep_next_device(handle, &id); + if (err < 0) + goto end; + if (id < 0) { + err = -ENODEV; + goto end; + } + + hinawa_unit_query_get_unit_type(id, exception); +end: + if (err < 0) { + id = -1; + g_set_error(exception, g_quark_from_static_string(__func__), + -err, "%s", snd_strerror(err)); + } + if (handle != NULL) + snd_ctl_close(handle); + + return id; +} + +/** + * hinawa_unit_query_get_unit_type: + * @id: An ID for unit. + * @exception: An #GError + * + * Returns: The types of the unit. The value of SNDRV_FIREWIRE_TYPE_XXX. + */ +gint hinawa_unit_query_get_unit_type(gint id, GError **exception) +{ + snd_hwdep_t *handle = NULL; + char path[10] = {0}; + struct snd_firewire_get_info info; + gint type = -1; + int err; + + /* Check id and make device string */ + if (id < 0) { + err = -EINVAL; + goto end; + } + snprintf(path, sizeof(path), "hw:%d", id); + + /* Open hwdep handle. */ + err = snd_hwdep_open(&handle, path, 0); + if (err < 0) + goto end; + + /* Get FireWire sound device information. */ + err = snd_hwdep_ioctl(handle, SNDRV_FIREWIRE_IOCTL_GET_INFO, &info); + if (err < 0) + goto end; + type = info.type; +end: + if (err < 0) + g_set_error(exception, g_quark_from_static_string(__func__), + -err, "%s", snd_strerror(err)); + if (handle != NULL) + snd_hwdep_close(handle); + + return type; +} diff --git a/libhinawa/src/unit_query.h b/libhinawa/src/unit_query.h new file mode 100644 index 0000000..cdaf09b --- /dev/null +++ b/libhinawa/src/unit_query.h @@ -0,0 +1,48 @@ +#ifndef __ALSA_TOOLS_HINAWA_UNIT_QUERY_H__ +#define __ALSA_TOOLS_HINAWA_UNIT_QUERY_H__ + +#include <glib.h> +#include <glib-object.h> + +G_BEGIN_DECLS + +#define HINAWA_TYPE_UNIT_QUERY (hinawa_unit_query_get_type()) + +#define HINAWA_UNIT_QUERY(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + HINAWA_TYPE_UNIT_QUERY, \ + HinawaUnitQuery)) +#define HINAWA_IS_UNIT_QUERY(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + HINAWA_TYPE_UNIT_QUERY)) + +#define HINAWA_UNIT_QUERY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), \ + HINAWA_TYPE_UNIT_QUERY, \ + HinawaUnitQueryClass)) +#define HINAWA_IS_UNIT_QUERY_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass), \ + HINAWA_TYPE_UNIT_QUERY)) +#define HINAWA_UNIT_QUERY_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), \ + HINAWA_TYPE_UNIT_QUERY, \ + HinawaUnitQueryClass)) + +typedef struct _HinawaUnitQuery HinawaUnitQuery; +typedef struct _HinawaUnitQueryClass HinawaUnitQueryClass; + +struct _HinawaUnitQuery { + GObject parent_instance; +}; + +struct _HinawaUnitQueryClass { + GObjectClass parent_class; +}; + +GType hinawa_unit_query_get_type(void) G_GNUC_CONST; + +gint hinawa_unit_query_get_sibling(gint id, GError **exception); + +gint hinawa_unit_query_get_unit_type(gint id, GError **exception); + +#endif
This commit adds some sample scripts written by Python 2/3. In Python, PyGObject is required for GObject Introspection library.
There're three scripts, using Gtk+, Qt4 and Qt5. Each of them require python bindings as: - PyGObject - PyQt4 - PyQt5
I note that most of methods in libhinawa require 32bit array as its method arguments. In Python, 'array' module is useful but the actual width of the array element depents on machine architecture. Please refer to sample scripts to solve this issue.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- libhinawa/README | 10 +++ libhinawa/samples/gtk3.py | 190 ++++++++++++++++++++++++++++++++++++++++++ libhinawa/samples/qt4.py | 206 ++++++++++++++++++++++++++++++++++++++++++++++ libhinawa/samples/qt5.py | 192 ++++++++++++++++++++++++++++++++++++++++++ libhinawa/samples/run.sh | 15 ++++ 5 files changed, 613 insertions(+) create mode 100755 libhinawa/samples/gtk3.py create mode 100755 libhinawa/samples/qt4.py create mode 100755 libhinawa/samples/qt5.py create mode 100755 libhinawa/samples/run.sh
diff --git a/libhinawa/README b/libhinawa/README index 42d31f5..4e3c92c 100644 --- a/libhinawa/README +++ b/libhinawa/README @@ -18,3 +18,13 @@ How to refer document $ ./configure --enable-gtk-doc $ make $ make install + +How to test +(needless to install) + $ ./autogen.sh + $ ./configure + $ make + $ ./samples/run.sh [gtk|qt4|qt5] +gtk - PyGObject is required. +qt4 - PyQt4 is required (also test python2). +qt5 - PyQt5 is required. diff --git a/libhinawa/samples/gtk3.py b/libhinawa/samples/gtk3.py new file mode 100755 index 0000000..41a817e --- /dev/null +++ b/libhinawa/samples/gtk3.py @@ -0,0 +1,190 @@ +#!/usr/bin/env python3 + +import sys + +# Gtk+3 gir +from gi.repository import Gtk + +# Hinawa-1.0 gir +from gi.repository import Hinawa + +from array import array + +# helper function +def get_array(): + # The width with 'L' parameter is depending on environment. + arr = array('L') + if arr.itemsize is not 4: + arr = array('I') + return arr + +# query sound devices +index = -1 +while True: + try: + index = Hinawa.UnitQuery.get_sibling(index) + except Exception as e: + break + break + +# no fw sound devices are detected. +if index == -1: + print('No sound FireWire devices found.') + sys.exit() + +# get unit type +try: + unit_type = Hinawa.UnitQuery.get_unit_type(index) +except Exception as e: + print(e) + sys.exit() + +# create sound unit +def handle_lock_status(snd_unit, status): + if status: + print("streaming is locked."); + else: + print("streaming is unlocked."); +if unit_type == 1: + snd_unit = Hinawa.SndDice() +elif unit_type == 2: + snd_unit = Hinawa.SndEfw() +elif unit_type == 3 or unit_type == 4: + snd_unit = Hinawa.SndUnit() +path = "hw:{0}".format(index) +try: + snd_unit.open(path) +except Exception as e: + print(e) + sys.exit() +print('Sound device info:') +print(' type:\t{0}'.format(snd_unit.get_property("type"))) +print(' card:\t{0}'.format(snd_unit.get_property("card"))) +print(' device:\t{0}'.format(snd_unit.get_property("device"))) +print(' GUID:\t{0:016x}'.format(snd_unit.get_property("guid"))) +snd_unit.connect("lock-status", handle_lock_status) + +# create FireWire unit +def handle_bus_update(snd_unit): + print(snd_unit.get_property('generation')) +snd_unit.connect("bus-update", handle_bus_update) + +# start listening +try: + snd_unit.listen() +except Exception as e: + print(e) + sys.exit() + +# create firewire responder +resp = Hinawa.FwResp() +def handle_request(resp, tcode, req_frame): + print('Requested with tcode {0}:'.format(tcode)) + for i in range(len(req_frame)): + print(' [{0:02d}]: 0x{1:08x}'.format(i, req_frame[i])) + # Return no data for the response frame + return None +try: + resp.register(snd_unit, 0xfffff0000d00, 0x100) + resp.connect('requested', handle_request) +except Exception as e: + print(e) + sys.exit() + +# create firewire requester +req = Hinawa.FwReq() + +# Fireworks/BeBoB/OXFW supports FCP and some AV/C commands +if snd_unit.get_property('type') is not 1: + request = bytes([0x01, 0xff, 0x19, 0x00, 0xff, 0xff, 0xff, 0xff]) + try: + response = snd_unit.fcp_transact(request) + except Exception as e: + print(e) + sys.exit() + print('FCP Response:') + for i in range(len(response)): + print(' [{0:02d}]: 0x{1:02x}'.format(i, response[i])) + +# Echo Fireworks Transaction +if snd_unit.get_property("type") is 2: + args = get_array() + args.append(5) + try: + params = snd_unit.transact(6, 1, args) + except Exception as e: + print(e) + sys.exit() + print('Echo Fireworks Transaction Response:') + for i in range(len(params)): + print(" [{0:02d}]: {1:08x}".format(i, params[i])) + +# Dice notification +def handle_notification(self, message): + print("Dice Notification: {0:08x}".format(message)) +if snd_unit.get_property('type') is 1: + snd_unit.connect('notified', handle_notification) + args = get_array() + args.append(0x0000030c) + try: + # The address of clock in Impact Twin + snd_unit.transact(0xffffe0000074, args, 0x00000020) + except Exception as e: + print(e) + sys.exit() + +# GUI +class Sample(Gtk.Window): + + def __init__(self): + Gtk.Window.__init__(self, title="Hinawa-1.0 gir sample") + self.set_border_width(20) + + vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10) + self.add(vbox) + + topbox = Gtk.Box(spacing=10) + vbox.pack_start(topbox, True, True, 0) + + button = Gtk.Button("transact") + button.connect("clicked", self.on_click_transact) + topbox.pack_start(button, True, True, 0) + + button = Gtk.Button("_Close", use_underline=True) + button.connect("clicked", self.on_click_close) + topbox.pack_start(button, True, True, 0) + + bottombox = Gtk.Box(spacing=10) + vbox.pack_start(bottombox, True, True, 0) + + self.entry = Gtk.Entry() + self.entry.set_text("0xfffff0000980") + bottombox.pack_start(self.entry, True, True, 0) + + self.label = Gtk.Label("result") + self.label.set_text("0x00000000") + bottombox.pack_start(self.label, True, True, 0) + + def on_click_transact(self, button): + try: + addr = int(self.entry.get_text(), 16) + val = snd_unit.read_transact(addr, 1) + except Exception as e: + print(e) + return + + self.label.set_text('0x{0:08x}'.format(val[0])) + print(self.label.get_text()) + + def on_click_close(self, button): + print("Closing application") + Gtk.main_quit() + +# Main logic +win = Sample() +win.connect("delete-event", Gtk.main_quit) +win.show_all() + +Gtk.main() + +sys.exit() diff --git a/libhinawa/samples/qt4.py b/libhinawa/samples/qt4.py new file mode 100755 index 0000000..43611a1 --- /dev/null +++ b/libhinawa/samples/qt4.py @@ -0,0 +1,206 @@ +#!/usr/bin/env python2 + +import sys + +# PyQt4 is not released for python3, sigh... +# The combination of Python2 and Qt4 has a disadvantage for QString. +# This forces interpretor to handle QString as usual unicode string. +import sip +sip.setapi('QString', 2) +from PyQt4.QtCore import Qt +from PyQt4.QtGui import QApplication, QWidget, QHBoxLayout, QVBoxLayout +from PyQt4.QtGui import QToolButton, QGroupBox, QLineEdit, QLabel + +# Hinawa-1.0 gir +from gi.repository import Hinawa + +from array import array + +# helper function +def get_array(): + # The width with 'L' parameter is depending on environment. + arr = array('L') + if arr.itemsize is not 4: + arr = array('I') + return arr + +# query sound devices +index = -1 +while True: + try: + index = Hinawa.UnitQuery.get_sibling(index) + except Exception as e: + break + break + +# no fw sound devices are detected. +if index == -1: + print('No sound FireWire devices found.') + sys.exit() + +# get unit type +try: + unit_type = Hinawa.UnitQuery.get_unit_type(index) +except Exception as e: + print(e) + sys.exit() + +# create sound unit +def handle_lock_status(snd_unit, status): + if status: + print("streaming is locked."); + else: + print("streaming is unlocked."); +if unit_type == 1: + snd_unit = Hinawa.SndDice() +elif unit_type == 2: + snd_unit = Hinawa.SndEfw() +elif unit_type == 3 or unit_type == 4: + snd_unit = Hinawa.SndUnit() +path = "hw:{0}".format(index) +try: + snd_unit.open(path) +except Exception as e: + print(e) + sys.exit() +print('Sound device info:') +print(' type:\t{0}'.format(snd_unit.get_property("type"))) +print(' card:\t{0}'.format(snd_unit.get_property("card"))) +print(' device:\t{0}'.format(snd_unit.get_property("device"))) +print(' GUID:\t{0:016x}'.format(snd_unit.get_property("guid"))) +snd_unit.connect("lock-status", handle_lock_status) + +# create FireWire unit +def handle_bus_update(snd_unit): + print(snd_unit.get_property('generation')) +snd_unit.connect("bus-update", handle_bus_update) + +# start listening +try: + snd_unit.listen() +except Exception as e: + print(e) + sys.exit() + +# create firewire responder +resp = Hinawa.FwResp() +def handle_request(resp, tcode, req_frame): + print('Requested with tcode {0}:'.format(tcode)) + for i in range(len(req_frame)): + print(' [{0:02d}]: 0x{1:08x}'.format(i, req_frame[i])) + # Return no data for the response frame + return None +try: + resp.register(snd_unit, 0xfffff0000d00, 0x100) + resp.connect('requested', handle_request) +except Exception as e: + print(e) + sys.exit() + +# create firewire requester +req = Hinawa.FwReq() + +# Fireworks/BeBoB/OXFW supports FCP and some AV/C commands +if snd_unit.get_property('type') is not 1: + request = bytearray(8) + request[0] = 0x01 + request[1] = 0xff + request[2] = 0x19 + request[3] = 0x00 + request[4] = 0xff + request[5] = 0xff + request[6] = 0xff + request[7] = 0xff + + try: + response = snd_unit.fcp_transact(request) + except Exception as e: + print(e) + sys.exit() + print('FCP Response:') + for i in range(len(response)): + print(' [{0:02d}]: 0x{1:02x}'.format(i, ord(response[i]))) + +# Echo Fireworks Transaction +if snd_unit.get_property("type") is 2: + args = get_array() + args.append(5) + try: + params = snd_unit.transact(6, 1, args) + except Exception as e: + print(e) + sys.exit() + print('Echo Fireworks Transaction Response:') + for i in range(len(params)): + print(" [{0:02d}]: {1:08x}".format(i, params[i])) + +# Dice notification +def handle_notification(self, message): + print("Dice Notification: {0:08x}".format(message)) +if snd_unit.get_property('type') is 1: + snd_unit.connect('notified', handle_notification) + args = get_array() + args.append(0x0000030c) + try: + # The address of clock in Impact Twin + snd_unit.transact(0xffffe0000074, args, 0x00000020) + except Exception as e: + print(e) + sys.exit() + +# GUI +class Sample(QWidget): + def __init__(self, parent=None): + super(Sample, self).__init__(parent) + + self.setWindowTitle("Hinawa-1.0 gir sample with PyQt4") + + layout = QVBoxLayout() + self.setLayout(layout) + + top_grp = QGroupBox(self) + top_layout = QHBoxLayout() + top_grp.setLayout(top_layout) + layout.addWidget(top_grp) + + buttom_grp = QGroupBox(self) + buttom_layout = QHBoxLayout() + buttom_grp.setLayout(buttom_layout) + layout.addWidget(buttom_grp) + + button = QToolButton(top_grp) + button.setText('transact') + top_layout.addWidget(button) + button.clicked.connect(self.transact) + + close = QToolButton(top_grp) + close.setText('close') + top_layout.addWidget(close) + close.clicked.connect(app.quit) + + self.addr = QLineEdit(buttom_grp) + self.addr.setText('0xfffff0000980') + buttom_layout.addWidget(self.addr) + + self.value = QLabel(buttom_grp) + self.value.setText('00000000') + buttom_layout.addWidget(self.value) + + def transact(self, val): + try: + addr = int(self.addr.text(), 16) + val = req.read(snd_unit, addr, 1) + except Exception as e: + print(e) + return + + self.value.setText('0x{0:08x}'.format(val[0])) + print(self.value.text()) + +app = QApplication(sys.argv) +sample = Sample() + +sample.show() +app.exec_() + +sys.exit() diff --git a/libhinawa/samples/qt5.py b/libhinawa/samples/qt5.py new file mode 100755 index 0000000..ffe528b --- /dev/null +++ b/libhinawa/samples/qt5.py @@ -0,0 +1,192 @@ +#!/usr/bin/env python3 + +import sys + +# Qt5 python binding +from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout +from PyQt5.QtWidgets import QToolButton, QGroupBox, QLineEdit, QLabel + +# Hinawa-1.0 gir +from gi.repository import Hinawa + +from array import array + +# helper function +def get_array(): + # The width with 'L' parameter is depending on environment. + arr = array('L') + if arr.itemsize is not 4: + arr = array('I') + return arr + +# query sound devices +index = -1 +while True: + try: + index = Hinawa.UnitQuery.get_sibling(index) + except Exception as e: + break + break + +# no fw sound devices are detected. +if index == -1: + print('No sound FireWire devices found.') + sys.exit() + +# get unit type +try: + unit_type = Hinawa.UnitQuery.get_unit_type(index) +except Exception as e: + print(e) + sys.exit() + +# create sound unit +def handle_lock_status(snd_unit, status): + if status: + print("streaming is locked."); + else: + print("streaming is unlocked."); +if unit_type == 1: + snd_unit = Hinawa.SndDice() +elif unit_type == 2: + snd_unit = Hinawa.SndEfw() +elif unit_type == 3 or unit_type == 4: + snd_unit = Hinawa.SndUnit() +path = "hw:{0}".format(index) +try: + snd_unit.open(path) +except Exception as e: + print(e) + sys.exit() +print('Sound device info:') +print(' type:\t{0}'.format(snd_unit.get_property("type"))) +print(' card:\t{0}'.format(snd_unit.get_property("card"))) +print(' device:\t{0}'.format(snd_unit.get_property("device"))) +print(' GUID:\t{0:016x}'.format(snd_unit.get_property("guid"))) +snd_unit.connect("lock-status", handle_lock_status) + +# create FireWire unit +def handle_bus_update(snd_unit): + print(snd_unit.get_property('generation')) +snd_unit.connect("bus-update", handle_bus_update) + +# start listening +try: + snd_unit.listen() +except Exception as e: + print(e) + sys.exit() + +# create firewire responder +resp = Hinawa.FwResp() +def handle_request(resp, tcode, req_frame): + print('Requested with tcode {0}:'.format(tcode)) + for i in range(len(req_frame)): + print(' [{0:02d}]: 0x{1:08x}'.format(i, req_frame[i])) + # Return no data for the response frame + return None +try: + resp.register(snd_unit, 0xfffff0000d00, 0x100) + resp.connect('requested', handle_request) +except Exception as e: + print(e) + sys.exit() + +# create firewire requester +req = Hinawa.FwReq() + +# Fireworks/BeBoB/OXFW supports FCP and some AV/C commands +if snd_unit.get_property('type') is not 1: + request = bytes([0x01, 0xff, 0x19, 0x00, 0xff, 0xff, 0xff, 0xff]) + try: + response = snd_unit.fcp_transact(request) + except Exception as e: + print(e) + sys.exit() + print('FCP Response:') + for i in range(len(response)): + print(' [{0:02d}]: 0x{1:02x}'.format(i, response[i])) + +# Echo Fireworks Transaction +if snd_unit.get_property("type") is 2: + args = get_array() + args.append(5) + try: + params = snd_unit.transact(6, 1, args) + except Exception as e: + print(e) + sys.exit() + print('Echo Fireworks Transaction Response:') + for i in range(len(params)): + print(" [{0:02d}]: {1:08x}".format(i, params[i])) + +# Dice notification +def handle_notification(self, message): + print("Dice Notification: {0:08x}".format(message)) +if snd_unit.get_property('type') is 1: + snd_unit.connect('notified', handle_notification) + args = get_array() + args.append(0x0000030c) + try: + # The address of clock in Impact Twin + snd_unit.transact(0xffffe0000074, args, 0x00000020) + except Exception as e: + print(e) + sys.exit() + +# GUI +class Sample(QWidget): + def __init__(self, parent=None): + super(Sample, self).__init__(parent) + + self.setWindowTitle("Hinawa-1.0 gir sample with PyQt5") + + layout = QVBoxLayout() + self.setLayout(layout) + + top_grp = QGroupBox(self) + top_layout = QHBoxLayout() + top_grp.setLayout(top_layout) + layout.addWidget(top_grp) + + buttom_grp = QGroupBox(self) + buttom_layout = QHBoxLayout() + buttom_grp.setLayout(buttom_layout) + layout.addWidget(buttom_grp) + + button = QToolButton(top_grp) + button.setText('transact') + top_layout.addWidget(button) + button.clicked.connect(self.transact) + + close = QToolButton(top_grp) + close.setText('close') + top_layout.addWidget(close) + close.clicked.connect(app.quit) + + self.addr = QLineEdit(buttom_grp) + self.addr.setText('0xfffff0000980') + buttom_layout.addWidget(self.addr) + + self.value = QLabel(buttom_grp) + self.value.setText('00000000') + buttom_layout.addWidget(self.value) + + def transact(self, val): + try: + addr = int(self.addr.text(), 16) + val = req.read(snd_unit, addr, 1) + except Exception as e: + print(e) + return + + self.value.setText('0x{0:08x}'.format(val[0])) + print(self.value.text()) + +app = QApplication(sys.argv) +sample = Sample() + +sample.show() +app.exec() + +sys.exit() diff --git a/libhinawa/samples/run.sh b/libhinawa/samples/run.sh new file mode 100755 index 0000000..8db3abc --- /dev/null +++ b/libhinawa/samples/run.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# NOTE: +# Current working directory should be in root of this repository. + +export LD_LIBRARY_PATH=src/.libs/:/usr/lib:/lib +export GI_TYPELIB_PATH=src/:/usr/lib/girepository-1.0 + +if [[ $1 == 'qt4' ]] ; then + ./samples/qt4.py +elif [[ $1 == 'qt5' ]] ; then + ./samples/qt5.py +elif [[ $1 == 'gtk' ]] ; then + ./samples/gtk3.py +fi
25.01.2015 16:34, Takashi Sakamoto wrote:
+from array import array
+# helper function +def get_array():
- # The width with 'L' parameter is depending on environment.
- arr = array('L')
- if arr.itemsize is not 4:
arr = array('I')
- return arr
If you insist on using arrays, then please add an assertion that you have actually got an array with itemsize 4 at the end. But, if I were you, I'd go with the "ctypes" module instead, if it works. Here is how you get a fixed-size (in the example, 10 elements) array with signed 4-byte elements:
from ctypes import * TenInts = c_int32 * 10 ii = TenInts()
The result supports buffer protocol.
Hi Alexander,
On Jan 25 2014 21:14, Alexander E. Patrakov wrote:
25.01.2015 16:34, Takashi Sakamoto wrote:
+from array import array
+# helper function +def get_array():
- # The width with 'L' parameter is depending on environment.
- arr = array('L')
- if arr.itemsize is not 4:
arr = array('I')
- return arr
If you insist on using arrays, then please add an assertion that you have actually got an array with itemsize 4 at the end.
Thanks for your comment. Certainly, I should put assersion to the function for guarantee to return 32bit array.
But, if I were you, I'd go with the "ctypes" module instead, if it works. Here is how you get a fixed-size (in the example, 10 elements) array with signed 4-byte elements:
from ctypes import * TenInts = c_int32 * 10 ii = TenInts()
The result supports buffer protocol.
I didn't realize this way, thank you.
But I'm too lazy to like fixed size of array. With the array module, I can expand the length of array automatically, like:
{{{ from array import array arr = array('L') arr.append(1) arr.append(2) ... arr.append("Aaargh, how large number!") }}}
Do you know the ways for flexible length in ctype array?
Regards
Takashi Sakamoto
27.01.2015 20:09, Takashi Sakamoto wrote:
Hi Alexander,
On Jan 25 2014 21:14, Alexander E. Patrakov wrote:
25.01.2015 16:34, Takashi Sakamoto wrote:
+from array import array
+# helper function +def get_array():
- # The width with 'L' parameter is depending on environment.
- arr = array('L')
- if arr.itemsize is not 4:
arr = array('I')
- return arr
If you insist on using arrays, then please add an assertion that you have actually got an array with itemsize 4 at the end.
Thanks for your comment. Certainly, I should put assersion to the function for guarantee to return 32bit array.
But, if I were you, I'd go with the "ctypes" module instead, if it works. Here is how you get a fixed-size (in the example, 10 elements) array with signed 4-byte elements:
from ctypes import * TenInts = c_int32 * 10 ii = TenInts()
The result supports buffer protocol.
I didn't realize this way, thank you.
But I'm too lazy to like fixed size of array. With the array module, I can expand the length of array automatically, like:
{{{ from array import array arr = array('L') arr.append(1) arr.append(2) ... arr.append("Aaargh, how large number!") }}}
Do you know the ways for flexible length in ctype array?
Unfortunately, there is no such thing in ctypes.
Hi Takashi S
On Sun, Jan 25, 2015 at 08:34:21PM +0900, Takashi Sakamoto wrote:
This is RFC for a new library into alsa-tools.
ALSA in Linux 3.16 or later extends a support for FireWire sound devices. Currently ALSA drivers supports streaming functionality only, while most of these devices require software implementation to control its internal DSP. The way to achieve this is to transfer byte sequence to the unit and wait byte sequence which the unit transfers if required.
By way of clarifying the intent here, this library seems to exist to funnel arbitary async transactions through the alsa kernel module. This covers the case whereby the streaming component (in the kernel) influences the way these commands are carried out, or when an ARM handler (which by definition must be a centralised resource) forms an integral part of the data exchange. Is this more or less correct?
Regards jonathan
Folks,
Why can't we just use the proven alsa-mixer control system for all this?
It seems like you are reinventing the wheel just to save a little extra code in the kernel.
Some of the benefits are that for pro-audio devices, you can use alsactl save and restore to preserve internal sound card configuration between bootups. Also things like gnome-mixer just work out of the box. Timing of when to send the commands is automatically solved, and the problem of which sound card is which is already solved when multiple sound cards are used.
Some of the sound cards don't have internal mixer matrices, and so for these devices only the clock source control would be necessary.
Surely this is not too much of a burden to add to the kernel for the benefits it provides?
Damien
On 25/01/15 22:34, Takashi Sakamoto wrote:
This is RFC for a new library into alsa-tools.
ALSA in Linux 3.16 or later extends a support for FireWire sound devices. Currently ALSA drivers supports streaming functionality only, while most of these devices require software implementation to control its internal DSP. The way to achieve this is to transfer byte sequence to the unit and wait byte sequence which the unit transfers if required.
This library, libhinawa, just support these operations, nothing others. The supported types of transactions are:
- IEEE 1394 read transaction
- IEEE 1394 write transaction
- IEEE 1394 lock transaction
- IEC 61883-1 FCP transaction
- Echo Fireworks transaction (with a help of snd-fireworks kernel driver)
- Dice notification (with a help of snd-dice kernel driver)
To help new developers, this library supports GObject Introspection for language bindings. The main logic of applications can be written with preferred languages such as Python, Ruby, Perl and so on. In the end of this patchset, some Python scripts with Gtk+, Qt4 and Qt5 are committed as samples.
This is my first development with GNU Autotools, GLib/GObject and GObject Introspection. Furthermore, I'm a beginner of FireWire subsystem programming. I'm happy to receive your comments, especially:
- the way to write Linux version dependency in configure.ac
- the way of libtool versioning
- the value of poll timeout in fw_unit/snd_unit
- the value of thread condition timeout in fw_fcp/snd_dice/snd_efw
- improvements of 'unit_query' object
- any programming mistakes (threading and so on...)
Regards
Takashi Sakamoto (13): libhinawa: add build definitions libhinawa: add hinawa context libhinawa: support GTK-Doc to generate references libhinawa: add 'fw_unit' object as a listener for FireWire unit libhinawa: support GObject Introspection for language bindings libhinawa: add 'fw_resp' object as a responder for FireWire transaction libhinawa: add 'fw_req' object as requester for FireWire transaction libhinawa: add 'fw_fcp' object as a helper of FCP transaction libhinawa: add 'snd_unit' object as a listener for ALSA FireWire devices libhinawa: add 'snd_dice' object as a helper for Dice notification libhinawa: add 'snd_efw' object as a helper for EFW transaction libhinawa: add 'unit_query' as a query for ALSA FireWire devices libhinawa: add sample scripts
Makefile | 2 +- libhinawa/AUTHORS | 1 + libhinawa/COPYING | 504 ++++++++++++++++++++++++++++ libhinawa/ChangeLog | 5 + libhinawa/Makefile.am | 6 + libhinawa/NEWS | 0 libhinawa/README | 30 ++ libhinawa/autogen.sh | 11 + libhinawa/configure.ac | 68 ++++ libhinawa/doc/Makefile.am | 2 + libhinawa/doc/reference/Makefile.am | 46 +++ libhinawa/doc/reference/hinawa-docs.sgml | 47 +++ libhinawa/doc/reference/version.xml.in | 1 + libhinawa/samples/gtk3.py | 190 +++++++++++ libhinawa/samples/qt4.py | 206 ++++++++++++ libhinawa/samples/qt5.py | 192 +++++++++++ libhinawa/samples/run.sh | 15 + libhinawa/src/Makefile.am | 97 ++++++ libhinawa/src/backport.h | 41 +++ libhinawa/src/fw_fcp.c | 282 ++++++++++++++++ libhinawa/src/fw_fcp.h | 58 ++++ libhinawa/src/fw_req.c | 265 +++++++++++++++ libhinawa/src/fw_req.h | 56 ++++ libhinawa/src/fw_resp.c | 232 +++++++++++++ libhinawa/src/fw_resp.h | 51 +++ libhinawa/src/fw_unit.c | 343 +++++++++++++++++++ libhinawa/src/fw_unit.h | 52 +++ libhinawa/src/hinawa_context.c | 60 ++++ libhinawa/src/hinawa_context.h | 10 + libhinawa/src/internal.h | 31 ++ libhinawa/src/snd_dice.c | 195 +++++++++++ libhinawa/src/snd_dice.h | 53 +++ libhinawa/src/snd_efw.c | 315 ++++++++++++++++++ libhinawa/src/snd_efw.h | 54 +++ libhinawa/src/snd_unit.c | 548 +++++++++++++++++++++++++++++++ libhinawa/src/snd_unit.h | 69 ++++ libhinawa/src/unit_query.c | 116 +++++++ libhinawa/src/unit_query.h | 48 +++ 38 files changed, 4301 insertions(+), 1 deletion(-) create mode 100644 libhinawa/AUTHORS create mode 100644 libhinawa/COPYING create mode 100644 libhinawa/ChangeLog create mode 100644 libhinawa/Makefile.am create mode 100644 libhinawa/NEWS create mode 100644 libhinawa/README create mode 100755 libhinawa/autogen.sh create mode 100644 libhinawa/configure.ac create mode 100644 libhinawa/doc/Makefile.am create mode 100644 libhinawa/doc/reference/Makefile.am create mode 100644 libhinawa/doc/reference/hinawa-docs.sgml create mode 100644 libhinawa/doc/reference/version.xml.in create mode 100755 libhinawa/samples/gtk3.py create mode 100755 libhinawa/samples/qt4.py create mode 100755 libhinawa/samples/qt5.py create mode 100755 libhinawa/samples/run.sh create mode 100644 libhinawa/src/Makefile.am create mode 100644 libhinawa/src/backport.h create mode 100644 libhinawa/src/fw_fcp.c create mode 100644 libhinawa/src/fw_fcp.h create mode 100644 libhinawa/src/fw_req.c create mode 100644 libhinawa/src/fw_req.h create mode 100644 libhinawa/src/fw_resp.c create mode 100644 libhinawa/src/fw_resp.h create mode 100644 libhinawa/src/fw_unit.c create mode 100644 libhinawa/src/fw_unit.h create mode 100644 libhinawa/src/hinawa_context.c create mode 100644 libhinawa/src/hinawa_context.h create mode 100644 libhinawa/src/internal.h create mode 100644 libhinawa/src/snd_dice.c create mode 100644 libhinawa/src/snd_dice.h create mode 100644 libhinawa/src/snd_efw.c create mode 100644 libhinawa/src/snd_efw.h create mode 100644 libhinawa/src/snd_unit.c create mode 100644 libhinawa/src/snd_unit.h create mode 100644 libhinawa/src/unit_query.c create mode 100644 libhinawa/src/unit_query.h
Damien Zammit wrote:
Why can't we just use the proven alsa-mixer control system for all this?
This does not prevent implementing ALSA userspace controls, which are stored and accessed like 'real' hardware controls.
Regards, Clemens
participants (5)
-
Alexander E. Patrakov
-
Clemens Ladisch
-
Damien Zammit
-
Jonathan Woithe
-
Takashi Sakamoto