diff options
47 files changed, 550 insertions, 1183 deletions
diff --git a/debian/README.source b/debian/README.source deleted file mode 100644 index a52add2..0000000 --- a/debian/README.source +++ /dev/null @@ -1,6 +0,0 @@ -libisnativec-java for Debian ----------------------------- - -The lib directory and also doc/3rd_party_licenses were manually removed -from the source tree. Also, the unzipped folder "distribution" was -changed to the versioned package name prior to preparing. the orig.tar.gz. diff --git a/debian/changelog b/debian/changelog index 0214a2a..8c40a11 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,16 @@ +libisnativec-java (5.6.20131203+dfsg-1) unstable; urgency=medium + + * Team upload. + * New upstream version + * Official Homepage vanished - use download source at sourceforge + * d/copyright: DEP5 + * Remove unwanted files from upstream source via Files-Excluded + * Build-Depends: s/default-jdk/default-jdk-headless/ + * Standards-Version: 4.7.0 (routine-update) + * Reorder sequence of d/control fields by cme (routine-update) + + -- Andreas Tille <tille@debian.org> Wed, 05 Feb 2025 19:37:12 +0100 + libisnativec-java (5.3.20100629+fix-4) unstable; urgency=medium * Team upload. diff --git a/debian/control b/debian/control index 85e8a1e..b96ef59 100644 --- a/debian/control +++ b/debian/control @@ -1,21 +1,21 @@ Source: libisnativec-java +Maintainer: Steffen Moeller <moeller@debian.org> Section: java Priority: optional -Maintainer: Steffen Moeller <moeller@debian.org> -Build-Depends: - debhelper-compat (= 13), - default-jdk, - javahelper (>= 0.37), - libisrt-java, - libjna-java -Standards-Version: 4.5.0 -Vcs-Git: https://salsa.debian.org/moeller/libisnativec-java.git -Vcs-Browser: https://salsa.debian.org/moeller/libisnativec-java -Homepage: http://opensource.intarsys.de/home/en/index.php?n=IsNativeC.HomePage +Build-Depends: debhelper-compat (= 13), + default-jdk-headless, + javahelper, + libisrt-java, + libjna-java +Standards-Version: 4.7.0 +Vcs-Browser: https://salsa.debian.org/java-team/libisnativec-java +Vcs-Git: https://salsa.debian.org/java-team/libisnativec-java.git +Homepage: https://sourceforge.net/projects/jpodrenderer/files/dependencies/5.6/ Package: libisnativec-java Architecture: all -Depends: ${java:Depends}, ${misc:Depends} +Depends: ${java:Depends}, + ${misc:Depends} Recommends: ${java:Recommends} Description: helper routines to access native code from Java The package presents a solution completely written in Java to access @@ -30,10 +30,11 @@ Description: helper routines to access native code from Java basic native binding provided by any third party (currently jna). Package: libisnativec-java-doc +Architecture: all Section: doc -Depends: ${java:Depends}, ${misc:Depends} +Depends: ${java:Depends}, + ${misc:Depends} Recommends: ${java:Recommends} -Architecture: all Description: Javadoc API description for isNativeC Autogenerated from the Java source code, this package offers the HTML files describing the library for programmers. diff --git a/debian/copyright b/debian/copyright index be87cd5..56760c0 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,40 +1,34 @@ -This work was packaged for Debian by: - - Steffen Moeller <moeller@debian.org> on Mon, 18 Jan 2010 00:29:38 +0100 - -It was downloaded from http://opensource.intarsys.de/home/en/index.php?n=IsNativeC.Download - -Upstream Authors: - - Bernd Wild - Michael Traut - Karl Kagermeier - - the three are leading the company intarsys together. Explicit - authorships are not specified. - -Copyright: - - Copyright (c) 2008, intarsys consulting GmbH - intarsys@intarsys.de - -License: - - +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: isNative +Source: https://sourceforge.net/projects/jpodrenderer/files/dependencies/ +Files-Excluded: */*.jar + */*.zip + */javadoc/* + */3rd_party_licenses + +Files: * +Copyright: 2008, intarsys consulting GmbH +License: BSD-3-clause + +Files: debian/* +Copyright: 2010 Steffen Möller <moeller@debian.org> +License: BSD-3-clause + +License: BSD-3-clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + . - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + . - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + . - Neither the name of intarsys nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -46,10 +40,3 @@ License: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -The Debian packaging is: - - Copyright (C) 2010 Steffen Moeller <moeller@debian.org> - -and distributed under the same license. diff --git a/debian/orig-tar.sh b/debian/orig-tar.sh deleted file mode 100755 index 47245f4..0000000 --- a/debian/orig-tar.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -e - -ZIP=$3 -TAR=../libisnativec-java_$2.orig.tar.gz -DIR=libisnativec-java-$2 - -unzip $ZIP -mv distribution $DIR -tar -c -z -f $TAR --exclude '*.jar' --exclude '*.zip' --exclude '*/javadoc/*' $DIR -rm -rf $DIR $ZIP - -# move to directory 'tarballs' -if [ -r .svn/deb-layout ]; then - . .svn/deb-layout - mv $TAR $origDir - echo "moved $TAR to $origDir" -fi - diff --git a/debian/patches/fix_ftbfs.patch b/debian/patches/fix_ftbfs.patch index 6b4bc54..cf35abf 100644 --- a/debian/patches/fix_ftbfs.patch +++ b/debian/patches/fix_ftbfs.patch @@ -12,20 +12,20 @@ Forwarded: no --- ---- libisnativec-java-5.3.20100629+fix.orig/src/de/intarsys/nativec/jna/JnaNativeHandle.java -+++ libisnativec-java-5.3.20100629+fix/src/de/intarsys/nativec/jna/JnaNativeHandle.java -@@ -126,7 +126,7 @@ public class JnaNativeHandle implements - }
+--- a/src/de/intarsys/nativec/jna/JnaNativeHandle.java ++++ b/src/de/intarsys/nativec/jna/JnaNativeHandle.java +@@ -140,7 +140,7 @@ public class JnaNativeHandle implements + @Override
public String getWideString(int index) {
- return getPointer().getString(index, true);
+ return getPointer().getWideString(index);
}
@Override
-@@ -181,7 +181,7 @@ public class JnaNativeHandle implements - }
+@@ -206,7 +206,7 @@ public class JnaNativeHandle implements + @Override
public void setWideString(int index, String value) {
- getPointer().setString(index, value, true);
+ getPointer().setWideString(index, value);
diff --git a/debian/patches/series b/debian/patches/series index 72476e7..1adadf1 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,2 +1,2 @@ -01-java9-compatibility.patch +# 01-java9-compatibility.patch fix_ftbfs.patch diff --git a/debian/watch b/debian/watch index 0446620..dbff55c 100644 --- a/debian/watch +++ b/debian/watch @@ -1,3 +1,4 @@ -version=3 +version=4 -https://sf.net/jpodrenderer/isNative\.(.*)\.zip debian debian/orig-tar.sh +opts="repacksuffix=+dfsg,dversionmangle=auto" \ + https://sf.net/jpodrenderer/isNative\.(.*)\.zip diff --git a/doc/3rd_party_licenses/jna_license.txt b/doc/3rd_party_licenses/jna_license.txt deleted file mode 100644 index fa153a0..0000000 --- a/doc/3rd_party_licenses/jna_license.txt +++ /dev/null @@ -1,5 +0,0 @@ -This program uses jna (https://jna.dev.java.net/).
-
-jna is governed by the LGPL license, available in this directory.
-
-jna source code is available at https://jna.dev.java.net/.
\ No newline at end of file diff --git a/doc/3rd_party_licenses/lgpl-2.1.txt b/doc/3rd_party_licenses/lgpl-2.1.txt deleted file mode 100644 index 53afb04..0000000 --- a/doc/3rd_party_licenses/lgpl-2.1.txt +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE
- Version 2.1, February 1999
-
- Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-[This is the first released version of the Lesser GPL. It also counts
- as the successor of the GNU Library Public License, version 2, hence
- the version number 2.1.]
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-Licenses are intended to guarantee your freedom to share and change
-free software--to make sure the software is free for all its users.
-
- This license, the Lesser General Public License, applies to some
-specially designated software packages--typically libraries--of the
-Free Software Foundation and other authors who decide to use it. You
-can use it too, but we suggest you first think carefully about whether
-this license or the ordinary General Public License is the better
-strategy to use in any particular case, based on the explanations below.
-
- When we speak of free software, we are referring to freedom of use,
-not price. Our General Public Licenses are designed to make sure that
-you have the freedom to distribute copies of free software (and charge
-for this service if you wish); that you receive source code or can get
-it if you want it; that you can change the software and use pieces of
-it in new free programs; and that you are informed that you can do
-these things.
-
- To protect your rights, we need to make restrictions that forbid
-distributors to deny you these rights or to ask you to surrender these
-rights. These restrictions translate to certain responsibilities for
-you if you distribute copies of the library or if you modify it.
-
- For example, if you distribute copies of the library, whether gratis
-or for a fee, you must give the recipients all the rights that we gave
-you. You must make sure that they, too, receive or can get the source
-code. If you link other code with the library, you must provide
-complete object files to the recipients, so that they can relink them
-with the library after making changes to the library and recompiling
-it. And you must show them these terms so they know their rights.
-
- We protect your rights with a two-step method: (1) we copyright the
-library, and (2) we offer you this license, which gives you legal
-permission to copy, distribute and/or modify the library.
-
- To protect each distributor, we want to make it very clear that
-there is no warranty for the free library. Also, if the library is
-modified by someone else and passed on, the recipients should know
-that what they have is not the original version, so that the original
-author's reputation will not be affected by problems that might be
-introduced by others.
-
- Finally, software patents pose a constant threat to the existence of
-any free program. We wish to make sure that a company cannot
-effectively restrict the users of a free program by obtaining a
-restrictive license from a patent holder. Therefore, we insist that
-any patent license obtained for a version of the library must be
-consistent with the full freedom of use specified in this license.
-
- Most GNU software, including some libraries, is covered by the
-ordinary GNU General Public License. This license, the GNU Lesser
-General Public License, applies to certain designated libraries, and
-is quite different from the ordinary General Public License. We use
-this license for certain libraries in order to permit linking those
-libraries into non-free programs.
-
- When a program is linked with a library, whether statically or using
-a shared library, the combination of the two is legally speaking a
-combined work, a derivative of the original library. The ordinary
-General Public License therefore permits such linking only if the
-entire combination fits its criteria of freedom. The Lesser General
-Public License permits more lax criteria for linking other code with
-the library.
-
- We call this license the "Lesser" General Public License because it
-does Less to protect the user's freedom than the ordinary General
-Public License. It also provides other free software developers Less
-of an advantage over competing non-free programs. These disadvantages
-are the reason we use the ordinary General Public License for many
-libraries. However, the Lesser license provides advantages in certain
-special circumstances.
-
- For example, on rare occasions, there may be a special need to
-encourage the widest possible use of a certain library, so that it becomes
-a de-facto standard. To achieve this, non-free programs must be
-allowed to use the library. A more frequent case is that a free
-library does the same job as widely used non-free libraries. In this
-case, there is little to gain by limiting the free library to free
-software only, so we use the Lesser General Public License.
-
- In other cases, permission to use a particular library in non-free
-programs enables a greater number of people to use a large body of
-free software. For example, permission to use the GNU C Library in
-non-free programs enables many more people to use the whole GNU
-operating system, as well as its variant, the GNU/Linux operating
-system.
-
- Although the Lesser General Public License is Less protective of the
-users' freedom, it does ensure that the user of a program that is
-linked with the Library has the freedom and the wherewithal to run
-that program using a modified version of the Library.
-
- The precise terms and conditions for copying, distribution and
-modification follow. Pay close attention to the difference between a
-"work based on the library" and a "work that uses the library". The
-former contains code derived from the library, whereas the latter must
-be combined with the library in order to run.
-
- GNU LESSER GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License Agreement applies to any software library or other
-program which contains a notice placed by the copyright holder or
-other authorized party saying it may be distributed under the terms of
-this Lesser General Public License (also called "this License").
-Each licensee is addressed as "you".
-
- A "library" means a collection of software functions and/or data
-prepared so as to be conveniently linked with application programs
-(which use some of those functions and data) to form executables.
-
- The "Library", below, refers to any such software library or work
-which has been distributed under these terms. A "work based on the
-Library" means either the Library or any derivative work under
-copyright law: that is to say, a work containing the Library or a
-portion of it, either verbatim or with modifications and/or translated
-straightforwardly into another language. (Hereinafter, translation is
-included without limitation in the term "modification".)
-
- "Source code" for a work means the preferred form of the work for
-making modifications to it. For a library, complete source code means
-all the source code for all modules it contains, plus any associated
-interface definition files, plus the scripts used to control compilation
-and installation of the library.
-
- Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running a program using the Library is not restricted, and output from
-such a program is covered only if its contents constitute a work based
-on the Library (independent of the use of the Library in a tool for
-writing it). Whether that is true depends on what the Library does
-and what the program that uses the Library does.
-
- 1. You may copy and distribute verbatim copies of the Library's
-complete source code as you receive it, in any medium, provided that
-you conspicuously and appropriately publish on each copy an
-appropriate copyright notice and disclaimer of warranty; keep intact
-all the notices that refer to this License and to the absence of any
-warranty; and distribute a copy of this License along with the
-Library.
-
- You may charge a fee for the physical act of transferring a copy,
-and you may at your option offer warranty protection in exchange for a
-fee.
-
- 2. You may modify your copy or copies of the Library or any portion
-of it, thus forming a work based on the Library, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) The modified work must itself be a software library.
-
- b) You must cause the files modified to carry prominent notices
- stating that you changed the files and the date of any change.
-
- c) You must cause the whole of the work to be licensed at no
- charge to all third parties under the terms of this License.
-
- d) If a facility in the modified Library refers to a function or a
- table of data to be supplied by an application program that uses
- the facility, other than as an argument passed when the facility
- is invoked, then you must make a good faith effort to ensure that,
- in the event an application does not supply such function or
- table, the facility still operates, and performs whatever part of
- its purpose remains meaningful.
-
- (For example, a function in a library to compute square roots has
- a purpose that is entirely well-defined independent of the
- application. Therefore, Subsection 2d requires that any
- application-supplied function or table used by this function must
- be optional: if the application does not supply it, the square
- root function must still compute square roots.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Library,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Library, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote
-it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Library.
-
-In addition, mere aggregation of another work not based on the Library
-with the Library (or with a work based on the Library) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may opt to apply the terms of the ordinary GNU General Public
-License instead of this License to a given copy of the Library. To do
-this, you must alter all the notices that refer to this License, so
-that they refer to the ordinary GNU General Public License, version 2,
-instead of to this License. (If a newer version than version 2 of the
-ordinary GNU General Public License has appeared, then you can specify
-that version instead if you wish.) Do not make any other change in
-these notices.
-
- Once this change is made in a given copy, it is irreversible for
-that copy, so the ordinary GNU General Public License applies to all
-subsequent copies and derivative works made from that copy.
-
- This option is useful when you wish to copy part of the code of
-the Library into a program that is not a library.
-
- 4. You may copy and distribute the Library (or a portion or
-derivative of it, under Section 2) in object code or executable form
-under the terms of Sections 1 and 2 above provided that you accompany
-it with the complete corresponding machine-readable source code, which
-must be distributed under the terms of Sections 1 and 2 above on a
-medium customarily used for software interchange.
-
- If distribution of object code is made by offering access to copy
-from a designated place, then offering equivalent access to copy the
-source code from the same place satisfies the requirement to
-distribute the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 5. A program that contains no derivative of any portion of the
-Library, but is designed to work with the Library by being compiled or
-linked with it, is called a "work that uses the Library". Such a
-work, in isolation, is not a derivative work of the Library, and
-therefore falls outside the scope of this License.
-
- However, linking a "work that uses the Library" with the Library
-creates an executable that is a derivative of the Library (because it
-contains portions of the Library), rather than a "work that uses the
-library". The executable is therefore covered by this License.
-Section 6 states terms for distribution of such executables.
-
- When a "work that uses the Library" uses material from a header file
-that is part of the Library, the object code for the work may be a
-derivative work of the Library even though the source code is not.
-Whether this is true is especially significant if the work can be
-linked without the Library, or if the work is itself a library. The
-threshold for this to be true is not precisely defined by law.
-
- If such an object file uses only numerical parameters, data
-structure layouts and accessors, and small macros and small inline
-functions (ten lines or less in length), then the use of the object
-file is unrestricted, regardless of whether it is legally a derivative
-work. (Executables containing this object code plus portions of the
-Library will still fall under Section 6.)
-
- Otherwise, if the work is a derivative of the Library, you may
-distribute the object code for the work under the terms of Section 6.
-Any executables containing that work also fall under Section 6,
-whether or not they are linked directly with the Library itself.
-
- 6. As an exception to the Sections above, you may also combine or
-link a "work that uses the Library" with the Library to produce a
-work containing portions of the Library, and distribute that work
-under terms of your choice, provided that the terms permit
-modification of the work for the customer's own use and reverse
-engineering for debugging such modifications.
-
- You must give prominent notice with each copy of the work that the
-Library is used in it and that the Library and its use are covered by
-this License. You must supply a copy of this License. If the work
-during execution displays copyright notices, you must include the
-copyright notice for the Library among them, as well as a reference
-directing the user to the copy of this License. Also, you must do one
-of these things:
-
- a) Accompany the work with the complete corresponding
- machine-readable source code for the Library including whatever
- changes were used in the work (which must be distributed under
- Sections 1 and 2 above); and, if the work is an executable linked
- with the Library, with the complete machine-readable "work that
- uses the Library", as object code and/or source code, so that the
- user can modify the Library and then relink to produce a modified
- executable containing the modified Library. (It is understood
- that the user who changes the contents of definitions files in the
- Library will not necessarily be able to recompile the application
- to use the modified definitions.)
-
- b) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (1) uses at run time a
- copy of the library already present on the user's computer system,
- rather than copying library functions into the executable, and (2)
- will operate properly with a modified version of the library, if
- the user installs one, as long as the modified version is
- interface-compatible with the version that the work was made with.
-
- c) Accompany the work with a written offer, valid for at
- least three years, to give the same user the materials
- specified in Subsection 6a, above, for a charge no more
- than the cost of performing this distribution.
-
- d) If distribution of the work is made by offering access to copy
- from a designated place, offer equivalent access to copy the above
- specified materials from the same place.
-
- e) Verify that the user has already received a copy of these
- materials or that you have already sent this user a copy.
-
- For an executable, the required form of the "work that uses the
-Library" must include any data and utility programs needed for
-reproducing the executable from it. However, as a special exception,
-the materials to be distributed need not include anything that is
-normally distributed (in either source or binary form) with the major
-components (compiler, kernel, and so on) of the operating system on
-which the executable runs, unless that component itself accompanies
-the executable.
-
- It may happen that this requirement contradicts the license
-restrictions of other proprietary libraries that do not normally
-accompany the operating system. Such a contradiction means you cannot
-use both them and the Library together in an executable that you
-distribute.
-
- 7. You may place library facilities that are a work based on the
-Library side-by-side in a single library together with other library
-facilities not covered by this License, and distribute such a combined
-library, provided that the separate distribution of the work based on
-the Library and of the other library facilities is otherwise
-permitted, and provided that you do these two things:
-
- a) Accompany the combined library with a copy of the same work
- based on the Library, uncombined with any other library
- facilities. This must be distributed under the terms of the
- Sections above.
-
- b) Give prominent notice with the combined library of the fact
- that part of it is a work based on the Library, and explaining
- where to find the accompanying uncombined form of the same work.
-
- 8. You may not copy, modify, sublicense, link with, or distribute
-the Library except as expressly provided under this License. Any
-attempt otherwise to copy, modify, sublicense, link with, or
-distribute the Library is void, and will automatically terminate your
-rights under this License. However, parties who have received copies,
-or rights, from you under this License will not have their licenses
-terminated so long as such parties remain in full compliance.
-
- 9. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Library or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Library (or any work based on the
-Library), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Library or works based on it.
-
- 10. Each time you redistribute the Library (or any work based on the
-Library), the recipient automatically receives a license from the
-original licensor to copy, distribute, link with or modify the Library
-subject to these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties with
-this License.
-
- 11. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Library at all. For example, if a patent
-license would not permit royalty-free redistribution of the Library by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Library.
-
-If any portion of this section is held invalid or unenforceable under any
-particular circumstance, the balance of the section is intended to apply,
-and the section as a whole is intended to apply in other circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 12. If the distribution and/or use of the Library is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Library under this License may add
-an explicit geographical distribution limitation excluding those countries,
-so that distribution is permitted only in or among countries not thus
-excluded. In such case, this License incorporates the limitation as if
-written in the body of this License.
-
- 13. The Free Software Foundation may publish revised and/or new
-versions of the Lesser General Public License from time to time.
-Such new versions will be similar in spirit to the present version,
-but may differ in detail to address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Library
-specifies a version number of this License which applies to it and
-"any later version", you have the option of following the terms and
-conditions either of that version or of any later version published by
-the Free Software Foundation. If the Library does not specify a
-license version number, you may choose any version ever published by
-the Free Software Foundation.
-
- 14. If you wish to incorporate parts of the Library into other free
-programs whose distribution conditions are incompatible with these,
-write to the author to ask for permission. For software which is
-copyrighted by the Free Software Foundation, write to the Free
-Software Foundation; we sometimes make exceptions for this. Our
-decision will be guided by the two goals of preserving the free status
-of all derivatives of our free software and of promoting the sharing
-and reuse of software generally.
-
- NO WARRANTY
-
- 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
-WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
-EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
-OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
-KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
-LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
-THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
-WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
-AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
-FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
-CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
-LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
-RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
-FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
-SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Libraries
-
- If you develop a new library, and you want it to be of the greatest
-possible use to the public, we recommend making it free software that
-everyone can redistribute and change. You can do so by permitting
-redistribution under these terms (or, alternatively, under the terms of the
-ordinary General Public License).
-
- To apply these terms, attach the following notices to the library. It is
-safest to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least the
-"copyright" line and a pointer to where the full notice is found.
-
- <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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-Also add information on how to contact you by electronic and paper mail.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the library, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the
- library `Frob' (a library for tweaking knobs) written by James Random Hacker.
-
- <signature of Ty Coon>, 1 April 1990
- Ty Coon, President of Vice
-
-That's all there is to it!
-
-
diff --git a/resource/META-INF/services/de.intarsys.nativec.api.INativeInterface b/resource/META-INF/services/de.intarsys.nativec.api.INativeInterface index ba31608..83a5ac9 100644 --- a/resource/META-INF/services/de.intarsys.nativec.api.INativeInterface +++ b/resource/META-INF/services/de.intarsys.nativec.api.INativeInterface @@ -1 +1 @@ -de.intarsys.nativec.jna.JnaNativeInterface # The JNA based native interface implementation
\ No newline at end of file +de.intarsys.nativec.jna.JnaNativeInterface
\ No newline at end of file diff --git a/src/com/sun/jna/FastMemory.java b/src/com/sun/jna/FastMemory.java deleted file mode 100644 index 17657ed..0000000 --- a/src/com/sun/jna/FastMemory.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.sun.jna;
-
-public class FastMemory extends Pointer {
-
- protected long size; // Size of the malloc'ed space
-
- public FastMemory() {
- super();
- }
-
- public FastMemory(int size) {
- super(Memory.malloc(size));
- }
-
- @Override
- protected void finalize() {
- Memory.free(peer);
- peer = 0;
- }
-
-}
diff --git a/src/com/sun/jna/JNATools.java b/src/com/sun/jna/JNATools.java deleted file mode 100644 index 61f4a8d..0000000 --- a/src/com/sun/jna/JNATools.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.sun.jna;
-
-public class JNATools {
-
- public static long getPeer(Pointer p) {
- if (p == null) {
- return 0;
- }
- return p.peer;
- }
-}
diff --git a/src/de/intarsys/nativec/Opaque.java b/src/de/intarsys/nativec/Opaque.java new file mode 100644 index 0000000..61bd5f1 --- /dev/null +++ b/src/de/intarsys/nativec/Opaque.java @@ -0,0 +1,11 @@ +package de.intarsys.nativec;
+
+import de.intarsys.nativec.type.NativeVoid;
+
+/** A @{link PseudoObject} where the wrapped entity is a handle */
+public class Opaque extends PseudoObject<NativeVoid> {
+
+ public Opaque(NativeVoid nativeObject) {
+ super(nativeObject);
+ }
+}
diff --git a/src/de/intarsys/nativec/PseudoObject.java b/src/de/intarsys/nativec/PseudoObject.java new file mode 100644 index 0000000..4d0b0ed --- /dev/null +++ b/src/de/intarsys/nativec/PseudoObject.java @@ -0,0 +1,22 @@ +package de.intarsys.nativec;
+
+import de.intarsys.nativec.type.INativeObject;
+
+/**
+ * A wrapper object for a handle or struct. Many libraries have groups of
+ * functions that take a handle or struct as first argument and work on that
+ * "object". We can treat the latter as real objects by wrapping them in an
+ * instance of a subclass of this class.
+ */
+public class PseudoObject<T extends INativeObject> {
+
+ private T nativeObject;
+
+ public PseudoObject(T pNativeObject) {
+ nativeObject = pNativeObject;
+ }
+
+ public T getNativeObject() {
+ return nativeObject;
+ }
+}
diff --git a/src/de/intarsys/nativec/api/ICallback.java b/src/de/intarsys/nativec/api/ICallback.java index 841c506..0c4e81e 100644 --- a/src/de/intarsys/nativec/api/ICallback.java +++ b/src/de/intarsys/nativec/api/ICallback.java @@ -31,10 +31,11 @@ package de.intarsys.nativec.api; public interface ICallback {
+ public Object getCallingConvention();
+
public Class<?>[] getParameterTypes();
public Class<?> getReturnType();
public Object invoke(Object[] objects);
-
}
diff --git a/src/de/intarsys/nativec/api/INativeFunction.java b/src/de/intarsys/nativec/api/INativeFunction.java index 085275d..cf0bb7e 100644 --- a/src/de/intarsys/nativec/api/INativeFunction.java +++ b/src/de/intarsys/nativec/api/INativeFunction.java @@ -34,6 +34,9 @@ package de.intarsys.nativec.api; */
public interface INativeFunction {
+ public static final Object CallingConventionCdecl = new Object();
+ public static final Object CallingConventionStdcall = new Object();
+
/**
* Invoke the native function.
*
diff --git a/src/de/intarsys/nativec/api/INativeHandle.java b/src/de/intarsys/nativec/api/INativeHandle.java index 7dc3ecd..fa487d0 100644 --- a/src/de/intarsys/nativec/api/INativeHandle.java +++ b/src/de/intarsys/nativec/api/INativeHandle.java @@ -219,7 +219,7 @@ public interface INativeHandle { *
* @param index
* The byte offset from the start of the memory chunk
- * @param value
+ * @param valueHandle
* The value to write.
*/
public void setNativeHandle(int index, INativeHandle valueHandle);
diff --git a/src/de/intarsys/nativec/api/INativeInterface.java b/src/de/intarsys/nativec/api/INativeInterface.java index 8a78a44..f39c54d 100644 --- a/src/de/intarsys/nativec/api/INativeInterface.java +++ b/src/de/intarsys/nativec/api/INativeInterface.java @@ -29,7 +29,6 @@ */
package de.intarsys.nativec.api;
-
/**
* The abstraction of a generic interface to c native code.
*/
@@ -65,6 +64,8 @@ public interface INativeInterface { */
public INativeFunction createFunction(long address);
+ public INativeFunction createFunction(long address, Object callingConvention);
+
/**
* Create a void {@link INativeHandle} to a memory address.
* <p>
@@ -86,6 +87,18 @@ public interface INativeInterface { public INativeLibrary createLibrary(String name);
/**
+ * Load a new {@link INativeLibrary}.
+ *
+ * @param name
+ * The name of the library to load.
+ * @param callingConvention
+ * The calling convention to use as default for functions in this
+ * library.
+ * @return The new {@link INativeLibrary}
+ */
+ public INativeLibrary createLibrary(String name, Object callingConvention);
+
+ /**
* The platform long size.
*
* @return The platform long size.
diff --git a/src/de/intarsys/nativec/api/IValueHolder.java b/src/de/intarsys/nativec/api/IValueHolder.java new file mode 100644 index 0000000..ed1b461 --- /dev/null +++ b/src/de/intarsys/nativec/api/IValueHolder.java @@ -0,0 +1,51 @@ +/*
+ * Copyright (c) 2007, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.api;
+
+/**
+ * Generic interface for objects holding references to others.
+ */
+public interface IValueHolder<T> {
+
+ /**
+ * Dereference the {@link IValueHolder}.
+ *
+ * @return The referenced object.
+ */
+ public T get();
+
+ /**
+ * Assign a new value.
+ *
+ * @param newValue
+ * @return The previous value (optional)
+ */
+ public T set(T newValue);
+}
diff --git a/src/de/intarsys/nativec/api/NativeInterface.java b/src/de/intarsys/nativec/api/NativeInterface.java index aa1e84d..f5e3087 100644 --- a/src/de/intarsys/nativec/api/NativeInterface.java +++ b/src/de/intarsys/nativec/api/NativeInterface.java @@ -30,23 +30,21 @@ package de.intarsys.nativec.api;
import java.util.Iterator;
-
-import sun.misc.Service;
+import java.util.ServiceLoader;
/**
* Access the VM singleton for {@link INativeInterface}.
* <p>
* To make this work, just do one of the following:
* <ul>
- * <li> set the class name of your implementation with {@link NativeInterface}
- * </li>
- * <li> set a {@link INativeInterface} of your choice in {@link NativeInterface}.
+ * <li>set the class name of your implementation with {@link NativeInterface}</li>
+ * <li>set a {@link INativeInterface} of your choice in {@link NativeInterface}.
* </li>
- * <li> set system property "de.intarsys.nativec.api.INativeInterface" to the
- * class name of your implementation. </li>
- * <li> include a service provider file
+ * <li>set system property "de.intarsys.nativec.api.INativeInterface" to the
+ * class name of your implementation.</li>
+ * <li>include a service provider file
* "de.intarsys.nativec.api.INativeInterface" in your deployment with the class
- * name of your implementation. </li>
+ * name of your implementation.</li>
* </ul>
*
*/
@@ -77,14 +75,12 @@ public class NativeInterface { }
static protected INativeInterface findNativeInterface() {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if (loader == null) {
- loader = NativeInterface.class.getClassLoader();
- }
- Iterator ps = Service.providers(INativeInterface.class, loader);
+ ServiceLoader<INativeInterface> loader = ServiceLoader
+ .load(INativeInterface.class);
+ Iterator<INativeInterface> ps = loader.iterator();
if (ps.hasNext()) {
try {
- return (INativeInterface) ps.next();
+ return ps.next();
} catch (Throwable e) {
// ignore and try on
}
diff --git a/src/de/intarsys/nativec/api/NativeTools.java b/src/de/intarsys/nativec/api/NativeTools.java index 8cd6ba9..cebe985 100644 --- a/src/de/intarsys/nativec/api/NativeTools.java +++ b/src/de/intarsys/nativec/api/NativeTools.java @@ -36,8 +36,6 @@ import de.intarsys.nativec.type.NativeBuffer; import de.intarsys.nativec.type.NativeBufferType;
import de.intarsys.nativec.type.NativeInt;
import de.intarsys.nativec.type.NativeLong;
-import de.intarsys.tools.valueholder.IValueHolder;
-import de.intarsys.tools.valueholder.ObjectValueHolder;
/**
* Tool class for for dealing with the native framework.
@@ -124,19 +122,6 @@ public class NativeTools { }
}
- public static void toNativeCLong(long ptr, IValueHolder<Number> value) {
- toNativeCLong(ptr, value.get().longValue());
- }
-
- public static void toNativeCLong(long ptr, long value) {
- INativeHandle handle;
- NativeLong nativeValue;
-
- handle = NativeInterface.get().createHandle(ptr);
- nativeValue = (NativeLong) NativeLong.META.createNative(handle);
- nativeValue.setValue(value);
- }
-
public static void toNativeCLong(long ptr, int[] value) {
if (value != null) {
INativeHandle handle;
@@ -152,6 +137,19 @@ public class NativeTools { }
}
+ public static void toNativeCLong(long ptr, IValueHolder<Number> value) {
+ toNativeCLong(ptr, value.get().longValue());
+ }
+
+ public static void toNativeCLong(long ptr, long value) {
+ INativeHandle handle;
+ NativeLong nativeValue;
+
+ handle = NativeInterface.get().createHandle(ptr);
+ nativeValue = (NativeLong) NativeLong.META.createNative(handle);
+ nativeValue.setValue(value);
+ }
+
public static void toNativeCLong(long ptr, long[] value) {
if (value != null) {
INativeHandle handle;
diff --git a/src/de/intarsys/nativec/api/ObjectValueHolder.java b/src/de/intarsys/nativec/api/ObjectValueHolder.java new file mode 100644 index 0000000..a0c7973 --- /dev/null +++ b/src/de/intarsys/nativec/api/ObjectValueHolder.java @@ -0,0 +1,58 @@ +/*
+ * Copyright (c) 2007, intarsys consulting GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.intarsys.nativec.api;
+
+/**
+ * A object holding nothing but a value
+ *
+ * This can easily be plugged in for a {@link IValueHolder}.
+ */
+public class ObjectValueHolder<T> implements IValueHolder<T> {
+
+ private T value;
+
+ public ObjectValueHolder(T value) {
+ super();
+ this.value = value;
+ }
+
+ @Override
+ public T get() {
+ return value;
+ }
+
+ @Override
+ public T set(T newValue) {
+ T oldValue = value;
+ value = newValue;
+ return oldValue;
+ }
+
+}
diff --git a/src/de/intarsys/nativec/jna/JNATools.java b/src/de/intarsys/nativec/jna/JNATools.java new file mode 100644 index 0000000..cad11ea --- /dev/null +++ b/src/de/intarsys/nativec/jna/JNATools.java @@ -0,0 +1,14 @@ +package de.intarsys.nativec.jna;
+
+import com.sun.jna.Pointer;
+
+public class JNATools {
+
+ public static long getPeer(Pointer p) {
+ if (p == null) {
+ return 0;
+ }
+ return Pointer.nativeValue(p);
+ }
+
+}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeCallback.java b/src/de/intarsys/nativec/jna/JnaNativeCallback.java index af5b7c5..f946dd2 100644 --- a/src/de/intarsys/nativec/jna/JnaNativeCallback.java +++ b/src/de/intarsys/nativec/jna/JnaNativeCallback.java @@ -43,7 +43,8 @@ import de.intarsys.nativec.type.INativeType; import de.intarsys.nativec.type.NativeObject;
import de.intarsys.nativec.type.NativeType;
-public class JnaNativeCallback implements INativeCallback, CallbackProxy {
+abstract public class JnaNativeCallback implements INativeCallback,
+ CallbackProxy {
public static Class<?> translateType(Class<?> type) {
// TODO implement more elegant type translation
@@ -75,8 +76,8 @@ public class JnaNativeCallback implements INativeCallback, CallbackProxy { WString wstring = (WString) args[index];
object = new CWideString(wstring.toString());
} else if (CLong.class.isAssignableFrom(parameterType)) {
- NativeLong nativeLong = (NativeLong) args[index];
- object = new CLong(nativeLong.longValue());
+ Number nativeNumber = (Number) args[index];
+ object = new CLong(nativeNumber.longValue());
} else if (NativeObject.class.isAssignableFrom(parameterType)) {
Pointer pointer = (Pointer) args[index];
if (pointer == null) {
diff --git a/src/de/intarsys/nativec/jna/JnaNativeCallbackAlt.java b/src/de/intarsys/nativec/jna/JnaNativeCallbackAlt.java new file mode 100644 index 0000000..74be61d --- /dev/null +++ b/src/de/intarsys/nativec/jna/JnaNativeCallbackAlt.java @@ -0,0 +1,14 @@ +package de.intarsys.nativec.jna;
+
+import com.sun.jna.AltCallingConvention;
+
+import de.intarsys.nativec.api.ICallback;
+
+public class JnaNativeCallbackAlt extends JnaNativeCallback implements
+ AltCallingConvention {
+
+ public JnaNativeCallbackAlt(ICallback pCallback) {
+ super(pCallback);
+ }
+
+}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeCallbackStd.java b/src/de/intarsys/nativec/jna/JnaNativeCallbackStd.java new file mode 100644 index 0000000..1abea8a --- /dev/null +++ b/src/de/intarsys/nativec/jna/JnaNativeCallbackStd.java @@ -0,0 +1,11 @@ +package de.intarsys.nativec.jna;
+
+import de.intarsys.nativec.api.ICallback;
+
+public class JnaNativeCallbackStd extends JnaNativeCallback {
+
+ public JnaNativeCallbackStd(ICallback pCallback) {
+ super(pCallback);
+ }
+
+}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeHandle.java b/src/de/intarsys/nativec/jna/JnaNativeHandle.java index 75680ee..fa7f9b3 100644 --- a/src/de/intarsys/nativec/jna/JnaNativeHandle.java +++ b/src/de/intarsys/nativec/jna/JnaNativeHandle.java @@ -29,7 +29,6 @@ */
package de.intarsys.nativec.jna;
-import com.sun.jna.JNATools;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
@@ -64,18 +63,22 @@ public class JnaNativeHandle implements INativeHandle { && size == otherHandle.getSize();
}
+ @Override
public long getAddress() {
return JNATools.getPeer(pointer);
}
+ @Override
public byte getByte(int index) {
return pointer.getByte(index);
}
+ @Override
public byte[] getByteArray(int index, int count) {
return pointer.getByteArray(index, count);
}
+ @Override
public long getCLong(int index) {
if (Native.LONG_SIZE == 4) {
return pointer.getInt(index);
@@ -83,16 +86,23 @@ public class JnaNativeHandle implements INativeHandle { return pointer.getLong(index);
}
+ @Override
public int getInt(int index) {
return pointer.getInt(index);
}
+ @Override
public long getLong(int index) {
return pointer.getLong(index);
}
+ @Override
public INativeHandle getNativeHandle(int index) {
Pointer tempPointer = pointer.getPointer(index);
+ if (tempPointer == null) {
+ // TODO can we reuse the existing "NULL" object?
+ return new JnaNativeHandle(0);
+ }
return new JnaNativeHandle(tempPointer);
}
@@ -100,14 +110,17 @@ public class JnaNativeHandle implements INativeHandle { return pointer;
}
+ @Override
public short getShort(int index) {
return pointer.getShort(index);
}
+ @Override
public int getSize() {
return size;
}
+ @Override
public String getString(int index) {
// if (buffer == null) {
// return null;
@@ -125,6 +138,7 @@ public class JnaNativeHandle implements INativeHandle { return getPointer().getString(index);
}
+ @Override
public String getWideString(int index) {
return getPointer().getString(index, true);
}
@@ -134,19 +148,23 @@ public class JnaNativeHandle implements INativeHandle { return pointer.hashCode();
}
+ @Override
public INativeHandle offset(int offset) {
return new JnaNativeHandle(this, offset);
}
+ @Override
public void setByte(int index, byte value) {
pointer.setByte(index, value);
}
+ @Override
public void setByteArray(int index, byte[] value, int valueOffset,
int valueCount) {
pointer.write(index, value, valueOffset, valueCount);
}
+ @Override
public void setCLong(int index, long value) {
if (Native.LONG_SIZE == 4) {
pointer.setInt(index, (int) value);
@@ -155,31 +173,38 @@ public class JnaNativeHandle implements INativeHandle { pointer.setLong(index, value);
}
+ @Override
public void setInt(int index, int value) {
pointer.setInt(index, value);
}
+ @Override
public void setLong(int index, long value) {
pointer.setLong(index, value);
}
+ @Override
public void setNativeHandle(int index, INativeHandle handle) {
pointer.setPointer(index, new Pointer(handle.getAddress()));
}
+ @Override
public void setShort(int index, short value) {
pointer.setShort(index, value);
}
+ @Override
public void setSize(int pSize) {
this.size = pSize;
}
+ @Override
public void setString(int index, String value) {
// // todo encoding
getPointer().setString(index, value);
}
+ @Override
public void setWideString(int index, String value) {
getPointer().setString(index, value, true);
}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeInterface.java b/src/de/intarsys/nativec/jna/JnaNativeInterface.java index 3f5d4b1..31035dc 100644 --- a/src/de/intarsys/nativec/jna/JnaNativeInterface.java +++ b/src/de/intarsys/nativec/jna/JnaNativeInterface.java @@ -29,13 +29,18 @@ */
package de.intarsys.nativec.jna;
+import java.lang.reflect.Constructor;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
-import com.sun.jna.FastMemory;
import com.sun.jna.Function;
+import com.sun.jna.Library;
+import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
+import com.sun.org.apache.xalan.internal.xsltc.compiler.util.InternalError;
import de.intarsys.nativec.api.ICallback;
import de.intarsys.nativec.api.INativeCallback;
@@ -55,6 +60,8 @@ import de.intarsys.nativec.api.INativeLibrary; */
public class JnaNativeInterface implements INativeInterface {
+ private static Constructor<? extends Pointer> pointerFactory;
+
static {
/*
* Ugly hack - multithreaded loading caused a deadlock here as
@@ -69,13 +76,29 @@ public class JnaNativeInterface implements INativeInterface { try {
Class.forName("com.sun.jna.Native", true, loader);
} catch (ClassNotFoundException e) {
- // will fail later anyway
+ throw new InternalError("can not load JNA");
+ }
+ }
+
+ /*
+ * Another hack. We *can* use a stripped down version of the Memory
+ * class if available. If not simply fallback...
+ */
+ try {
+ Class clazz = Class.forName("com.sun.jna.FastMemory", true, loader);
+ pointerFactory = clazz.getConstructor(Integer.TYPE);
+ } catch (Exception e) {
+ try {
+ pointerFactory = Memory.class.getConstructor(Long.TYPE);
+ } catch (Exception e1) {
+ throw new InternalError("can not load JNA");
}
}
}
private List<String> searchPaths = new ArrayList<String>();
+ @Override
public void addSearchPath(String path) {
if (searchPaths.contains(path)) {
return;
@@ -83,44 +106,98 @@ public class JnaNativeInterface implements INativeInterface { searchPaths.add(path);
}
+ @Override
public INativeHandle allocate(int size) {
- return new JnaNativeHandle(new FastMemory(size));
+ return new JnaNativeHandle(createMemory(size));
}
+ @Override
public INativeCallback createCallback(ICallback callback) {
- return new JnaNativeCallback(callback);
+ if (callback == null) {
+ return null;
+ }
+ if (callback.getCallingConvention() == INativeFunction.CallingConventionStdcall) {
+ return new JnaNativeCallbackAlt(callback);
+ }
+ if (callback.getCallingConvention() == INativeFunction.CallingConventionCdecl) {
+ return new JnaNativeCallbackStd(callback);
+ }
+ throw new IllegalArgumentException("illegal calling convention");
}
+ @Override
public INativeFunction createFunction(long address) {
- Pointer pointer;
- Function function;
+ return createFunction(address, INativeFunction.CallingConventionCdecl);
+ }
- pointer = new Pointer(address);
- function = Function.getFunction(pointer);
+ @Override
+ public INativeFunction createFunction(long address, Object callingConvention) {
+ int callFlags;
+ if (callingConvention == INativeFunction.CallingConventionCdecl) {
+ callFlags = Function.C_CONVENTION;
+ } else if (callingConvention == INativeFunction.CallingConventionStdcall) {
+ callFlags = Function.ALT_CONVENTION;
+ } else {
+ throw new IllegalArgumentException("illegal calling convention");
+ }
+ Pointer pointer = new Pointer(address);
+ Function function = Function.getFunction(pointer, callFlags);
return new JnaNativeFunction(function);
}
+ @Override
public INativeHandle createHandle(long address) {
return new JnaNativeHandle(address);
}
+ @Override
public INativeLibrary createLibrary(String name) {
- return new JnaNativeLibrary(this, name);
+ return createLibrary(name, INativeFunction.CallingConventionCdecl);
+ }
+
+ @Override
+ public INativeLibrary createLibrary(String name, Object callingConvention) {
+ Map<String, Object> options = new HashMap<>(2);
+ if (callingConvention == INativeFunction.CallingConventionCdecl) {
+ options.put(Library.OPTION_CALLING_CONVENTION,
+ Function.C_CONVENTION);
+ } else if (callingConvention == INativeFunction.CallingConventionStdcall) {
+ options.put(Library.OPTION_CALLING_CONVENTION,
+ Function.ALT_CONVENTION);
+ } else {
+ throw new IllegalArgumentException("illegal calling convention");
+ }
+ options.put(Library.OPTION_OPEN_FLAGS, -1);
+ return new JnaNativeLibrary(this, name, options);
+ }
+
+ protected Pointer createMemory(int size) {
+ try {
+ Pointer p = pointerFactory.newInstance(size);
+ p.clear(size);
+ return p;
+ } catch (Exception e) {
+ throw new InternalError("can not create Pointer");
+ }
}
protected List<String> getSearchPaths() {
return searchPaths;
}
+ @Override
public int longSize() {
return Native.LONG_SIZE;
}
+ @Override
public int pointerSize() {
return Native.POINTER_SIZE;
}
+ @Override
public int wideCharSize() {
return 2;
}
+
}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeLibrary.java b/src/de/intarsys/nativec/jna/JnaNativeLibrary.java index 6a0a617..628e8d6 100644 --- a/src/de/intarsys/nativec/jna/JnaNativeLibrary.java +++ b/src/de/intarsys/nativec/jna/JnaNativeLibrary.java @@ -30,6 +30,7 @@ package de.intarsys.nativec.jna;
import java.util.Iterator;
+import java.util.Map;
import com.sun.jna.Function;
import com.sun.jna.NativeLibrary;
@@ -45,7 +46,8 @@ public class JnaNativeLibrary implements INativeLibrary { final private JnaNativeInterface nativeInterface;
- public JnaNativeLibrary(JnaNativeInterface nativeInterface, String name) {
+ public JnaNativeLibrary(JnaNativeInterface nativeInterface, String name,
+ Map<String, Object> options) {
this.nativeInterface = nativeInterface;
// this is a kludge - but i can't ask for the searchpaths already
// registered
@@ -54,14 +56,16 @@ public class JnaNativeLibrary implements INativeLibrary { String path = it.next();
NativeLibrary.addSearchPath(name, path);
}
- library = NativeLibrary.getInstance(name);
+ library = NativeLibrary.getInstance(name, options);
}
+ @Override
public INativeFunction getFunction(String name) {
Function function = getLibrary().getFunction(name);
return new JnaNativeFunction(function);
}
+ @Override
public INativeHandle getGlobal(String symbolName) {
Pointer pointer = getLibrary().getGlobalVariableAddress(symbolName);
return new JnaNativeHandle(pointer);
diff --git a/src/de/intarsys/nativec/type/INativeObject.java b/src/de/intarsys/nativec/type/INativeObject.java index 89ac2cc..179ddd7 100644 --- a/src/de/intarsys/nativec/type/INativeObject.java +++ b/src/de/intarsys/nativec/type/INativeObject.java @@ -51,14 +51,14 @@ public interface INativeObject { /**
* The {@link INativeHandle} to the c memory for the object.
*
- * @return
+ * @return The {@link INativeHandle} to the c memory for the object.
*/
public INativeHandle getNativeHandle();
/**
* The {@link INativeType} for the object.
*
- * @return
+ * @return The {@link INativeType} for the object.
*/
public INativeType getNativeType();
diff --git a/src/de/intarsys/nativec/type/NativeBuffer.java b/src/de/intarsys/nativec/type/NativeBuffer.java index a4b0568..df4a01a 100644 --- a/src/de/intarsys/nativec/type/NativeBuffer.java +++ b/src/de/intarsys/nativec/type/NativeBuffer.java @@ -88,7 +88,7 @@ public class NativeBuffer extends NativeObject { /**
* The number of elements in the NativeBuffer
*
- * @return
+ * @return The number of elements in the NativeBuffer
*/
public int getSize() {
return type.getByteCount();
diff --git a/src/de/intarsys/nativec/type/NativeByte.java b/src/de/intarsys/nativec/type/NativeByte.java index e11fd45..7355720 100644 --- a/src/de/intarsys/nativec/type/NativeByte.java +++ b/src/de/intarsys/nativec/type/NativeByte.java @@ -69,40 +69,21 @@ public class NativeByte extends NativeNumber { super(handle);
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativeNumber#byteValue()
- */
@Override
public byte byteValue() {
return handle.getByte(0);
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
- */
@Override
public INativeType getNativeType() {
return META;
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativePrimitive#getValue()
- */
+ @Override
public Object getValue() {
return new Byte(byteValue());
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativeNumber#intValue()
- */
@Override
public int intValue() {
return byteValue();
@@ -117,27 +98,21 @@ public class NativeByte extends NativeNumber { handle.setByte(0, value);
}
+ @Override
public void setValue(Object value) {
setValue(((Number) value).byteValue());
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativeNumber#shortValue()
- */
@Override
public short shortValue() {
return byteValue();
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
@Override
public String toString() {
+ if (getNativeHandle() == null) {
+ return "nope - no handle"; //$NON-NLS-1$
+ }
if (getNativeHandle().getAddress() == 0) {
return "nope - null pointer"; //$NON-NLS-1$
}
diff --git a/src/de/intarsys/nativec/type/NativeFunction.java b/src/de/intarsys/nativec/type/NativeFunction.java new file mode 100644 index 0000000..b8891c5 --- /dev/null +++ b/src/de/intarsys/nativec/type/NativeFunction.java @@ -0,0 +1,47 @@ +package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeFunction;
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeInterface;
+
+public class NativeFunction extends NativeVoid {
+
+ public static class NativeFunctionType extends NativeVoidType {
+
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeFunction(handle);
+ }
+
+ }
+
+ public static final NativeFunctionType META = new NativeFunctionType();
+
+ private Object callingConvention;
+ private INativeFunction function;
+
+ protected NativeFunction(INativeHandle handle) {
+ super(handle);
+ callingConvention = INativeFunction.CallingConventionCdecl;
+ }
+
+ public Object getCallingConvention() {
+ return callingConvention;
+ }
+
+ public INativeFunction getFunction() {
+ // TODO do we want to check if handle has changed?
+ if (function == null) {
+ function = NativeInterface.get().createFunction(
+ getNativeHandle().getAddress(), callingConvention);
+ }
+ return function;
+ }
+
+ public void setCallingConvention(Object callingConvention) {
+ if(function != null) {
+ throw new IllegalStateException();
+ }
+ this.callingConvention = callingConvention;
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeInt.java b/src/de/intarsys/nativec/type/NativeInt.java index 6c15ddb..53926bd 100644 --- a/src/de/intarsys/nativec/type/NativeInt.java +++ b/src/de/intarsys/nativec/type/NativeInt.java @@ -79,6 +79,7 @@ public class NativeInt extends NativeNumber { return META;
}
+ @Override
public Object getValue() {
return new Integer(intValue());
}
@@ -97,6 +98,7 @@ public class NativeInt extends NativeNumber { handle.setInt(0, value);
}
+ @Override
public void setValue(Object value) {
setValue(((Number) value).intValue());
}
@@ -108,6 +110,9 @@ public class NativeInt extends NativeNumber { @Override
public String toString() {
+ if (getNativeHandle() == null) {
+ return "nope - no handle"; //$NON-NLS-1$
+ }
if (getNativeHandle().getAddress() == 0) {
return "nope - null pointer"; //$NON-NLS-1$
}
diff --git a/src/de/intarsys/nativec/type/NativeLong.java b/src/de/intarsys/nativec/type/NativeLong.java index 5e2fac9..a479592 100644 --- a/src/de/intarsys/nativec/type/NativeLong.java +++ b/src/de/intarsys/nativec/type/NativeLong.java @@ -79,6 +79,7 @@ public class NativeLong extends NativeNumber { return META;
}
+ @Override
public Object getValue() {
return new Long(longValue());
}
@@ -97,6 +98,7 @@ public class NativeLong extends NativeNumber { handle.setCLong(0, value);
}
+ @Override
public void setValue(Object value) {
setValue(((Number) value).longValue());
}
@@ -108,6 +110,9 @@ public class NativeLong extends NativeNumber { @Override
public String toString() {
+ if (getNativeHandle() == null) {
+ return "nope - no handle"; //$NON-NLS-1$
+ }
if (getNativeHandle().getAddress() == 0) {
return "nope - null pointer"; //$NON-NLS-1$
}
diff --git a/src/de/intarsys/nativec/type/NativeLongLP64.java b/src/de/intarsys/nativec/type/NativeLongLP64.java index 379f9cb..7a6770d 100644 --- a/src/de/intarsys/nativec/type/NativeLongLP64.java +++ b/src/de/intarsys/nativec/type/NativeLongLP64.java @@ -80,6 +80,7 @@ public class NativeLongLP64 extends NativeNumber { return META;
}
+ @Override
public Object getValue() {
return new Long(longValue());
}
@@ -105,6 +106,7 @@ public class NativeLongLP64 extends NativeNumber { handle.setLong(0, value);
}
+ @Override
public void setValue(Object value) {
setValue(((Number) value).longValue());
}
@@ -116,6 +118,9 @@ public class NativeLongLP64 extends NativeNumber { @Override
public String toString() {
+ if (getNativeHandle() == null) {
+ return "nope - no handle"; //$NON-NLS-1$
+ }
if (getNativeHandle().getAddress() == 0) {
return "nope - null pointer"; //$NON-NLS-1$
}
diff --git a/src/de/intarsys/nativec/type/NativeLongLP64Type.java b/src/de/intarsys/nativec/type/NativeLongLP64Type.java index 5c8ad31..8be71c3 100644 --- a/src/de/intarsys/nativec/type/NativeLongLP64Type.java +++ b/src/de/intarsys/nativec/type/NativeLongLP64Type.java @@ -47,6 +47,17 @@ public class NativeLongLP64Type extends NativeNumberType { return value.longValue();
}
+ /**
+ * Utility method: return the java class whose instances have compatible
+ * byte size
+ */
+ public static Class<? extends Number> primitiveClass() {
+ if (NativeObject.SIZE_PTR == 4) {
+ return Integer.class;
+ }
+ return Long.class;
+ }
+
protected NativeLongLP64Type() {
super();
}
diff --git a/src/de/intarsys/nativec/type/NativeObject.java b/src/de/intarsys/nativec/type/NativeObject.java index 21b85b3..e6b54f3 100644 --- a/src/de/intarsys/nativec/type/NativeObject.java +++ b/src/de/intarsys/nativec/type/NativeObject.java @@ -129,7 +129,7 @@ public abstract class NativeObject implements INativeObject { }
/**
- * The byte at index as a native byte.
+ * The byte at index as a byte.
*
* @param index
* The index of the element to be reported.
@@ -140,8 +140,8 @@ public abstract class NativeObject implements INativeObject { }
/**
- * The element at index as an array of native byte with dimension count.
- * This is a lightweight optimization.
+ * The element at index as an array of bytes with dimension count. This is a
+ * lightweight optimization.
*
* @param index
* The index of the element to be reported.
diff --git a/src/de/intarsys/nativec/type/NativeReference.java b/src/de/intarsys/nativec/type/NativeReference.java index a139d8c..6de74ce 100644 --- a/src/de/intarsys/nativec/type/NativeReference.java +++ b/src/de/intarsys/nativec/type/NativeReference.java @@ -35,7 +35,7 @@ import de.intarsys.nativec.api.NativeInterface; /**
* An object representing a reference to another object ("pointer").
*/
-public class NativeReference extends NativeObject {
+public class NativeReference<T extends INativeObject> extends NativeObject {
/** The meta class instance */
public static final NativeReferenceType META = new NativeReferenceType(
@@ -45,14 +45,15 @@ public class NativeReference extends NativeObject { NativeType.register(NativeReference.class, META);
}
- public static NativeReference create(INativeType baseType) {
+ public static <U extends INativeObject> NativeReference<U> create(
+ INativeType baseType) {
NativeReferenceType type = new NativeReferenceType(baseType);
- return new NativeReference(type);
+ return new NativeReference<U>(type);
}
private INativeHandle dereferenceHandle;
- private INativeObject dereferenced;
+ private T dereferenced;
private NativeReferenceType type;
@@ -81,12 +82,16 @@ public class NativeReference extends NativeObject { return type;
}
- synchronized public Object getValue() {
+ public long getReferencedAddress() {
+ return getNativeHandle(0).getAddress();
+ }
+
+ synchronized public T getValue() {
dereferenceHandle = handle.getNativeHandle(0);
// check if not yet computed or handle changed
if (dereferenced == null
|| !dereferenced.getNativeHandle().equals(dereferenceHandle)) {
- dereferenced = type.getBaseType().createNative(
+ dereferenced = (T) type.getBaseType().createNative(
dereferenceHandle);
}
return dereferenced;
@@ -100,11 +105,11 @@ public class NativeReference extends NativeObject { synchronized public void setValue(Object value) {
if (value instanceof INativeObject) {
- INativeHandle valueHandle = ((INativeObject) value)
- .getNativeHandle();
+ T nativeObject = (T) value;
+ INativeHandle valueHandle = nativeObject.getNativeHandle();
handle.setNativeHandle(0, valueHandle);
dereferenceHandle = valueHandle;
- dereferenced = ((INativeObject) value);
+ dereferenced = nativeObject;
} else if (value instanceof INativeHandle) {
INativeHandle valueHandle = (INativeHandle) value;
handle.setNativeHandle(0, valueHandle);
@@ -115,4 +120,12 @@ public class NativeReference extends NativeObject { }
}
+ @Override
+ public String toString() {
+ if (handle == null) {
+ return "Ref to null";
+ }
+ return "Ref to " + getReferencedAddress();
+ }
+
}
diff --git a/src/de/intarsys/nativec/type/NativeShort.java b/src/de/intarsys/nativec/type/NativeShort.java index 07da63f..de4fff7 100644 --- a/src/de/intarsys/nativec/type/NativeShort.java +++ b/src/de/intarsys/nativec/type/NativeShort.java @@ -69,40 +69,21 @@ public class NativeShort extends NativeNumber { setValue(value);
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativeNumber#byteValue()
- */
@Override
public byte byteValue() {
return (byte) shortValue();
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
- */
@Override
public INativeType getNativeType() {
return META;
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativePrimitive#getValue()
- */
+ @Override
public Object getValue() {
return new Short(shortValue());
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativeNumber#intValue()
- */
@Override
public int intValue() {
return shortValue();
@@ -113,6 +94,7 @@ public class NativeShort extends NativeNumber { return shortValue();
}
+ @Override
public void setValue(Object value) {
setValue(((Number) value).shortValue());
}
@@ -121,23 +103,16 @@ public class NativeShort extends NativeNumber { handle.setShort(0, value);
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativeNumber#shortValue()
- */
@Override
public short shortValue() {
return handle.getShort(0);
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
@Override
public String toString() {
+ if (getNativeHandle() == null) {
+ return "nope - no handle"; //$NON-NLS-1$
+ }
if (getNativeHandle().getAddress() == 0) {
return "nope - null pointer"; //$NON-NLS-1$
}
diff --git a/src/de/intarsys/nativec/type/NativeStructType.java b/src/de/intarsys/nativec/type/NativeStructType.java index 58f0f38..0019e73 100644 --- a/src/de/intarsys/nativec/type/NativeStructType.java +++ b/src/de/intarsys/nativec/type/NativeStructType.java @@ -72,7 +72,7 @@ public class NativeStructType extends NativeType { super();
}
- protected NativeStructType(Class<?> instanceClass) {
+ protected NativeStructType(Class<? extends NativeStruct> instanceClass) {
super(instanceClass);
}
@@ -146,10 +146,11 @@ public class NativeStructType extends NativeType { return packing;
}
+ @Override
public int getPreferredBoundary() {
return getByteBoundary();
}
-
+
public void setPacking(int pPacking) {
if (!fields.isEmpty()) {
throw new IllegalStateException(
diff --git a/src/de/intarsys/nativec/type/NativeVoid.java b/src/de/intarsys/nativec/type/NativeVoid.java index 26da8d3..b051ad1 100644 --- a/src/de/intarsys/nativec/type/NativeVoid.java +++ b/src/de/intarsys/nativec/type/NativeVoid.java @@ -34,7 +34,8 @@ import de.intarsys.nativec.api.NativeInterface; import de.intarsys.nativec.api.NativeTools;
/**
- * An object representing "void" (nothing)
+ * An object representing "void" ("nothing" or rather nothing we can specify
+ * more explicitly). Mostly (only?) useful with references.
*/
public class NativeVoid extends NativeSimple {
@@ -53,36 +54,23 @@ public class NativeVoid extends NativeSimple { .toHandle(address));
}
- /**
- * Create a new wrapper instance
- */
- public NativeVoid() {
- allocate();
- }
-
protected NativeVoid(INativeHandle handle) {
super(handle);
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
- */
@Override
public INativeType getNativeType() {
return META;
}
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativePrimitive#getValue()
- */
+ @Override
public Object getValue() {
- return null;
+ throw new UnsupportedOperationException();
}
+ @Override
public void setValue(Object value) {
+ throw new UnsupportedOperationException();
}
+
}
diff --git a/src/de/intarsys/nativec/type/NativeVoidType.java b/src/de/intarsys/nativec/type/NativeVoidType.java index f585a9c..6432d58 100644 --- a/src/de/intarsys/nativec/type/NativeVoidType.java +++ b/src/de/intarsys/nativec/type/NativeVoidType.java @@ -47,11 +47,12 @@ public class NativeVoidType extends NativeSimpleType { @Override
public INativeObject createNative(Object value) {
- return new NativeVoid();
+ throw new UnsupportedOperationException();
}
@Override
public int getByteCount() {
return 0;
}
+
}
\ No newline at end of file diff --git a/src/de/intarsys/nativec/type/NativeWideStringType.java b/src/de/intarsys/nativec/type/NativeWideStringType.java index 9c4f1bd..3dd880c 100644 --- a/src/de/intarsys/nativec/type/NativeWideStringType.java +++ b/src/de/intarsys/nativec/type/NativeWideStringType.java @@ -29,6 +29,7 @@ */
package de.intarsys.nativec.type;
+import de.intarsys.nativec.api.CWideString;
import de.intarsys.nativec.api.INativeHandle;
/**
@@ -36,6 +37,13 @@ import de.intarsys.nativec.api.INativeHandle; */
public class NativeWideStringType extends NativeAbstractStringType {
+ public static CWideString convert(String string) {
+ if (string == null) {
+ return null;
+ }
+ return new CWideString(string);
+ }
+
public static NativeWideStringType create(int size) {
return new NativeWideStringType(size);
}
diff --git a/src/de/intarsys/nativec/type/StructMember.java b/src/de/intarsys/nativec/type/StructMember.java index da450f8..01e5a6b 100644 --- a/src/de/intarsys/nativec/type/StructMember.java +++ b/src/de/intarsys/nativec/type/StructMember.java @@ -71,7 +71,7 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
+ * @return The byte at index within the memory range of struct
*/
public byte getByte(NativeStruct struct, int index) {
return struct.handle.getByte(offset + index);
@@ -84,7 +84,8 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
+ * @return The byte array starting at index of length count within the
+ * memory range of struct
*/
public byte[] getByteArray(NativeStruct struct, int index, int count) {
return struct.handle.getByteArray(offset + index, count);
@@ -98,7 +99,8 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
+ * @return The platform sized long at index within the memory range of
+ * struct
*/
public long getCLong(NativeStruct struct, int index) {
return struct.handle.getCLong(offset + index);
@@ -111,7 +113,7 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
+ * @return The int at index within the memory range of struct
*/
public int getInt(NativeStruct struct, int index) {
return struct.handle.getInt(offset + index);
@@ -124,7 +126,7 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
+ * @return The long at index within the memory range of struct
*/
public long getLong(NativeStruct struct, int index) {
return struct.handle.getLong(offset + index);
@@ -155,7 +157,7 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
+ * @return The INativeHandle at index within the memory range of struct
*/
public INativeHandle getNativeHandle(NativeStruct struct, int index) {
return struct.handle.getNativeHandle(offset + index);
@@ -190,7 +192,7 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
+ * @return The short at index within the memory range of struct
*/
public short getShort(NativeStruct struct, int index) {
return struct.handle.getShort(offset + index);
@@ -203,7 +205,7 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
+ * @return The String at index within the memory range of struct
*/
public String getString(NativeStruct struct, int index) {
return struct.handle.getString(offset + index);
@@ -221,7 +223,8 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
+ * @return The wide character String at index within the memory range of
+ * struct
*/
public String getWideString(NativeStruct struct, int index) {
return struct.handle.getWideString(offset + index);
@@ -234,7 +237,6 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
*/
public void setByte(NativeStruct struct, int index, byte value) {
struct.handle.setByte(offset + index, value);
@@ -247,7 +249,6 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
*/
public void setByteArray(NativeStruct struct, int index, byte[] value,
int valueOffset, int valueCount) {
@@ -263,7 +264,6 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
*/
public void setCLong(NativeStruct struct, int index, long value) {
struct.handle.setCLong(offset + index, value);
@@ -276,7 +276,6 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
*/
public void setInt(NativeStruct struct, int index, int value) {
struct.handle.setInt(offset + index, value);
@@ -289,7 +288,6 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
*/
public void setLong(NativeStruct struct, int index, long value) {
struct.handle.setLong(offset + index, value);
@@ -302,7 +300,6 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
*/
public void setNativeHandle(NativeStruct struct, int index,
INativeHandle value) {
@@ -316,7 +313,6 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
*/
public void setShort(NativeStruct struct, int index, short value) {
struct.handle.setShort(offset + index, value);
@@ -329,7 +325,6 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
*/
public void setString(NativeStruct struct, int index, String value) {
struct.handle.setString(offset + index, value);
@@ -347,7 +342,6 @@ public class StructMember { * The container struct instance
* @param index
* The memory offset from the struct member base
- * @return
*/
public void setWideString(NativeStruct struct, int index, String value) {
struct.handle.setWideString(offset + index, value);
diff --git a/src/overview.html b/src/overview.html deleted file mode 100644 index 619b5c0..0000000 --- a/src/overview.html +++ /dev/null @@ -1,397 +0,0 @@ -<html>
-<body>
-
-This is a generic native code wrapper.
-
-<h2><a name="Content">Content</a></h2>
-<ol type="a" >
- <li><a href="#Overview">Overview</a></li>
- <li><a href="#Manual">Manual</a></li>
- <li><a href="#License">License</a></li>
- <li><a href="#Support">Service and support</a></li>
-</ol>
-<!-- ============== -->
-
-<hr></hr>
-
-<h2><a name="Overview">Overview</a></h2>
-
-This is "another" JNI wrapping library, but in some regards quite different.
-
-<p>
-The real memory / JNI access semantics is delegated to some concrete service implementation.
-Actually we dont'tprovide one of our own, the default implementation we use is JNA.
-
-<p>
-The real strength of this library is its high level model of JNI access, allowing more easy and
-understandable API's. We feel that at this point most of the candidates we reviewed
-are quite poor or hard to understand.
-
-<p>
-The design goals were as follows:
-
-<ul>
-<li>Provide access to all levels of a native interface. As we can not forsee what different libaries and
-systems will work together, access is provided from bottom up using the plain address as the least common
-denominator. </li>
-<li>Provide clean abstractions</li>
-<li>Differentiate between a "pointer" or "memory handle" and the data semantics. This allows to work
-as well using plain pointer arithmetics as object state access. </li>
-</ul>
-
-<p>
-The high level model provides the following abstractions:
-
-<ul>
-<li>Interface
-</li>
-The concrete implementation for accessing JNI. This interface is quite small and allows for
-the adaption of many JNI libraries out there. It should not be to hard to create one of your own.
-<li>Library
-</li>
-The loadable library providing state and behavior.
-<li>Function
-</li>
-The behavior part of the library, accepting parameters and return results.
-<li>Handle
-</li>
-An abstraction of a pointer, without any data specific features. This could be viewed
-as a plain wrapper around an address, another representation for "void *".
-<li>Object
-</li>
-The data referenced by a handle (or pointer). The object deals with the bytes referenced by the handle.
-
-The object defines the semantics of how to interpret the memory referenced by the handle.
-The handle defines "where" to find data, the object defines "what" data you will find there -
-it deals only with the "dereferenced" part of the handle.
-
-On the C side, the object is always represented by the handle / pointer. This means that an object
-is always used and forwarded by reference. Do not confuse this with the handling on primitive
-types. In this code snippet
-
-<pre>
-int a;
-NativeInt b = new NativeInt();
-...
-int result = function.invoke(Integer.class, a, b);
-...
-</pre>
-
-the function is called using the value of "a" and a pointer to "b".
-</li>
-
-</ul>
-
-<p>
-This library currently does not provide any convenience for some aspects of
-native calls, for example
-
-<ul>
-<li>primitive arrays</li>
-<li>float / double support</li>
-<li>String encodings</li>
-<li>callbacks</li>
-<li>maybe other features we didn't need until now and so are not aware of..</li>
-</ul>
-
-The underlying infrastructure (JNA) may handle such constructs, but as long as the
-semantics is not defined on this library level, you should expect unportable
-behavior.
-
-We propose, even if not convenient, to express all call semantics using documented
-features only. Feel free to ask for the inclusion of more library features.
-
-<h2><a name="Manual">Manual</a></h2>
-
-<h3>Common scenarios</h3>
-
-<h4>Call functions with primitive types</h4>
-
-The most simple calls use only primitive types. These are mapped by the "invoke" itself
-using builtin rules to target the C types.
-
-<p>
-The C part may look like this:
-
-<pre>
-int intValue;
-float floatValue;
-...
-int result = function(intValue, floatValue);
-...
-</pre>
-
-<p>
-An equivalent call from Java would look like:
-
-<pre>
-int intValue;
-float floatValue;
-...
-int result = function.invoke(Integer.class, intValue, floatValue);
-...
-...
-</pre>
-
-This seems straightforward....
-
-<h4>Call functions with String parameters</h4>
-
-The first problems are expected when dealing with strings or char* on the C side. But
-no problem here:
-
-<p>
-The C part may look like this:
-
-<pre>
-char* string = "test";
-...
-int result = function(string);
-...
-</pre>
-
-<p>
-An equivalent call from Java would look like:
-
-<pre>
-String string = "test";
-...
-int result = function.invoke(Integer.class, string);
-...
-</pre>
-
-String semantics are handled internally. Even the platform wide character features
-can be accessed quite easy - simply wrap the String in a "WideString" to indicate the
-special treatment on invocation marshalling.
-
-<pre>
-String string = "test";
-WideString wideString = new WideString(string);
-...
-int result = function.invoke(Integer.class, wideString);
-...
-</pre>
-
-In much the same way you can request a wide string conversion on the result.
-
-<pre>
-...
-WideString result = function.invoke(WideString.class);
-String string = result.toString();
-...
-</pre>
-
-<h4>Call with parameters "by reference" (out parameters)</h4>
-
-Other functions return values via "out" parameters, via references to C memory.
-
-<p>
-The C part may look like this:
-
-<pre>
-int value;
-
-...
-int result = function(&value);
-if (value == 42) {
- ...
-}
-...
-</pre>
-
-<p>
-An equivalent call from Java would look like:
-
-<pre>
-NativeInt value = new NativeInt();
-
-int result = function.invoke(Integer.class, value);
-if (value.intValue() == 42) {
- ...
-}
-...
-</pre>
-
-The NativeObject is allocated in C memory and forwarded "by reference".
-
-This call pattern stays the same regardless of the complexity of the NativeObject - so this is
-the call for your Java side definition of the C struct:
-
-<pre>
-// allocates memory for the struct in C
-MyStruct value = new MyStruct();
-
-// call function with a pointer to the new struct
-int result = function.invoke(Integer.class, value);
-...
-</pre>
-
-<h4>Wrapping pointers returned from out parameters</h4>
-
-With C you find quite often a pointer to a newly create memory chunk returned via
-an out parameter.
-
-<pre>
-my_struct *value;
-...
-function(&value);
-int a = value->a;
-...
-</pre>
-
-This is one of the rare occasions you will deal with the "NativeReference" directly.
-If we follow exactly the pattern we have used so far we get:
-
-<pre>
-// allocate memory for holding a pointer to a struct
-NativeReference ptrValue = new NativeReference(MyStruct.META);
-// call the function with the pointer to the pointer
-int result = function.invoke(Integer.class, ptrValue);
-// dereference the result...
-MyStruct value = (MyStruct)ptrValue.getValue();
-</pre>
-
-Here's a common pattern to manage "transparent" handles that do not designate data
-structures you should deal with - for sure you can declare a NativeVoid subclass
-of you own for better readability or to add methods.
-
-<pre>
-// allocate memory for holding a void pointer
-NativeReference ptrValue = new NativeReference(NativeVoid.META);
-// call the function with the pointer to the pointer
-int result = function.invoke(Integer.class, value);
-// dereference the result...
-NativeVoid value = (NativeVoid)ptrValue.getValue();
-</pre>
-
-<h4>Wrapping a pointer returned as function result</h4>
-
-Many functions return handles to newly created objects. Wrapping this result to the
-INativeObject framework is simply a matter of declaration:
-
-<pre>
-NativeVoid result = function.invoke(NativeVoid.class, ...);
-</pre>
-
-You have just wrapped a "void *" (void pointer)! Notice how you "hide" the C reference or pointer
-semantics. The less you think about it, the more it is intuitive :-). Using this code
-will return "null" in case of a "0" address.
-
-<p>
-NativeVoid is a "stateless" object, declaring to be of size "0". This is often the case with transparent handles
-to some proprietary / private information. Only the handle itself is used to manipulate state via the associated
-library functions.
-
-<p>
-In much the same way you can create a NativeStruct instances, holding public state information
-and allowing easy access to it.
-
-<p>
-Assume you have defined a NativeStruct subclass "MyStruct" of any memory layout. The above
-code sequence changes to
-
-<pre>
-MyStruct structObj = function.invoke(MyStruct.class, ...);
-</pre>
-
-Behind this code is a simple two step process. You can do it manually if the default is
-not exactly what you want, for example in some cases where an address of "-1" means failure.
-
-<ul>
-<li>Create the INativeHandle wrapper. This object represents a memory address and implements
-some access primitives</li>
-<li>Use the INativeHandle to build the INativeObject wrapper that is situated at this memory location.
-This can be any of the INativeObject subclasses, such as a primitive, composite or even void representation.</li>
-</ul>
-
-<pre>
-int address = function.invoke(Integer.class, ...);
-if (address == 0) {
- return null;
-}
-INativeHandle handle = NativeInterface.get().createHandle(address);
-return NativeVoid.META.createNative(handle);
-</pre>
-
-<p>
-The pointer, represented by the INativeHandle is wrapped by a NativeObject which is
-what is referenced by the pointer.
-
-<h4>Primitive arrays and buffers</h4>
-
-You can call a native function using primitive arrays the same way as using plain primitives.
-The basic marshalling will map the values in both direction, so you see C side changes in the
-Java array directly.
-
-Conceptually you should treat such a call as follows:
-The memory is managed by the library. Upon entry, memory is allocated in C address space, the data is copied.
-The C function is called with the pointer to the newly allocated memory. After
-termination of the function, memory is copied back to Java address space, and the
-newly allocated memory is discarded. Access to the memory in C address space is no longer valid!
-
-So, if you want to provide a buffer to C for use even outside the function call this
-is not the correct way! You must use NativeObject instances, for example NativeBuffer,
-to force C memory allocation resident in memory (controlled by your application).
-
-To optimize the marshalling between Java and C you may use direct "ByteBuffer" objects. Using
-this objects marshalling MAY be optimized by the underlying implementation to share memory
-between Java and C.
-
-In any case you may use a NativeBuffer and access the memory allocated in heap space from both
-sides. NativeBuffer can be seen as an explicit equivalent to a DirectBuffer.
-
-<h2><a name="License">License</a></h2>
-
-<pre>
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-</pre>
-
-<h2><a name="Service & Support">Service & Support</a></h2>
-
-If you need further support, feel free to contact us.
-
-intarsys consulting GmbH<br>
-Bahnhofplatz 8<br>
-76137 Karlsruhe<br>
-Fon +49 721 38479-0<br>
-Fax +49 721 38479-60<br>
-info@intarsys.de<br>
-www.intarsys.de<br>
-
-<p>For service and support contact</p>
-
-<ol>
- <li>EMail support: <a href="mailto://support@intarsys.de">support@intarsys.de</a></li>
-</ol>
-
-
-</body>
-</html>
\ No newline at end of file |
